本文整理汇总了Java中com.jmatio.types.MLCell类的典型用法代码示例。如果您正苦于以下问题:Java MLCell类的具体用法?Java MLCell怎么用?Java MLCell使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MLCell类属于com.jmatio.types包,在下文中一共展示了MLCell类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeHistoricalData
import com.jmatio.types.MLCell; //导入依赖的package包/类
public void writeHistoricalData(ForecastErrorsHistoricalData forecastErrorsHistoricalData) throws IOException {
Objects.requireNonNull(forecastErrorsHistoricalData, "forecast errors historical data is null");
// LOGGER.debug("Preparing stochastic variables mat data");
// MLStructure stochasticVariables = stochasticVariablesAsMLStructure(forecastErrorsHistoricalData.getStochasticVariables());
LOGGER.debug("Preparing injections mat data");
MLCell injections = histoDataHeadersAsMLChar(forecastErrorsHistoricalData.getForecastsData().columnKeyList());
LOGGER.debug("Preparing injections countries mat data");
MLCell injectionsCountries = injectionCountriesAsMLChar(forecastErrorsHistoricalData.getStochasticVariables());
LOGGER.debug("Preparing forecasts mat data");
MLDouble forecastsData = histoDataAsMLDouble("forec_filt", forecastErrorsHistoricalData.getForecastsData());
LOGGER.debug("Preparing snapshots mat data");
MLDouble snapshotsData = histoDataAsMLDouble("snap_filt", forecastErrorsHistoricalData.getSnapshotsData());
LOGGER.debug("Saving mat data into " + matFile.toString());
List<MLArray> mlarray = new ArrayList<>();
// mlarray.add((MLArray) stochasticVariables );
mlarray.add((MLArray) injections);
mlarray.add((MLArray) forecastsData);
mlarray.add((MLArray) snapshotsData);
mlarray.add((MLArray) injectionsCountries);
MatFileWriter writer = new MatFileWriter();
writer.write(matFile.toFile(), mlarray);
}
示例2: readStringsArrayFromMat
import com.jmatio.types.MLCell; //导入依赖的package包/类
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;
}
示例3: createMLStruct
import com.jmatio.types.MLCell; //导入依赖的package包/类
/** Create ML Structure with data for a channel
* @param index Index of channel in model
* @param name Channel name
* @param times Time stamps
* @param values Values
* @param severities Severities
* @return {@link MLStructure}
*/
private MLStructure createMLStruct(final int index, final String name,
final List<Instant> times,
final List<Double> values,
final List<AlarmSeverity> severities)
{
final MLStructure struct = new MLStructure("channel" + index, new int[] { 1, 1 });
final int N = values.size();
final int[] dims = new int[] { N, 1 };
final MLCell time = new MLCell(null, dims);
final MLDouble value = new MLDouble(null, dims);
final MLCell severity = new MLCell(null, dims);
for (int i=0; i<N; ++i)
{
setCellText(time, i, TimestampHelper.format(times.get(i)));
value.set(values.get(i), i);
setCellText(severity, i, severities.get(i).toString());
}
struct.setField("name", new MLChar(null, name));
struct.setField("time", time);
struct.setField("value", value);
struct.setField("severity", severity);
return struct;
}
示例4: writeToMatlab
import com.jmatio.types.MLCell; //导入依赖的package包/类
/**
* 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);
}
示例5: writeToMatlab
import com.jmatio.types.MLCell; //导入依赖的package包/类
/**
* Write a CSV timeIndex to a {@link MLCell} writen to a .mat data file
* @param path
* @throws IOException
*/
public static void writeToMatlab(String path) throws IOException {
Path timeMatPath = new Path(path + "/times/timeIndex.mat");
FileSystem fs = HadoopToolsUtil.getFileSystem(timeMatPath);
LinkedHashMap<Long, IndependentPair<Long, Long>> timeIndex = readTimeCountLines(path);
MLCell timeCell = new MLCell("times",new int[]{timeIndex.size(),2});
System.out.println("... reading times");
for (Entry<Long, IndependentPair<Long, Long>> ent : timeIndex.entrySet()) {
long time = (long)ent.getKey();
int timeCellIndex = (int)(long)ent.getValue().secondObject();
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);
}
ArrayList<MLArray> list = new ArrayList<MLArray>();
list.add(timeCell);
new MatFileWriter(Channels.newChannel(fs.create(timeMatPath)),list );
}
示例6: main
import com.jmatio.types.MLCell; //导入依赖的package包/类
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));
}
示例7: prepareFolds
import com.jmatio.types.MLCell; //导入依赖的package包/类
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");
}
}
示例8: histoDataHeadersAsMLChar
import com.jmatio.types.MLCell; //导入依赖的package包/类
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;
}
示例9: injectionCountriesAsMLChar
import com.jmatio.types.MLCell; //导入依赖的package包/类
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;
}
示例10: writeMatlabFile2
import com.jmatio.types.MLCell; //导入依赖的package包/类
public void writeMatlabFile2() throws Exception
{
// Example values
final VType[] values = new VType[10];
for (int i=0; i<10; ++i)
values[i] = new ArchiveVNumber(VTypeHelper.getTimestamp(null), AlarmSeverity.NONE, "OK",
ValueFactory.displayNone(),
Math.exp(-((5.0-i)*(5.0-i))) );
// Turn values into Matlab data
final int[] dims = new int[] { values.length, 1 };
final MLDouble value = new MLDouble(null, dims);
final MLCell time = new MLCell(null, dims);
final MLCell severity = new MLCell(null, dims);
final MLCell status = new MLCell(null, dims);
for (int i=0; i<values.length; ++i)
{
value.set(VTypeHelper.toDouble(values[i]), i);
setCellText(time, i, TimestampHelper.format(VTypeHelper.getTimestamp(values[i])));
setCellText(severity, i, VTypeHelper.getSeverity(values[i]).toString());
setCellText(severity, i, VTypeHelper.getMessage(values[i]));
}
final MLStructure struct = new MLStructure("channel0", new int[] { 1, 1 });
struct.setField("value", value);
struct.setField("time", time);
struct.setField("severity", severity);
struct.setField("status", status);
// Write to file
final MatFileIncrementalWriter writer = new MatFileIncrementalWriter("mat_file2.mat");
writer.write(struct);
writer.close();
}
示例11: prepareVocabulary
import com.jmatio.types.MLCell; //导入依赖的package包/类
private void prepareVocabulary() {
this.keepIndex = new HashSet<Integer>();
final MLDouble keepIndex = (MLDouble) this.content.get("voc_keep_terms_index");
if(keepIndex != null){
final double[] filterIndexArr = keepIndex.getArray()[0];
for (final double d : filterIndexArr) {
this.keepIndex.add((int) d - 1);
}
}
final MLCell vocLoaded = (MLCell) this.content.get("voc");
if(vocLoaded!=null){
this.indexToVoc = new HashMap<Integer, Integer>();
final ArrayList<MLArray> vocArr = vocLoaded.cells();
int index = 0;
int vocIndex = 0;
this.voc = new HashMap<Integer, String>();
for (final MLArray vocArrItem : vocArr) {
final MLChar vocChar = (MLChar) vocArrItem;
final String vocString = vocChar.getString(0);
if (filter && this.keepIndex.contains(index)) {
this.voc.put(vocIndex, vocString);
this.indexToVoc.put(index, vocIndex);
vocIndex++;
}
index++;
}
} else {
}
}
示例12: getMeasurements
import com.jmatio.types.MLCell; //导入依赖的package包/类
private LinkedList<IndependentMeasurement> getMeasurements(MatFileReader matFileReader, String sourcePath) {
LinkedList<IndependentMeasurement> measurements = new LinkedList<IndependentMeasurement>();
try {
MLStructure root = (MLStructure) matFileReader.getMLArray(rootKey);
MLCell accX = (MLCell) root.getField(accXKey);
MLCell accY = (MLCell) root.getField(accYKey);
MLCell accZ = (MLCell) root.getField(accZKey);
MLCell label = (MLCell) root.getField(labelKey);
fillSampleProperyLists(root);
int nOfSamples = (int) Math.round(((MLDouble) root.getField(nOfSamplesKey)).get(0));
for (int i = 0; i < nOfSamples; i++) {
double[] accXValues = getSampleRow(accX, i);
double[] accYValues = getSampleRow(accY, i);
double[] accZValues = getSampleRow(accZ, i);
double[] labelValues = getSampleRow(label, i);
List<IndependentMeasurement> newMeasurements = getMeasurementsFromSample(accXValues, accYValues, accZValues,
labelValues, i);
measurements.addAll(newMeasurements);
}
} catch (NullPointerException e) {
throwInvalidFormatException(sourcePath, e);
}
return measurements;
}
示例13: setCellText
import com.jmatio.types.MLCell; //导入依赖的package包/类
private void setCellText(final MLCell cell, final int index, final String text)
{
cell.set(new MLChar(null, text), index);
}
示例14: MatlabFileDataGenerator
import com.jmatio.types.MLCell; //导入依赖的package包/类
public MatlabFileDataGenerator(File matfile) throws IOException {
MatFileReader reader = new MatFileReader(matfile);
Map<String, MLArray> content = reader.getContent();
this.data= (MLCell) content.get("XYs");
this.index = 0;
}
示例15: getSampleRow
import com.jmatio.types.MLCell; //导入依赖的package包/类
private double[] getSampleRow(MLCell rows, int i) {
MLDouble sampleXML = (MLDouble) rows.cells().get(i);
double[] values = new DoubleMatrix(sampleXML.getArray()).toArray();
return values;
}