Autoencoder in MATLAB - matlab

My goal is to train an Autoencoder in Matlab. I am using the Deep Learning Toolbox. I am new to both autoencoders and Matlab, so please bear with me if the question is trivial.
My input datasets is a list of 2000 time series, each with 501 entries for each time component. So my input dataset is stored into an array called inputdata which has dimensions 2000*501.
The autoencoder should reproduce the time series. Thi means the output should be 2000 times a time series of 501 components. So, my understanding is that the input nodes should be 501 and the same should be true for the output nodes.
However, if I do:
hiddenSize = 100;
autoenc = trainAutoencoder(y_sorted,hiddenSize);
to train an autoencoder with 100 nodes in the hidden layer, I think the Autoencoder automatically chooses to have 2000 input nodes. What is the correct way of training this Autoencoder?

Hi I haven't tried to train an autoencoder myself with the Deeplearning toolbox, but as far as i can read here (https://www.mathworks.com/help/deeplearning/ref/trainautoencoder.html?s_tid=doc_ta) your input matrix should have the samples as columns and the features/values of your timeseries in the rows. You can do this easy by transposing your input matrix. In MATLAB this is done by:
inputdata = inputdata.'

Related

SVM Classifications on set of images of digits in Matlab

I have to use SVM classifier on digits dataset. The dataset consists of images of digits 28x28 and a toal of 2000 images.
I tried to use svmtrain but the matlab gave an error that svmtrain has been removed. so now i am using fitcsvm.
My code is as below:
labelData = zeros(2000,1);
for i=1:1000
labelData(i,1)=1;
end
for j=1001:2000
labelData(j,1)=1;
end
SVMStruct =fitcsvm(trainingData,labelData)
%where training data is the set of images of digits.
I need to know how i can predict the outputs of test data using svm? Further is my code correct?
The function that you are looking for is predict. It takes the SVM-object as input followed by a data-matrix and returns the predicted labels.
Make sure that you do not train your model on all data but on a reasonable subset (usually 70%). You can use the cross-validation preparation:
% create cross-validation object
cvp = cvpartition(Lbl,'HoldOut',0.3);
% extract logical vectors for training and testing data
lgTrn = cvp.training;
lgTst = cvp.test;
% train SVM
mdl = fitcsvm(Dat(lgTrn,:),Lbl(lgTrn));
% test / predict SVM
Lbl_prd = predict(mdl,Dat(lgTst,:));
Note that your labeling produces a single vector of ones.
The reason why The Mathworks changed svmtrain to fitcsvm is conciseness. It is now clear whether it is "classification" (fitcsvm) or "regression" (fitrsvm).

Simulink neural network data input

I have a 2x147 matrix as an input and a 3x147 matrix as an output, and I trained the NN pattern recognition with the input matrix and output matrix. I then generated a Simulink model of the trained NN, and now I want to test the new dataset of same size (2x147).
I am getting the following errors:
Error in port widths or dimensions. Output port 1 of NN_Trail/Constant is a [2x147] matrix.
Error in port widths or dimensions. Input port 1 of NN_Trail/Pattern Recognition Neural Network is a one dimensional vector with 2 elements.
If I give a constant value of 2 elements, then the Simulink runs for the mentioned time and gives the desired output. How can I get it to work with the data I've described?
My idea in future is to connect the trained neural network to a simulated plant and find the abnormal data from the plant.
So your model has an input of dimenstion 2 and an output of dimenson 3.
And you have an calculated signal of 147 timesteps that you want to run on the inputs.
To import that signal to your model you can use a Matlab time series object.
http://ch.mathworks.com/help/simulink/ug/importing-matlab-timeseries-data-to-a-root-level-input-port.html

Matlab predict function not working

I am trying to train a linear SVM on a data which has 100 dimensions. I have 80 instances for training. I train the SVM using fitcsvm function in MATLAB and check the function using predict on the training data. When I classify the training data with the SVM all the data points are being classified into only one class.
SVM = fitcsvm(votes,b,'ClassNames',unique(b)');
predict(SVM,votes);
This gives outputs as all 0's which corresponds to 0th class. b contains 1's and 0's indicating the class to which each data point belongs.
The data used, i.e. matrix votes and vector b are given the following link
Make sure you use a non-linear kernel, such as a gaussian kernel and that the parameters of the kernel are tweaked. Just as a starting point:
SVM = fitcsvm(votes,b,'KernelFunction','RBF', 'KernelScale','auto');
bp = predict(SVM,votes);
that said you should split your set in a training set and a testing set, otherwise you risk overfitting

how to predict the values at future timesteps in matlab ntstool

I have to use NAR network to train a time-series for my project. To have an idea of how time-series tool (ntstool) works in MATLAB , I used the GUI of ntstool in matlab with a dataset containing 427 timesteps of one element. While training I used a neural network with 10 hidden layers and delay value = 5.
Now I have following Three questions :
What does the **delay value (d) ** in the GUI means. Does it mean that while training the network assumes that each timestep value is dependent on last 'd' timesteps' values ?
how to predict the values at future timesteps in ntstool?
Delay value means that neural network inputs are current input value and N delay values of input signals, in your case N=5. Hope this will help you.

Matlab train svm regressor using LIBVM with a sparse matrix of text

I am conducting a Bag Of Words analysis where I have a sparse matrix of 80x60452, where 1:80 represent the number of days for the text collected on each day. This matrix represents a collection of tweets on a particular day. The experiment is part of a univariate time series prediction and im not to sure how to implement this.
I am using the Text Matrix Generator (TMG) to construct this sparse matrix which will be used agains a response column vector of price observations(80x1).
I will use a the first 70 observations to train the SVM regressor to predict future price instances given a test data set of the remaining instances.
For example:
T = (length(priceData)-10);
trainBoW = BoW(1:T,1:end);
testBoW = BoW(T+1:end,1:end);
trainPrice = pData(1:T);
testPrice = pData(T+1:end);
model = svmtrain(trainBoW, trainPrice,'-c 1 -g 0.07 -b 1');
Running this code throws the error:
Error using svmtrain (line 274)
SVMTRAIN only supports classification into two groups. GROUP contains 62 groups.
How can I train a SVM regression model using libsvm to predict future price instances ?