public List<MLArray> smallsignalMLArray(Double stepMin, Double varMin, Double f1, Double f2, Double d1, Double d2, Double d3, Double nm, Double fInstant, Double fDuration) { MLDouble mStepMin = new MLDouble("step_min", new double[]{stepMin}, 1); MLDouble mVarMin = new MLDouble("var_min", new double[]{varMin}, 1); MLDouble mF = new MLDouble("f", new double[]{f1, f2}, 1); MLDouble mD = new MLDouble("d", new double[]{d1, d2, d3}, 1); MLDouble mNm = new MLDouble("Nm", new double[]{nm}, 1); MLDouble mFInstant = new MLDouble("f_instant", new double[] {fInstant}, 1); MLDouble mFDuration = new MLDouble("f_duration", new double[] {fDuration}, 1); List<MLArray> mlarray = Arrays.asList(mStepMin, mVarMin, mF, mD, mNm, mFInstant, mFDuration); return mlarray; }
/** * Gets two-dimensional real array. * * @return - 2D real array */ public double[][] getArray() { double[][] result = new double[getM()][]; for ( int m = 0; m < getM(); m++ ) { result[m] = new double[ getN() ]; for ( int n = 0; n < getN(); n++ ) { result[m][n] = getReal(m,n); } } return result; } /**
public synchronized double getDouble(long... coordinates) { return matrix.get(getIndex(coordinates)); }
public Double buldFromBytes(byte[] bytes) { if ( bytes.length != getBytesAllocated() ) { throw new IllegalArgumentException( "To build from byte array I need array of size: " + getBytesAllocated() ); } return ByteBuffer.wrap( bytes ).getDouble(); } public byte[] getByteArray(Double value)
@Test public void testMultipleDimArrayRealWIndicesFromMatlabCreatedFile() throws IOException { int ndims = 5; int[] dims = new int[]{2, 3, 4, 5, 6}; File file = getTestFile("multiDimMatrix.mat"); MatFileReader reader = new MatFileReader(file); MLDouble mlArray = (MLDouble) reader.getMLArray("in"); int testNDims = mlArray.getNDimensions(); Assert.assertEquals(ndims, testNDims); int[] testDims = mlArray.getDimensions(); for (int i = 0; i < ndims; i++) { Assert.assertEquals(dims[i], testDims[i]); } Double expectedVal = 0.0; for (int i = 0; i < dims[4]; i++) { for (int j = 0; j < dims[3]; j++) { for (int k = 0; k < dims[2]; k++) { for (int l = 0; l < dims[1]; l++) { for (int m = 0; m < dims[0]; m++, expectedVal += 1.0) { Double actual = mlArray.get(m, l, k, j, i); Assert.assertEquals(expectedVal, actual); } } } } } }
@Test public void testMultipleDimArrayRealFromMatlabCreatedFile() throws IOException { int ndims = 5; int[] dims = new int[]{2, 3, 4, 5, 6}; File file = getTestFile("multiDimMatrix.mat"); MatFileReader reader = new MatFileReader(file); MLDouble mlArray = (MLDouble) reader.getMLArray("in"); int testNDims = mlArray.getNDimensions(); Assert.assertEquals(ndims, testNDims); int[] testDims = mlArray.getDimensions(); for (int i = 0; i < ndims; i++) { Assert.assertEquals(dims[i], testDims[i]); } Double expectedVal = 0.0; for (int i = 0; i < dims[4]; i++) { for (int j = 0; j < dims[3]; j++) { for (int k = 0; k < dims[2]; k++) { for (int l = 0; l < dims[1]; l++) { for (int m = 0; m < dims[0]; m++, expectedVal += 1.0) { Double actual = mlArray.get(mlArray.getIndex(m, l, k, j, i)); Assert.assertEquals(expectedVal, actual); } } } } } }
/** * <a href="http://math.nist.gov/javanumerics/jama/">Jama</a> [math.nist.gov] style: * construct a matrix from a one-dimensional packed array * * @param name - array name * @param vals - One-dimensional array of doubles, packed by columns (ala Fortran). * @param m - Number of rows */ public MLDouble(String name, double[] vals, int m) { this(name, castToDouble(vals), m); }
/** * <a href="http://math.nist.gov/javanumerics/jama/">Jama</a> [math.nist.gov] style: * construct a 2D real matrix from <code>double[][]</code> * * Note: array is converted to Double[] * * @param name - array name * @param vals - two-dimensional array of values */ public MLDouble(String name, double[][] vals) { this(name, double2DToDouble(vals), vals.length); }
assertThat(((MLChar) dataO.get("function_name")).getString(0), equalTo("quad_fcn_subtype")); assertThat(((MLChar) dataO.get("function_inputs")).getString(0), equalTo("c,a,b:{x:real|(a=0 => x /= 0) AND (a /= 0 => (x^2) - 4*a*c >= 0)}")); assertThat(((MLDouble) dataO.get("open")).get(0), equalTo(0.0)); assertThat(((MLDouble) dataO.get("fig")).getSize(), equalTo(0)); // This field should just exist, but be empty! assertThat(((MLDouble) dataO.get("multi_mode")).get(0), equalTo(1.0)); assertThat(((MLDouble) dataO.get("checked")).get(0), equalTo(0.0)); assertThat(((MLDouble) settings.getField("set")).get(0), equalTo(1.0)); assertThat((settings.getField("inputs")), instanceOf(MLDouble.class)); assertThat(((MLDouble) settings.getField("count")).get(0), equalTo(1000.0)); assertThat(((MLDouble) settings.getField("range")).get(0), equalTo(100.0)); assertThat(((MLDouble) settings.getField("except")).get(0), equalTo(0.0)); Map<String, MLArray> gridO = Grid2.getFields(0); assertThat(((MLDouble) gridO.get("num_cells")).get(0), equalTo(2.0)); assertThat(gridO.get("split_pb").getSize(), equalTo(0)); assertThat(gridO.get("parent_grid").getSize(), equalTo(0)); assertThat(gridO.get("delete_cell_pb").getSize(), equalTo(0)); assertThat(((MLObject) gridO.get("rGrid")).getFields(0), equalTo(((MLObject) dataO.get("Grid0")).getFields(0))); assertThat(((MLDouble) gridO.get("grid_index")).get(0), equalTo(2.0));
public synchronized void setDouble(double value, long... coordinates) { matrix.set(value, getIndex(coordinates)); }
/** * Gets two-dimensional real array. * * @return - 2D real array */ public double[][] getArray() { double[][] result = new double[getM()][]; for ( int m = 0; m < getM(); m++ ) { result[m] = new double[ getN() ]; for ( int n = 0; n < getN(); n++ ) { result[m][n] = getReal(m,n); } } return result; } /**
public static void main(String[] args) throws IOException { final Map<Integer, String> database = readDatabase(); final File outbase = new File("/Users/jon/Data/lfw/matlab-fvs/"); for (int i = 1; i <= 128; i++) { final File chunk = new File( "/Users/jon/Downloads/data/lfw_aligned/SIFT_1pix_PCA64_GMM512/features/poolfv/1/", String.format( "feat_%d-v6.mat", i)); System.out.println(chunk); final MatFileReader reader = new MatFileReader(chunk); final MLSingle feats = (MLSingle) reader.getMLArray("chunk"); final MLDouble index = (MLDouble) reader.getMLArray("index"); for (int j = 0; j < index.getN(); j++) { final int id = (int) (double) index.get(0, j); final File outfile = new File(outbase, database.get(id).replace(".jpg", ".bin")); outfile.getParentFile().mkdirs(); final float[] vec = new float[feats.getM()]; for (int k = 0; k < feats.getM(); k++) { vec[k] = feats.get(k, j); } final FloatFV fv = new FloatFV(vec); IOUtils.writeBinary(outfile, fv); } } }
private void prepareDayPolls() { final ArrayList<String> pollKeys = FilterUtils.filter(this.content.keySet(), new Predicate<String>() { @Override public boolean test(String object) { return object.endsWith("per_unique_extended"); } }); this.ntasks = pollKeys.size(); dayPolls = new ArrayList<Matrix>(); for (int i = 0; i < this.ndays; i++) { dayPolls.add(SparseMatrixFactoryMTJ.INSTANCE.createMatrix(1, this.ntasks)); } this.tasks = new String[this.ntasks]; for (int t = 0; t < this.ntasks; t++) { final String pollKey = pollKeys.get(t); this.tasks[t] = pollKey; final MLDouble arr = (MLDouble) this.content.get(pollKey); for (int i = 0; i < this.ndays; i++) { final Matrix dayPoll = dayPolls.get(i); dayPoll.setElement(0, t, arr.get(i, 0)); } } }
public Double buldFromBytes(byte[] bytes) { if ( bytes.length != getBytesAllocated() ) { throw new IllegalArgumentException( "To build from byte array I need array of size: " + getBytesAllocated() ); } return ByteBuffer.wrap( bytes ).getDouble(); } public byte[] getByteArray(Double value)