65 lines
646 B
JavaScript
65 lines
646 B
JavaScript
|
// MLP Function Approximation f(x)=y=x/2^3-5
|
||
|
|
||
|
var x = [
|
||
|
0,
|
||
|
1,
|
||
|
2,
|
||
|
3,
|
||
|
4,
|
||
|
5,
|
||
|
6,
|
||
|
7,
|
||
|
8,
|
||
|
9,
|
||
|
10,
|
||
|
11,
|
||
|
12,
|
||
|
13,
|
||
|
14,
|
||
|
15,
|
||
|
16,
|
||
|
17,
|
||
|
18,
|
||
|
19
|
||
|
];
|
||
|
|
||
|
x=ml.stats.utils.wrap(x);
|
||
|
|
||
|
// y=Math.pow(x/2,3)-5
|
||
|
var y = [
|
||
|
-5,
|
||
|
-4.875,
|
||
|
-4,
|
||
|
-1.625,
|
||
|
3,
|
||
|
10.625,
|
||
|
22,
|
||
|
37.875,
|
||
|
59,
|
||
|
86.125,
|
||
|
120,
|
||
|
161.375,
|
||
|
211,
|
||
|
269.625,
|
||
|
338,
|
||
|
416.875,
|
||
|
507,
|
||
|
609.125,
|
||
|
724,
|
||
|
852.375
|
||
|
];
|
||
|
|
||
|
var model = ml.learn({
|
||
|
algorithm : ml.ML.MLP,
|
||
|
x : x,
|
||
|
y : y,
|
||
|
normalize:true,
|
||
|
regression: true,
|
||
|
epochs : 1000000,
|
||
|
hidden_layers : [3,4]
|
||
|
});
|
||
|
|
||
|
print(model)
|
||
|
print(merge(ml.stats.utils.wrap(ml.predict(model,x)),y,'c'));
|
||
|
|