probability

Netlogo: Assign variable using probabilities

左心房为你撑大大i 提交于 2019-11-30 07:30:45
问题 How to assign a string or integer variable to turtle, using probabilities of the variables in a group/list? For example it is 0.4 probability that one specific variable is used from specific group/list. The function selects randomly the variable based on probability. I need to use the same method afterwards to choose a variable (string) from a list according to probability. In python it should be: import random def random_value(probability_list, values): r = random.random() index = 0 while(r

How to generate a random number from specified discrete distribution?

删除回忆录丶 提交于 2019-11-30 07:15:06
问题 Lets say we have some discrete distribution with finite number of possible results, is it possible to generate a random number from this distribution faster than in O(logn), where n is number possible results? How to make it in O(logn): - Make an array with cumulative probability (Array[i] = Probability that random number will be less or equal to i) - Generate random number from uniform distribution (lets denote it by k) - Find the smallest i such that k < Array[i]. It can be done using

Effective Java Item 47: Know and use your libraries - Flawed random integer method example

不想你离开。 提交于 2019-11-30 06:37:38
In the example Josh gives of the flawed random method that generates a positive random number with a given upper bound n , I don't understand the two of the flaws he states. The method from the book is: private static final Random rnd = new Random(); //Common but deeply flawed static int random(int n) { return Math.abs(rnd.nextInt()) % n; } He says that if n is a small power of 2, the sequence of random numbers that are generated will repeat itself after a short period of time. Why is this the case? The documentation for Random.nextInt() says Returns the next pseudorandom, uniformly

Random numbers with different probabilities [duplicate]

夙愿已清 提交于 2019-11-30 05:25:31
Possible Duplicate: C++ function for picking from a list where each element has a distinct probability I need to randomly determine a yes or no outcome (kind of a coin flip) based on a probability that I can define (.25, .50, .75). So for example, I want to randomly determine yes or no where yes has a 75% chance of being chosen. What are my options for this? Is there a C++ library I can use for this? You can easily implement this using the rand function: bool TrueFalse = (rand() % 100) < 75; The rand() % 100 will give you a random number between 0 and 100, and the probability of it being under

How to calculate conditional probability of values in dataframe pandas-python?

…衆ロ難τιáo~ 提交于 2019-11-30 05:23:51
I want to calculate conditional probabilites of ratings('A','B','C') in ratings column. company model rating type 0 ford mustang A coupe 1 chevy camaro B coupe 2 ford fiesta C sedan 3 ford focus A sedan 4 ford taurus B sedan 5 toyota camry B sedan Output: Prob(rating=A) = 0.333333 Prob(rating=B) = 0.500000 Prob(rating=C) = 0.166667 Prob(type=coupe|rating=A) = 0.500000 Prob(type=sedan|rating=A) = 0.500000 Prob(type=coupe|rating=B) = 0.333333 Prob(type=sedan|rating=B) = 0.666667 Prob(type=coupe|rating=C) = 0.000000 Prob(type=sedan|rating=C) = 1.000000 Any help, Thanks..!! You can use .groupby()

Constructing a multi-order Markov chain transition matrix in Matlab

纵然是瞬间 提交于 2019-11-30 02:25:35
A first-order transition matrix of 6 states can be constructed very elegantly as follows x = [1 6 1 6 4 4 4 3 1 2 2 3 4 5 4 5 2 6 2 6 2 6]; % the Markov chain tm = full(sparse(x(1:end-1),x(2:end),1)) % the transition matrix. So here is my problem, how do you construct a second-order transition matrix elegantly? The solution I came up with is as follows [si sj] = ndgrid(1:6); s2 = [si(:) sj(:)]; % combinations for 2 contiguous states tm2 = zeros([numel(si),6]); % initialize transition matrix for i = 3:numel(x) % construct transition matrix tm2(strmatch(num2str(x(i-2:i-1)),num2str(s2)),x(i))=...

Fast weighted random selection from very large set of values

橙三吉。 提交于 2019-11-30 02:00:35
I'm currently working on a problem that requires the random selection of an element from a set. Each of the elements has a weight(selection probability) associated with it. My problem is that for sets with a small number of elements say 5-10, the complexity (running time) of the solution I was is acceptable, however as the number of elements increases say for 1K or 10K etc, the running time becomes unacceptable. My current strategy is: Select random value X with range [0,1) Iterate elements summing their weights until the sum is greater than X The element which caused the sum to exceed X is

How much can you truncate a SHA1 hash and be reasonably sure of having an unique ID?

孤者浪人 提交于 2019-11-30 01:54:46
I am making an application that stores documents and gives each one a UID based on a SHA1 digest of a few things including the timestamp. The digest has a lot of characters, and I want to allow users to identify the documents by using the first x characters of the full digest. What's a good value for x if the number of documents is maybe around 10K - 100K? bdonlan Adapting the formulas on on wikipedia for the Birthday problem , you can approximate the probability of collision as e^(-n^2/(2^(b+1))) , where n is the document count and b is the number of bits. Graphing this formula with n=100,000

Minimizing NExpectation for a custom distribution in Mathematica

百般思念 提交于 2019-11-29 23:24:37
This relates to an earlier question from back in June: Calculating expectation for a custom distribution in Mathematica I have a custom mixed distribution defined using a second custom distribution following along the lines discussed by @Sasha in a number of answers over the past year. Code defining the distributions follows: nDist /: CharacteristicFunction[nDist[a_, b_, m_, s_], t_] := (a b E^(I m t - (s^2 t^2)/2))/((I a + t) (-I b + t)); nDist /: PDF[nDist[a_, b_, m_, s_], x_] := (1/(2*(a + b)))*a* b*(E^(a*(m + (a*s^2)/2 - x))* Erfc[(m + a*s^2 - x)/(Sqrt[2]*s)] + E^(b*(-m + (b*s^2)/2 + x))*

Game Design/theory, Loot Drop Chance/Spawn Rate

本小妞迷上赌 提交于 2019-11-29 21:36:57
I have a very specific and long-winded question for you all. This question is both about programming and game-theory. I recently added spawnable ore to my Turn Based Strategy Game: http://imgur.com/gallery/0F5D5Ij (For those of you that look please forgive the development textures). Now, onto the enigma that I have been contemplating. In my game, ore is generated each time a new map is created. 0-8 ore nodes are generated per level-creation. I already have this working; except it only generates "Emeraldite" at this point, which brings me to my question. How would I, the programmer, make it so