/** * Divides all of the given elements of the vector by the 1-norm (the sum * of the absolute values of the elements). If the 1-norm is zero (which * means all the elements are zero), then the vector is not modified. * * @param vector * The vector to divide the elements by the 1-norm. It is modified by * this method. */ public static void divideByNorm1Equals( final Vector vector) { final double norm1 = vector.norm1(); if (norm1 != 0.0) { vector.scaleEquals(1.0 / norm1); } }
/** * Divides all of the given elements of the vector by the 1-norm (the sum * of the absolute values of the elements). If the 1-norm is zero (which * means all the elements are zero), then the vector is not modified. * * @param vector * The vector to divide the elements by the 1-norm. It is modified by * this method. */ public static void divideByNorm1Equals( final Vector vector) { final double norm1 = vector.norm1(); if (norm1 != 0.0) { vector.scaleEquals(1.0 / norm1); } }
/** * Divides all of the given elements of the vector by the 1-norm (the sum * of the absolute values of the elements). If the 1-norm is zero (which * means all the elements are zero), then the vector is not modified. * * @param vector * The vector to divide the elements by the 1-norm. It is modified by * this method. */ public static void divideByNorm1Equals( final Vector vector) { final double norm1 = vector.norm1(); if (norm1 != 0.0) { vector.scaleEquals(1.0 / norm1); } }
/** * Divides all of the given elements of the vector by the 2-norm (the square * root of the sum of the squared values of the elements). If the 2-norm is * zero (which means all the elements are zero), then the vector is not * modified. * * @param vector * The vector to divide the elements by the 2-norm. It is modified by * this method. */ public static void divideByNorm2Equals( final Vector vector) { final double norm2 = vector.norm2(); if (norm2 != 0.0) { vector.scaleEquals(1.0 / norm2); } }
/** * @param vt * @return mean of each row */ public static Vector rowMean(Matrix vt) { final Vector sumOfColumns = vt.sumOfColumns(); sumOfColumns.scaleEquals(1. / vt.getNumColumns()); return sumOfColumns; }
/** * @param vt * @return mean of each row */ public static Vector colMean(Matrix vt) { final Vector sumOfColumns = vt.sumOfRows(); sumOfColumns.scaleEquals(1. / vt.getNumRows()); return sumOfColumns; }
public Vector computeLocalWeights( final Vector counts) { // Since the counts are positive, the 1-norm of them is their sum. final Vector result = this.vectorFactory.copyVector(counts); final double countSum = counts.norm1(); if (countSum != 0.0) { result.scaleEquals(1.0 / countSum); } return result; }
public Vector computeLocalWeights( final Vector counts) { // Since the counts are positive, the 1-norm of them is their sum. final Vector result = this.vectorFactory.copyVector(counts); final double countSum = counts.norm1(); if (countSum != 0.0) { result.scaleEquals(1.0 / countSum); } return result; }
public Vector computeLocalWeights( final Vector counts) { // Since the counts are positive, the 1-norm of them is their sum. final Vector result = this.vectorFactory.copyVector(counts); final double countSum = counts.norm1(); if (countSum != 0.0) { result.scaleEquals(1.0 / countSum); } return result; }
@Override public Vector computeLocalWeights( final Vector counts) { // Compute the local weights. final Vector result = super.computeLocalWeights(counts); final int dimensionality = result.getDimensionality(); if (dimensionality != 0) { final double average = counts.norm1() / dimensionality; final double divisor = Math.log(1.0 + average); result.scaleEquals(1.0 / divisor); } return result; }
@Override public Vector computeLocalWeights( final Vector counts) { // Compute the local weights. final Vector result = super.computeLocalWeights(counts); final int dimensionality = result.getDimensionality(); if (dimensionality != 0) { final double average = counts.norm1() / dimensionality; final double divisor = Math.log(1.0 + average); result.scaleEquals(1.0 / divisor); } return result; }
@Override public Vector computeLocalWeights( final Vector counts) { // Compute the local weights. final Vector result = super.computeLocalWeights(counts); final int dimensionality = result.getDimensionality(); if (dimensionality != 0) { final double average = counts.norm1() / dimensionality; final double divisor = Math.log(1.0 + average); result.scaleEquals(1.0 / divisor); } return result; }
/** * Updates the initial probabilities from sequenceGammas * @param firstGammas * The first gamma of the each sequence * @return * Updated initial probability Vector for the HMM. */ protected Vector updateInitialProbabilities( ArrayList<Vector> firstGammas ) { RingAccumulator<Vector> pi = new RingAccumulator<Vector>(); for( int k = 0; k < firstGammas.size(); k++ ) { pi.accumulate( firstGammas.get(k) ); } Vector pisum = pi.getSum(); pisum.scaleEquals( 1.0 / pisum.norm1() ); return pisum; }
/** * Updates the initial probabilities from sequenceGammas * @param firstGammas * The first gamma of the each sequence * @return * Updated initial probability Vector for the HMM. */ protected Vector updateInitialProbabilities( ArrayList<Vector> firstGammas ) { RingAccumulator<Vector> pi = new RingAccumulator<Vector>(); for( int k = 0; k < firstGammas.size(); k++ ) { pi.accumulate( firstGammas.get(k) ); } Vector pisum = pi.getSum(); pisum.scaleEquals( 1.0 / pisum.norm1() ); return pisum; }
@Override protected void initialize( final LinearBinaryCategorizer target, final Vector input, final boolean actualCategory) { final double norm = input.norm2(); if (norm != 0.0) { final Vector weights = this.getVectorFactory().copyVector(input); final double actual = actualCategory ? +1.0 : -1.0; weights.scaleEquals(actual / input.norm2()); target.setWeights(weights); } }
@Override protected void initialize( final LinearBinaryCategorizer target, final Vector input, final boolean actualCategory) { final double norm = input.norm2(); if (norm != 0.0) { final Vector weights = this.getVectorFactory().copyVector(input); final double actual = actualCategory ? +1.0 : -1.0; weights.scaleEquals(actual / input.norm2()); target.setWeights(weights); } }
@Override protected void initialize( final LinearBinaryCategorizer target, final Vector input, final boolean actualCategory) { final double norm = input.norm2(); if (norm != 0.0) { final Vector weights = this.getVectorFactory().copyVector(input); final double actual = actualCategory ? +1.0 : -1.0; weights.scaleEquals(actual / input.norm2()); target.setWeights(weights); } }
public Vector computeParameterGradientAmalgamate( Collection<Object> partialResults ) { RingAccumulator<Vector> numerator = new RingAccumulator<Vector>(); double denominator = 0.0; for( Object result : partialResults ) { GradientPartialSSE sse = (GradientPartialSSE) result; numerator.accumulate( sse.getFirst() ); denominator += sse.getSecond(); } Vector scaleSum = numerator.getSum(); if( denominator != 0.0 ) { scaleSum.scaleEquals( 1.0 / (2.0*denominator) ); } return scaleSum; }
public Vector computeParameterGradientAmalgamate( Collection<Object> partialResults ) { RingAccumulator<Vector> numerator = new RingAccumulator<Vector>(); double denominator = 0.0; for( Object result : partialResults ) { GradientPartialSSE sse = (GradientPartialSSE) result; numerator.accumulate( sse.getFirst() ); denominator += sse.getSecond(); } Vector scaleSum = numerator.getSum(); if( denominator != 0.0 ) { scaleSum.scaleEquals( 1.0 / (2.0*denominator) ); } return scaleSum; }
public Vector computeParameterGradientAmalgamate( Collection<Object> partialResults ) { RingAccumulator<Vector> numerator = new RingAccumulator<Vector>(); double denominator = 0.0; for( Object result : partialResults ) { GradientPartialSSE sse = (GradientPartialSSE) result; numerator.accumulate( sse.getFirst() ); denominator += sse.getSecond(); } Vector scaleSum = numerator.getSum(); if( denominator != 0.0 ) { scaleSum.scaleEquals( 1.0 / (2.0*denominator) ); } return scaleSum; }