WOLFRAM NOTEBOOK

Manually construct a net and initialize it with random parameters:
net=NetInitialize@NetChain[{LinearLayer[10],BatchNormalizationLayer[],ElementwiseLayer[Ramp],LinearLayer[10],BatchNormalizationLayer[],ElementwiseLayer[Ramp],LinearLayer[1]},"Input""Scalar","Output""Scalar"]
Out[]=
NetChain
Input
scalar
vector
(size: 1)
1
LinearLayer
vector
(size: 10)
2
BatchNormalizationLayer
vector
(size: 10)
3
Ramp
vector
(size: 10)
4
LinearLayer
vector
(size: 10)
5
BatchNormalizationLayer
vector
(size: 10)
6
Ramp
vector
(size: 10)
7
LinearLayer
vector
(size: 1)
Output
scalar
Evaluate it on a set of values:
net[{1,2,3}]
Out[]=
{0.240015,0.48003,0.720045}
In[]:=
x=Range[-5,5,.01];f:=x.3x^2+2x-4y=f[x];
Train the net for a few rounds checking in real time how it is fitting the model:
trainedNet=NetTrain[net,<|"Input"x,"Output"y|>,MaxTrainingRounds300,TrainingProgressReporting{Function[Plot[{f[x],#Net[x]},{x,-5,5},PlotLegends{HoldForm[f[x]],HoldForm[net[x]]}]],"Interval"1}];
Out[]=
f(x)
net(x)
The net result is now close to the symbolic computation:
trainedNet[{1,2,3}]
Out[]=
{-1.55553,1.0997,4.77498}
f[{1,2,3}]
Out[]=
{-1.7,1.2,4.7}
Wolfram Cloud

You are using a browser not supported by the Wolfram Cloud

Supported browsers include recent versions of Chrome, Edge, Firefox and Safari.


I understand and wish to continue anyway »

You are using a browser not supported by the Wolfram Cloud. Supported browsers include recent versions of Chrome, Edge, Firefox and Safari.