I'm trying to apply a PCA solution to a 3d matrix (x,y,z)
I have 552 occurences of this matrix to use as my sample.
I'm not trying to reduce the dimensionality, instead I want to be able to predict these matrix using the information that I will extract from the first 3 vectors of the PCA.
I searched online but I couldn't find any clear solution to that problem.
One approach that I thought was to "unwrap" my 3d matrix on a 2d set of information
so, for instance assuming that I have a matrix that is
C D
A 1.5 2.4
B 2 3.4
I could work with the linear combination
(A,C) (A,D) (C,B) (B,D)
1.5 2.4 2 3.4
As my variables
Does it make sense?
Am I missing something?
is there any easier way ?
Looking forward to hear other members !
Cheers,
Related
I have a 3d matrix of EEG data containing (time x electrode x trial). I would like to collapse the data across trials to obtain average trial values for each electrode and time point.
Can someone please walk be through how to do this in MATLAB?
mean will do it.
meanData = mean(data, 3)
In general, the MATLAB documentation is quite good. Googling what you want done and adding "MATLAB" to your query will produce pretty good results. If you know what function you are looking for, you can type help <function name> in your MATLAB interpreter and it will show you the docs.
A proof of concept prototype I have to do for my final year project is to implement K-Means Clustering on a big data set and display the results on a graph. I only know object-oriented languages like Java and C# and decided to give MATLAB a try. I notice that with a functional language the approach to solving problems is very different, so I would like some insight on a few things if possible.
Suppose I have the following data set:
raw_data
400.39 513.29 499.99 466.62 396.67
234.78 231.92 215.82 203.93 290.43
15.07 14.08 12.27 13.21 13.15
334.02 328.79 272.2 306.99 347.79
49.88 52.2 66.35 47.69 47.86
732.88 744.62 687.53 699.63 694.98
And I picked row 2 and 4 to be the 2 centroids:
centroids
234.78 231.92 215.82 203.93 290.43 % Centroid 1
334.02 328.79 272.2 306.99 347.79 % Centroid 2
I want to now compute the euclidean distances of each point to each centroid, then assign each point to it's closest centroid and display this on a graph. Let's say I want I want to classify the centroids as blue and green. How can I do this in MATLAB? If this was Java I would initialise each row as an object and add to separate ArrayLists (representing the clusters).
If rows 1, 2 and 3 all belong to the first centroid / cluster, and rows 4, 5 and 6 belong to the second centroid / cluster - how can I classify these to display them as blue or green points on a graph? I am new to MATLAB and really curious about this. Thanks for any help.
(To begin with, Matlab has a flexible distance measuring function, pdist2 and also kmeans implementation, but I'm assuming that you want to build your code from scratch).
In Matlab, you try to implement everything as matrix algebra, without loops over elements.
In your case, if R is the raw_data matrix and C is the centroids matrix,
you can shift the dimension that represents centroid number to the 3rd place by
permC=permute(C,[3 2 1]); Then the bsxfun function allows you to subtract C from R while expanding R's third dimension as necessary: D=bsxfun(#minus,R,permC). Element-wise square followed by summation across columns SqD=sum(D.^2,2) will give you the squared distances of each observation from each centroid. Performing all these operations within a single statement and shifting the third (centroid) dimension back to the 2nd place will look like this:
SqD=permute(sum(bsxfun(#minus,R,permute(C,[3 2 1])).^2,2),[1 3 2])
Picking the centroid of minimal distance is now straightforward: [minDist,minCentroid]=min(SqD,[],2)
If this looks complex, I recommend inspecting the product of each sub-step and reading the help of each command.
This is the link that explain to solve inverse kinematics using ANFIS
http://www.mathworks.com/help/fuzzy/examples/modeling-inverse-kinematics-in-a-robotic-arm.html
But the example is only for 2 DOFs Robot. How to make the data set if the robot using 4 motors?
Because there is always an error that says :"Error using meshgrid. Too many input arguments." when running the code:
a= 0:(1*pi/180):(180*pi/180);
b= 0:(1*pi/180):(180*pi/180);
c= 0:(1*pi/180):(180*pi/180);
d= (25*180/pi):(1*pi/180):(180*pi/180);
[THETA1, THETA2, THETA3, THETA4] = meshgrid(a, b, c, d);
Any Suggestion will be appreciated
Thanks!
meshgrid is specifically for 2D or 3D data. For arbitrary n-dimensional data, the appropriately-named ndgrid is the guy you want.
Note that meshgrid is intended for working intuitively with Cartesian X,Y{,Z} data, so swaps the first two dimensions in the shape of its output to reflect X,Y order rather than row,column. ndgrid, being more general, just gives you standard multidimensional matrix order.
My aim is to classify types of cars (Sedans,SUV,Hatchbacks) and earlier I was using corner features for classification but it didn't work out very well so now I am trying Gabor features.
code from here
Now the features are extracted and suppose when I give an image as input then for 5 scales and 8 orientations I get 2 [1x40] matrices.
1. 40 columns of squared Energy.
2. 40 colums of mean Amplitude.
Problem is I want to use these two matrices for classification and I have about 230 images of 3 classes (SUV,sedan,hatchback).
I do not know how to create a [N x 230] matrix which can be taken as vInputs by the neural netowrk in matlab.(where N be the total features of one image).
My question:
How to create a one dimensional image vector from the 2 [1x40] matrices for one image.(should I append the mean Amplitude to square energy matrix to get a [1x80] matrix or something else?)
Should I be using these gabor features for my purpose of classification in first place? if not then what?
Thanks in advance
In general, there is nothing to think about - simple neural network requires one dimensional feature vector and does not care about the ordering, so you can simply concatenate any number of feature vectors into one (and even do it in random order - it does not matter). In particular if you have same feature matrices you also concatenate each of its row to create a vectorized format.
The only exception is when your data actually has some underlying geometrical dependicies, for example - matrix is actualy a pixels matrix. In such case architectures like PyraNet, Convolutional Neural Networks and others, which apply some kind of receptive fields based on this 2d structure - should be better. But those implementations simply accept 2d feature vector as an input.
I have the Rotation matrix and the translation vector between the 2 cameras .Is there a way to find out the 4 X 4 disparity-to-depth mapping matrix using Matlab ?
I used this link for finding the R and T parameter values between the two cameras.
You can always compile OpenCv and use it in matlab as external DLL.