private MLCell histoDataHeadersAsMLChar(List<String> histoDataHeaders) { int colsSize = histoDataHeaders.size() - 2; MLCell injections = new MLCell("inj_ID", new int[]{1, colsSize}); int i = 0; for (String colkey : histoDataHeaders) { if (colkey.equals("forecastTime") || colkey.equals("datetime")) { continue; } injections.set(new MLChar("", colkey), 0, i); i++; } return injections; }
public void set(MLArray value, int m, int n) { cells.set( getIndex(m,n), value ); } public void set(MLArray value, int index)
break; case MLArray.mxCELL_CLASS: MLCell cell = new MLCell(name, dims, type, attributes); for (int i = 0; i < cell.getM() * cell.getN(); i++) { tag = new ISMatTag(buf); if (tag.size > 0) { cell.set(cellmatrix, i); } else { cell.set(new MLEmptyArray(), i); for (MLArray candidate : cellContent.cells()) { if (candidate instanceof MLNumericArray) { binaryContent = (MLNumericArray<?>) candidate; MLStructure structureContent = (MLStructure) wrappedContent; MLCell cellContent = (MLCell) structureContent.getField("Values", 0); binaryContent = (MLNumericArray<?>) cellContent.get(0); } else { throw new IOException("Unexpected array type: " + wrappedContent.name);
System.out.println("Preparing matlab files"); final MLCell wordCell = new MLCell("words", new int[] { wordIndex.size(), 2 }); final MLCell timeCell = new MLCell("times", new int[] { timeIndex.size(), 2 }); final int timeCellIndex = (int) (long) ent.getValue().secondObject(); final long count = ent.getValue().firstObject(); timeCell.set(new MLDouble(null, new double[][] { new double[] { time } }), timeCellIndex, 0); timeCell.set(new MLDouble(null, new double[][] { new double[] { count } }), timeCellIndex, 1); final int wordCellIndex = (int) (long) ent.getValue().secondObject(); final long count = ent.getValue().firstObject(); wordCell.set(new MLChar(null, word), wordCellIndex, 0); wordCell.set(new MLDouble(null, new double[][] { new double[] { count } }), wordCellIndex, 1); wtd.time = Integer.parseInt(line[1]); wtd.idf = new WordDFIDF(); wtd.idf.timeperiod = timeCell.getIndex(wtd.time, 0); wtd.idf.wf = Integer.parseInt(line[2]); wtd.idf.tf = Integer.parseInt(line[3]);
public static void main(String[] args) throws IOException { // MLCell cell = new MLCell("data", new int[]{100000,1}); // Random r = new Random(); // for (int i = 0; i < 100000; i++) { // MLCell inner = new MLCell(null, new int[]{2,1}); // inner.set(new MLChar(null,"Dummy String" + r.nextDouble()), 0, 0); // MLDouble d = new MLDouble(null, new double[][]{new // double[]{r.nextDouble()}}); // inner.set(d, 1, 0); // cell.set(inner, i,0); // } // ArrayList<MLArray> arr = new ArrayList<MLArray>(); // arr.add(cell); // new MatFileWriter( "mat_file.mat", arr); final MatFileReader reader = new MatFileReader("/Users/ss/Development/python/storm-spams/XYs.mat"); final Map<String, MLArray> content = reader.getContent(); final MLCell cell = (MLCell) content.get("XYs"); System.out.println(cell.get(0, 0)); System.out.println(cell.get(0, 1)); } }
public static String[] readStringsArrayFromMat(Path matFile, String stringsArrayName) throws IOException { Objects.requireNonNull(matFile, "mat file is null"); Objects.requireNonNull(stringsArrayName, "strings array name is null"); MatFileReader matFileReader = new MatFileReader(); Map<String, MLArray> matFileContent = matFileReader.read(matFile.toFile()); MLCell stringsArray = (MLCell) matFileContent.get(stringsArrayName); String[] strings = new String[stringsArray.getN()]; for (int i = 0; i < stringsArray.getN(); i++) { strings[i] = ((MLChar) stringsArray.get(0, i)).getString(0); } return strings; }
if(vocLoaded!=null){ this.indexToVoc = new HashMap<Integer, Integer>(); final ArrayList<MLArray> vocArr = vocLoaded.cells(); int index = 0; int vocIndex = 0;
Map<String, MLArray> mcosContent = matFile.getContent(); MLCell mcosInfo = (MLCell) ((MLStructure) mcosContent.get("@0")).getField("MCOS"); ByteBuffer mcosDataBuf = ((MLUInt8) mcosInfo.get(0)).getRealByteBuffer(); break; case 1: property = mcosInfo.get(heapIndex + 2); break; case 2: MLCell attribBag = (MLCell) mcosInfo.get(mcosInfo.getSize() - 1); // Get the grab bag. for (MatMCOSObjectInformation it : objectInfoList.values()) { MLStructure attributes = (MLStructure) attribBag.get(it.classId); Collection<String> attributeNames = attributes.getFieldNames(); Map<String, MLArray> objAttributes = it.structure;
public int getIndex(int m, int n) { return m+n*getM(); } public ArrayList<MLArray> cells()
break; case MLArray.mxCELL_CLASS: MLCell cell = new MLCell(name, dims, type, attributes); for (int i = 0; i < cell.getM() * cell.getN(); i++) { tag = new ISMatTag(buf); if (tag.size > 0) { cell.set(cellmatrix, i); } else { cell.set(new MLEmptyArray(), i); for (MLArray candidate : cellContent.cells()) { if (candidate instanceof MLNumericArray) { binaryContent = (MLNumericArray<?>) candidate; MLStructure structureContent = (MLStructure) wrappedContent; MLCell cellContent = (MLCell) structureContent.getField("Values", 0); binaryContent = (MLNumericArray<?>) cellContent.get(0); } else { throw new IOException("Unexpected array type: " + wrappedContent.name);
System.out.println("Preparing matlab files"); final MLCell wordCell = new MLCell("words", new int[] { wordIndex.size(), 2 }); final MLCell timeCell = new MLCell("times", new int[] { timeIndex.size(), 2 }); final int timeCellIndex = (int) (long) ent.getValue().secondObject(); final long count = ent.getValue().firstObject(); timeCell.set(new MLDouble(null, new double[][] { new double[] { time } }), timeCellIndex, 0); timeCell.set(new MLDouble(null, new double[][] { new double[] { count } }), timeCellIndex, 1); final int wordCellIndex = (int) (long) ent.getValue().secondObject(); final long count = ent.getValue().firstObject(); wordCell.set(new MLChar(null, word), wordCellIndex, 0); wordCell.set(new MLDouble(null, new double[][] { new double[] { count } }), wordCellIndex, 1); wtd.time = Integer.parseInt(line[1]); wtd.idf = new WordDFIDF(); wtd.idf.timeperiod = timeCell.getIndex(wtd.time, 0); wtd.idf.wf = Integer.parseInt(line[2]); wtd.idf.tf = Integer.parseInt(line[3]);
public static void main(String[] args) throws IOException { // MLCell cell = new MLCell("data", new int[]{100000,1}); // Random r = new Random(); // for (int i = 0; i < 100000; i++) { // MLCell inner = new MLCell(null, new int[]{2,1}); // inner.set(new MLChar(null,"Dummy String" + r.nextDouble()), 0, 0); // MLDouble d = new MLDouble(null, new double[][]{new // double[]{r.nextDouble()}}); // inner.set(d, 1, 0); // cell.set(inner, i,0); // } // ArrayList<MLArray> arr = new ArrayList<MLArray>(); // arr.add(cell); // new MatFileWriter( "mat_file.mat", arr); final MatFileReader reader = new MatFileReader("/Users/ss/Development/python/storm-spams/XYs.mat"); final Map<String, MLArray> content = reader.getContent(); final MLCell cell = (MLCell) content.get("XYs"); System.out.println(cell.get(0, 0)); System.out.println(cell.get(0, 1)); } }
private void prepareFolds() { final MLArray setfolds = this.content.get("set_fold"); if(setfolds==null) return; if (setfolds.isCell()) { this.folds = new ArrayList<Fold>(); final MLCell foldcells = (MLCell) setfolds; final int nfolds = foldcells.getM(); System.out.println(String.format("Found %d folds", nfolds)); for (int i = 0; i < nfolds; i++) { final MLDouble training = (MLDouble) foldcells.get(i, 0); final MLDouble test = (MLDouble) foldcells.get(i, 1); final MLDouble validation = (MLDouble) foldcells.get(i, 2); final Fold f = new Fold(toIntArray(training), toIntArray(test), toIntArray(validation)); folds.add(f); } } else { throw new RuntimeException( "Can't find set_folds in expected format"); } }