res = {
let losses = []
for(let e=0; e<epochs; e++) {
let loss = 0;
let diff = 0;
let regularization = 0;
mlp.zeroGrad();
for(let i=0; i<housePricesNorm.length; i++) {
let sample = housePricesNorm[i];
let input = [new Value(parseFloat(sample.LotArea)),
new Value(parseFloat(sample.OverallQual)),
new Value(parseFloat(sample.SalePrice))];
let target = new Value(parseFloat(sample.SalePrice));
let score = mlp.calc(input)[0];
let mse = pow(sub(score, target), 2);
let reg = mul(new Value(alpha), mlp.parameters().reduce((acc, current) => add(acc, pow(current, 2)), new Value(0)));
let result = div(add(mse, reg), new Value(housePricesNorm.length));
result.backward()
diff += mse.data;
regularization += reg.data;
loss += result.data
}
losses.push({epoch: e, loss: loss})
mlp.parameters().forEach(p => {p.data -= lr * p.grad});
yield {
log: losses,
network: mlp
};
}
}