Mathematica for machine learning - Learning a map
Mathematica newly introduced machine learning to its kitty. And I was excited to see its capabilities! So I decided to test its RNN abilities..to begin with (Really RNN!).
So here is a simple problem for Mathematica's RNN chain to learn - A simple map 2x Mod 1.
You start with a number say 'x' the next number in the series is 2*x modulus 1. That multiplies the number by 2 and take only the decimal parts (remove the integer part).
Ex. x=1.2 , 2x mod 1 = 0.4
The question I tried to ask was that does the RNN learn the map after some iterations?
Here is the code for doing the training:
f [x_] := Mod[2*x, 1];
data = NestList[f, 0.1, 100];
n = 1;
training =
RandomSample[
List /@ Most[#] -> List@Last[#] & /@ (Partition[data, n + 1, 1])];
net = NetChain[{GatedRecurrentLayer[40], GatedRecurrentLayer[40],
GatedRecurrentLayer[40], GatedRecurrentLayer[40],
GatedRecurrentLayer[20], GatedRecurrentLayer[20],
GatedRecurrentLayer[20], GatedRecurrentLayer[20], LinearLayer[1]},
"Input" -> {n, 1}, "Output" -> 1]
trained = NetTrain[net, training, TargetDevice -> "CPU"]
trainedmap [x_] := Flatten[Append[Rest[x], trained[x]]];
Here is the plot of the result where predicted is in blue and ground truth in yellow. I gave RNN an initial condition then its output was used over and over again.

And Now the deeper question did it actually learn the function?

The Red is the original function and the blue what RNN learns.
Can you make it better and learn the complete function!? That's for some other time.
Posts
-
Sets of Learning
-
Policy Gradient Algorithm
-
Visit to Weston Park Sheffield
-
Notes on Inverse transform sampling
-
Eigenvalues and poles
-
Back Prop Algorithm - What remains constant in derivatives
-
Wordpress to Jekyll Conversion
-
Phase functions
-
Solving Dynamical Systems in Javascript
-
Javascript on markdown file
-
Walking data
-
Walking, it is complicated
-
PRC
-
Isochrone
-
Walking, it's complicated
-
Newtons iteration as a map - Part 2
-
Newton's iteration as map - Part 1
-
ChooseRight
-
Mathematica for machine learning - Learning a map
-
Prediction and Detection, A Note
-
Why we walk ?
-
The equations that fall in love!
-
Oru cbi diarykkuripp(ഒരു സിബിഐ ഡയറിക്കുറിപ്പ്)
-
A way to detect your stress levels!!
-
In search of the cause in motor control
-
Compressive sensing - the most magical of signal processing.
-
Machine Learning using python in 5 lines
-
Can we measure blood pressure from radial artery pulse?
subscribe via RSS