probability

Randomly fill a 3D grid according to a probability density function p(x,y,z)

荒凉一梦 提交于 2019-12-10 11:45:56
问题 How can I fill a 3D grid in the order specified by a given probability density function? Using python, I'd like to lay down points in a random order, but according to some specified probability distribution over that region, with no repeated points. Sequentially: create a discrete 3D grid specify a probability density function for every grid point, pdf(x,y,z) lay down a point (x0,y0,z0) whose random location is proportional to the pdf(x,y,z) continue adding points (without repeating) until

How can I find out how many rows of a matrix satisfy a rather complicated criterion (in R)?

与世无争的帅哥 提交于 2019-12-10 10:19:42
问题 As an example, here is a way to get a matrix of all possible outcomes of rolling 4 (fair) dice. z <- as.matrix(expand.grid(c(1:6),c(1:6),c(1:6),c(1:6))) As you may already have understood, I'm trying to work out a question that was closed, though, in my opinion, it's a challenging one. I used counting techniques to solve it (I mean by hand) and I finaly arrived to a number of outcomes, with a sum of subset being 5, equal to 1083 out of 1296. That result is consistent with the answers provided

naive classifier matlab

余生长醉 提交于 2019-12-10 10:11:32
问题 When testing the naive classifier in matlab I get different results even though I trained and tested on the same sample data, I was wondering if my code is correct and if someone could help explain why this is? %% dimensionality reduction columns = 6 [U,S,V]=svds(fulldata,columns); %% randomly select dataset rows = 1000; columns = 6; %# pick random rows indX = randperm( size(fulldata,1) ); indX = indX(1:rows)'; %# pick random columns %indY = randperm( size(fulldata,2) ); indY = indY(1:columns

Generating a binomial distribution around zero

▼魔方 西西 提交于 2019-12-10 10:04:52
问题 I'm looking to generate a binomial-esque distribution. I want a binomial distribution but I want it centred around zero (I know this doesn't make much sense with respect to the definition of binomial distributions but still, this is my goal.) The only way I have found of doing this in python is: def zeroed_binomial(n,p,size=None): return numpy.random.binomial(n,p,size) - n*p Is there a real name for this distribution? Does this code actually give me what I want (and how can I tell)? Is there

Dice odds: Simulating a game of Craps

感情迁移 提交于 2019-12-10 02:56:11
问题 My brother turns 21 in a couple of weeks and my parents and I are taking him to Las Vegas. For my 21st, I brought $200 to gamble in Vegas and came home with around $450, mostly from playing craps. I plan on bringing $200 again for this trip and before I go I thought I'd run some craps simulations to see if I can double my money again. I've read from several sources that the house has the smallest advantage in craps when placing a passline bet with maximum odds. From my memory, and as surveyed

Fisher Yates variation

爷,独闯天下 提交于 2019-12-10 01:45:54
问题 The classic Fisher Yates looks something like this: void shuffle1(std::vector<int>& vec) { int n = vec.size(); for (int i = n - 1; i > 0; --i) { std::swap(vec[i], vec[rand() % (i + 1)]); } } Yesterday, I implemented the iteration "backwards" by mistake: void shuffle2(std::vector<int>& vec) { int n = vec.size(); for (int i = 1; i < n; ++i) { std::swap(vec[i], vec[rand() % (i + 1)]); } } Is this version in any way worse (or better) than the first? Does it skew the resulting probabilities? 回答1:

MATLAB code for a lot of Gaussian Mixture Model

允我心安 提交于 2019-12-09 22:19:47
问题 I have applied gaussmix function in voicebox MATLAB tools to calculate GMM. However, the code gives me error when I run it for 512 GMM components. No_of_Clusters = 512; No_of_Iterations = 10; [m_ubm1,v_ubm1,w_ubm1]=gaussmix(feature,[],No_of_Iterations,No_of_Clusters); Error using * Inner matrix dimensions must agree. Error in gaussmix (line 256) pk=px*wt; % pk(k,1) effective number of data points for each mixture (could be zero due to underflow) I need 1024 or 2048 Mixtures for Universal

Calculating Probability of a Random Variable in a Distribution in Python

假装没事ソ 提交于 2019-12-09 17:19:19
问题 Given a mean and standard-deviation defining a normal distribution, how would you calculate the following probabilities in pure-Python (i.e. no Numpy/Scipy or other packages not in the standard library)? The probability of a random variable r where r < x or r <= x. The probability of a random variable r where r > x or r >= x. The probability of a random variable r where x > r > y. I've found some libraries, like Pgnumerics, that provide functions for calculating these, but the underlying math

Function that returns array of array combinations

核能气质少年 提交于 2019-12-09 17:12:24
问题 I'm trying to make a _.combinations function (underscore mixin) that takes three parameters arr, pockets, duplicates . Here's a test that I designed to show how the behavior should be. expect(_.combinations([1, 2], 1, false)).to.be.equal([[1],[2]]) expect(_.combinations([1, 2], 1, true)).to.be.equal([[1],[2]]) expect(_.combinations([1, 2, 3], 2, false)).to.be.equal([[1,2],[1,3],[2,3]]) expect(_.combinations([1, 2, 3], 2, true)).to.be.equal([[1,2],[1,3],[2,3],[2,1],[3,1],[3,2]]) expect(_

Get true or false with a given probability

不羁岁月 提交于 2019-12-09 17:10:34
问题 I'm trying to write a function in c++ that will return true or false based on a probability given. So, for example if the probability given was 0.634 then, 63.4% of the time the function would return true. I've tried a few different things, and failed. Any help? 回答1: If you'd like to do this in C++11, you can use its various random number engines, combined with the uniform_real_distribution to provide a good result. The following code demonstrates: #include <random> std::knuth_b rand_engine;