I'm quite weak in math so I hope you don't mind that I'll try to fully describe how I think when solving this (I think easy) problem. Please tell me if I made some totally invalid assumptions.

I have some data - a slope of a linear regression curve of a price of a particular commodity in stock exchange.

This is the data plot.

data = importdata('E:\data.txt');

Unscaled data plot

These data are used as the training data for a neural network. And since the NN uses tanh as the activation function, I need to rescale these data to the range -1 to 1. I've managed to do that.

dmin = min(data);
dmax = max(data);
dataScaled = ((data-dmin)./(dmax-dmin) - 0.5 ) *2;

And the plot of the scaled data:


Wrongly scaled dataplot

This plot is wrong though, the linear regression slope by nature oscilates around 0, scaling by the maximum and minimum shifted the oscilation center down because the maximum and minimum values were different.

So I looked at the maximum and minimum and saw this.

dmax = 3.7348
dmin = -1.8465

I told myself that I cannot rescale by asymetric minimum and maximum...so I thought I'll take the one furthest away from zero and use that with opposite sign for the second value.

Since |dmax| > |dmin| then

dmin = -dmax;

Now that both values are the same distance from zero, I'm going to rescale by that and hopefuly the rescaled values will oscillate around zero.

dataScaled = ((data-dmin)./(dmax-dmin) - 0.5 ) *2;

Data scaled the right way

And now the problem.

The standard deviation of the scaled data is 0.0553 - that's very wrong (I discovered that in my previous question here). My neural network is not learning anything becuase the standard values are pushed near zero. Well, I guess the NN is learning something but on a scale so small that it makes working with the neural network difficult (at least difficult for me).

So I thought I have to ...somehow rescale it, logarithmically, in a way that the logarithm is going from 0 to positive values the same way it goes from 0 to negative values.

The standard deviation is 0.0553 ... so most values oscillate between -0.0553 to 0.0553.

I'd like to convert the vector in a way that the oscillation from -0.0553 to 0.0553 stretches to the range, say, -0.8 to 0.8 - I'd like to test more ranges to see which one I like the most - and values above or below the standard deviation are compressed. How do I do that in matlab?

Does my question make sense? Just tell me and I'll be hopefully able to rephrase it.


Just read from "And now the problem".


2 Answers 2


You could normalise your data by subtracting the mean and dividing by a multiple of the standard deviation such that say 95% of your training data lies in the range -1 to 1. It's not necessary to ensure that all data lies in this range, just the majority so that the training can be faster. The actual mean and standard deviation values will need to be recorded so that they can be applied as a data pre-processing step to new, unseen data.


Would applying $\tanh(a x)$ to your data solve your problem? $a$ should probably be something like $(2\sigma)^{-1}$ where $\sigma$ is the standard deviation of your data.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.