@Override public double calculateLoss(DoubleMatrix y, DoubleMatrix hypothesis) { return y.subtract(hypothesis).sum() / y.getRowCount(); }
@Override public double calculateLoss(DoubleMatrix y, DoubleMatrix hypothesis) { return y.multiplyElementWise(MathUtils.logMatrix(hypothesis)).sum() / y.getRowCount(); }
public static double calculateRegularization(DoubleMatrix[] thetas, final int m, NetworkConfiguration conf) { double regularization = 0d; // only calculate the regularization term if lambda is not 0 if (conf.lambda != 0d) { for (DoubleMatrix theta : thetas) { regularization += (theta.slice(0, theta.getRowCount(), 1, theta.getColumnCount())).pow(2).sum(); } regularization = (conf.lambda / (2.0d * m)) * regularization; } return regularization; }
@Override public double calculateLoss(DoubleMatrix y, DoubleMatrix hypothesis) { DoubleMatrix negativeOutcome = y.subtractBy(1.0d); DoubleMatrix inverseOutcome = y.multiply(-1d); DoubleMatrix negativeHypo = hypothesis.subtractBy(1d); DoubleMatrix negativeLogHypo = MathUtils.logMatrix(negativeHypo); DoubleMatrix positiveLogHypo = MathUtils.logMatrix(hypothesis); DoubleMatrix negativePenalty = negativeOutcome .multiplyElementWise(negativeLogHypo); DoubleMatrix positivePenalty = inverseOutcome .multiplyElementWise(positiveLogHypo); return (positivePenalty.subtract(negativePenalty)).sum() / y.getRowCount(); }
double j = data.subtract(negativeData).pow(2).sum();