本文整理汇总了Java中com.jmatio.types.MLArray类的典型用法代码示例。如果您正苦于以下问题:Java MLArray类的具体用法?Java MLArray怎么用?Java MLArray使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MLArray类属于com.jmatio.types包,在下文中一共展示了MLArray类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: writeSamplingNetworkData
import com.jmatio.types.MLArray; //导入依赖的package包/类
public void writeSamplingNetworkData(SamplingNetworkData mcNetworkSamplingData) throws IOException {
Objects.requireNonNull(mcNetworkSamplingData, "sampling network data is null");
LOGGER.debug("Preparing buses mat data");
MLStructure buses = busesDataAsMLStructure(mcNetworkSamplingData.getBusesData());
LOGGER.debug("Preparing generators mat data");
MLStructure generators = generatorsDataAsMLStructure(mcNetworkSamplingData.getGeneratorsData());
LOGGER.debug("Preparing loads mat data");
MLStructure loads = loadsDataAsMLStructure(mcNetworkSamplingData.getLoadsData());
LOGGER.debug("Saving mat data into " + matFile.toString());
List<MLArray> mlarray = new ArrayList<>();
mlarray.add((MLArray) buses);
mlarray.add((MLArray) generators);
mlarray.add((MLArray) loads);
MatFileWriter writer = new MatFileWriter();
writer.write(matFile.toFile(), mlarray);
}
开发者ID:itesla,项目名称:ipst,代码行数:18,代码来源:MCSMatFileWriter.java
示例2: writeHistoricalData
import com.jmatio.types.MLArray; //导入依赖的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);
}
开发者ID:itesla,项目名称:ipst,代码行数:23,代码来源:FEAMatFileWriter.java
示例3: readStringsArrayFromMat
import com.jmatio.types.MLArray; //导入依赖的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;
}
开发者ID:itesla,项目名称:ipst,代码行数:13,代码来源:Utils.java
示例4: write
import com.jmatio.types.MLArray; //导入依赖的package包/类
/**
* Writes <code>MLArrays</code> into <code>WritableByteChannel</code>.
*
* @param channel
* the channel to write to
* @param data
* the collection of <code>{@link MLArray}</code> objects
* @throws IOException
* if writing fails
*/
public synchronized void write( Collection<MLArray> data) throws IOException
{
try
{
//write data
for ( MLArray matrix : data )
{
write(matrix);
}
}
catch ( IllegalArgumentException iae)
{
isStillValid = false;
throw iae;
}
catch ( IOException e )
{
throw e;
}
}
开发者ID:lovro-i,项目名称:apro,代码行数:32,代码来源:MatFileIncrementalWriter.java
示例5: writeFlags
import com.jmatio.types.MLArray; //导入依赖的package包/类
/**
* Writes MATRIX flags into <code>OutputStream</code>.
*
* @param os - <code>OutputStream</code>
* @param array - a <code>MLArray</code>
* @throws IOException
*/
private void writeFlags(DataOutputStream os, MLArray array) throws IOException
{
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
DataOutputStream bufferDOS = new DataOutputStream(buffer);
bufferDOS.writeInt( array.getFlags() );
if ( array.isSparse() )
{
bufferDOS.writeInt( ((MLSparse)array).getMaxNZ() );
}
else
{
bufferDOS.writeInt( 0 );
}
OSArrayTag tag = new OSArrayTag(MatDataTypes.miUINT32, buffer.toByteArray() );
tag.writeTo( os );
}
开发者ID:lovro-i,项目名称:apro,代码行数:27,代码来源:MatFileIncrementalWriter.java
示例6: write
import com.jmatio.types.MLArray; //导入依赖的package包/类
/**
* Writes <code>MLArrays</code> into <code>File</code>
*
* @param file
* the MAT-file to which data is written
* @param data
* the collection of <code>{@link MLArray}</code> objects
* @throws IOException
* if error occurred during MAT-file writing
*/
public synchronized void write(File file, Collection<MLArray> data)
throws IOException
{
FileOutputStream fos = new FileOutputStream(file);
try
{
write(fos.getChannel(), data);
}
catch ( IOException e )
{
throw e;
}
finally
{
fos.close();
}
}
开发者ID:lovro-i,项目名称:apro,代码行数:29,代码来源:MatFileWriter.java
示例7: fromFile
import com.jmatio.types.MLArray; //导入依赖的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());
}
}
开发者ID:ujmp,项目名称:universal-java-matrix-package,代码行数:20,代码来源:ImportMatrixMAT.java
示例8: writeMatlabFile1
import com.jmatio.types.MLArray; //导入依赖的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();
}
开发者ID:kasemir,项目名称:org.csstudio.display.builder,代码行数:18,代码来源:JMatioDemo.java
示例9: write
import com.jmatio.types.MLArray; //导入依赖的package包/类
/**
* Writes <code>MLArrays</code> into <code>WritableByteChannel</code>.
*
* @param channel
* the channel to write to
* @param data
* the collection of <code>{@link MLArray}</code> objects
* @throws IOException
* if writing fails
*/
public synchronized void write( Collection<MLArray> data) throws IOException
{
try
{
//write data
for ( MLArray matrix : data )
{
write(matrix);
}
}
catch ( IllegalArgumentException iae)
{
isStillValid = false;
throw iae;
}
catch ( IOException e )
{
throw e;
}
}
开发者ID:kasemir,项目名称:org.csstudio.display.builder,代码行数:32,代码来源:MatFileIncrementalWriter.java
示例10: writeFlags
import com.jmatio.types.MLArray; //导入依赖的package包/类
/**
* Writes MATRIX flags into <code>OutputStream</code>.
*
* @param os - <code>OutputStream</code>
* @param array - a <code>MLArray</code>
* @throws IOException
*/
private void writeFlags(DataOutputStream os, MLArray array) throws IOException
{
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
DataOutputStream bufferDOS = new DataOutputStream(buffer);
bufferDOS.writeInt( array.getFlags() );
if ( array.isSparse() )
{
bufferDOS.writeInt( ((MLSparse)array).getMaxNZ() );
}
else
{
bufferDOS.writeInt( 0 );
}
OSArrayTag tag = new OSArrayTag(MatDataTypes.miUINT32, buffer.toByteArray() );
tag.writeTo( os );
}
开发者ID:kasemir,项目名称:org.csstudio.display.builder,代码行数:27,代码来源:MatFileIncrementalWriter.java
示例11: write
import com.jmatio.types.MLArray; //导入依赖的package包/类
/**
* Writes <code>MLArrays</code> into <code>File</code>
*
* @param file
* the MAT-file to which data is written
* @param data
* the collection of <code>{@link MLArray}</code> objects
* @throws IOException
* if error occurred during MAT-file writing
*/
public synchronized void write(File file, Collection<MLArray> data)
throws IOException
{
FileOutputStream fos = new FileOutputStream(file);
try
{
write(fos.getChannel(), data);
}
catch ( IOException e )
{
throw e;
}
finally
{
fos.close();
}
}
开发者ID:kasemir,项目名称:org.csstudio.display.builder,代码行数:29,代码来源:MatFileWriter.java
示例12: MatFileReader
import com.jmatio.types.MLArray; //导入依赖的package包/类
/**
* Creates instance of <code>MatFileReader</code> and reads MAT-file
* from <code>file</code>.
*
* Results are filtered by <code>MatFileFilter</code>. Arrays that do not meet
* filter match condition will not be avalable in results.
*
* @param file the MAT-file
* @param filter array name filter.
* @throws IOException when error occured while processing the file.
*/
public MatFileReader(File file, MatFileFilter filter) throws IOException
{
this.filter = filter;
data = new LinkedHashMap<String, MLArray>();
//Create a read-only memory-mapped file
FileChannel roChannel = new RandomAccessFile(file, "r").getChannel();
ByteBuffer buf = roChannel.map(FileChannel.MapMode.READ_ONLY, 0, (int)roChannel.size());
//read in file header
readHeader(buf);
while ( buf.remaining() > 0 )
{
readData( buf );
}
//close file channel
roChannel.close();
}
开发者ID:mpgerstl,项目名称:tEFMA,代码行数:33,代码来源:MatFileReader.java
示例13: writeToMatlab
import com.jmatio.types.MLArray; //导入依赖的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);
}
开发者ID:openimaj,项目名称:openimaj,代码行数:25,代码来源:WordIndex.java
示例14: writeToMatlab
import com.jmatio.types.MLArray; //导入依赖的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 );
}
开发者ID:openimaj,项目名称:openimaj,代码行数:24,代码来源:TimeIndex.java
示例15: main
import com.jmatio.types.MLArray; //导入依赖的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));
}
开发者ID:openimaj,项目名称:openimaj,代码行数:21,代码来源:MatlabIO.java
示例16: prepareFolds
import com.jmatio.types.MLArray; //导入依赖的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");
}
}
开发者ID:openimaj,项目名称:openimaj,代码行数:23,代码来源:BillMatlabFileDataGenerator.java
示例17: saveFoldParameterLearner
import com.jmatio.types.MLArray; //导入依赖的package包/类
private void saveFoldParameterLearner(int fold, int j, BilinearSparseOnlineLearner learner) {
// save the state
final File learnerOut = new File(String.format("%s/fold_%d", currentOutputRoot(), fold), String.format(
"learner_%d", j));
final File learnerOutMat = new File(String.format("%s/fold_%d", currentOutputRoot(), fold), String.format(
"learner_%d.mat", j));
learnerOut.getParentFile().mkdirs();
try {
IOUtils.writeBinary(learnerOut, learner);
final Collection<MLArray> data = new ArrayList<MLArray>();
data.add(CFMatrixUtils.toMLArray("u", learner.getU()));
data.add(CFMatrixUtils.toMLArray("w", learner.getW()));
if (learner.getBias() != null) {
data.add(CFMatrixUtils.toMLArray("b", learner.getBias()));
}
final MatFileWriter writer = new MatFileWriter(learnerOutMat, data);
} catch (final IOException e) {
throw new RuntimeException(e);
}
}
开发者ID:openimaj,项目名称:openimaj,代码行数:21,代码来源:LambdaSearchAustrian.java
示例18: testSimSpatialClusterInverseHardcoded
import com.jmatio.types.MLArray; //导入依赖的package包/类
/**
* @throws IOException
*
*/
@Test
public void testSimSpatialClusterInverseHardcoded() throws IOException{
SpatialClusterer<DoubleDBSCANClusters,double[]> inner = new DoubleNNDBSCAN(
0.2, 2, new DoubleNearestNeighboursExact.Factory(DoubleFVComparison.EUCLIDEAN)
);
SpectralClusteringConf<double[]> conf = new SpectralClusteringConf<double[]>(inner, new GraphLaplacian.Normalised());
conf.eigenChooser = new AbsoluteValueEigenChooser(0.95, 0.1);
DoubleSpectralClustering clust = new DoubleSpectralClustering(conf);
SparseMatrix mat_norm = normalisedSimilarity(Double.MAX_VALUE);
Collection<MLArray> col = new ArrayList<MLArray>();
col.add(MatlibMatrixUtils.asMatlab(mat_norm));
// MatFileWriter writ = new MatFileWriter(new File("/Users/ss/Experiments/python/Whard.mat"), col);
IndexClusters res = clust.cluster(mat_norm);
confirmClusters(res);
}
开发者ID:openimaj,项目名称:openimaj,代码行数:20,代码来源:TestDoubleNormalisedSpecralClustering.java
示例19: testMLCharUnicode
import com.jmatio.types.MLArray; //导入依赖的package包/类
@Test
public void testMLCharUnicode() throws Exception
{
//array name
String name = "chararr";
//file name in which array will be storred
String fileName = "mlcharUTF.mat";
File outFile = temp.newFile( fileName );
//temp
String valueS;
//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(outFile, Arrays.asList( (MLArray) mlChar ) );
MatFileReader reader = new MatFileReader( outFile );
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) );
}
开发者ID:gradusnikov,项目名称:jmatio,代码行数:25,代码来源:MatIOTest.java
示例20: testDoubleFromMatlabCreatedFile
import com.jmatio.types.MLArray; //导入依赖的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);
}
开发者ID:gradusnikov,项目名称:jmatio,代码行数:25,代码来源:MatIOTest.java
注:本文中的com.jmatio.types.MLArray类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论