I want to select a random number from [0,1,2,3] in a probability of [0.1, 0.2, 0.3, 0.4] in anylogic. This can be easily done in Python by using numpy.random.choice. However, I couldn't find someway to do this in anylogic. I don't want to use the customized distribution since I want to apply it to many agents in different parameters.
I am looking for someway to do this in anylogic.
you can do this with customDistributions
YOu can just get the value by calling customDistribution()
If you want to do it in a more flexible way:
Create a variable called cd in your agent of type CustomDistribution and then you can do something like this:
int[]x={0,1,2,3,4};//you need an extra number to complete the interval
double[]y={0.1,0.2,0.3,0.4,0};//extra number has probability 0
cd=new CustomDistribution(x,y,new Random());
to get the random value you do
roundToInt(cd.get(new Random()));
Related
I used the p5 editor to build an nft, and I'm working on getting it working in the fxhash sandbox. Using p5's random() function worked great when I uploaded my project to the sandbox, but quickly realized I needed to implement the fxrand() function to ensure that each individual iteration is the same when refreshing with the same hash.
Simply replacing all instances of the p5 random() function with fxrand() did not work, and I'm assuming because fxrand() simply generates a random number, whereas p5's random() function can be used in other ways (ie; random(-50, 50)).
How do I need to incorporate the fxrand() function into my project in a way that still works the same way as p5's random() function?
You may have already figured this out, and there's probably far better solutions (I'm very new to this), but here is what I figured out.
If I need a number from 0 to 9 then I can use this:
let randChoose1 = Math.floor(fxrand() * 10;
Anywhere I need to call that number I can simply use randChoose1 in place. For example, if I have an array named "bg" with 10 entries in the array, and I want to choose something from the array I can do this:
let randoBg = bg[randChoose1];
Maybe that's an image that I want to center on the canvas, I can call it with:
image(randoBg, width / 2, height / 2);
If I have 23 items in the array then I just need to declare randChoose1 with:
let randChoose1 = Math.floor(fxrand() * 23);
If you want to be able to have negative numbers be chosen, such as your example of a range from -50 to 50, it's just a matter of multiplying by rough total range you want and then subtracting half that.
let randChoose1 = Math.floor(fxrand() * 101 - 50;
In this case, randChoose1 will give you that range of results from -50 to 50. You have to multiply by 101 in order to make it possible for Math.floor to deliver 100 since it always rounds down.
If you found a better solution I'd love to hear it! This is something I'm struggling with as well, and my total experience with p5.js is less than a week at this point.
If you use randomSeed(int(fxrand()*987654321)) at the beginning of the setup function every time you call to the random function it will depend on fxrand
I transformed my stat data with logarithm, square root,... but my dependent variable doesn't achieve normality distribution yet.
Then, I know that the Box-Cox transformation permit us to find out the best transformation approach in order to achieve normality distribution and therefore apply parametric test such as ANOVA.
Can anybody help me in how I can perform this Box-Cox transformation in SPSS software? It is possible to apply through its syntax?
There is a Box Cox transformation syntax on Raynald's SPSS tools website. The data are just to give an example.
I added some simple syntax to easily see the results.
* Box-Cox transformation for all 31 values of lambda between -2 to 1
(increments of .1).
* Raynald Levesque 2003/11/08.
* http://www.spsstools.net/en/syntax/syntax-index/compute/box-cox-transformation/
GET FILE="C:\{SPSS user folder}\Employee data.sav".
COMPUTE var1=salary./* salary is a skewed test variable.
VECTOR lam(31) /xl(31).
LOOP idx=1 TO 31.
COMPUTE lam(idx)=-2.1 + idx * .1.
DO IF lam(idx)=0.
COMPUTE xl(idx)=LN(var1).
ELSE.
COMPUTE xl(idx)=(var1**lam(idx) - 1)/lam(idx).
END IF.
END LOOP.
* visual examination of results.
EXAMINE
VARIABLES= salary xl1 to xl31
/PLOT=NPPLOT
/stat descrip.
* numerical examination of results.
FREQUENCIES
/VARIABLES= salary, xl1 to xl31
/FORMAT= NOTABLE
/STATISTICS=SKEWNESS KURTOSIS.
The numerical examination works best after having copied the results in a spreadsheet.
This worked for me: "Go to Transform – Prepare Data for Modelling Automatic from the drop down list. In the Fields tab you can specify which variables to transform by moving them to the Inputs box. In the Settings tab click on Rescale Fields. Tick the box before ‘Rescale a continuous target with a Box-Cox transformation to reduce skew’. Click Run. This will create a new column with the transformed variable."
From: https://www.researchgate.net/post/How_can_I_do_Box-Cox_transformations_in_SPSS
You might want to double check with another source.
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.
I'd like to calculate the standard deviation over two fields from the same dataset.
example:
MyFields1 = 10, 10
MyFields2 = 20
What I want now, is the standard deviation for (10,10,20), the expected result is 4.7
In SSRS I'd like to have something like this:
=StDevP(Fields!MyField1.Value + Fields!MyField2.Value)
Unfortunately this isn't possible, since (Fields!MyField1.Value + Fields!MyField2.Value) returns a single value and not a list of values. Is there no way to combine two fields from the same dataset into some kind of temporary dataset?
The only solutions I have are:
To create a new Dataset that contains all values from both fields. But this is very annoying because I need about twenty of those and I have six report parameters that need to filter every query. => It's probably getting very slow and annoying to maintain.
Write the formula by hand. But I don't really know how yet. StDevP is not that trivial to me. This is how I did it with Avg which is mathematically simpler:
=(SUM(Fields!MyField1.Value)+SUM(Fields!MyField2.Value))/2
found here: http://social.msdn.microsoft.com/Forums/is/sqlreportingservices/thread/7ff43716-2529-4240-a84d-42ada929020e
Btw. I know that it's odd to make such a calculation, but this is what my customer wants and I have to deliver somehow.
Thanks for any help.
CTDevP is standard deviation.
Such expression works fine for me
=StDevP(Fields!MyField1.Value + Fields!MyField2.Value) but it's deviation from one value (Fields!MyField1.Value + Fields!MyField2.Value) which is always 0.
you can look here for formula:
standard deviation (wiki)
I believe that you need to calculate this for some group (or full dataset), to do this you need set in the CTDevP your scope:
=StDevP(Fields!MyField1.Value + Fields!MyField2.Value, "MyDataSet1")
I just meet a problem. I use redis to store the geo information. for
example:
hset 10001 la 41.000333
hset 10001 lo 121.999999
or
zadd la 41.xxxxx pk-value
zadd lo 121.xxxxx pk-value
about 40000 key-values
the key is for the terminal id, and value is set, storing the termianl
gps info.
I have a requirement to computing the around terminal.
for example, my location is 41.000123, 121.999988, and I want to the
fastest compute the terminal around my location, I have idea how to
compute the two location's distance.
All I want is to think a way to fast iterate all data. In Redis 2.6 there is lua support. Can it help to resolve my problem?
You probably want to use geohashes, then you will be able to store (and search by) lon/lat with any precision you want, also it's relatively easy to get points which are in given bounding box.
For implementation with redis, have a look at geodis.
As I understand your question, you want to find all values close to some coordinates? One way would be to use Lua scripting, another would be to store one sorted set for each approximate latitude/longitude (if you know in advance which granularity you require). Example:
zadd la.41 41.000333 pk-value
zadd lo.121 121.999999 pk-value
Then, when you need to find something close to some coords (let's say (42.01, 122.03)), you would do something like:
lat = 42.01
lon = 122.03
lat_min, lat_mid, lat_max = round(lat - 1), round(lat), round(lat + 1)
lon_min, lon_mid, lon_max = round(lon - 1), round(lon), round(lon + 1)
Thus, you would look in the sorted sets la.41, la.42, la.43, lo.121, lo.122, lo.123:
zinterstore close.${lat},${lon} 6 la.${lat_min}, la.${lat_mid}, la.${lat_max}, lo.${lon_min}, lo.${lon_mid}, lo.${lon_max}
Now, close.${lat},${lon} should contain the id of every terminal close to the supplied coordinates.
Obviously, you could store each coordinate with greater granularity, like la.41.0, lo.121.0 and look only for terminals that close. Optionally, you could further filter the result in your client code.