/** * L2 normalize a counter in place. * * @param c The {@link Counter} to be L2 normalized. This counter is modified * @return the passed in counter l2-normalized */ public static <E> Counter<E> L2NormalizeInPlace(Counter<E> c) { return multiplyInPlace(c, 1.0 / L2Norm(c)); }
/** * Takes all the support vectors, and their corresponding alphas, and computes a weight * vector that can be used in a vanilla LinearClassifier. This only works because * we are using a linear kernel. The Counter is over the feature indices (+1 cos for * some reason svm_light is 1-indexed), not features. */ private static ClassicCounter<Integer> getWeights(List<Pair<Double, ClassicCounter<Integer>>> supportVectors) { ClassicCounter<Integer> weights = new ClassicCounter<>(); for (Pair<Double, ClassicCounter<Integer>> sv : supportVectors) { ClassicCounter<Integer> c = new ClassicCounter<>(sv.second()); Counters.multiplyInPlace(c, sv.first()); Counters.addInPlace(weights, c); } return weights; }
Counter<String> weights = logcl.weightsAsCounter(); if (l.equals(Boolean.FALSE.toString())) { Counters.multiplyInPlace(weights, -1);
logpos_i.setCount(en.getKey(), Math.log(en.getValue().size())); Counters.multiplyInPlace(currentPatternWeights4Label, logpos_i);
/** * L2 normalize a counter in place. * * @param c The {@link Counter} to be L2 normalized. This counter is modified * @return the passed in counter l2-normalized */ public static <E> Counter<E> L2NormalizeInPlace(Counter<E> c) { return multiplyInPlace(c, 1.0 / L2Norm(c)); }
/** * L2 normalize a counter in place. * * @param c The {@link Counter} to be L2 normalized. This counter is modified * @return the passed in counter l2-normalized */ public static <E> Counter<E> L2NormalizeInPlace(Counter<E> c) { return multiplyInPlace(c, 1.0 / L2Norm(c)); }
/** * Normalizes the target counter in-place, so the sum of the resulting values * equals 1. * * @param <E> Type of elements in Counter */ public static <E> void normalize(Counter<E> target) { multiplyInPlace(target, 1.0 / target.totalCount()); }
/** * Normalizes the target counter in-place, so the sum of the * resulting values equals 1. * @param <E> */ public static <E> void normalize(Counter<E> target) { multiplyInPlace(target, 1.0 / target.totalCount()); }
/** L2 normalize a counter in place. * * @param c The {@link Counter} to be L2 normalized. This counter is modified * @return the passed in counter l2-normalized */ public static <E,C extends Counter<E>> Counter<E> L2NormalizeInPlace(Counter<E> c) { return multiplyInPlace(c, 1.0/ L2Norm(c)); }
static public Counter<String> normalize(Counter<String> wts) { Counters.multiplyInPlace(wts, 1.0 / l1norm(wts)); return wts; }
/** * L2 normalize a counter in place. * * @param c The {@link Counter} to be L2 normalized. This counter is modified * @return the passed in counter l2-normalized */ public static <E> Counter<E> L2NormalizeInPlace(Counter<E> c) { return multiplyInPlace(c, 1.0 / L2Norm(c)); }
static public Counter<String> normalize(Counter<String> wts) { Counters.multiplyInPlace(wts, 1.0 / l1norm(wts)); return wts; }
Counters.multiplyInPlace(combinedDir, -1.0); combinedDir.addAll(p[p.length - 1]);
/** * Takes all the support vectors, and their corresponding alphas, and computes a weight * vector that can be used in a vanilla LinearClassifier. This only works because * we are using a linear kernel. The Counter is over the feature indices (+1 cos for * some reason svm_light is 1-indexed), not features. */ private static ClassicCounter<Integer> getWeights(List<Pair<Double, ClassicCounter<Integer>>> supportVectors) { ClassicCounter<Integer> weights = new ClassicCounter<>(); for (Pair<Double, ClassicCounter<Integer>> sv : supportVectors) { ClassicCounter<Integer> c = new ClassicCounter<>(sv.second()); Counters.multiplyInPlace(c, sv.first()); Counters.addInPlace(weights, c); } return weights; }
Counters.multiplyInPlace(combinedDir, -1.0); combinedDir.addAll(p[p.length - 1]);
/** * Takes all the support vectors, and their corresponding alphas, and computes a weight * vector that can be used in a vanilla LinearClassifier. This only works because * we are using a linear kernel. The Counter is over the feature indices (+1 cos for * some reason svm_light is 1-indexed), not features. */ private static ClassicCounter<Integer> getWeights(List<Pair<Double, ClassicCounter<Integer>>> supportVectors) { ClassicCounter<Integer> weights = new ClassicCounter<Integer>(); for (Pair<Double, ClassicCounter<Integer>> sv : supportVectors) { ClassicCounter<Integer> c = new ClassicCounter<Integer>(sv.second()); Counters.multiplyInPlace(c, sv.first()); Counters.addInPlace(weights, c); } return weights; }
/** * Takes all the support vectors, and their corresponding alphas, and computes a weight * vector that can be used in a vanilla LinearClassifier. This only works because * we are using a linear kernel. The Counter is over the feature indices (+1 cos for * some reason svm_light is 1-indexed), not features. */ private static ClassicCounter<Integer> getWeights(List<Pair<Double, ClassicCounter<Integer>>> supportVectors) { ClassicCounter<Integer> weights = new ClassicCounter<Integer>(); for (Pair<Double, ClassicCounter<Integer>> sv : supportVectors) { ClassicCounter<Integer> c = new ClassicCounter<Integer>(sv.second()); Counters.multiplyInPlace(c, sv.first()); Counters.addInPlace(weights, c); } return weights; }
logpos_i.setCount(en.getKey(), Math.log(en.getValue().size())); Counters.multiplyInPlace(currentPatternWeights4Label, logpos_i);
logpos_i.setCount(en.getKey(), Math.log(en.getValue().size())); Counters.multiplyInPlace(currentPatternWeights4Label, logpos_i);