Combining several distributions into kernel-like distribution
Show older comments
I have the following code, where I start from three different values, and the probability of them occuring (excuse me, I do not know the correct statistical term). For example, in the case below, the number "3" has a 25% chance of appearing, "5" has 50% and "7" has 25%.
The aim is to replace these 3 discrete, integer values with continuous distributions of real numbers with some desired standard deviation, and then "combine" them to a single probability distribution.
The code I've written below kind of does the job, utilizing the kernel distribution, but it feels a bit wonky and not customizable enough.
ValueAndProbability(1,:) = [3 0.25];
ValueAndProbability(2,:) = [5 0.50];
ValueAndProbability(3,:) = [7 0.25];
values =[];
n = 10000;
for i=1:size(ValueAndProbability,1)
% Add each value n times to the array
addValues = ValueAndProbability(i,1) + zeros(1, ValueAndProbability(i,2) * n );
values = single(cat(2,values,addValues));
end
pd = fitdist(values',"Kernel","Width",0.3);
minx = min(ValueAndProbability(:,1)) - 2;
maxx = max(ValueAndProbability(:,1)) + 2;
xvals = linspace(minx,maxx);
yvals = pdf(pd,xvals);
plot(xvals,yvals)
I was wondering if there's any way to make the process a bit more elegant (skipping this akward loop and the 10000-sized array perhaps), and create the final distribution as a "sum" of desired distributions of my choice (not limited to gaussian for example).
Accepted Answer
More Answers (0)
Categories
Find more on Half-Normal Distribution in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
