public (FloatArray errorL, FloatArray errorR, FloatArray errorC, FloatArray2D dws, FloatArray2D dwhp, FloatArray2D dwhc, FloatArray2D dwpl, FloatArray2D dwpr, FloatArray2D dwc, FloatArray dbh, FloatArray dbc, FloatArray dbp) ComputeErrorNBackWard(FloatArray s, FloatArray p, FloatArray c, FloatArray h, FloatArray pl, FloatArray pr, FloatArray cx, FloatArray targetScore) { var ce = s - targetScore; var des = ActivationFunctions.Dsigmoid(s) * ce; var bkpS = (des * wS).SumColumn(); var deh = ActivationFunctions.Dtanh(h) * bkpS; var bkpHp = (deh * wHP).SumColumn(); var bkpHc = (deh * wHC).SumColumn(); var dep = ActivationFunctions.Dtanh(p) * bkpHp; var bkpPl = (dep * wpl).SumColumn(); var bkpPr = (dep * wpr).SumColumn(); var dec = ActivationFunctions.Dtanh(c) * bkpHc; var bkpC = (dec * wC).SumColumn(); var dws = (h.T * des); var dwhp = (p.T * deh); var dwhc = (c.T * deh); var dwpl = (pl.T * dep); var dwpr = (pr.T * dep); var dwc = (cx.T * dec); return(bkpPl, bkpPr, bkpC, dws, dwhp, dwhc, dwpl, dwpr, dwc, deh, dec, dep); }
ComputeErrorNBackWard(FloatArray p, FloatArray score, FloatArray inputs, FloatArray target) { var loss = 1 * (score - target).Pow(2).Sum(); var ce = score - target; var deScore = ActivationFunctions.Dsigmoid(score) * ce; var error = (deScore * wScore).SumColumn(); var de = ActivationFunctions.Dtanh(p) * error; var dh = (de * w).SumColumn(); var backProp = dh.Split(2); var dwScore = (p.T * deScore); var dw = (inputs.T * de); return(loss, backProp[0], backProp[0], dw, dwScore, de);