computation

Numpy: Masked elements in computation

江枫思渺然 提交于 2019-12-08 04:52:49
问题 I have a function to built a polynomial from a given x: [1, x^2,x^3,x^4,...,x^degree] def build_poly(x, degree): """polynomial basis functions for input data x, for j=0 up to j=degree.""" D = len(x) polyome = np.ones((D, 1)) for i in range(1, degree+1): polyome = np.c_[polyome, x**i] return polyome Now, I would like to calculate polynom for a given x, but omiting sume values. Hence, what this is what I did: Created X: x=np.array([[1,2,3],[4,5,6]])]) I masked away the value with I wanted to

How to make a computation loop easily splittable and resumable?

浪子不回头ぞ 提交于 2019-12-06 16:13:31
I want to find optimal parameters i, j, k in 0..99 for a given computational problem, and I need to run: for i in range(100): for j in range(100): for k in range(100): dothejob(i, j, k) # 1 second per computation This takes a total of 10^6 seconds, i.e. 11.5 days. I started doing it by splitting the work among 4 processes (to use 100% computing power of my 4-core CPU computer): for i in range(100): if i % 4 != 0: # replace != 0 by 1, 2, or 3 for the parallel scripts #2, #3, #4 continue for j in range(100): for k in range(100): dothejob(i, j, k) with open('done.log', 'a+') as f: # log what has

Evenly duplicate games to reach a maximum amount per participant

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-06 05:44:33
I have a round robin tournament where I create all the games necessary (7 games per participant) for 8 teams. I however need 10 games per participant which means I need to duplicate matchups, and on top of that 1 and 5 can't play each other. You can see from the data below the games I generated for each participant (# of games) in the order it was created which would be the round. I am trying to figure out the best possible way to duplicate the matchups and evently distribute the matchups in such a way that there aren't matchups that duplicate three times and still retain 10 games per

Can a Turing machine perform Quicksort?

…衆ロ難τιáo~ 提交于 2019-12-06 01:48:56
As far as I know, a Turing machine can be made to execute loops or iterations of instructions encoded on a Tape. This can be done by identifying Line separators and making the Turing machine go back until a specific count of Line separators is reached (that is, inside the loop). But, can a Turing machine also execute a recursive program? Can someone describe various details for such a Turing Machine? I suppose, if recursion can be executed by a Turing machine, the Quicksort can also be performed? If the question is if a Turing Machine can execute a sorting algorithm, the answer is yes, since

GCD algorithms for a large integers

跟風遠走 提交于 2019-12-04 13:56:05
I looking for the information about fast GCD computation algorithms. Especially, I would like to take a look at the realizations of that. The most interesting for me: - Lehmer GCD algorithm, - Accelerated GCD algorithm, - k-ary algorithm, - Knuth-Schonhage with FFT. I have completely NO information about the accelerated GCD algorithm, I just have seen a few articles where it was mentioned as the most effective and fast gcd computation method on the medium inputs (~1000 bits) They looks much difficult for me to understand from the theory view. Could anybody please share the code (preferable on

Java exception invalid int for long integer

大憨熊 提交于 2019-12-02 15:44:33
问题 I'm currently developing a math application that makes long computations. I'm getting java.lang.NumberFormatException: Invalid int: "..." error (where the ... is replaced by a very long number) whenever I type an integer that contains more than 9 digits. When I type in an integer that is less than or equal to 9 digits, the application runs fine. I need the output to be an int (i.e. no decimal places). Not quite sure why the error's occurring. The bit of code that's causing the problem is:

Java exception invalid int for long integer

删除回忆录丶 提交于 2019-12-02 11:13:00
I'm currently developing a math application that makes long computations. I'm getting java.lang.NumberFormatException: Invalid int: "..." error (where the ... is replaced by a very long number) whenever I type an integer that contains more than 9 digits. When I type in an integer that is less than or equal to 9 digits, the application runs fine. I need the output to be an int (i.e. no decimal places). Not quite sure why the error's occurring. The bit of code that's causing the problem is: Intent intent = getIntent(); String message = intent.getStringExtra(MainActivity.NUMBER); int inp =

How to calculate the mod of large exponents?

喜夏-厌秋 提交于 2019-12-02 08:53:04
问题 For example I want to calculate (reasonably efficiently) 2^1000003 mod 12321 And finally I want to do (2^1000003 - 3) mod 12321. Is there any feasible way to do this? 回答1: Basic modulo properties tell us that 1) a + b (mod n) is (a (mod n)) + (b (mod n)) (mod n) , so you can split the operation in two steps 2) a * b (mod n) is (a (mod n)) * (b (mod n)) (mod n) , so you can use modulo exponentiation (pseudocode): x = 1 for (10000003 times) { x = (x * 2) % 12321; # x will never grow beyond

How to calculate the mod of large exponents?

我与影子孤独终老i 提交于 2019-12-02 03:34:05
For example I want to calculate (reasonably efficiently) 2^1000003 mod 12321 And finally I want to do (2^1000003 - 3) mod 12321. Is there any feasible way to do this? Basic modulo properties tell us that 1) a + b (mod n) is (a (mod n)) + (b (mod n)) (mod n) , so you can split the operation in two steps 2) a * b (mod n) is (a (mod n)) * (b (mod n)) (mod n) , so you can use modulo exponentiation (pseudocode): x = 1 for (10000003 times) { x = (x * 2) % 12321; # x will never grow beyond 12320 } Of course, you shouldn't do 10000003 iterations, just remember that 2 1000003 = 2 * 2 1000002 , and 2

Calculating big float number fast like 0.4 ^ 100000000 ,, any ideas?

大城市里の小女人 提交于 2019-12-01 08:19:10
问题 Ehm ... I got a problem I've a certain calculation that result is over 10^-308 (the biggest value in double .net ) any way I solved this problem through a library called BIGFLOAT http://www.fractal-landscapes.co.uk/bigint.html , What ever I need to calculate something like 0.4 ^(1000 or 100000000) the problem it takes very very long time I didn't study parallel or distributed programming yet but I need a solution that is fast and understandable for me I'm going to deliver this project in next