@Override public void transformNonZerosEquals( final UnivariateScalarFunction function) { // Default implementation uses an iterator. However, specialized // sub-classes can add optimizations. for (final VectorEntry entry : this) { final double value = entry.getValue(); if (value != 0.0) { entry.setValue(function.evaluate(value)); } } }
/** * @param vec * @return checks elements using {@link Double#isNaN()} */ public static boolean containsNaN(Vector vec) { for (final VectorEntry vectorEntry : vec) { if (Double.isNaN(vectorEntry.getValue())) { return true; } } return false; }
@Override public void transformNonZerosEquals( final UnivariateScalarFunction function) { // Default implementation uses an iterator. However, specialized // sub-classes can add optimizations. for (final VectorEntry entry : this) { final double value = entry.getValue(); if (value != 0.0) { entry.setValue(function.evaluate(value)); } } }
/** * Get the minimum element value * * @param column * the vector * @return the min value */ public static double min(Vector column) { double min = Double.MAX_VALUE; for (final VectorEntry vectorEntry : column) { min = Math.min(min, vectorEntry.getValue()); } return min; }
@Override public void transformNonZerosEquals( final UnivariateScalarFunction function) { // Default implementation uses an iterator. However, specialized // sub-classes can add optimizations. for (final VectorEntry entry : this) { final double value = entry.getValue(); if (value != 0.0) { entry.setValue(function.evaluate(value)); } } }
/** * Get the maximum element value * * @param column * the vector * @return the max value */ public static double max(Vector column) { double max = -Double.MAX_VALUE; for (final VectorEntry vectorEntry : column) { max = Math.max(max, vectorEntry.getValue()); } return max; }
public Vector computeLocalWeights( final Vector counts) { // Create the vector to hold the result. final Vector result = this.getVectorFactory().copyVector(counts); // Compute the local weight, which is log(1 + count) for each term. for (VectorEntry entry : result) { final double value = entry.getValue(); if (value > 0.0) { entry.setValue(Math.log(1.0 + value)); } else if (value != 0.0) { entry.setValue(0.0); } } return result; }
/** * Prints the SparseVector in "Index: Value" format. * * @return String containing the representation of the SparseVector */ @Override public String toString() { final StringBuffer result = new StringBuffer(); for ( VectorEntry e : this ) { result.append("(" + e.getIndex() + "): " + e.getValue() + "\n"); } return result.toString(); }
@Override public void transformNonZerosEquals( final IndexValueTransform function) { // Default implementation uses an iterator. However, specialized // sub-classes can add optimizations. for (final VectorEntry entry : this) { final double value = entry.getValue(); if (value != 0.0) { entry.setValue(function.transform(entry.getIndex(), value)); } } }
public Vector computeLocalWeights( final Vector counts) { // Create the vector to hold the result. final Vector result = this.getVectorFactory().copyVector(counts); // Compute the local weight, which is log(1 + count) for each term. for (VectorEntry entry : result) { final double value = entry.getValue(); if (value > 0.0) { entry.setValue(Math.log(1.0 + value)); } else if (value != 0.0) { entry.setValue(0.0); } } return result; }
/** * Prints the SparseVector in "Index: Value" format. * * @return String containing the representation of the SparseVector */ @Override public String toString() { final StringBuffer result = new StringBuffer(); for ( VectorEntry e : this ) { result.append("(" + e.getIndex() + "): " + e.getValue() + "\n"); } return result.toString(); }