fit a custom distribution on univariate data in matlab - matlab

I have one dimensional data like Y=[ . . . .. ]. I want to fit a custom distribution, Porter-Thomas, to the data histogram and find its parameter v. I tried to use mle, but it gave me the following error: "the pdf function returned negative or zero values".
This is my function:
My code:
f=#(v,y)((v./(2*0.99)).^(v/2)).*(y.^(v/2 -1)).*exp(-v.*y./(2*0.99))./gamma(v/2);
V=mle(Y,'pdf',f,'Start',rand,'lowerbound',[0],'upperbound',[1]);
h=histfit(Y,50);
hold on
bins=linspace(min(Y),max(Y),105);
plot(bins,f(bins,V),'r--')
How can I fit this distribution?

Related

How to generate 3d scatter plot with different colours for labels in MATLAB?

I have used TSNE in MATLAB for dimensionality reduction of a large data. I have been able to generate the Scatter Plot for TSNE in 2 dimensions which shows the labels of the cluster in different colors for each label, but, I am unable to do so in 3D. Referring to https://uk.mathworks.com/help/stats/tsne.html, I used the following syntax:-
Where, merged_data_all is a 21392x1974 table with the last column named FunctionalGroup containing different labels (similar to the Fisheriris species labels in the Mathworks example on tsne). Y2 is the 3 dimensional variable which I have been successfully able to generate of dimensions 21392 x 3 double.
figure
v = double(categorical(merged_data_all.FunctionalGroup));
c = full(sparse(1:numel(v),v,ones(size(v)),numel(v),3));
scatter3(Y2(:,1),Y2(:,2),Y2(:,3),15,c,'filled')
title('3-D Embedding')
view(-50,8)
When I use this code, I get the error "Error using sparse- Index exceeds array bounds". I even tried to use a modified version of the code and doing something like this
scatter3(Y(:,1), Y(:,2),Y(:,3),merged_data_all.FunctionalGroup)
In case of this, I get the error "Error using scatter3- Input arguments must be numeric, datetime or categorical". I am quite confused as to how I can plot a 3d scatter plot, with 14 different colors (for the 14 types of different labels I have in my FunctionalGroup column of merged_data_all). Any help in this regard would be highly appreciated. Thanks

Maximum likelihood estimate custom pdf in matlab

I have a custom pdf that has 3 parameters (X,n,k), where X represents the data (vector) and n,k are two scalars. I want to calculate the mle for this custom pdf, so I wrote this in matlab:
custpdf=#(X,n,k)custompdf(length(X),n,k)
phat =mle(X,'pdf',custpdf,'start',[n0,k0])
But I get this error:
Too many input arguments.
I searched for an answer, but couldn't find one. What am I doing wrong here?
Thank you guys.

Generate symbols according to PDF (Probability Density Function) in Matlab

In Matlab I've got a binomial PDF already defined where the set of possible events are 0-255. I would like to generate symbols, from 0-255, according to that PDF. How can I do that?
This is the code used in order to generate the PDF:
x=0:255; %range of possible values
m=255;
b=0.06245;
y=binopdf(x,m,b); %generates a binomial distribution
When plotting "y" I can see that most of the times the symbol that the source will generate will be between 9 to 23. Again, how can I design that symbol source? Thank you.
Use
result = binornd(m,b,R,C);
to generate an R x C matrix of random values drawn from an (m,b) binomial distribution.
If you then plot the histogram
hist(result(:),-.5:255.5)
you can check that (for R and/or C large enough) the obtained values follow the desired binomial distribution.

OpenCV: Creating a histogram from a number of float arrays

I have a number of float arrays, and my purpose is to create a histogram for them. I want to get a graph of the values' frequencies - one graph per each array. and I need all the graphs to be shown on the same window, like this Opencv example does for rgb color histogram. I'm looking for a way to do it using OpenCv or to dump the values out to a file and do the histogram using Matlab. Any idea?
Matlab has a built-in histogram function - hist. It can calculate the histogram, or plot it, or both. For example, if f is a list of files with data you can use
for i=1:length(f)
d=importdata(f(i));
subfigure(length(f),1,i);
hist(d);
end
(Of course, you have to tweak the data importing thingy to make it work. I don't know what the format of your data is in)

Using skewness and kurtosis functions in image matching

I am using the skewness and kurtosis functions for image color Histogram in image retrieval system as a statistical color features then using these features to compare between two images to retrieve the similarity images....but I get 'NaN' value in some results which is causes an error in image retrieval process:
S=double(imread('im.jpg');
R=S(:,:,1)/64; R1=floor(R);
G=S(:,:,2)/64; G1=floor(G);
B=S(:,:,3)/64; B1=floor(B);
[rr cc c]=size(R1);
ImageHist = zeros(4,4,4);
for row = 1 :rr
for col = 1:cc
ImageHist(R1(row,col)+1, G1(row,col)+1,B1(row,col)+1 )= ImageHist(R1(row,col)+1, G1(row,col)+1,B1(row,col)+1)+1;
end
end
ImageHist = ImageHist/(rr*cc);
then I compute the Kurtosis as:
QKurColHis = kurtosis(ImageHist);
I make the same thing to second function (skewness)
It is suitable to use this function to the color histogram to extract color feature? then using it in image retrieval?
if it is OK, how can I correct this Error, how can I remove the NaN values from my mat.file?
I want to use these function as image features in matching between color images... any one please could help me to solve this problem?
I don't know how the builtin kurtosis function is working but it might be that you have to supply it a vector instead of 3D matrix as an input
kurtosis(ImageHist(:))
Apart from the NaN problem, kurtosis and skewness give you some info about statistical distribution of the data in ImageHist so they could be treated as some image features. But how good will they perform in image matching is hard to say.