The MATLAB code looks like this, how can I plot these coefficients in a graph? In the same graph.
coefFp1=corrcoef(hFp1,mddFp1);
coefF3=corrcoef(hF3,mddF3);
coefC3=corrcoef(hC3,mddC3);
coefP3=corrcoef(hP3,mddC3);
coefO1=corrcoef(hO1,mddO1);
coefF7=corrcoef(hF7,mddF7);
coefT3=corrcoef(hT3,mddT3);
coefT5=corrcoef(hT5,mddT5);
coefFz=corrcoef(hFz,mddFz);
coefFp2=corrcoef(hFp2,mddFp2);
coefF4=corrcoef(hF4,mddF4);
coefP4=corrcoef(hP4,mddP4);
coefC4=corrcoef(hC4,mddC4);
coefO2=corrcoef(hO2,mddO2);
coefF8=corrcoef(hF8,mddF8);
coefT4=corrcoef(hT4,mddT4);
coefT6=corrcoef(hT6,mddT6);
coefCz=corrcoef(hCz,mddCz);
coefPz=corrcoef(hPz,mddPz);
coefA2A1=corrcoef(hA2A1,mddA2A1);
Related
How to plot the precision and recall curves of a CNN?
I have generated the scores from CNN and want to plot the precision-recall curve, but I am unable to get that.
I have calculated TP, TN, FP, and FN using:
idx = (ACTUAL()==1);
p = length(ACTUAL(idx));
n = length(ACTUAL(~idx));
N = p+n;
tp = sum(ACTUAL(idx)==PREDICTED(idx));
tn = sum(ACTUAL(~idx)==PREDICTED(~idx));
fp = n-tn;
fn = p-tp;
The formula of precision and recall is
precision = tp/(tp+fp)
but with that, I am getting some undesired plot.
I have obtained scores of the CNN using the following command:
[YTest,score]=classify(convnet,TestData)
MATLAB has a function for creating ROC curves and similar performance curves (such as precision-recall curves) in the Statistics and Machine Learning Toolbox: perfcurve.
By default, the ROC curve is calculated.
The function has the following syntax:
[X, Y] = perfcurve(labels, scores, posclass)
Here, labels is the true label for each sample, scores is the prediction of the CNN (or any other classifier), and posclass is the label of the class you assume to be "positive" - which appears to be 1 in your example. The outputs of the perfcurve function are the (x, y) coordinates of the ROC curve, so you can easily plot it using
plot(X, Y)
To make perfcurve plot the precision-recall curve instead of the ROC curve, you have to set the optional 'XCrit' and 'YCrit' arguments of the function. As described in the documentation, different pre-defined criteria such as number of false positives ('fp'), true positive rate ('tpr'), accuracy ('accu') and many more, or even custom functions can be used.
By setting 'XCrit' to 'tpr' (Recall) and 'YCrit' to 'prec' (Precision), a precision-recall curve is created:
[X, Y] = perfcurve(labels, scores, posclass, 'XCrit', 'tpr', 'YCrit', 'prec');
plot(X, Y);
xlabel('Recall')
ylabel('Precision')
xlim([0, 1])
ylim([0, 1])
For example (using randomly generated data and a SVM):
The answer of hbaderts is correct but the end of the answer is wrong.
[X,Y] = perfcurve(labels,scores,posclass,'xCrit', 'fpr', 'yCrit', 'tpr');
Then the generated Receiver operating characteristic (ROC) curve is correct.
I want to use CS to reconstruct an image from fewer samples.
I use Gaussian random matrix as measurement matrix. My problem is with Psi matrix which I want to be Haar wavelet coefficients but I don't know how to define it.
I have used DCT and Fourier basis and it worked well. Here is my code with Fourier basis.
Can anyone tell me how to define Psi matrix as haar wavelet transform?
Thanks in advance.
clc
clear all
close all
[fn,fp]=uigetfile({'*.*'});
tic
A=im2double(rgb2gray(imread([fp,fn])));
figure(1),imshow(A)
xlabel('original')
x=A(:);
n=length(x);
m=1900;
Phi=randn(m,n); %Measurment Matrix
Psi=fft(eye(n)); %sensing Matrix( or can be dct(eye(n)) )
y=Phi*x; %compressed signal
Theta=Phi*Psi;
%Initial Guess: y=Theta*s => s=Theta\y
s2=Theta\y;
%Solution
s1=OMP( Theta, y, 1e-3);
%Reconstruction
x1=Psi*s1;
figure,imshow(reshape(x1,size(A))),xlabel('OMP')
toc
You just need to generate a haar matrix of appropriate dimensions. Consider this MATLAB function:
function [h]=haargen(N)
% Generating Haar Matrix
ih=zeros(N,N);
h(1,1:N)=ones(1,N)/sqrt(N);
for k=1:N-1
p=fix(log(k)/log(2));
q=k-(2^p);
k1=2^p; t1=N/k1;
k2=2^(p+1); t2=N/k2;
for i=1:t2
h(k+1,i+q*t1) = (2^(p/2))/sqrt(N);
h(k+1,i+q*t1+t2) =-(2^(p/2))/sqrt(N);
end
end
In matlab, if I have this code :
v=10;
for t=1:v
Rateall(1:v) = (1/2)*(log2(1+SINR1)+log2(1+SINR2));
distanceall(1:v)=pdist([randomclusters{1};randomclusters{2}],'euclidean');
end
Rateall has 10 values and distanceall has 10 values after the for loop. How to plot the cdf graph between both Rateall and distanceall?
I am wondering if anyone knows (or is it possible?) how to generate a trend equation from a 3D surf plot from Matlab? I understand that we can create trendline for 2D plots (linear and nonlinear) and show its equation, but how about 3D plot? Can we create something like:
z = ax + by?
Regards
Kit
If you have the curve fitting toolbox you can fit 3D surfaces using cftool as described here.
Here's an example:
[X,Y] = meshgrid(1:100,1:100);
X = reshape(X,numel(X),1);
Y = reshape(Y,numel(Y),1);
Z = 3*X+4*Y;
plot3(X,Y,Z)
f = fit([X, Y], Z, 'poly11');
coeffvalues(f)
With the following code I'm able to draw the plot of a single 2D-Gaussian function:
x=linspace(-3,3,1000);
y=x';
[X,Y]=meshgrid(x,y);
z=exp(-(X.^2+Y.^2)/2);
surf(x,y,z);shading interp
This is the produced plot:
However, I'd like to plot a grid having a specified number x of these 2D-Gaussians.
Think of the following picture as an above view of the plot I'd like to produce (where in particular the grid is made of 5x5 2D-Gaussians). Each Gaussian should be weighed by a coefficient such that if it's negative the Gaussian is pointing towards negative values of the z axis (black points in the grid below) and if it's positive it's as in the above image (white points in the grid below).
Let me provide some mathematical details. The grid corresponds to a mixture of 2D-Gaussians summed as in the following equation:
In which each Gaussian has its own mean and deviation.
Note that each Gaussian of the mixture should be put in a determined (X,Y) coordinate, in such a way that they are equally distant from each other. e.g think of the central Gaussian in (0,0) then the other ones should be in (-1,1) (0,1) (1,1) (-1,0) (1,0) (-1,-1) (0,-1) (1,-1) in the case of a grid with dimension 3x3.
Can you provide me (and explain to me) how can I do such a plot?
Thanks in advance for the help.
Indeed you said yourself, put (as an example just for the means)
[X,Y]=meshgrid(x,y); % //mesh
g_centers = -3:3;
[x_g,y_g] = meshgrid(g_centers,g_centers); % //grid of centers (coarser)
mu = [x_g(:) , y_g(:)]; % // mesh of centers in column
z = zeros(size(X));
for i = 1:size(mu,1)
z= z + exp(-((X-mu(i,1)).^2+(Y-mu(i,2)).^2)/( 2* .001) );
end
surf(X,Y,z);shading interp