How to reverse data normalized with bsx function

I used the code below to normalise the targets to perform RVM regression.
mn1 = mean(yTest);
sd1 = std(yTest);
sd1(sd1==0) = 1;
ynV = bsxfun(@minus,yTest,mn1);
ynV = bsxfun(@rdivide,ynV,sd1);
Can you please help to extract the predicted targets ..Thank you..

2 comentarios

Iain
Iain el 22 de Mayo de 2013
I don't understand your question...
Greg Heath
Greg Heath el 24 de Mayo de 2013
Editada: Greg Heath el 24 de Mayo de 2013
What is RVM?
size(yTest) = ?
help zscore
doc zscore

Iniciar sesión para comentar.

 Respuesta aceptada

José-Luis
José-Luis el 22 de Mayo de 2013
Editada: José-Luis el 22 de Mayo de 2013
your_original_data = bsxfun(@times,ynV,sd1);
your_original_data = bsxfun(@plus,your_original_data,mn1);
What is the purpose of sd1(sd1==0) = 1 ? If that is really what you meant then, you also need to store the indexes of the affected values:
mn1 = mean(yTest);
sd1 = std(yTest);
idx = find(sd1 == 0);
sd1(sd1==0) = 1;
ynV = bsxfun(@minus,yTest,mn1);
ynV = bsxfun(@rdivide,ynV,sd1);
your_original_data = bsxfun(@times,ynV,sd1);
your_original_data(idx) = 0;
your_original_data = bsxfun(@plus,your_original_data,mn1);

6 comentarios

Diana
Diana el 22 de Mayo de 2013
Editada: Diana el 22 de Mayo de 2013
Thanks for your answer Jose-Luis.I just implemented the code from http://stackoverflow.com/questions/4521593/fast-technique-for-normalizing-a-matrix-in-matlab?rq=1 without understanding the physical meaning of it. am a complete novice in this....The code i developed for performing rvm regression is as below...all i need is the original data that is predicted in dataSetOutTrain and dataSetOutTest which are in normalised form
%% Generate data:
clear all;
close all;
% Training data:
xTrain = xlsread('RVM data.xlsx','test');
yTrain = xlsread('RVM data.xlsx','Sheet12');
mn = mean(yTrain);
sd = std(yTrain);
idx = find(sd == 0);
sd(sd==0) = 1;
ynT = bsxfun(@minus,yTrain,mn);
ynT = bsxfun(@rdivide,ynT,sd);
dsTrain = prtDataSetRegress(xTrain,ynT);
% Testing data:
xTest = xlsread('RVM data.xlsx','val');
yTest = xlsread('RVM data.xlsx','Sheet13'); mn1 = mean(yTest); sd1 = std(yTest);
idx = find(sd1 == 0);
sd1(sd1==0) = 1;
ynV = bsxfun(@minus,yTest,mn1);
ynV = bsxfun(@rdivide,ynV,sd1);
dsTest = prtDataSetRegress(xTest,ynV);
%regress regress = prtRegressRvm;
kernels = prtKernelDc & prtKernelRbfNdimensionScale('sigma', 2);
reg.kernels = kernels
regress = regress.train(dsTrain);
dataSetOutTrain = regress.run(dsTrain);
dataSetOutTest = regress.run(dsTest);
tOut =bsxfun(@times,dataSetOutTrain.targets,sd);
yTrainout = bsxfun(@plus,tOut,mn);
vOut =bsxfun(@times,dataSetOutTest.targets,sd1);
yTestout = bsxfun(@plus,vOut,mn1);
The last part of the code(tOut and vOut) just gives me the exact values of yTrain and yTest
José-Luis
José-Luis el 22 de Mayo de 2013
Editada: José-Luis el 22 de Mayo de 2013
That is what I understood you had asked, how to reverse the normalization. I don't understand what you actually want to achieve.
I insist that sd1(sd1==0) = 1 makes no sense. Why would you want to set the standard deviation equal to 1 when it is equal to 0?
Please look at this article on normalization:
What it says is :
norm_data = (data - mean(data)) / std(data)
What I gave you is:
data = (norm_data * std(data)) + mean(data)
The only difference is that you apply it column by column to your matrix.
If you get the exact same values, it might mean that you model your data perfectly.
Diana
Diana el 23 de Mayo de 2013
Thank you for explaining me... I now understand and have corrected the "sd code". Let me explain with what I am trying to achieve....I am trying to predict values by training the RVM model with a MxN input variables and Mx1 target vector. I then validate data sets and obtain predictions. RVM requires target vectors(in training &Validation) to be normalised and returns its targets in dataSetOutTRain and dataSetOutTest as normalised values. What puzzles me is when I get exact values how come these errors ???? rmseTrain = 0.0512 ; rmseTest = 0.9868; trnMAE = 0.0039; chkMAE = 0.1296; trnR = 0.9991;chkR = 0.1479; covT = 37.1067;covV = -2.4692; Is everything right with the coding and its sequence...I hope am clear with the point..
José-Luis
José-Luis el 23 de Mayo de 2013
That's a totally different question than what's in your original post. I have never used genetic algorithms or neural networks. That being said, I have two questions:
  • Are you sure you are comparing the right things? If you compare your data after normalizing/de-normalizing it they are bound to be very similar, albeit perhaps not identical.
  • If you are comparing the right things, are you actually comparing their stored values and not looking at the display editor? Even if the same value is displayed, the stored value might differ. Please try _ data(:)-result(:) _ to see if they are actually the same.
Diana
Diana el 23 de Mayo de 2013
I now found my error...i was actually comparing the stored values...it should have been the "data" instead of "targets" in code....you are great!!!thanks a lot for your time answering me!!!!Cheers
José-Luis
José-Luis el 23 de Mayo de 2013
Glad to help.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Arduino Hardware en Centro de ayuda y File Exchange.

Preguntada:

el 22 de Mayo de 2013

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by