Does anyone know how to generate a random number in vdm++? The math library doesn't work for me.
You should be able to use the random generator in VDM (Both in VDMTools and Overture).
In Overture the argument must be larger than 0 and the seed must be set, which it is by default. Remember to include the standard MATH lib by selecting the project in the explorer and New->Add VDM Library and selecting MATH.
It can be called like this: MATH.rand(100) which will return a number between 0 and 100.
The seed can be changed through MATH.srand(5) it returns the seed set.
Related
I have a parameter that says default value 120 in the main that is linked to the initial number of agents for a particular agent. Now if I wanted that parameter to provide random numbers between 115 to 125 I tried using some distribution but it didn't work.
The error shown in the screenshot refers to type mismatch. triangular() returns a double but the parameter is of type int. This particular error can be fixed by changing the code to (int)triangular(2,5).
Admittingly, it would be good to understand what the purpose of this is in order to provide a more useful method as this approach will generate a sample value between 2 and 5 only at model start.
I want to generate random numbers within an activation function such that every time the activation function is called a random number is generated. I tried with random.uniform and with tf.random_uniform but it only generates a single random value when it's compiled and it doesn't change anymore. How can I make it update every time?
Funny fact:
When I create a variable using tf.Variable(random.uniform(1,2)) every time the function it's called the value is slightly larger, for instance:
1.22069513798
1.22072458267
1.22075247765
1.22077202797
Edit:
The function is very simple
Function:
def activation(tensor):
alpha = tf.Variable(random.uniform(1,2))
return alpha*tensor,alpha
I will omit all the lines in the neural network, but I simply call it as:
act,alpha = activation(dense_layer+bias)
I later get the value by simply:
[ts,c,alph]=sess.run([train_step,cost,alpha], feed_dict={xi: x_raw, yi: y_raw})
Thanks
Hard to tell without source code, but maybe you are initializing your variable with that random value and reusing same value?
Another possibility:
How can I have different parameters value defined in .ini file for each repeat in omnet using cmdenv? I have repeat value as 4 and trying to have different value of accidentStart and accidentDuration.
You can't. And shouldn't. The whole point of repetition is that all parameters have the same value, just the RNGs are seeded differently. So you get a different sample of the same distribution for every result value.
What you're looking for are iteration variables.
Something like this:
**.accidentStart = ${100, 200, 350}s
This will generate 3 runs without repetition, and 12 runs with repeat=4.
and if you add
**.accidentDuration = ${duration=300, 450, 600..1800 step 600}s
this will multiply the number of runs by another factor of 5.
By default, iteration variables produce a Cartesian product of their respective assigned sets of values. But there are ways to change this, consult the manual for how.
When I assign the result of a intuniform(a,b) function call to a number, it always results in the same value. For example:
val = intuniform(0,100);
val is always 44 for every run.
How can I manage that?
Generating the same values by OMNeT++ RNG is intentional behaviour. In order to manage generated sequence one can change seed or just add a repetition in omnetpp.ini.
I'm using healpy.synfast to create maps, but it seems that healpy does not have the "iseed" function (as in here: http://healpix.jpl.nasa.gov/html/facilitiesnode14.htm) which let me define the random seed to be used for the generation of alms from the power spectrum.
Could anyone tell me how to achieve the "iseed" function in healpy? Thanks!
healpy internally uses np.random.standard_normal to generate the real and imaginary components of the alms, see sphtfunc.py.
Therefore you can use the numpy.random.seed function to set the seed, as:
numpy.random.seed(1234)
before running synfast.