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; }
private void putStochasticVariablesIntoMLStructure(StochasticVariable stochasticVariable, MLStructure stochVars, int i) { LOGGER.debug("Preparing mat data for stochastic variable " + stochasticVariable.getId()); // id MLChar id = new MLChar("", stochasticVariable.getId()); stochVars.setField("id", id, 0, i); // type MLChar type = new MLChar("", stochasticVariable.getType()); stochVars.setField("type", type, 0, i); }
private MLCell injectionTypesAsMLChar(List<StochasticVariable> stochasticVariables) { int colsSize = stochasticVariables.size() * 2; MLCell injectionsTypes = new MLCell("type_ID", new int[]{1, colsSize}); int i = 0; for (StochasticVariable injection : stochasticVariables) { String type = ""; switch (injection.getType()) { case StochasticVariable.TYPE_LOAD: type = "L"; break; case StochasticVariable.TYPE_DISPATCHABLE_GENERATOR: type = "G"; break; default: type = "W"; break; } injectionsTypes.set(new MLChar("", type), 0, i); i++; injectionsTypes.set(new MLChar("", type), 0, i); // twice, for P and Q i++; } return injectionsTypes; }
/** * Write a CSV wordIndex to a {@link MLCell} writen to a .mat data file * * @param path * @throws IOException */ public static void writeToMatlab(String path) throws IOException { final Path wordMatPath = new Path(path + "/words/wordIndex.mat"); final FileSystem fs = HadoopToolsUtil.getFileSystem(wordMatPath); final LinkedHashMap<String, IndependentPair<Long, Long>> wordIndex = readWordCountLines(path); final MLCell wordCell = new MLCell("words", new int[] { wordIndex.size(), 2 }); System.out.println("... reading words"); for (final Entry<String, IndependentPair<Long, Long>> ent : wordIndex.entrySet()) { final String word = ent.getKey(); 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); } final ArrayList<MLArray> list = new ArrayList<MLArray>(); list.add(wordCell); new MatFileWriter(Channels.newChannel(fs.create(wordMatPath)), list); }
private MLCell injectionCountriesAsMLChar(List<StochasticVariable> stochasticVariables) { int colsSize = stochasticVariables.size() * 2; MLCell injectionsCountries = new MLCell("nat_ID", new int[]{1, colsSize}); int i = 0; for (StochasticVariable injection : stochasticVariables) { injectionsCountries.set(new MLChar("", injection.getCountry().name()), 0, i); i++; injectionsCountries.set(new MLChar("", injection.getCountry().name()), 0, i); // twice, for P and Q i++; } return injectionsCountries; }
/** * Write a CSV wordIndex to a {@link MLCell} writen to a .mat data file * * @param path * @throws IOException */ public static void writeToMatlab(String path) throws IOException { final Path wordMatPath = new Path(path + "/words/wordIndex.mat"); final FileSystem fs = HadoopToolsUtil.getFileSystem(wordMatPath); final LinkedHashMap<String, IndependentPair<Long, Long>> wordIndex = readWordCountLines(path); final MLCell wordCell = new MLCell("words", new int[] { wordIndex.size(), 2 }); System.out.println("... reading words"); for (final Entry<String, IndependentPair<Long, Long>> ent : wordIndex.entrySet()) { final String word = ent.getKey(); 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); } final ArrayList<MLArray> list = new ArrayList<MLArray>(); list.add(wordCell); new MatFileWriter(Channels.newChannel(fs.create(wordMatPath)), list); }
switch (flag) { case 0: property = new MLChar(propertyName, strs[heapIndex - 1]); break; case 1:
switch (flag) { case 0: property = new MLChar(propertyName, strs[heapIndex - 1]); break; case 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);
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);
loads.setField("estremo_ID", estremoId, 0, i); MLChar estremo = new MLChar("", loadData.getBusId()); loads.setField("estremo", estremo, 0, i); MLChar codice = new MLChar("", loadData.getLoadId()); loads.setField("codice", codice, 0, i); loads.setField("V", v, 0, i); MLChar country = new MLChar("", loadData.getCountry().name()); loads.setField("nation", country, 0, i);
@Test public void testMLStructureFieldNames() throws IOException { // test column-packed vector double[] src = new double[]{1.3, 2.0, 3.0, 4.0, 5.0, 6.0}; // create 3x2 double matrix // [ 1.0 4.0 ; // 2.0 5.0 ; // 3.0 6.0 ] MLDouble mlDouble = new MLDouble(null, src, 3); MLChar mlChar = new MLChar(null, "I am dummy"); MLStructure mlStruct = new MLStructure("str", new int[]{1, 1}); mlStruct.setField("f1", mlDouble); mlStruct.setField("f2", mlChar); Collection<String> fieldNames = mlStruct.getFieldNames(); assertEquals(2, fieldNames.size()); assertTrue(fieldNames.contains("f1")); assertTrue(fieldNames.contains("f2")); }
/** * Tests filtered reading * * @throws IOException */ @Test public void testFilteredReading() throws IOException { // 1. First create arrays // array name String name = "doublearr"; String name2 = "dummy"; // file name in which array will be storred String fileName = "filter.mat"; double[] src = new double[]{1.3, 2.0, 3.0, 4.0, 5.0, 6.0}; MLDouble mlDouble = new MLDouble(name, src, 3); MLChar mlChar = new MLChar(name2, "I am dummy"); // 2. write arrays to file ArrayList<MLArray> list = new ArrayList<MLArray>(); list.add(mlDouble); list.add(mlChar); new MatFileWriter(getTempFile(fileName), list); // 3. create new filter instance MatFileFilter filter = new MatFileFilter(); filter.addArrayName(name); // 4. read array form file MatFileReader mfr = new MatFileReader(getTempFile(fileName), filter); // check size of Map<String, MLArray> content = mfr.getContent(); assertEquals("Test if only one array was red", 1, content.size()); }
@Test public void testMLCharStringArray() { String[] expected = new String[]{"a", "quick", "brown", "fox"}; MLChar mlchar = new MLChar("array", expected); assertEquals(expected[0], mlchar.getString(0)); assertEquals(expected[1], mlchar.getString(1)); assertEquals(expected[2], mlchar.getString(2)); assertEquals(expected[3], mlchar.getString(3)); }
private void putBusDataIntoMLStructure(BusData busData, MLStructure buses, int i) { LOGGER.debug("Preparing mat data for bus " + busData.getBusId()); MLChar nome = new MLChar("", busData.getBusName()); buses.setField("nome", nome, 0, i); MLChar codice = new MLChar("", busData.getBusId()); buses.setField("codice", codice, 0, i);
@Test public void testMLCharUnicode() throws Exception { // array name String name = "chararr"; // file name in which array will be storred String fileName = "mlcharUTF.mat"; // create MLChar array of a name "chararr" containig one // string value "dummy" MLChar mlChar = new MLChar(name, new String[]{"\u017C\u00F3\u0142w", "\u017C\u00F3\u0142i"}); MatFileWriter writer = new MatFileWriter(); writer.write(getTempFile(fileName), Arrays.asList((MLArray) mlChar)); MatFileReader reader = new MatFileReader(getTempFile(fileName)); MLChar mlChar2 = (MLChar) reader.getMLArray(name); assertEquals("\u017C\u00F3\u0142w", mlChar.getString(0)); assertEquals("\u017C\u00F3\u0142w", mlChar2.getString(0)); assertEquals("\u017C\u00F3\u0142i", mlChar2.getString(1)); }
generators.setField("estremo_ID", estremoId, 0, i); MLChar estremo = new MLChar("", generatorData.getBusId()); generators.setField("estremo", estremo, 0, i); MLChar codice = new MLChar("", generatorData.getGeneratorId()); generators.setField("codice", codice, 0, i); generators.setField("dispacc", dispacc, 0, i); MLChar country = new MLChar("", generatorData.getCountry().name()); generators.setField("nation", country, 0, i);
MLChar mlChar = new MLChar(name, "dummy");
MLChar mlChar = new MLChar(null, "I am dummy");
MLChar mlChar = new MLChar(name2, "none");