本文整理汇总了Java中com.jmatio.types.MLDouble类的典型用法代码示例。如果您正苦于以下问题:Java MLDouble类的具体用法?Java MLDouble怎么用?Java MLDouble使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MLDouble类属于com.jmatio.types包,在下文中一共展示了MLDouble类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doImportGTfromMatlab
import com.jmatio.types.MLDouble; //导入依赖的package包/类
synchronized public void doImportGTfromMatlab() {
JFileChooser chooser = new JFileChooser();
chooser.setDialogTitle("Choose ground truth file");
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
chooser.setMultiSelectionEnabled(false);
if (chooser.showOpenDialog(chip.getAeViewer().getFilterFrame()) == JFileChooser.APPROVE_OPTION) {
try {
vxGTframe = ((MLDouble) (new MatFileReader(chooser.getSelectedFile().getPath())).getMLArray("vxGT")).getArray();
vyGTframe = ((MLDouble) (new MatFileReader(chooser.getSelectedFile().getPath())).getMLArray("vyGT")).getArray();
tsGTframe = ((MLDouble) (new MatFileReader(chooser.getSelectedFile().getPath())).getMLArray("ts")).getArray();
importedGTfromMatlab = true;
log.info("Imported ground truth file");
} catch (IOException ex) {
log.log(Level.SEVERE, null, ex);
}
}
}
示例2: getSampledData
import com.jmatio.types.MLDouble; //导入依赖的package包/类
public SampledData getSampledData() {
// get generators active power
MLDouble pGen = (MLDouble) matFileContent.get("PGEN");
double[][] generatorsActivePower = null;
if (pGen != null) {
generatorsActivePower = pGen.getArray();
}
// get loads active power
MLDouble pLoad = (MLDouble) matFileContent.get("PLOAD");
double[][] loadsActivePower = null;
if (pLoad != null) {
loadsActivePower = pLoad.getArray();
}
// get loads reactive power
MLDouble qLoad = (MLDouble) matFileContent.get("QLOAD");
double[][] loadsReactivePower = null;
if (qLoad != null) {
loadsReactivePower = qLoad.getArray();
}
SampledData sampledData = new SampledData(generatorsActivePower, loadsActivePower, loadsReactivePower);
return sampledData;
}
示例3: writeHistoricalData
import com.jmatio.types.MLDouble; //导入依赖的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);
}
示例4: histoDataAsMLDouble
import com.jmatio.types.MLDouble; //导入依赖的package包/类
private MLDouble histoDataAsMLDouble(String name, ArrayTable<Integer, String, Float> histoData) {
int rowsSize = histoData.rowKeySet().size();
int colsSize = histoData.columnKeySet().size();
MLDouble mlDouble = new MLDouble(name, new int[] {rowsSize, colsSize});
int i = 0;
for (Integer rowKey : histoData.rowKeyList()) {
int j = 0;
for (String colkey : histoData.columnKeyList()) {
Float v = histoData.get(rowKey, colkey);
mlDouble.set(new Double(v), i, j);
j++;
}
i++;
}
return mlDouble;
}
示例5: readMDoubleFromCSVFile
import com.jmatio.types.MLDouble; //导入依赖的package包/类
public static MLDouble readMDoubleFromCSVFile(Path inFilePath, String mName, int nrows, int ncols, char delimiter) throws NumberFormatException, IOException {
MLDouble mlDouble = new MLDouble(mName, new int[] {nrows, ncols});
CsvReader cvsReader = new CsvReader(inFilePath.toString());
cvsReader.setDelimiter(delimiter);
int i = 0;
while (cvsReader.readRecord()) {
String[] rows = cvsReader.getValues();
int j = 0;
for (String col : rows) {
mlDouble.set(new Double(col), i, j);
j++;
}
i++;
}
return mlDouble;
}
示例6: fromFile
import com.jmatio.types.MLDouble; //导入依赖的package包/类
public static Matrix fromFile(File file, Object... parameters) throws IOException {
String key = null;
if (parameters != null && parameters.length > 0 && parameters[0] instanceof String) {
key = (String) parameters[0];
}
MatFileReader reader = new MatFileReader();
Map<String, MLArray> map = reader.read(file);
if (key == null) {
key = map.keySet().iterator().next();
}
MLArray array = map.get(key);
if (array == null) {
throw new RuntimeException("matrix with label [" + key + "] was not found in .mat file");
} else if (array instanceof MLDouble) {
return new MLDenseDoubleMatrix((MLDouble) array);
} else {
throw new RuntimeException("This type is not yet supported: " + array.getClass());
}
}
示例7: writeMatlabFile1
import com.jmatio.types.MLDouble; //导入依赖的package包/类
public void writeMatlabFile1() throws Exception
{
//1. First create example arrays
double[] src = new double[] { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 };
MLDouble mlDouble = new MLDouble( "double_arr", src, 2 );
MLChar mlChar = new MLChar( "char_arr", "I am dummy" );
//2. write arrays to file
ArrayList<MLArray> list = new ArrayList<MLArray>();
list.add( mlDouble );
list.add( mlChar );
MatFileIncrementalWriter writer = new MatFileIncrementalWriter("mat_file.mat");
writer.write(mlDouble);
writer.write(mlChar);
writer.close();
}
示例8: createMLStruct
import com.jmatio.types.MLDouble; //导入依赖的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;
}
示例9: writeToMatlab
import com.jmatio.types.MLDouble; //导入依赖的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);
}
示例10: writeToMatlab
import com.jmatio.types.MLDouble; //导入依赖的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 );
}
示例11: prepareFolds
import com.jmatio.types.MLDouble; //导入依赖的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");
}
}
示例12: parseAnnotations
import com.jmatio.types.MLDouble; //导入依赖的package包/类
private void parseAnnotations(FileObject annotationFile) throws IOException {
if (!annotationFile.exists()) {
return;
}
final MatFileReader reader = new MatFileReader(annotationFile.getContent().getInputStream());
final MLDouble boxes = (MLDouble) reader.getMLArray("box_coord");
this.bounds = new Rectangle(
(float) (double) boxes.getReal(2) - 1,
(float) (double) boxes.getReal(0) - 1,
(float) (boxes.getReal(3) - boxes.getReal(2)) - 1,
(float) (boxes.getReal(1) - boxes.getReal(0)) - 1);
final double[][] contourData = ((MLDouble) reader.getMLArray("obj_contour")).getArray();
this.contour = new Polygon();
for (int i = 0; i < contourData[0].length; i++) {
contour.points.add(
new Point2dImpl((float) contourData[0][i] + bounds.x - 1,
(float) contourData[1][i] + bounds.y - 1)
);
}
contour.close();
}
示例13: testMLStructureFieldNames
import com.jmatio.types.MLDouble; //导入依赖的package包/类
@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") );
}
示例14: testDoubleFromMatlabCreatedFile
import com.jmatio.types.MLDouble; //导入依赖的package包/类
/**
* Regression bug
*
* @throws Exception
*/
@Test
public void testDoubleFromMatlabCreatedFile() throws Exception
{
//array name
String name = "arr";
//file name in which array will be stored
String fileName = "src/test/resources/matnativedouble.mat";
//test column-packed vector
double[] src = new double[] { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 };
MLDouble mlDouble = new MLDouble( name, src, 3 );
//read array form file
MatFileReader mfr = new MatFileReader( fileName );
MLArray mlArrayRetrived = mfr.getMLArray( name );
//test if MLArray objects are equal
assertEquals("Test if value red from file equals value stored", mlDouble, mlArrayRetrived);
}
示例15: testDoubleFromMatlabCreatedFile2
import com.jmatio.types.MLDouble; //导入依赖的package包/类
/**
* Regression bug.
* <pre><code>
* Matlab code:
* >> arr = [1.1, 4.4; 2.2, 5.5; 3.3, 6.6];
* >> save('matnativedouble2', arr);
* </code></pre>
*
* @throws IOException
*/
@Test
public void testDoubleFromMatlabCreatedFile2() throws IOException
{
//array name
String name = "arr";
//file name in which array will be stored
String fileName = "src/test/resources/matnativedouble2.mat";
//test column-packed vector
double[] src = new double[] { 1.1, 2.2, 3.3, 4.4, 5.5, 6.6 };
MLDouble mlDouble = new MLDouble( name, src, 3 );
//read array form file
MatFileReader mfr = new MatFileReader( fileName );
MLArray mlArrayRetrived = mfr.getMLArray( name );
//test if MLArray objects are equal
assertEquals("Test if value red from file equals value stored", mlDouble, mlArrayRetrived);
}