assertEquals(0, v1.getDistanceSquared(dv1), FUZZ); assertEquals(dv1.zSum() - dv1.size() * 3.4, v1.assign(Functions.minus(3.4)).zSum(), FUZZ); assertEquals(dv1.zSum() - dv1.size() * 4.5, v1.assign(Functions.MINUS, 1.1).zSum(), FUZZ); v1.assign(dv1);
@Override public Vector classify(Vector instance) { Vector result = classifyNoLink(instance); // Convert to probabilities by exponentiation. double max = result.maxValue(); result.assign(Functions.minus(max)).assign(Functions.EXP); result = result.divide(result.norm(1)); return result.viewPart(1, result.size() - 1); }
@Override public Vector classify(Vector instance) { Vector result = classifyNoLink(instance); // Convert to probabilities by exponentiation. double max = result.maxValue(); result.assign(Functions.minus(max)).assign(Functions.EXP); result = result.divide(result.norm(1)); return result.viewPart(1, result.size() - 1); }
@Override public Vector classify(Vector instance) { Vector result = classifyNoLink(instance); // Convert to probabilities by exponentiation. double max = result.maxValue(); result.assign(Functions.minus(max)).assign(Functions.EXP); result = result.divide(result.norm(1)); return result.viewPart(1, result.size() - 1); }
/** * Computes the inverse link function, by default the logistic link function. * * @param v The output of the linear combination in a GLM. Note that the value * of v is disturbed. * @return A version of v with the link function applied. */ public static Vector link(Vector v) { double max = v.maxValue(); if (max >= 40) { // if max > 40, we subtract the large offset first // the size of the max means that 1+sum(exp(v)) = sum(exp(v)) to within round-off v.assign(Functions.minus(max)).assign(Functions.EXP); return v.divide(v.norm(1)); } else { v.assign(Functions.EXP); return v.divide(1 + v.norm(1)); } }
/** * Computes the inverse link function, by default the logistic link function. * * @param v The output of the linear combination in a GLM. Note that the value * of v is disturbed. * @return A version of v with the link function applied. */ public static Vector link(Vector v) { double max = v.maxValue(); if (max >= 40) { // if max > 40, we subtract the large offset first // the size of the max means that 1+sum(exp(v)) = sum(exp(v)) to within round-off v.assign(Functions.minus(max)).assign(Functions.EXP); return v.divide(v.norm(1)); } else { v.assign(Functions.EXP); return v.divide(1 + v.norm(1)); } }
/** * Computes the inverse link function, by default the logistic link function. * * @param v The output of the linear combination in a GLM. Note that the value * of v is disturbed. * @return A version of v with the link function applied. */ public static Vector link(Vector v) { double max = v.maxValue(); if (max >= 40) { // if max > 40, we subtract the large offset first // the size of the max means that 1+sum(exp(v)) = sum(exp(v)) to within round-off v.assign(Functions.minus(max)).assign(Functions.EXP); return v.divide(v.norm(1)); } else { v.assign(Functions.EXP); return v.divide(1 + v.norm(1)); } }