How draw decision boundry of 4 dimentional Iris data in libsvm? - matlab

I tried svm with 4 features. I used Libsvm for training classifier then I want to draw decision boundries. I tried to draw in 2D space in matlab for 1 vs 3 (One vs One) and the 2D features were columns 1 and 3 of Iris data but it drew the wrong decision boundry. What is wrong? What should I do?
coef1v3 = [model.sv_coef(1:7,2); model.sv_coef(27:45,1)];
SVs1v3 = [model.SVs(1:7,:); model.SVs(27:45,:)];
b=model.rho;
w1v3 = SVs1v3'*coef1v3;
b1v3=b(2);
xp=linspace(min (data(:,1)),max (data(:,1)));
yp1=(-w1v3(1)*xp+b1v3)/w1v3(3);
plot(xp , yp1);

Nothing is wrong. just try dimension 1 and 3.No need to try every dimension.I did it and got true response.

Related

Depth map merging or Point Cloud Merging

My goal is to create a single 3D point-cloud based on 2 pairs of images(AB, BC) and their projection matrices. Each image comes from the same camera (not video) with 3 distinct positions.
I use the "standard process": Point matching (sift or surf), keeping inliers only, finding the position, doing the bundle adjustment...images rectifications. Up to now everything works well.
Next I use the Matlab function "disparity" to create the 2 disparity maps, one for each pair of images.
Next i create 2 separated 3dpoint-clouds, one for each pair of images, using the projection matrices.
But, how can i merge the 2 points clouds coming from AB and BC. Apparently, the 3D coordinates depends on the "DisparityRange" parameters of the function disparity.
Did i miss a step in the process ?
Thanks in advance for any help
Alvaro
Please see the answer on MATLAB Answers
Problem solved.
The problem was that I processed wide-baseline stereo images as if they were short-baseline. Fatal Error!

My observations are less than the feature vector of each. Any solution to overcome this?

I'm using GMM to fit my data to 256 Gaussians. I'm using Matlab's fitgmdist to achieve this.
gmm{i} = fitgmdist(model_feats, gaussians, 'Options',statset('MaxIter',1000), ...
'CovType','diagonal', 'SharedCov',false, 'Regularize',0.01, 'Start',cInd);
I am using RootSIFT to extract the features of each image. This produces a vector of 1x128 for each image.
Now I have 45 images maximum for each writer. So after feature extraction and everything the size of my model_feats is 45 x 128.
According to the help file for data arrangement for X is:
The rows of X correspond to observations, and columns correspond to
variables.
The problem I have is when I run the above function I am told that:
"X must have more rows than columns."
I have a total of 45 images for each writer. How will I be able to get this function to run? This is a strange limitation for such a function, I mean even if I am able to get 100 images for each writer it will not work.
I will appreciate any workaround to this.
P.S. I've tried the same with VL_Feat's vl_gmm and it works without any problems but I need this to work in Matlab not VL_FEAT.
With SIFT you usually don't compute the feature for the whole image, but literally hundreds of keypoints for each image. Then you won't have this problem anymore.
Next step then probably is a “bag of visual words” mapping of each image.

MATLAB - interpolating a 2D curve with multiple Y's per X

I would like to interpolate a data set, but a given X can have multiple Y's, example given below:
A(:,1:2,1)=
95.2343 70.6159
96.4501 71.5573
97.4430 72.7315
98.9743 72.8699
100.0470 71.7690
100.3872 70.2699
100.7797 68.7837
102.1478 68.0814
103.6851 68.0521
105.0307 68.7966
105.8972 70.0666
106.7177 71.3665
107.7095 72.5416
108.9175 73.4924
110.3574 74.0309
111.8943 73.9859
113.3936 73.6446
114.6645 72.7794
115.5911 71.5522
116.2426 70.1591
116.3922 68.6286
116.3503 67.0914
116.7771 65.6147
117.9045 64.5692
119.4065 64.2425
120.9432 64.2923
122.2526 65.0975
122.9486 66.4682
122.8841 68.0043
122.5492 69.5051
122.2403 71.0109
122.0819 72.5402
These are points along the body of a snake, digitized from top-down video. Their posture frequently results in 2 or more Y points per X, and because they turn (often dramatically) while I need to maintain a consistent XY framework, I can't just rotate my X and Y.
I can make a spline function using cscvn, and when plotted using fnplt it looks great! But the moment I try to get values back using ppval, it all goes to crap and I get two curves that look nothing like the snake or what's shown in fnplt.
IMAGE HERE:
http://imgur.com/aYJ0Ftj
All I want is to fit a curve to those points, and convert that curve to a series of maybe 200 XY points.
I'm assuming that there is some obscenely simple answer, some command I've just never turned up in my searching, but I cannot find it for the life of me. This is quite far outside my usual skillset (I'm more used to crawling through swamps catching anything scaly or slimy), so I'm sure I'm overlooking something totally obvious to a skilled MATLAB user.
Thanks!
Perhaps this is what you already tried, but a comment was a bit small, so here is one idea that may help you
x = [1 2 3 4 5 6 7 6 5];
y = [1 4 4 3 2 2 2 3 4];
t = 1:length(x);
figure; plot(x,y)
xx = interp1(t,x,1:.01:length(x),'pchip');
yy = interp1(t,y,1:.01:length(x),'pchip');
hold on; plot(xx,yy,'g')
I avoided the unique values restriction on interp by interpolating x and y both as a function of t.
OK, thanks to Yvon and Trogdor, I managed to crudely cludge together some code:
ht=[1:32];
tx=linspace(1,32,500);
m=ht;
m(2:3,:)=squeeze(A(:,:,i))';
m1=m(1,:);
m2=m(2,:);
m3=m(3,:);
SFX=spline(m1,m2);
pSFX=ppval(SFX,tx);
SFY=spline(m1,m3);
pSFY=ppval(SFY,tx);
AS(:,1,i)=pSFX;
AS(:,2,i)=pSFY;
plot(AS(:,1,i),AS(:,2,i),'Marker','o');
It's riddled with pointless variables, steps, and redundancies, but I'm an anatomist, so that makes me comfortable (seriously, google 'recurrent laryngeal nerve').
How do I add reputation for y'all?

Data fitting for time dependent matrix sets in Matlab

I have 6 data sets, each data set is a 576by576 matrix. Each set of data represents measurements taken within 30 second intervals. e.g. set1 at t=0, set2 at time =30, ... ,set5 at 150 seconds.
You can look at these sets as frames if you will. I need to take first data point (1,1) from each data set -> (1,1,0), (1,1,3),(1,1,6),(1,1,9),(1,1,12),(1,1,15) and based on those 6 points find a fitting formula, then assign that general solution to the first spot of my solution matriz SM(1,1). I need to do this for every data point in the 6 sets until I have a 576by576 solution matriz.
if everything goes right I should be able to plot SM(0s)=set1, SM(30s)=set2,etc. but not only that. SM(45) should return a prediction of measurements at t=45 and so on and so forth. The purpose is to have one matrix than can predict data fluctuation from time t= 0 to 150 seconds.
Additional information:
1.- Each data point is independent form the rest of the data points in the same set.
2.- it is a none-linear fit
3.- all values are real
Does Matlab have an optimization tool for this kind of problem?
Should I treat the problem as 1D data fit and create a for loop that does the job 576^2 times?
(I don't even know where to begin)
Feel free to ask or edit anything if I wasn't clear enough. I am not sure that I've chosen the most precise title for this kind of problem.Thanks
Update:
Based on Guddu's answer I came up with this:
%% Loadint data Matrix A
A(:,:,1) = abs(set1);
A(:,:,2) = abs(set2);
A(:,:,3) = abs(set3);
A(:,:,4) = abs(set4);
A(:,:,5) = abs(set5);
A(:,:,6) = abs(set6);
%% Creating Solution Matrix B
t=0:30:150;
SM=zeros([576 576 150]);
for i=1:576
for j=1:576
y=squeeze(A(i,j,1:6));
f=fit(t',y,'smoothingspline');
data=feval(f,1:150);
SM(i,j,:)=data;
end
end
%% Plotting Frame at t=45
figure(1);
imshow(SM(:,:,45),[])
I am not sure if this is the most efficient way to do it, but it works. I am open to new ideas or suggestions. Thanks
i would suggest your main data matrix would be of size (6,576,576) -> a. first point (1,1) from each dataset would be a(1,1,1), a(2,1,1), a(3,1,1) .. a(6,1,1). as you have said each point (i,j) in each dataset from other point (k,l), i would suggest treat each position (i,j) for all datasets separately from other positions. so it would be looping 576*576 times. code could be something like this
t=0:30:150;
for i=1:576
for j=1:576
datavec=squeeze(a(1:6,i,j)); % Select (i,j) point from all 6 frames
% do the curve fitting and save in SM(i,j)
end
end
i am just curious what kind of non-linear function you want to fit to 6 points. this might not be the answer you want but it was kind of long to put in a comment

Thumb Recognition in matlab using SVM algo

I am working on a project thumb recognition. following is code I am reading the 118 images of order 42 X 25 and storing them in training matrix.
training=zeros(118, 1050);
imagefiles = dir('*.png');
nfiles = length(imagefiles);
for ii=1:nfiles
currentfilename = imagefiles(ii).name;
I = imread(currentfilename);
BW=im2bw(I,graythresh(I));
temp = reshape(BW,1,1050);
training(ii,:)=temp;
end
Now I am creating a matrix of labelData to assign labels to images.
labelData = zeros(118,1);
labelData(1:50,:) = 0;
labelData(51:83,:) = 1;
labelData(84:118,:) = 2;
Here i am training my system by giving training data and label data.
options=optimset('MaxIter',5000);
SVMStruct = svmtrain(training,labelData,'Kernel_Function','linear','QuadProg_Opts',options);
BUT when I run this code it is giving me an error like
Error 1 : SVMTRAIN only supports classification into two groups. GROUP contains 3 groups.
Error 2 : SVMStruct = svmtrain(training,labelData,'Kernel_Function','linear','QuadProg_Opts',options);
Kindly help me what is the problem I used it before it was working fine but now I dont know what is going on. Thanks in advance.
Error 1 tells you what the problem is - the MATLAB built-in SVM only supports binary classification. You are assigning 3 classes.
Your options are:
Construct three classifiers: 0 vs. 1,2 then 1 vs. 0,2 then 2 vs. 0,1 and look at the output of each.
Construct 0 vs. not 0 and then 1 vs. 2
Use a multi-class SVM trainer from LIBSVM or svmlight or other such packages.
The error message is pretty clear. MATLAB's svmtrain does not support multiclass classification, that is only two classes are allowed.
So, you have two options: 1) write your own multiclass classifier as a wrapper around svmtrain. You can implement one-vs-all or one-vs-one strategies. 2) use a svm implementation that already supports multiclass classification such as libsvm.
Your problem is in the labelData vector ceck it and find the eror, yoy shoild OAA architector if hthe number of classes is more then .