All Questions

Tagged with
Filter by
Sorted by
Tagged with
25 votes
7 answers
39k views

Generate random number with given probability matlab

I want to generate a random number with a given probability but I'm not sure how to: I need a number between 1 and 3 num = ceil(rand*3); but I need different values to have different probabilities ...
Eamonn McEvoy's user avatar
12 votes
2 answers
16k views

How do I draw samples from multivariate gaussian distribution parameterized by precision in matlab

I am wondering how to draw samples in matlab, where I have precision matrix and mean as the input argument. I know mvnrnd is a typical way to do so, but it requires the covariance matrix (i.e inverse ...
Jing's user avatar
  • 925
9 votes
1 answer
25k views

Simple binary logistic regression using MATLAB

I'm working on doing a logistic regression using MATLAB for a simple classification problem. My covariate is one continuous variable ranging between 0 and 1, while my categorical response is a binary ...
chex's user avatar
  • 111
8 votes
1 answer
7k views

Constructing a multi-order Markov chain transition matrix in Matlab

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)...
pangyuteng's user avatar
  • 1,799
7 votes
1 answer
2k views

Why do the inverse t-distributions for small values differ in Matlab and R?

I would like to evaluate the inverse Student's t-distribution function for small values, e.g., 1e-18, in Matlab. The degrees of freedom is 2. Unfortunately, Matlab returns NaN: tinv(1e-18,2) NaN ...
rozsasarpi's user avatar
  • 1,631
7 votes
1 answer
7k views

How to calculate derivative of multivariate normal probability density function

Is there any built in function calculating the value of a gradient of multivariate normal probability density function for a given point? Edit: found this how to evaluate derivative of function in ...
Karusmeister's user avatar
6 votes
2 answers
4k views

Simulate samples from a joint cumulative distribution function?

I have a joint density function for two independent variables X and Y. And I now want to sample new x,y from this distribution. What I believe I have to do is to find the joint cumulative ...
Groot's user avatar
  • 14.1k
5 votes
6 answers
14k views

Determining probability mass function of random variable

If we have a discrete random variable x and the data pertaining to it in X(n), how in matlab can we determine the probability mass function pmf(X)?
SkypeMeSM's user avatar
  • 3,257
5 votes
4 answers
1k views

SET game odds simulation (MATLAB)

I have recently found the great card came - SET. Briefly, there are 81 cards with the four features: symbol (oval, squiggle or diamond), color (red, purple or green), number (one, two or three) and ...
yuk's user avatar
  • 19.1k
5 votes
2 answers
5k views

Normal Probability Plot interpretation [closed]

I have a very basic question. What is the basis of the normal probability plot i.e. what do the probabilities represent? I am testing for a standard normal distribution. My normplot (in MATLAB) ...
Imelza's user avatar
  • 301
5 votes
3 answers
12k views

How To Fit Multivariate Normal Distribution To Data In MATLAB?

I'm trying to fit a multivariate normal distribution to data that I collected, in order to take samples from it. I know how to fit a (univariate) normal distribution, using the fitdist function (with ...
Shaked's user avatar
  • 495
4 votes
1 answer
3k views

How does this MATLAB code work? (probabilities and random sequences)

I saw this code in a comment for the article "Never-ending Shuffled Sequence". I understand the basic premise, but I don't know how it works. The biggest explanation I need is of the first two lines ...
Robert K's user avatar
  • 30.2k
4 votes
1 answer
16k views

Shannon's Entropy calculation

I have a probability distribution that defines the probability of occurrence of n possible states. I would like to calculate the value of Shannon's entropy, in bits, of the given probability ...
Composer's user avatar
  • 245
4 votes
3 answers
2k views

Algorithm to find the 'possible' combinations of variables with constraints in Matlab?

Say I have 7 items in A and 4 items in B A=[10;40;90;130;200;260;320] B=[100;300;500;1000] I want to have the list of possible combinations where : All sub-components of A MUST be included sub-...
NLed's user avatar
  • 1,865
4 votes
2 answers
2k views

Interpretation of Probability Estimate for Multi-class classification in LibSVM for MATLAB

Problem: 3 class classification with labels 1,2,3. Tool: LibSVM for MATLAB svmModel = svmtrain(<Trainfeatures>, <TrainclassLabels>, '-b 1 -c <someCValue> -g <someGammaValue>'...
Vinayak Agarwal's user avatar
4 votes
1 answer
9k views

How do I generate a random vector (0,1) with a known probability in MATLAB

I am using the following code operation=[rand(1,noOfNodes)>prob]; to generate 1 and zeros (noOfNodes times). If I use prob=0.2 and try 100 values there exist in some cases 40 zeros. Isn't it ...
pac's user avatar
  • 291
4 votes
2 answers
6k views

Given a covarince matrix, generate a Gaussian random variable in Matlab

Given a M x M desired covariance, R, and a desired number of sample vectors, N calculate a N x M Gaussian random vector, X in vanilla MATLAB (i.e. can't use r = mvnrnd(MU,SIGMA,cases)). Not really ...
Elpezmuerto's user avatar
  • 5,491
4 votes
2 answers
12k views

How to make a CDF from a histogram in MATLAB

I am trying to create function that takes a histogram and makes a CDF from it. However I cannot use the cdfplot function in Matlab. How would I go about doing this? This produces the input ...
Sari's user avatar
  • 101
4 votes
1 answer
1k views

Discrete probability distribution calculation in Matlab

I have given P(x1...n) discrete independent probability values which represent for example the possibility of happening X. I want a universal code for the question: With which probability does ...
Clemens's user avatar
  • 245
4 votes
3 answers
3k views

Random number in a certain interval with a exponential distribution [closed]

I'd like to generate a random number in a certain interval using an exponential distribution. My problem is that if I use exprnd I can't control the interval, I can only give a mean value, but that ...
user1797895's user avatar
4 votes
1 answer
279 views

pdf of a particular distribution

I am new to Matlab. I would like to check the so call "logarithmic law" for determinant of random matrices with Matlab, but still do not know how. Logarithmic law: Let A be a random Bernoulli ...
H. H.'s user avatar
  • 41
4 votes
1 answer
357 views

Can you replicate matlab's older pseudo-random number generators in python?

I am trying to analyze random streams of random numbers in python. Specifically I am studying the following pseudo-random streams from matlab: mt19937ar (the Mersenne Twister), mcg16807 (an LCG), and ...
Jorge MD's user avatar
4 votes
1 answer
859 views

Estimate pdf of a vector using Gaussian Kernel

I am using Gaussian kernel to estimate a pdf of a data based on the equation where K(.) is Gaussian kernel, data is a given vector. z is bin from 1 to 256. size of bin is 1. I implemented by matlab ...
user3051460's user avatar
  • 1,465
4 votes
1 answer
847 views

Randomize matrix elements between two values while keeping row and column sums fixed (MATLAB)

I have a bit of a technical issue, but I feel like it should be possible with MATLAB's powerful toolset. What I have is a random n by n matrix of 0's and w's, say generated with A=w*(rand(n,n)<p)...
user129412's user avatar
3 votes
3 answers
10k views

MATLAB's "SIGMA must be symmetric and positive definite" error sometimes not making sense

I am not sure if this is a programming or statistics question, but I am %99 sure that there should be a numerical problem. So maybe a programmatic solution can be proposed. I am using MATLAB's mvnpdf ...
user avatar
3 votes
3 answers
1k views

MATLAB: sample from population randomly many times?

I am aware of MATLAB's datasample which allows to select k times from a certain population. Suppose population=[1,2,3,4] and I want to uniformly sample, with replacement, k=5 times from it. Then: ...
space_voyager's user avatar
3 votes
4 answers
2k views

draw random number following a custom distribution [duplicate]

I need to draw random numbers following a distribution I chose. Example: draw 7 numbers from 1 to 7 with those probabilities: 1: 0.3 2: 0.2 3: 0.15 4: 0.15 5: 0.1 6: 0.05 7: 0.05 Since in my ...
Maik Xhani's user avatar
3 votes
2 answers
3k views

How to catch warning in Matlab?

I'm using the distfit function of Matlab to fit a probability distribution to my data. Sometimes the following warning message appears: Maximum likelihood estimation did not converge. Iteration ...
machinery's user avatar
  • 6,092
3 votes
2 answers
7k views

Generate random samples from arbitrary discrete probability density function in Matlab

I've got an arbitrary probability density function discretized as a matrix in Matlab, that means that for every pair x,y the probability is stored in the matrix: A(x,y) = probability This is a ...
Miguel's user avatar
  • 33
3 votes
2 answers
2k views

Matlab: How to generate a 4x1 matrix of random variables, assuming a 4x4 correlation matrix?

I start with 4 time series, labelled A, B, C, D. I generate the following: A 4x1 matrix of means. A 4x1 matrix of standard deviations. A 4x4 correlation matrix, by taking 30 samples from each time ...
Contango's user avatar
  • 78.3k
3 votes
1 answer
2k views

Sampling from multivariate customised cumulative distribution function in Matlab

Consider a 5-variate cumulative distribution function (cdf) which I call F. I want to sample random 5x1 vectors from this cdf in Matlab. F is not a cdf that has been already implemented in Matlab (...
Star's user avatar
  • 2,259
3 votes
3 answers
114 views

defining the X values for a code

I have this task to create a script that acts similarly to normcdf on matlab. x=linspace(-5,5,1000); %values for x p= 1/sqrt(2*pi) * exp((-x.^2)/2); % THE PDF for the standard normal ...
Rey's user avatar
  • 33
3 votes
2 answers
13k views

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

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....
radhika's user avatar
  • 534
3 votes
1 answer
1k views

naive classifier matlab

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 ...
G Gr's user avatar
  • 6,050
3 votes
1 answer
2k views

MATLAB | calculating parameters of gamma dist based on mean and probability interval

I have a system of 2 equations in 2 unknowns that I want to solve using MATLAB but don't know exactly how to program. I've been given some information about a gamma distribution (mean of 1.86, 90% ...
jefflovejapan's user avatar
3 votes
1 answer
5k views

How do I calculate conditional probabilities from data

I'm doing a naive Bayes in Matlab, and it was all good until they said I needed the conditional probabilities. Now I know the formula for conditional p(A|B) = P(A and B)/p(B), but when I have data to ...
Pedro.Alonso's user avatar
  • 1,006
3 votes
1 answer
376 views

Number series with uniform distribution for a given variance and a mean in matlab

I want to generate n number of points using a uniform distribution for a specific variance (v) and mean (m). I'm currently using MATLAB to achieve this task. This can be done for a normal ...
ccc's user avatar
  • 574
3 votes
1 answer
2k views

Define distribution using percentile points

In @Risk and Crystal Ball, we are allowed to define the probability distribution using percentile data. For example, we can define a log normal distribution just by inputting 3 data points, e.g. P10, ...
iFikr's user avatar
  • 153
3 votes
1 answer
9k views

Homework: Simulating coin tosses until consecutive heads using R

I am new to R hence asking here (haven't been able to find very helpful tutorials for simulation that are detailed.) The problem statement is this Simulate a coin toss for 20 times and record the ...
Raaj's user avatar
  • 1,200
3 votes
1 answer
2k views

Plot PDF of log-normal distribution

I'm using the randn function to generate a Gaussian random variable x1 with mean 0 and variance 1. After generating x1, I generate another Gaussian random variable x with mean m and variance σ2, that ...
user2443165's user avatar
3 votes
2 answers
3k views

Using random generator with probability using matlab

THe following code generates random numbers with a given probability of success: n=[randi([0 1],1,8) ones(1,8)]; n= n(randperm(10)); If the above lines are repeated random (...
pac's user avatar
  • 291
2 votes
3 answers
8k views

Generating a triangular distribution in Matlab

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....
Superbest's user avatar
  • 26k
2 votes
2 answers
2k views

How to choose one element based on its probability? [duplicate]

Let's say I have a vector containing N elements, each being its probability. For example, v = [0.01 0.01 0.09 0.82 0.07] So I want a function f(v) that returns 4 at 82% of the time, 3 at 9% of the ...
jeff's user avatar
  • 13.4k
2 votes
1 answer
4k views

MATLAB code for a lot of Gaussian Mixture Model

I have applied gaussmix from MATLAB's voicebox tools to calculate a Gaussian Mixture Model (GMM). However, the code gives me an error when I run it for 512 GMM components. No_of_Clusters = 512; ...
Ali Bodaghi's user avatar
2 votes
1 answer
861 views

Kurtosis function in Julia

So I've been playing around with Julia, and I've discovered that the function to calculate the kurtosis of a probability distribution is implemented differently between Julia and MATLAB. In Julia, do:...
Hasnain Raza's user avatar
2 votes
2 answers
4k views

How to calculate probability of a point using a probability distribution object?

I'm building up on my preivous question because there is a further issue. I have fitted in Matlab a normal distribution to my data vector: PD = fitdist(data,'normal'). Now I have a new data point ...
machinery's user avatar
  • 6,092
2 votes
2 answers
136 views

Set column to 0 with probability p

I've got a matrix A with the dimensions m X n. For every column i (i > 0and i <= n) I want to flip a coin and fill the whole column with 0 values with probability p. How can this be accomplished ...
Eric's user avatar
  • 1,624
2 votes
1 answer
2k views

choosing standard deviation parameter in MATLAB

If I want to use the gaussian random number generator in MATLAB R = normrnd(mu,sigma) Let mu = 1. The question is how to choose sigma? If I want 90% of the values to be near 1.Let us say +/-0.7 ...
pac's user avatar
  • 291
2 votes
2 answers
41 views

How can i create a sequence that differs from another one with some probability p?

Hello i have a random sequence of 10 bits x=0100100011 I want to create another sequence y but with probability 0.2 is different than x.That actually means that when i have 10 bits i approximately ...
Γιάννης Γιαννάκος's user avatar
2 votes
2 answers
3k views

Finding probability of Gaussian random variable with range

I am a beginner in MATLAB trying to use it to help me understand random signals, I was doing some Normal probability density function calculations until i came across this problem : Write a MATLAB ...
Emad Abdul Naser's user avatar

1
2 3 4 5 6