• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java MLChar类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.jmatio.types.MLChar的典型用法代码示例。如果您正苦于以下问题:Java MLChar类的具体用法?Java MLChar怎么用?Java MLChar使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



MLChar类属于com.jmatio.types包,在下文中一共展示了MLChar类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: readStringsArrayFromMat

import com.jmatio.types.MLChar; //导入依赖的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


示例2: writeMatlabFile1

import com.jmatio.types.MLChar; //导入依赖的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


示例3: createMLStruct

import com.jmatio.types.MLChar; //导入依赖的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;
}
 
开发者ID:kasemir,项目名称:org.csstudio.display.builder,代码行数:32,代码来源:MatlabFileExportJob.java


示例4: writeToMatlab

import com.jmatio.types.MLChar; //导入依赖的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


示例5: testMLCharUnicode

import com.jmatio.types.MLChar; //导入依赖的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


示例6: testMLStructureFieldNames

import com.jmatio.types.MLChar; //导入依赖的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") );
}
 
开发者ID:gradusnikov,项目名称:jmatio,代码行数:25,代码来源:MatIOTest.java


示例7: putBusDataIntoMLStructure

import com.jmatio.types.MLChar; //导入依赖的package包/类
private void putBusDataIntoMLStructure(BusData busData, MLStructure buses, int i) {
    LOGGER.debug("Preparing mat data for bus " + busData.getBusId());
    // nome
    MLChar nome = new MLChar("", busData.getBusName());
    buses.setField("nome", nome, 0, i);
    // codice
    MLChar codice = new MLChar("", busData.getBusId());
    buses.setField("codice", codice, 0, i);
    // ID
    MLInt64 id = new MLInt64("", new long[]{busData.getBusIndex()}, 1);
    buses.setField("ID", id, 0, i);
    // type
    MLInt64 type = new MLInt64("", new long[]{busData.getBusType()}, 1);
    buses.setField("type", type, 0, i);
    // Vnom
    MLDouble vNom = new MLDouble("", new double[]{busData.getNominalVoltage()}, 1);
    buses.setField("Vnom", vNom, 0, i);
    // V
    MLDouble v = new MLDouble("", new double[]{busData.getVoltage()}, 1);
    buses.setField("V", v, 0, i);
    // angle
    MLDouble angle = new MLDouble("", new double[]{busData.getAngle()}, 1);
    buses.setField("angle", angle, 0, i);
    // Vmin
    MLDouble vMin = new MLDouble("", new double[]{busData.getMinVoltage()}, 1);
    buses.setField("Vmin", vMin, 0, i);
    // Vmax
    MLDouble vMax = new MLDouble("", new double[]{busData.getMaxVoltage()}, 1);
    buses.setField("Vmax", vMax, 0, i);
    // P
    MLDouble p = new MLDouble("", new double[]{busData.getActivePower()}, 1);
    buses.setField("P", p, 0, i);
    // Q
    MLDouble q = new MLDouble("", new double[]{busData.getReactivePower() }, 1);
    buses.setField("Q", q, 0, i);
}
 
开发者ID:itesla,项目名称:ipst,代码行数:37,代码来源:MCSMatFileWriter.java


示例8: putGeneratorDataIntoMLStructure

import com.jmatio.types.MLChar; //导入依赖的package包/类
private void putGeneratorDataIntoMLStructure(LoadData loadData, MLStructure loads, int i) {
    LOGGER.debug("Preparing mat data for load " + loadData.getLoadId());
    // estremo_ID
    MLInt64 estremoId = new MLInt64("", new long[]{loadData.getBusIndex()}, 1);
    loads.setField("estremo_ID", estremoId, 0, i);
    // estremo
    MLChar estremo = new MLChar("", loadData.getBusId());
    loads.setField("estremo", estremo, 0, i);
    // codice
    MLChar codice = new MLChar("", loadData.getLoadId());
    loads.setField("codice", codice, 0, i);
    // conn
    int connected = 0;
    if (loadData.isConnected()) {
        connected = 1;
    }
    MLInt64 disp = new MLInt64("", new long[]{connected}, 1);
    loads.setField("conn", disp, 0, i);
    // P
    MLDouble p = new MLDouble("", new double[]{loadData.getActvePower()}, 1);
    loads.setField("P", p, 0, i);
    // Q
    MLDouble q = new MLDouble("", new double[]{loadData.getReactvePower()}, 1);
    loads.setField("Q", q, 0, i);
    // V
    MLDouble v = new MLDouble("", new double[]{loadData.getVoltage()}, 1);
    loads.setField("V", v, 0, i);
}
 
开发者ID:itesla,项目名称:ipst,代码行数:29,代码来源:MCSMatFileWriter.java


示例9: MCSMatFileReader

import com.jmatio.types.MLChar; //导入依赖的package包/类
public MCSMatFileReader(Path matFile) throws Exception {
    Objects.requireNonNull(matFile, "mat file is null");
    MatFileReader sampledDataFileReader = new MatFileReader();
    matFileContent = sampledDataFileReader.read(matFile.toFile());
    String errorMessage = Utils.MLCharToString((MLChar) matFileContent.get("errmsg"));
    if (!("Ok".equalsIgnoreCase(errorMessage))) {
        throw new MatlabException(errorMessage);
    }
}
 
开发者ID:itesla,项目名称:ipst,代码行数:10,代码来源:MCSMatFileReader.java


示例10: histoDataHeadersAsMLChar

import com.jmatio.types.MLChar; //导入依赖的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;
}
 
开发者ID:itesla,项目名称:ipst,代码行数:14,代码来源:FEAMatFileWriter.java


示例11: putStochasticVariablesIntoMLStructure

import com.jmatio.types.MLChar; //导入依赖的package包/类
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);
}
 
开发者ID:itesla,项目名称:ipst,代码行数:10,代码来源:FEAMatFileWriter.java


示例12: injectionCountriesAsMLChar

import com.jmatio.types.MLChar; //导入依赖的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;
}
 
开发者ID:itesla,项目名称:ipst,代码行数:13,代码来源:FEAMatFileWriter.java


示例13: computeBinSampling

import com.jmatio.types.MLChar; //导入依赖的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;
    }


}
 
开发者ID:itesla,项目名称:ipst,代码行数:37,代码来源:SamplerWp41.java


示例14: MLCharToString

import com.jmatio.types.MLChar; //导入依赖的package包/类
public static String MLCharToString(MLChar mlchar) {
    StringBuffer sb = new StringBuffer();
    for (int m = 0; m < mlchar.getM(); m++) {
        for (int n = 0; n < mlchar.getN(); n++) {
            sb.append(mlchar.getChar(m, n));
        }
    }
    return sb.toString();
}
 
开发者ID:itesla,项目名称:ipst,代码行数:10,代码来源:Utils.java


示例15: prepareVocabulary

import com.jmatio.types.MLChar; //导入依赖的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 {
		
	}
}
 
开发者ID:openimaj,项目名称:openimaj,代码行数:35,代码来源:BillMatlabFileDataGenerator.java


示例16: testCell

import com.jmatio.types.MLChar; //导入依赖的package包/类
@Test
public void testCell()
{
    MLChar actual = (MLChar) MLArrayQuery.q( array, "SPM.Sess(1,1).U(1,1).name");
    assertEquals( "aquarium", actual.getString(0) );
    
    String str = (String) MLArrayQuery.q( array, "SPM.Sess(1,1).U(1,2).name(1)");
    assertEquals( "bike", str );
}
 
开发者ID:gradusnikov,项目名称:jmatio,代码行数:10,代码来源:MLArrayQueryTest.java


示例17: testFilteredReading

import com.jmatio.types.MLChar; //导入依赖的package包/类
/**
 * 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";
    File outFile = temp.newFile( fileName );
    
    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( outFile, list );
    
    //3. create new filter instance
    MatFileFilter filter = new MatFileFilter();
    filter.addArrayName( name );
    
    //4. read array form file
    MatFileReader mfr = new MatFileReader( outFile, filter );
    
    //check size of
    Map<String, MLArray> content = mfr.getContent();
    assertEquals("Test if only one array was red", 1, content.size() );
    
}
 
开发者ID:gradusnikov,项目名称:jmatio,代码行数:39,代码来源:MatIOTest.java


示例18: testMLStructure

import com.jmatio.types.MLChar; //导入依赖的package包/类
/**
 * Test <code>MatFileFilter</code> options
 * @throws IOException 
 */
@Test
public void testMLStructure() throws IOException
{
    //array name
    //file name in which array will be storred
    String fileName = "mlstruct.mat";
    File outFile = temp.newFile( fileName );

    //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);
    
    //write array to file
    ArrayList<MLArray> list = new ArrayList<MLArray>();
    list.add( mlStruct );
    
    //write arrays to file
    new MatFileWriter( outFile, list );
    
    //read array form file
    MatFileReader mfr = new MatFileReader( outFile );
    MLStructure mlArrayRetrived = (MLStructure)mfr.getMLArray( "str" );
    
    assertEquals(mlDouble, mlArrayRetrived.getField("f1") );
    assertEquals(mlChar, mlArrayRetrived.getField("f2") );
    

}
 
开发者ID:gradusnikov,项目名称:jmatio,代码行数:44,代码来源:MatIOTest.java


示例19: testMLCharStringArray

import com.jmatio.types.MLChar; //导入依赖的package包/类
@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) );
}
 
开发者ID:gradusnikov,项目名称:jmatio,代码行数:13,代码来源:MatIOTest.java


示例20: computeModule3

import com.jmatio.types.MLChar; //导入依赖的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;
    }

}
 
开发者ID:itesla,项目名称:ipst,代码行数:43,代码来源:SamplerWp41.java



注:本文中的com.jmatio.types.MLChar类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java TableTag类代码示例发布时间:2022-05-22
下一篇:
Java MomentumBackpropagation类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap