Computing with random generators (MATLAB)

In summary, x=randn(5000); y=5*randn(5000); the 5*randn line takes ~30% longer to compute on my machine.
  • #1
Pythagorean
Gold Member
4,401
313
So I ran an ODE solver with an additional, random (using randn) injected input.

Then I took the same ODE solver and the same random line, and multiplied it by 5, so now I have (5*randn). The runtime is already ten times as long (and still not finished). Why does it take so much longer to compute larger random values?
 
Physics news on Phys.org
  • #2
Hmm, I checked this, the 5*randn line takes ~30% longer to compute on my machine.

tic
x=randn(5000);
toc
tic
y=5*randn(5000);
toc
 
  • #3
MRFMengineer said:
Hmm, I checked this, the 5*randn line takes ~30% longer to compute on my machine.

tic
x=randn(5000);
toc
tic
y=5*randn(5000);
toc

Hrm good thought, I didn't expect it to be that simple... I thought maybe because my equations were nonlinear and chaotic that I was causing weird bifurcations that lead to regimes that were more computationally intensive.

I do notice that computing a static regime (nothing changing) is a lot faster than computing a chaotic regime, even though I'm using the same system (the parameter values are what's different).

I will tic toc my program with and without randn and see if that accounts for the majority of it. I never had randn there at all before, so I'll have to see what the effect of the whole function is, not just the *5 increase. Really thought it would have something to do with the ODE solver.
 
  • #4
I'm curious about what equations you're using. By "input", ie. the thing you are varying with the random number generator, do you mean the initial conditions?

Any number produced by randn can also be produced by 5*randn since its a normal distribution, if it takes longer, it's probably because 5*randn is more likely to give a number of large magnitude which might happen to lead to a more computationally intensive region.

But I don't think there can be any sort of coupling between the random number generator and the chaotic equation. You're simply changing the likely range of initial conditions which changes the likely computation time of the solver.5*randn takes 38% longer on my machine too.
 
  • #5
MikeyW said:
I'm curious about what equations you're using.

a network of electrophysiological neurons. So one neuron is 2-D, but once you couple N neurons together, you have a 2*N-D system (generally on the order of hundreds to thousands of dimensions in my case)

Specifically:

http://en.wikipedia.org/wiki/Morris–Lecar_model

By "input", ie. the thing you are varying with the random number generator, do you mean the initial conditions?

It's actually a parameter (the injected current, I, in the model above).

Any number produced by randn can also be produced by 5*randn since its a normal distribution, if it takes longer, it's probably because 5*randn is more likely to give a number of large magnitude which might happen to lead to a more computationally intensive region.

That's what my intuition was.

But I don't think there can be any sort of coupling between the random number generator and the chaotic equation. You're simply changing the likely range of initial conditions which changes the likely computation time of the solver.

Not changing the initial conditions, changing the current injected at every time step for every neuron in the system.

5*randn takes 38% longer on my machine too.

Unfortunately, in my case, going from 1*randn to 5*randn more than double my time. I can't even quantify it (besides >200%) since I wasn't patient enough for it.

Next time I play with it, I'll do some more investigating and report back if I figure it out.
 

What is a random generator in MATLAB?

A random generator in MATLAB is a function that produces a sequence of random numbers based on a specific algorithm. These numbers are usually used for simulations, statistical analysis, and other applications that require randomness.

How do I use a random generator in MATLAB?

To use a random generator in MATLAB, you can use the built-in functions such as rand, randi, or randn. These functions take in parameters such as the size of the output and the range of numbers to generate.

Can I customize the random generator in MATLAB?

Yes, you can customize the random generator in MATLAB by setting the seed value, which determines the starting point for the sequence of random numbers. You can also use different probability distributions, such as uniform, normal, or exponential, to generate numbers with specific characteristics.

What are the advantages of using random generators in MATLAB?

Random generators in MATLAB are useful for creating data sets for simulations and statistical analysis. They can also be used for testing and debugging code, as well as generating random inputs for algorithms.

Are there any limitations to using random generators in MATLAB?

One limitation of using random generators in MATLAB is that the generated numbers are not truly random, but rather pseudo-random, meaning they are determined by a specific algorithm. This can lead to biased results if not used properly. Additionally, if the seed value is not set, the same sequence of numbers will be generated each time, which may not be ideal for some applications.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
746
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
2K
Replies
6
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • Set Theory, Logic, Probability, Statistics
Replies
5
Views
1K
Back
Top