本文整理汇总了Java中com.jmatio.types.MLDouble.getArray方法的典型用法代码示例。如果您正苦于以下问题:Java MLDouble.getArray方法的具体用法?Java MLDouble.getArray怎么用?Java MLDouble.getArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.jmatio.types.MLDouble
的用法示例。
在下文中一共展示了MLDouble.getArray方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: readDoublesMatrixFromMat
import com.jmatio.types.MLDouble; //导入方法依赖的package包/类
public static double[][] readDoublesMatrixFromMat(Path matFile, String doublesMatrixName) throws IOException {
Objects.requireNonNull(matFile, "mat file is null");
MatFileReader matFileReader = new MatFileReader();
Map<String, MLArray> matFileContent = matFileReader.read(matFile.toFile());
MLDouble doublesMatrix = (MLDouble) matFileContent.get(doublesMatrixName);
double[][] doubles = null;
if (doublesMatrix != null) {
doubles = doublesMatrix.getArray();
}
return doubles;
}
示例3: computeBinSampling
import com.jmatio.types.MLDouble; //导入方法依赖的package包/类
public double[][] computeBinSampling(double[] marginalExpectations, int nSamples) throws Exception {
Objects.requireNonNull(marginalExpectations);
if (marginalExpectations.length == 0) {
throw new IllegalArgumentException("empty marginalExpectations array");
}
if (nSamples <= 0) {
throw new IllegalArgumentException("number of samples must be positive");
}
try (CommandExecutor executor = computationManager.newCommandExecutor(createEnv(), WORKING_DIR_PREFIX, config.isDebug())) {
Path workingDir = executor.getWorkingDir();
Utils.writeWP41BinaryIndependentSamplingInputFile(workingDir.resolve(B1INPUTFILENAME), marginalExpectations);
LOGGER.info("binsampler, asking for {} samples", nSamples);
Command cmd = createBinSamplerCmd(workingDir.resolve(B1INPUTFILENAME), nSamples);
ExecutionReport report = executor.start(new CommandExecution(cmd, 1, priority));
report.log();
LOGGER.debug("Retrieving binsampler results from file {}", B1OUTPUTFILENAME);
MatFileReader mfr = new MatFileReader();
Map<String, MLArray> content;
content = mfr.read(workingDir.resolve(B1OUTPUTFILENAME).toFile());
String errMsg = Utils.MLCharToString((MLChar) content.get("errmsg"));
if (!("Ok".equalsIgnoreCase(errMsg))) {
throw new MatlabException(errMsg);
}
MLArray xNew = content.get("STATUS");
Objects.requireNonNull(xNew);
MLDouble mld = (MLDouble) xNew;
double[][] retMat = mld.getArray();
return retMat;
}
}
示例4: prepareVocabulary
import com.jmatio.types.MLDouble; //导入方法依赖的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 {
}
}
示例5: computeModule3
import com.jmatio.types.MLDouble; //导入方法依赖的package包/类
private double[][] computeModule3(int nSamples) throws Exception {
LOGGER.info("Executing wp41 module3 (IR: {}, tflag: {}, number of clusters: {}), getting {} samples", config.getIr(), config.getTflag(), nClusters, nSamples);
try (CommandExecutor executor = computationManager.newCommandExecutor(createEnv(), WORKING_DIR_PREFIX, config.isDebug())) {
Path workingDir = executor.getWorkingDir();
Command cmd = createMatm3PreCmd(nClusters, nSamples);
ExecutionReport report = executor.start(new CommandExecution(cmd, 1, priority));
report.log();
if (report.getErrors().isEmpty()) {
report = executor.start(new CommandExecution(createMatm3Cmd(), nClusters, priority));
report.log();
if (report.getErrors().isEmpty()) {
report = executor.start(new CommandExecution(createMatm3reduceCmd(nClusters), 1, priority));
report.log();
LOGGER.debug("Retrieving module3 results from file {}", M3OUTPUTFILENAME);
MatFileReader mfr = new MatFileReader();
Map<String, MLArray> content = mfr.read(workingDir.resolve(M3OUTPUTFILENAME).toFile());
String errMsg = Utils.MLCharToString((MLChar) content.get("errmsg"));
if (!("Ok".equalsIgnoreCase(errMsg))) {
throw new MatlabException(errMsg);
}
MLArray xNew = content.get("Y");
MLDouble mld = (MLDouble) xNew;
double[][] xNewMat = mld.getArray();
if (config.getValidationDir() != null) {
// store output file with the samples, for validation purposes
try {
Files.copy(workingDir.resolve(M3OUTPUTFILENAME), config.getValidationDir().resolve("MOD3_" + System.currentTimeMillis() + "_" + Thread.currentThread().getId() + ".mat"));
} catch (Throwable t) {
LOGGER.error(t.getMessage(), t);
}
}
return xNewMat;
}
}
return null;
}
}
示例6: load
import com.jmatio.types.MLDouble; //导入方法依赖的package包/类
public static int load(String fileName) {
fileName = fileName.trim();
String matFileName = fileName;
if (fileName.endsWith(".mat") == false)
matFileName = matFileName + ".mat"; // append the default extension
boolean absoluteFileName = false;
if (scalaExec.Interpreter.GlobalValues.hostIsUnix) {
if (fileName.startsWith("/"))
absoluteFileName = true;
} else {
if (fileName.length() > 1)
if (fileName.charAt(1) == ':')
absoluteFileName = true;
}
if (absoluteFileName == false) // construct the path by appending the current directory
matFileName = Directory.Current().get().path() + File.separator + matFileName;
int numVarsReaded = 0;
try {
//read in the file
MatFileReader mfr = new MatFileReader(matFileName);
// a map of MLArray objects that were inside MAT-file. MLArrays are mapped with MLArrays' names
Map matFileVars = mfr.getContent(); // a map of MLArray objects that were inside the MAT-file, mapped with their names
Set varsSet = matFileVars.keySet(); // a set view of the keys contained in the map
Iterator<String> varsIter = varsSet.iterator();
boolean isRoot = true;
while (varsIter.hasNext()) { // for all .mat file variables
String currentVariable = varsIter.next(); // get the String of the Matlab variable
// the value to which the read file maps the specified array name. Returns null if the file contains no content for this name.
MLArray objArrayRetrived = mfr.getMLArray(currentVariable);
if (objArrayRetrived instanceof MLDouble) {
// public MLArray getMLArray(String name)
// Returns the value to which the read file maps the specified array name. Returns null if the file contains no content for this name.
// Returns: - the MLArray to which this file maps the specified name, or null if the file contains no content for this name.
MLDouble mlArrayRetrived = (MLDouble) mfr.getMLArray(currentVariable);
String arrayName = mlArrayRetrived.getName();
int nrows = mlArrayRetrived.getM();
int ncols = mlArrayRetrived.getN();
double[][] data = mlArrayRetrived.getArray(); // get data
scalaExec.Interpreter.GlobalValues.data = new double[nrows][ncols]; // copy of data array
for (int r = 0; r < nrows; r++)
for (int c = 0; c < ncols; c++)
scalaExec.Interpreter.GlobalValues.data[r][c] = data[r][c];
// keep a global reference in order to be accessible from the interpreter
// prepare and execute a "var" command in order to pass the variable to the Interpreter
if (nrows == 1 && ncols == 1) // get as single double
{
double scalarData = data[0][0];
scalaExec.Interpreter.GlobalValues.scalarData = scalarData;
scalaExec.Interpreter.GlobalValues.scalarValuesFromMatlab.put(arrayName, scalarData);
} else {
scalaExec.Interpreter.GlobalValues.arrayValuesFromMatlab.put(arrayName, scalaExec.Interpreter.GlobalValues.data);
}
numVarsReaded++; // one more variable readed
} // for all .mat file variables
}
return numVarsReaded;
} catch (Exception e) {
System.out.println("Exception ");
e.printStackTrace();
return 0;
}
}
示例7: load
import com.jmatio.types.MLDouble; //导入方法依赖的package包/类
public static int load(String fileName) {
fileName=fileName.trim();
String matFileName = fileName;
if (fileName.endsWith(".mat")==false)
matFileName = matFileName+".mat"; // append the default extension
boolean absoluteFileName = false;
if (scalaExec.Interpreter.GlobalValues.hostIsUnix)
{
if (fileName.startsWith("/"))
absoluteFileName = true;
}
else {
if (fileName.length()> 1)
if (fileName.charAt(1)==':')
absoluteFileName = true;
}
if (absoluteFileName == false) // construct the path by appending the current directory
matFileName = Directory.Current().get().path()+File.separator+matFileName;
int numVarsReaded = 0;
try {
//read in the file
MatFileReader mfr = new MatFileReader( matFileName );
// a map of MLArray objects that were inside MAT-file. MLArrays are mapped with MLArrays' names
Map matFileVars = mfr.getContent(); // a map of MLArray objects that were inside the MAT-file, mapped with their names
Set varsSet = matFileVars.keySet(); // a set view of the keys contained in the map
Iterator <String> varsIter = varsSet.iterator();
boolean isRoot = true;
while (varsIter.hasNext()) { // for all .mat file variables
String currentVariable = varsIter.next(); // get the String of the Matlab variable
// the value to which the read file maps the specified array name. Returns null if the file contains no content for this name.
MLArray objArrayRetrived = mfr.getMLArray(currentVariable);
if (objArrayRetrived instanceof MLDouble) {
// public MLArray getMLArray(String name)
// Returns the value to which the read file maps the specified array name. Returns null if the file contains no content for this name.
// Returns: - the MLArray to which this file maps the specified name, or null if the file contains no content for this name.
MLDouble mlArrayRetrived = (MLDouble)mfr.getMLArray(currentVariable);
String arrayName = mlArrayRetrived.getName();
int nrows = mlArrayRetrived.getM();
int ncols = mlArrayRetrived.getN();
double [][] data = mlArrayRetrived.getArray(); // get data
scalaExec.Interpreter.GlobalValues.data = new double[nrows][ncols]; // copy of data array
for (int r=0; r < nrows; r++)
for (int c=0; c< ncols; c++)
scalaExec.Interpreter.GlobalValues.data[r][c] = data[r][c];
// keep a global reference in order to be accessible from the interpreter
// prepare and execute a "var" command in order to pass the variable to the Interpreter
if (nrows == 1 && ncols == 1) // get as single double
{
double scalarData = data[0][0];
scalaExec.Interpreter.GlobalValues.scalarData = scalarData;
scalaExec.Interpreter.GlobalValues.scalarValuesFromMatlab.put(arrayName, scalarData);
}
else {
scalaExec.Interpreter.GlobalValues.arrayValuesFromMatlab.put(arrayName, scalaExec.Interpreter.GlobalValues.data);
}
numVarsReaded++; // one more variable readed
} // for all .mat file variables
}
return numVarsReaded;
}
catch (Exception e)
{
System.out.println("Exception ");
e.printStackTrace();
return 0;
}
}
示例8: fromMLArray
import com.jmatio.types.MLDouble; //导入方法依赖的package包/类
private DenseMatrix fromMLArray(MLDouble mlArray) {
final DenseMatrix ret = new DenseMatrix(mlArray.getArray());
return ret;
}