@Override final public Vector dotTimes( final Vector v) { // By switch from this.dotTimes(v) to v.dotTimes(this), we get sparse // vectors dotted with dense still being sparse and dense w/ dense is // still dense. The way this was originally implemented in the Foundry // (this.clone().dotTimesEquals(v)), if v is sparse, it returns a // dense vector type storing sparse data. Vector result = v.clone(); result.dotTimesEquals(this); return result; }
@Override final public Vector dotTimes( final Vector v) { // By switch from this.dotTimes(v) to v.dotTimes(this), we get sparse // vectors dotted with dense still being sparse and dense w/ dense is // still dense. The way this was originally implemented in the Foundry // (this.clone().dotTimesEquals(v)), if v is sparse, it returns a // dense vector type storing sparse data. Vector result = v.clone(); result.dotTimesEquals(this); return result; }
@Override final public Vector dotTimes( final Vector v) { // By switch from this.dotTimes(v) to v.dotTimes(this), we get sparse // vectors dotted with dense still being sparse and dense w/ dense is // still dense. The way this was originally implemented in the Foundry // (this.clone().dotTimesEquals(v)), if v is sparse, it returns a // dense vector type storing sparse data. Vector result = v.clone(); result.dotTimesEquals(this); return result; }
/** * Evaluates the weighted Euclidean distance between two vectors. * * @param first * The first vector. * @param second * The second vector. * @return * The weighted Euclidean distance between the two vectors. */ @Override public double evaluate( final Vectorizable first, final Vectorizable second) { // \sqrt(\sum_i w_i * (x_i - y_i)^2) // First compute the difference between the two vectors. final Vector difference = first.convertToVector().minus(second.convertToVector()); // Now square it. difference.dotTimesEquals(difference); // Now compute the square root of the weights times the squared // difference. return Math.sqrt(this.weights.dotProduct(difference)); }
/** * Evaluates the weighted Euclidean distance between two vectors. * * @param first * The first vector. * @param second * The second vector. * @return * The weighted Euclidean distance between the two vectors. */ @Override public double evaluate( final Vectorizable first, final Vectorizable second) { // \sqrt(\sum_i w_i * (x_i - y_i)^2) // First compute the difference between the two vectors. final Vector difference = first.convertToVector().minus(second.convertToVector()); // Now square it. difference.dotTimesEquals(difference); // Now compute the square root of the weights times the squared // difference. return Math.sqrt(this.weights.dotProduct(difference)); }
/** * Evaluates the weighted Euclidean distance between two vectors. * * @param first * The first vector. * @param second * The second vector. * @return * The weighted Euclidean distance between the two vectors. */ @Override public double evaluate( final Vectorizable first, final Vectorizable second) { // \sqrt(\sum_i w_i * (x_i - y_i)^2) // First compute the difference between the two vectors. final Vector difference = first.convertToVector().minus(second.convertToVector()); // Now square it. difference.dotTimesEquals(difference); // Now compute the square root of the weights times the squared // difference. return Math.sqrt(this.weights.dotProduct(difference)); }
nextDelta.dotTimesEquals(bn); nextDelta.scaleEquals( 1.0/nextDelta.norm1() );
nextDelta.dotTimesEquals(bn); nextDelta.scaleEquals( 1.0/nextDelta.norm1() );
weights.dotTimesEquals(globalWeights);
weights.dotTimesEquals(globalWeights);
weights.dotTimesEquals(globalWeights);
alphaNext.dotTimesEquals(b);
alphaNext.dotTimesEquals(b);
alpha.dotTimesEquals(b); final double weight = alpha.norm1(); alpha.scaleEquals(1.0/weight);
alpha.dotTimesEquals(b); final double weight = alpha.norm1(); alpha.scaleEquals(1.0/weight);
alpha.dotTimesEquals(b); final double weight = alpha.norm1(); alpha.scaleEquals(1.0/weight);
/** * Computes the Viterbi recursion for a given "delta" and "b" * @param delta * Previous value of the Viterbi recursion. * @param bn * Current observation likelihood. * @return * Updated "delta" and state backpointers. */ protected Pair<Vector,int[]> computeViterbiRecursion( Vector delta, Vector bn ) { final int k = delta.getDimensionality(); final Vector dn = VectorFactory.getDefault().createVector(k); final int[] psi = new int[ k ]; for( int i = 0; i < k; i++ ) { WeightedValue<Integer> transition = this.findMostLikelyState(i, delta); psi[i] = transition.getValue(); dn.setElement(i, transition.getWeight()); } dn.dotTimesEquals( bn ); delta = dn; delta.scaleEquals( 1.0/delta.norm1() ); return DefaultPair.create( delta, psi ); }
/** * Computes the Viterbi recursion for a given "delta" and "b" * @param delta * Previous value of the Viterbi recursion. * @param bn * Current observation likelihood. * @return * Updated "delta" and state backpointers. */ protected Pair<Vector,int[]> computeViterbiRecursion( Vector delta, Vector bn ) { final int k = delta.getDimensionality(); final Vector dn = VectorFactory.getDefault().createVector(k); final int[] psi = new int[ k ]; for( int i = 0; i < k; i++ ) { WeightedValue<Integer> transition = this.findMostLikelyState(i, delta); psi[i] = transition.getValue(); dn.setElement(i, transition.getWeight()); } dn.dotTimesEquals( bn ); delta = dn; delta.scaleEquals( 1.0/delta.norm1() ); return DefaultPair.create( delta, psi ); }
/** * Computes the Viterbi recursion for a given "delta" and "b" * @param delta * Previous value of the Viterbi recursion. * @param bn * Current observation likelihood. * @return * Updated "delta" and state backpointers. */ protected Pair<Vector,int[]> computeViterbiRecursion( Vector delta, Vector bn ) { final int k = delta.getDimensionality(); final Vector dn = VectorFactory.getDefault().createVector(k); final int[] psi = new int[ k ]; for( int i = 0; i < k; i++ ) { WeightedValue<Integer> transition = this.findMostLikelyState(i, delta); psi[i] = transition.getValue(); dn.setElement(i, transition.getWeight()); } dn.dotTimesEquals( bn ); delta = dn; delta.scaleEquals( 1.0/delta.norm1() ); return DefaultPair.create( delta, psi ); }