probability

Choose random array element satisfying certain property

橙三吉。 提交于 2019-11-27 17:44:08
问题 Suppose I have a list, called elements , each of which does or does not satisfy some boolean property p . I want to choose one of the elements that satisfies p by random with uniform distribution. I do not know ahead of time how many items satisfy this property p . Will the following code do this?: pickRandElement(elements, p) randElement = null count = 0 foreach element in elements if (p(element)) count = count + 1 if (randInt(count) == 0) randElement = element return randElement ( randInt(n

Estimate Markov Chain Transition Matrix in MATLAB With Different State Sequence Lengths

大憨熊 提交于 2019-11-27 17:00:53
问题 I'm trying to build the transition matrix for a Markov Chain in MATLAB; I have several different observation sequences (all of varying lengths) and I need to generate the transition matrix using those. Constructing a multi-order Markov chain transition matrix in Matlab shows me how to build a transition matrix with a single observation sequence. How can I construct one using observations of different length? One example can be that one sequence is 1,2,3,4 and another is 4,5,6. Is there any

Creating Probability/Frequency Axis Grid (Irregularly Spaced) with Matplotlib

半腔热情 提交于 2019-11-27 16:24:47
问题 I'm trying to create a frequency curve plot, and I'm having trouble manipulating the axis to get the plot I want. Here is an example of the desired grid/plot I am trying to create: Here is what I have managed to create with matplotlib: To create the grid in this plot, I used the following code: m1 = pd.np.arange(.2, 1, .1) m2 = pd.np.arange(1, 2, .2) m3 = pd.np.arange(2, 10, 2) m4 = pd.np.arange(2, 20, 1) m5 = pd.np.arange(20, 80, 2) m6 = pd.np.arange(80, 98, 1) xTick_minor = pd.np

Fastest primality test

自古美人都是妖i 提交于 2019-11-27 15:29:32
Could you suggest a fast, deterministic method that is usable in practice, for testing if a large number is prime or not? Also, I would like to know how to use non-deterministic primality tests correctly. For example, if I'm using such a method, I can be sure that a number is not prime if the output is "no", but what about the other case, when the output is "probably"? Do I have to test for primality manually in this case? Thanks in advance. templatetypedef The only deterministic, polynomial-time algorithm for primality testing I know of is the AKS primality test ( http://en.wikipedia.org/wiki

Which java-library computes the cumulative standard normal distribution function?

无人久伴 提交于 2019-11-27 15:02:32
问题 For a project I have a specification with formulas, I have to implement. In these formulas a cumulative standard normal distribution function exists, that takes a float and outputs a probability. The function is symbolized by a Φ. Exists a Java-library, that computes this function? 回答1: Apache Commons - Math has what you are looking for. More specifically, check out the NormalDistribution class. 回答2: If you want the exact code, this one seems to be the same function used in OpenOffice Calc (I

Unbiased random number generator using a biased one

天大地大妈咪最大 提交于 2019-11-27 14:55:06
问题 You have a biased random number generator that produces a 1 with a probability p and 0 with a probability (1-p). You do not know the value of p. Using this make an unbiased random number generator which produces 1 with a probability 0.5 and 0 with a probability 0.5. Note : this problem is an exercise problem from Introduction to Algorithms by Cormen, Leiserson, Rivest, Stein.(clrs) 回答1: The events (p)(1-p) and (1-p)(p) are equiprobable. Taking them as 0 and 1 respectively and discarding the

Solving inverse problems with PyMC

五迷三道 提交于 2019-11-27 14:22:48
问题 Suppose we're given a prior on X (e.g. X ~ Gaussian) and a forward operator y = f(x) . Suppose further we have observed y by means of an experiment and that this experiment can be repeated indefinitely. The output Y is assumed to be Gaussian (Y ~ Gaussian) or noise-free (Y ~ Delta(observation)). How to consistently update our subjective degree of knowledge about X given the observations? I've tried the following model with PyMC, but it seems I'm missing something: from pymc import * xtrue = 2

Distributed probability random number generator

我是研究僧i 提交于 2019-11-27 13:39:35
问题 I want to generate a number based on a distributed probability. For example, just say there are the following occurences of each numbers: Number| Count 1 | 150 2 | 40 3 | 15 4 | 3 with a total of (150+40+15+3) = 208 then the probability of a 1 is 150/208= 0.72 and the probability of a 2 is 40/208 = 0.192 How do I make a random number generator that returns be numbers based on this probability distribution? I'm happy for this to be based on a static, hardcoded set for now but I eventually want

What are probabilistic data structures?

南笙酒味 提交于 2019-11-27 13:36:14
I have read about data structures like bloom filters and skip lists. What are the common characteristics of probabilistic data structures and what are they used for? There are probably a lot of different (and good) answers, but in my humble opinion, the common characteristics of probabilistic data structures is that they provide you with approximate, not precise answer. How many items are here? About 1523425 with probability of 99% Update: Quick search produced link to decent article on the issue: https://highlyscalable.wordpress.com/2012/05/01/probabilistic-structures-web-analytics-data

Plotting probability density function by sample with matplotlib [closed]

ⅰ亾dé卋堺 提交于 2019-11-27 12:31:33
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 6 years ago . I want to plot an approximation of probability density function based on a sample that I have; The curve that mimics the histogram behaviour. I can have samples as big as I want. 回答1: If you want to plot a