Java 类org.apache.commons.math3.linear.RealMatrixPreservingVisitor 实例源码

项目:incubator-hivemall    文件:MatrixUtils.java   
@Nonnull
public static double[] flatten(@Nonnull final RealMatrix[] grid) {
    Preconditions.checkArgument(grid.length >= 1, "The number of rows must be greather than 1");

    final int rows = grid.length;
    RealMatrix grid0 = grid[0];
    Preconditions.checkNotNull(grid0);
    int cellRows = grid0.getRowDimension();
    int cellCols = grid0.getColumnDimension();

    final DoubleArrayList list = new DoubleArrayList(rows * cellRows * cellCols);
    final RealMatrixPreservingVisitor visitor = new DefaultRealMatrixPreservingVisitor() {
        @Override
        public void visit(int row, int column, double value) {
            list.add(value);
        }
    };

    for (int row = 0; row < rows; row++) {
        RealMatrix cell = grid[row];
        cell.walkInRowOrder(visitor);
    }

    return list.toArray();
}
项目:pacaya    文件:WeightedIntDiGraph.java   
public static WeightedIntDiGraph fromMatrix(RealMatrix m) {
    WeightedIntDiGraph g = new WeightedIntDiGraph();
    m.walkInOptimizedOrder(new RealMatrixPreservingVisitor() {

        @Override
        public void visit(int row, int column, double value) {
            if (value != 0.0) {
                g.addEdge(row, column, value);
            }
        }

        @Override
        public void start(int rows, int columns, int startRow, int endRow, int startColumn, int endColumn) {
            // do nothing
        }

        @Override
        public double end() {
            // do nothing
            return 0;
        }
    });
    return g;
}
项目:incubator-hivemall    文件:MatrixUtils.java   
@Nonnull
public static double[] flatten(@Nonnull final RealMatrix[][] grid) {
    Preconditions.checkArgument(grid.length >= 1, "The number of rows must be greather than 1");
    Preconditions.checkArgument(grid[0].length >= 1,
        "The number of cols must be greather than 1");

    final int rows = grid.length;
    final int cols = grid[0].length;
    RealMatrix grid00 = grid[0][0];
    Preconditions.checkNotNull(grid00);
    int cellRows = grid00.getRowDimension();
    int cellCols = grid00.getColumnDimension();

    final DoubleArrayList list = new DoubleArrayList(rows * cols * cellRows * cellCols);
    final RealMatrixPreservingVisitor visitor = new DefaultRealMatrixPreservingVisitor() {
        @Override
        public void visit(int row, int column, double value) {
            list.add(value);
        }
    };

    for (int row = 0; row < rows; row++) {
        for (int col = 0; col < cols; col++) {
            RealMatrix cell = grid[row][col];
            cell.walkInRowOrder(visitor);
        }
    }

    return list.toArray();
}
项目:CRISIS    文件:InputOutputMatrix.java   
public double walkInColumnOrder(
   RealMatrixPreservingVisitor arg0,
   int arg1,
   int arg2,
   int arg3,
   int arg4
   ) throws OutOfRangeException, NumberIsTooSmallException {
   return matrix.walkInColumnOrder(
      arg0,
      arg1,
      arg2,
      arg3,
      arg4
      );
}
项目:CRISIS    文件:InputOutputMatrix.java   
public double walkInOptimizedOrder(
   RealMatrixPreservingVisitor arg0,
   int arg1,
   int arg2,
   int arg3,
   int arg4
   ) throws OutOfRangeException, NumberIsTooSmallException {
   return matrix.walkInOptimizedOrder(
      arg0,
      arg1,
      arg2,
      arg3,
      arg4);
}
项目:CRISIS    文件:InputOutputMatrix.java   
public double walkInRowOrder(
   RealMatrixPreservingVisitor arg0,
   int arg1,
   int arg2,
   int arg3,
   int arg4
   ) throws OutOfRangeException, NumberIsTooSmallException {
   return matrix.walkInRowOrder(
      arg0,
      arg1,
      arg2,
      arg3,
      arg4
      );
}
项目:oryx    文件:ClusterValidityStatistics.java   
/**
 * Calculates the normalized variation-of-information for the contingency contingencyMatrix.
 *
 * @return the normalized variation-of-information for the contingency contingencyMatrix
 */
private static double normVarInformation(
    RealMatrix contingencyMatrix,
    final double[] rowSums,
    final double[] colSums,
    final double n) {
  double den = n * (entropy(rowSums, n) + entropy(colSums, n));
  if (den == 0) {
    return Double.NaN;
  }

  double num = contingencyMatrix.walkInOptimizedOrder(new RealMatrixPreservingVisitor() {
    private double sum = 0.0;
    @Override
    public void start(int rows, int columns, int startRow, int endRow, int startColumn, int endColumn) {
      sum = 0.0;
    }

    @Override
    public void visit(int row, int column, double value) {
      if (value > 0.0) {
        sum += value * (Math.log(value * n) - Math.log(rowSums[row]) - Math.log(colSums[column]));
      }
    }

    @Override
    public double end() {
      return sum;
    }
  });

  return 1.0 + 2.0 * (num / den);
}
项目:CRISIS    文件:InputOutputMatrix.java   
public double walkInColumnOrder(RealMatrixPreservingVisitor arg0) {
   return matrix.walkInColumnOrder(arg0);
}
项目:CRISIS    文件:InputOutputMatrix.java   
public double walkInOptimizedOrder(RealMatrixPreservingVisitor arg0) {
   return matrix.walkInOptimizedOrder(arg0);
}
项目:CRISIS    文件:InputOutputMatrix.java   
public double walkInRowOrder(RealMatrixPreservingVisitor arg0) {
   return matrix.walkInRowOrder(arg0);
}