probability

IGRAPH IN R: Find the path between vertices that maximizes the product of edge attributes

蹲街弑〆低调 提交于 2020-06-16 05:33:32
问题 I need to find a way to find the path between two vertices that maximizes the product of edge attributes. In my case the edge attribute is a probability of connection. Let's assume I want to find the maximum probability path between the vertex 1 and 4 in the following example: require(igraph) G<-graph.data.frame(as.data.frame(cbind(id1=c(1,1,2,3,1,4),id2=c(2,3,4,4,5,5),weight=c(0.5,0.35,0.5,0.9,0.6,0.6))), directed=FALSE) plot(G, edge.label=paste(E(G),"=",signif(E(G)$weight, digits=1)),

IGRAPH IN R: Find the path between vertices that maximizes the product of edge attributes

眉间皱痕 提交于 2020-06-16 05:32:32
问题 I need to find a way to find the path between two vertices that maximizes the product of edge attributes. In my case the edge attribute is a probability of connection. Let's assume I want to find the maximum probability path between the vertex 1 and 4 in the following example: require(igraph) G<-graph.data.frame(as.data.frame(cbind(id1=c(1,1,2,3,1,4),id2=c(2,3,4,4,5,5),weight=c(0.5,0.35,0.5,0.9,0.6,0.6))), directed=FALSE) plot(G, edge.label=paste(E(G),"=",signif(E(G)$weight, digits=1)),

Performance for drawing numbers from Poisson distribution with low mean

北城余情 提交于 2020-05-28 06:03:48
问题 In order to draw random number from a Poisson distribution in C++, it is generally advised to use RNG_type rng; std::poisson_distribution<size_t> d(1e-6); auto r = d(rng); At each call of the std::poisson_distribution object, an entire sequence of random bits is consumed (e.g. 32 bits with std::mt19937, 64 bits for std::mt19937_64). It strikes me that with such low mean ( mean = 1e-6 ), the vast majority of times, only a few bits are enough to determine that the value to return is 0. The

How to compute lower tail probability for the Bivariate Normal Distribution

被刻印的时光 ゝ 提交于 2020-05-15 21:44:22
问题 G'day, I am trying to compute the lower tail probability for the bivariate Normal distribution given by the following formula for 2 random variables (X1, X2): Where X1 = -1.23, X2 = -2.75 and rho = 0.65. I am very curious how to solve this problem? The first term it's just calculations but how would you attack the integrals? Can someone provide me with some code or hints or if it's possible a solution? X's are log normal distributed random variables. Furthermore; how would extend it to

Ranger Predicted Class Probability of each row in a data frame

柔情痞子 提交于 2020-05-15 21:31:40
问题 With regard to this link Predicted probabilities in R ranger package, I have a question. Imagine I have a mixed data frame, df (comprising of factor and numeric variables) and I want to do classification using ranger. I am splitting this data frame as test and train sets as Train_Set and Test_Set. BiClass is my prediction factor variable and comprises of 0 and 1 (2 levels) I want to calculate and attach class probabilities to the data frame using ranger using the following commands: Biclass

How to choose keys from a python dictionary based on weighted probability?

天涯浪子 提交于 2020-05-14 16:32:58
问题 I have a Python dictionary where keys represent some item and values represent some (normalized) weighting for said item. For example: d = {'a': 0.0625, 'c': 0.625, 'b': 0.3125} # Note that sum([v for k,v in d.iteritems()]) == 1 for all `d` Given this correlation of items to weights, how can I choose a key from d such that 6.25% of the time the result is 'a', 32.25% of the time the result is 'b', and 62.5% of the result is 'c'? 回答1: def weighted_random_by_dct(dct): rand_val = random.random()

How to choose keys from a python dictionary based on weighted probability?

主宰稳场 提交于 2020-05-14 16:32:09
问题 I have a Python dictionary where keys represent some item and values represent some (normalized) weighting for said item. For example: d = {'a': 0.0625, 'c': 0.625, 'b': 0.3125} # Note that sum([v for k,v in d.iteritems()]) == 1 for all `d` Given this correlation of items to weights, how can I choose a key from d such that 6.25% of the time the result is 'a', 32.25% of the time the result is 'b', and 62.5% of the result is 'c'? 回答1: def weighted_random_by_dct(dct): rand_val = random.random()

How can I sample a multivariate log-normal distribution in Python?

陌路散爱 提交于 2020-04-11 02:54:10
问题 Using Python, how can I sample data from a multivariate log-normal distribution? For instance, for a multivariate normal, there are two options. Let's assume we have a 3 x 3 covariance matrix and a 3-dimensional mean vector mu. # Method 1 sample = np.random.multivariate_normal(mu, covariance) # Method 2 L = np.linalg.cholesky(covariance) sample = L.dot(np.random.randn(3)) + mu I found numpy's numpy.random.lognormal, but that only seems to work for univariate samples. I also noticed scipy's

Generating a triangular distribution in Matlab

只愿长相守 提交于 2020-03-21 03:51:58
问题 I have attempted to generate a triangular probability distribution in Matlab, but was not successful. I used the formula at http://en.wikipedia.org/wiki/Triangular_distribution. n = 10000000; a = 0.2; b = 0.7; c = 0.5; u = sqrt(rand(n, 1)); x = zeros(n, 1); for i = 1:n U = u(i); if U < (c-a)/(b-a) X = a + sqrt(U*(b-a)*(c-a)); else X = b - sqrt((1-U)*(b-a)*(b-c)); end x(i) = X; end hist(x, 100); The histogram looks like so: Doesn't look like much of a triangle to me. What's the problem? Am I

Generating a triangular distribution in Matlab

怎甘沉沦 提交于 2020-03-21 03:51:41
问题 I have attempted to generate a triangular probability distribution in Matlab, but was not successful. I used the formula at http://en.wikipedia.org/wiki/Triangular_distribution. n = 10000000; a = 0.2; b = 0.7; c = 0.5; u = sqrt(rand(n, 1)); x = zeros(n, 1); for i = 1:n U = u(i); if U < (c-a)/(b-a) X = a + sqrt(U*(b-a)*(c-a)); else X = b - sqrt((1-U)*(b-a)*(b-c)); end x(i) = X; end hist(x, 100); The histogram looks like so: Doesn't look like much of a triangle to me. What's the problem? Am I