@Test public void testSparseNormalizeColumnsL2() { DoubleMatrix2D unnormalisedColumns = nonZeroColumnMatrix(); MatrixUtils.normalizeSparseColumnL2(unnormalisedColumns, null); checkL2Normalization(unnormalisedColumns); }
public static DoubleMatrix2D normalizeSparseColumnL2( final DoubleMatrix2D A, final double[] work) { final double[] w = prepareWork(A, work); A.forEachNonZero( new IntIntDoubleFunction() { @Override public double apply(int row, int column, double value) { w[column] += value * value; return value; } }); for (int c = 0; c < A.columns(); c++) { w[c] = Math.sqrt(w[c]); } A.forEachNonZero( new IntIntDoubleFunction() { @Override public double apply(int row, int column, double value) { A.setQuick(row, column, value / w[column]); return 0; } }); return A; }
MatrixUtils { public static DoubleMatrix2D normalizeSparseColumnL2( final DoubleMatrix2D A, final double[] work) { final double[] w = prepareWork(A, work); A.forEachNonZero( new IntIntDoubleFunction() { @Override public double apply(int row, int column, double value) { w[column] += value * value; return value; } }); for (int c = 0; c < A.columns(); c++) { w[c] = Math.sqrt(w[c]); } A.forEachNonZero( new IntIntDoubleFunction() { @Override public double apply(int row, int column, double value) { A.setQuick(row, column, value / w[column]); return 0; } }); return A; } }
MatrixUtils { public static DoubleMatrix2D normalizeSparseColumnL2( final DoubleMatrix2D A, final double[] work) { final double[] w = prepareWork(A, work); A.forEachNonZero( new IntIntDoubleFunction() { @Override public double apply(int row, int column, double value) { w[column] += value * value; return value; } }); for (int c = 0; c < A.columns(); c++) { w[c] = Math.sqrt(w[c]); } A.forEachNonZero( new IntIntDoubleFunction() { @Override public double apply(int row, int column, double value) { A.setQuick(row, column, value / w[column]); return 0; } }); return A; }  }
MatrixUtils { public static DoubleMatrix2D normalizeSparseColumnL2( final DoubleMatrix2D A, final double[] work) { final double[] w = prepareWork(A, work); A.forEachNonZero( new IntIntDoubleFunction() { @Override public double apply(int row, int column, double value) { w[column] += value * value; return value; } }); for (int c = 0; c < A.columns(); c++) { w[c] = Math.sqrt(w[c]); } A.forEachNonZero( new IntIntDoubleFunction() { @Override public double apply(int row, int column, double value) { A.setQuick(row, column, value / w[column]); return 0; } }); return A; }  static DoubleMatrix2D normalizeColumnL2(DoubleMatrix2D A, double[] work); static DoubleMatrix2D normalizeSparseColumnL2(
      final DoubleMatrix2D A, final double[] work); static DoubleMatrix2D normalizeColumnL1(DoubleMatrix2D A, double[] work); static double computeOrthogonality(DoubleMatrix2D A); static double computeSparseness(DoubleMatrix2D A); static int[] minInColumns(DoubleMatrix2D A, int[] indices, double[] minValues); static int[] maxInColumns(DoubleMatrix2D A, int[] indices, double[] maxValues); static int[] maxInColumns(
      DoubleMatrix2D A, int[] indices, double[] maxValues, DoubleFunction transform); static int maxInRow(DoubleMatrix2D A, int row); static double[] sumRows(DoubleMatrix2D A, double[] sums); static double frobeniusNorm(DoubleMatrix2D matrix); static DoubleMatrix2D sortedRowsView(
      DoubleMatrix2D matrix, IndirectComparator comparator); }
MatrixUtils { public static DoubleMatrix2D normalizeSparseColumnL2( final DoubleMatrix2D A, final double[] work) { final double[] w = prepareWork(A, work); A.forEachNonZero( new IntIntDoubleFunction() { @Override public double apply(int row, int column, double value) { w[column] += value * value; return value; } }); for (int c = 0; c < A.columns(); c++) { w[c] = Math.sqrt(w[c]); } A.forEachNonZero( new IntIntDoubleFunction() { @Override public double apply(int row, int column, double value) { A.setQuick(row, column, value / w[column]); return 0; } }); return A; }  static DoubleMatrix2D normalizeColumnL2(DoubleMatrix2D A, double[] work); static DoubleMatrix2D normalizeSparseColumnL2(
      final DoubleMatrix2D A, final double[] work); static DoubleMatrix2D normalizeColumnL1(DoubleMatrix2D A, double[] work); static double computeOrthogonality(DoubleMatrix2D A); static double computeSparseness(DoubleMatrix2D A); static int[] minInColumns(DoubleMatrix2D A, int[] indices, double[] minValues); static int[] maxInColumns(DoubleMatrix2D A, int[] indices, double[] maxValues); static int[] maxInColumns(
      DoubleMatrix2D A, int[] indices, double[] maxValues, DoubleFunction transform); static int maxInRow(DoubleMatrix2D A, int row); static double[] sumRows(DoubleMatrix2D A, double[] sums); static double frobeniusNorm(DoubleMatrix2D matrix); static DoubleMatrix2D sortedRowsView(
      DoubleMatrix2D matrix, IndirectComparator comparator);  }