I made the following HTML nd javascript to predict $f(n) = 2n$. Basically, I am trying to design my first neural network which predicts 2 multiplied by a number. I know we don't need a neural network for this, but just for a beginner, can you tell how I can make it work properly? For example, when I input 2 it gives $89.7614166111441$. What's wrong with my implementation?
Here's my HTML file.
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<script src="l1.js" charset="utf-8"></script>
<script type="text/javascript">
//aa();alert(wheights[1]);
//amulth(lh);
/*alert(famulth([1,2],2,[0,0]));
alert(amulth([2,1],[1,2],[1,1]));
alert(amulth([2],[0],[1]));*/
//alert(eamulth([2,2],[2,2],[1,1]));
var n = 0;
var nn = 0;
var nnn = 0;
var nnnn = 0;
while (nnn < 100000000 /*0*/ ) {
nnnn = Math.round(100 * Math.random());
n = eamulth(lh1, amulth(lhlh, famulth(lh, nnnn + 0 /**parseFloat(prompt("Enter a number"))*/ , lh1lh), lhl), lh1l);
//alert(n);
/*n=1;*/
nn = /*parseFloat(prompt(""+n))*/ 2 * nnnn - n;
lh = t(lh, nn, 0.1);
lh1 = t(lh1, nn, 0.01);
/*lh1l=t(lh1l,nn,0.01);
lhl=t(lhl,nn,0.01);*/
nnn++;
//alert(lh);
lhlh = t(lhlh, nn, 0.01);
lh1lh = t(lh1lh, nn, 0.01);
}
alert(eamulth(lh1, famulth(lh, parseFloat(prompt("Enter a number")), lhl), lh1l));
alert(eamulth(lh1, amulth(lhlh, famulth(lh, nnnn + 0 /**parseFloat(prompt("Enter a number"))*/ , lh1lh), lhl), lh1l));
</script>
</body>
</html>
Here's the Javascript file.
//l1.js
//function aa(){alert('aa');}
var lh = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
var lh1 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
var lhl = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
var lh1l = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
lh = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1];
lh1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1];
lhl = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1];
lh1l = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1];
var lhlh = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1];
var lh1lh = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1];
function amulth(hh, hhh, aa) {
/*alert(hh[0]);*/
var ta = [];
var s = 0;
for (var i = 0; i < hh.length; i++) {
for (var j = 0; j < hhh.length; j++) {
s += hhh[j] * hh[i];
}
s += 0 + 0 + aa[i];
ta.push(s);
s = 0;
}
return ta;
}
function famulth(hh1, hhh1, aa1) {
/*alert(hh[0]);*/
var ta1 = [];
for (var i1 = 0; i1 < hh1.length; i1++) {
ta1.push(hh1[i1] * hhh1 + aa1[i1]);
}
return ta1;
}
function eamulth(hh2, hhh2, aa) {
/*alert(hh[0]);*/
var ta2 = 0;
for (var i2 = 0; i2 < hh2.length; i2++) {
ta2 += hhh2[i2] * hh2[i2] + aa[i2];
}
return ta2;
}
function t(hh3, d1, lhhhh) {
for (var il = 0; il < hh3.length; il++) {
hh3[il] = hh3[il] + d1 * lhhhh * 0.0001;
}
return hh3;
}