List of usage examples for org.apache.commons.math.linear Array2DRowRealMatrix getColumnDimension
@Override public int getColumnDimension()
From source file:org.micromanager.plugins.magellan.propsandcovariants.LaserPredNet.java
public byte[] forwardPass(double[][] x) { double[] ones = new double[x.length]; Arrays.fill(ones, 1.0);//w w w .j a v a 2s. c o m Array2DRowRealMatrix onesMat = new Array2DRowRealMatrix(ones); //assume x is properly normalized new Array2DRowRealMatrix(x[0]); Array2DRowRealMatrix xMat = (Array2DRowRealMatrix) MatrixUtils.createRealMatrix(x); Array2DRowRealMatrix h = xMat.multiply(W1_).add(onesMat.multiply(B1_)); relu(h); Array2DRowRealMatrix z = (Array2DRowRealMatrix) h.multiply(W2_.transpose()).add(onesMat.multiply(B2_)); byte[] powers = new byte[z.getRowDimension() * z.getColumnDimension()]; for (int i = 0; i < powers.length; i++) { powers[i] = (byte) Math.max(0, Math.min(255, z.getEntry(i, 0))); } return powers; }
From source file:org.micromanager.plugins.magellan.propsandcovariants.LaserPredNet.java
private static void relu(Array2DRowRealMatrix activations) { for (int r = 0; r < activations.getRowDimension(); r++) { for (int c = 0; c < activations.getColumnDimension(); c++) { if (activations.getEntry(r, c) < 0) { activations.setEntry(r, c, 0.0); }// w w w. java2 s. c o m } } }