当前位置: 首页>>代码示例>>Java>>正文


Java CSVRecordReader.initialize方法代码示例

本文整理汇总了Java中org.datavec.api.records.reader.impl.csv.CSVRecordReader.initialize方法的典型用法代码示例。如果您正苦于以下问题:Java CSVRecordReader.initialize方法的具体用法?Java CSVRecordReader.initialize怎么用?Java CSVRecordReader.initialize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.datavec.api.records.reader.impl.csv.CSVRecordReader的用法示例。


在下文中一共展示了CSVRecordReader.initialize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: test

import org.datavec.api.records.reader.impl.csv.CSVRecordReader; //导入方法依赖的package包/类
@Test
public void test() throws Exception {

    CSVRecordReader rr = new CSVRecordReader(0, ',');
    rr.initialize(new FileSplit(new ClassPathResource("iris.dat").getFile()));

    CSVRecordReader rr2 = new CSVRecordReader(0, ',');
    rr2.initialize(new FileSplit(new ClassPathResource("iris.dat").getFile()));

    RecordReader rrC = new ConcatenatingRecordReader(rr, rr2);

    int count = 0;
    while(rrC.hasNext()){
        rrC.next();
        count++;
    }

    assertEquals(300, count);
}
 
开发者ID:deeplearning4j,项目名称:DataVec,代码行数:20,代码来源:TestConcatenatingRecordReader.java

示例2: simpleTransformTest

import org.datavec.api.records.reader.impl.csv.CSVRecordReader; //导入方法依赖的package包/类
@Test
public void simpleTransformTest() throws Exception {
    Schema schema = new Schema.Builder().addColumnDouble("0").addColumnDouble("1").addColumnDouble("2")
                    .addColumnDouble("3").addColumnDouble("4").build();
    TransformProcess transformProcess = new TransformProcess.Builder(schema).removeColumns("0").build();
    CSVRecordReader csvRecordReader = new CSVRecordReader();
    csvRecordReader.initialize(new FileSplit(new ClassPathResource("iris.dat").getFile()));
    TransformProcessRecordReader transformProcessRecordReader =
                    new TransformProcessRecordReader(csvRecordReader, transformProcess);
    assertEquals(4, transformProcessRecordReader.next().size());

}
 
开发者ID:deeplearning4j,项目名称:DataVec,代码行数:13,代码来源:TransformProcessRecordReaderTests.java

示例3: testResetWithSkipLines

import org.datavec.api.records.reader.impl.csv.CSVRecordReader; //导入方法依赖的package包/类
@Test
public void testResetWithSkipLines() throws Exception {
    CSVRecordReader rr = new CSVRecordReader(10, ',');
    rr.initialize(new FileSplit(new ClassPathResource("iris.dat").getFile()));
    int lineCount = 0;
    while (rr.hasNext()) {
        rr.next();
        ++lineCount;
    }
    assertEquals(140, lineCount);
    rr.reset();
    lineCount = 0;
    while (rr.hasNext()) {
        rr.next();
        ++lineCount;
    }
    assertEquals(140, lineCount);
}
 
开发者ID:deeplearning4j,项目名称:DataVec,代码行数:19,代码来源:CSVRecordReaderTest.java

示例4: testCsvSkipAllLines

import org.datavec.api.records.reader.impl.csv.CSVRecordReader; //导入方法依赖的package包/类
@Test(expected = NoSuchElementException.class)
public void testCsvSkipAllLines() throws IOException, InterruptedException {
    final int numLines = 4;
    final List<Writable> lineList = Arrays.asList((Writable) new IntWritable(numLines - 1),
                    (Writable) new Text("one"), (Writable) new Text("two"), (Writable) new Text("three"));
    String header = ",one,two,three";
    List<String> lines = new ArrayList<>();
    for (int i = 0; i < numLines; i++)
        lines.add(Integer.toString(i) + header);
    File tempFile = File.createTempFile("csvSkipLines", ".csv");
    FileUtils.writeLines(tempFile, lines);

    CSVRecordReader rr = new CSVRecordReader(numLines, ',');
    rr.initialize(new FileSplit(tempFile));
    rr.reset();
    assertTrue(!rr.hasNext());
    rr.next();
}
 
开发者ID:deeplearning4j,项目名称:DataVec,代码行数:19,代码来源:CSVRecordReaderTest.java

示例5: testStreamReset

import org.datavec.api.records.reader.impl.csv.CSVRecordReader; //导入方法依赖的package包/类
@Test
public void testStreamReset() throws Exception {
    CSVRecordReader rr = new CSVRecordReader(0, ',');
    rr.initialize(new InputStreamInputSplit(new ClassPathResource("iris.dat").getInputStream()));

    int count = 0;
    while(rr.hasNext()){
        assertNotNull(rr.next());
        count++;
    }
    assertEquals(150, count);

    assertFalse(rr.resetSupported());

    try{
        rr.reset();
        fail("Expected exception");
    } catch (Exception e){
        e.printStackTrace();
    }
}
 
开发者ID:deeplearning4j,项目名称:DataVec,代码行数:22,代码来源:CSVRecordReaderTest.java

示例6: testMnist

import org.datavec.api.records.reader.impl.csv.CSVRecordReader; //导入方法依赖的package包/类
@Test
public void testMnist() throws Exception {
    ClassPathResource cpr = new ClassPathResource("mnist_first_200.txt");
    CSVRecordReader rr = new CSVRecordReader(0, ',');
    rr.initialize(new FileSplit(cpr.getTempFileFromArchive()));
    RecordReaderDataSetIterator dsi = new RecordReaderDataSetIterator(rr, 10, 0, 10);

    MnistDataSetIterator iter = new MnistDataSetIterator(10, 200, false, true, false, 0);

    while (dsi.hasNext()) {
        DataSet dsExp = dsi.next();
        DataSet dsAct = iter.next();

        INDArray fExp = dsExp.getFeatureMatrix();
        fExp.divi(255);
        INDArray lExp = dsExp.getLabels();

        INDArray fAct = dsAct.getFeatureMatrix();
        INDArray lAct = dsAct.getLabels();

        assertEquals(fExp, fAct);
        assertEquals(lExp, lAct);
    }
    assertFalse(iter.hasNext());
}
 
开发者ID:deeplearning4j,项目名称:deeplearning4j,代码行数:26,代码来源:DataSetIteratorTest.java

示例7: createReader

import org.datavec.api.records.reader.impl.csv.CSVRecordReader; //导入方法依赖的package包/类
@Override
public RecordReader createReader(InputSplit split) throws IOException, InterruptedException {
    CSVRecordReader ret = new CSVRecordReader();
    ret.initialize(split);
    return ret;

}
 
开发者ID:deeplearning4j,项目名称:DataVec,代码行数:8,代码来源:CSVInputFormat.java

示例8: testWrite

import org.datavec.api.records.reader.impl.csv.CSVRecordReader; //导入方法依赖的package包/类
@Test
public void testWrite() throws Exception {
    File tempFile = File.createTempFile("datavec", "writer");
    tempFile.deleteOnExit();

    CSVRecordWriter writer = new CSVRecordWriter(tempFile);

    List<Writable> collection = new ArrayList<>();
    collection.add(new Text("12"));
    collection.add(new Text("13"));
    collection.add(new Text("14"));

    writer.write(collection);

    CSVRecordReader reader = new CSVRecordReader(0);
    reader.initialize(new FileSplit(tempFile));
    int cnt = 0;
    while (reader.hasNext()) {
        List<Writable> line = new ArrayList<>(reader.next());
        assertEquals(3, line.size());

        assertEquals(12, line.get(0).toInt());
        assertEquals(13, line.get(1).toInt());
        assertEquals(14, line.get(2).toInt());
        cnt++;
    }
    assertEquals(1, cnt);
}
 
开发者ID:deeplearning4j,项目名称:DataVec,代码行数:29,代码来源:CSVRecordWriterTest.java

示例9: testCSVVariableSlidingWindowRecordReader

import org.datavec.api.records.reader.impl.csv.CSVRecordReader; //导入方法依赖的package包/类
@Test
public void testCSVVariableSlidingWindowRecordReader() throws Exception {
    int maxLinesPerSequence = 3;

    SequenceRecordReader seqRR = new CSVVariableSlidingWindowRecordReader(maxLinesPerSequence);
    seqRR.initialize(new FileSplit(new ClassPathResource("iris.dat").getFile()));

    CSVRecordReader rr = new CSVRecordReader();
    rr.initialize(new FileSplit(new ClassPathResource("iris.dat").getFile()));

    int count = 0;
    while (seqRR.hasNext()) {
        List<List<Writable>> next = seqRR.sequenceRecord();

        if(count==maxLinesPerSequence-1) {
            LinkedList<List<Writable>> expected = new LinkedList<>();
            for (int i = 0; i < maxLinesPerSequence; i++) {
                expected.addFirst(rr.next());
            }
            assertEquals(expected, next);

        }
        if(count==maxLinesPerSequence) {
            assertEquals(maxLinesPerSequence, next.size());
        }
        if(count==0) { // first seq should be length 1
            assertEquals(1, next.size());
        }
        if(count>151) { // last seq should be length 1
            assertEquals(1, next.size());
        }

        count++;
    }

    assertEquals(152, count);
}
 
开发者ID:deeplearning4j,项目名称:DataVec,代码行数:38,代码来源:CSVVariableSlidingWindowRecordReaderTest.java

示例10: testCSVNLinesSequenceRecordReader

import org.datavec.api.records.reader.impl.csv.CSVRecordReader; //导入方法依赖的package包/类
@Test
public void testCSVNLinesSequenceRecordReader() throws Exception {
    int nLinesPerSequence = 10;

    SequenceRecordReader seqRR = new CSVNLinesSequenceRecordReader(nLinesPerSequence);
    seqRR.initialize(new FileSplit(new ClassPathResource("iris.dat").getFile()));

    CSVRecordReader rr = new CSVRecordReader();
    rr.initialize(new FileSplit(new ClassPathResource("iris.dat").getFile()));

    int count = 0;
    while (seqRR.hasNext()) {
        List<List<Writable>> next = seqRR.sequenceRecord();

        List<List<Writable>> expected = new ArrayList<>();
        for (int i = 0; i < nLinesPerSequence; i++) {
            expected.add(rr.next());
        }

        assertEquals(10, next.size());
        assertEquals(expected, next);

        count++;
    }

    assertEquals(150 / nLinesPerSequence, count);
}
 
开发者ID:deeplearning4j,项目名称:DataVec,代码行数:28,代码来源:CSVNLinesSequenceRecordReaderTest.java

示例11: testCSVNlinesSequenceRecordReaderMetaData

import org.datavec.api.records.reader.impl.csv.CSVRecordReader; //导入方法依赖的package包/类
@Test
public void testCSVNlinesSequenceRecordReaderMetaData() throws Exception {
    int nLinesPerSequence = 10;

    SequenceRecordReader seqRR = new CSVNLinesSequenceRecordReader(nLinesPerSequence);
    seqRR.initialize(new FileSplit(new ClassPathResource("iris.dat").getFile()));

    CSVRecordReader rr = new CSVRecordReader();
    rr.initialize(new FileSplit(new ClassPathResource("iris.dat").getFile()));

    List<List<List<Writable>>> out = new ArrayList<>();
    while (seqRR.hasNext()) {
        List<List<Writable>> next = seqRR.sequenceRecord();
        out.add(next);
    }

    seqRR.reset();
    List<List<List<Writable>>> out2 = new ArrayList<>();
    List<SequenceRecord> out3 = new ArrayList<>();
    List<RecordMetaData> meta = new ArrayList<>();
    while (seqRR.hasNext()) {
        SequenceRecord seq = seqRR.nextSequence();
        out2.add(seq.getSequenceRecord());
        meta.add(seq.getMetaData());
        out3.add(seq);
    }

    assertEquals(out, out2);

    List<SequenceRecord> out4 = seqRR.loadSequenceFromMetaData(meta);
    assertEquals(out3, out4);
}
 
开发者ID:deeplearning4j,项目名称:DataVec,代码行数:33,代码来源:CSVNLinesSequenceRecordReaderTest.java

示例12: testNext

import org.datavec.api.records.reader.impl.csv.CSVRecordReader; //导入方法依赖的package包/类
@Test
public void testNext() throws Exception {
    CSVRecordReader reader = new CSVRecordReader();
    reader.initialize(new StringSplit("1,1,8.0,,,,14.0,,,,15.0,,,,,,,,,,,,1"));
    while (reader.hasNext()) {
        List<Writable> vals = reader.next();
        List<Writable> arr = new ArrayList<>(vals);

        assertEquals("Entry count", 23, vals.size());
        Text lastEntry = (Text) arr.get(arr.size() - 1);
        assertEquals("Last entry garbage", 1, lastEntry.getLength());
    }
}
 
开发者ID:deeplearning4j,项目名称:DataVec,代码行数:14,代码来源:CSVRecordReaderTest.java

示例13: testEmptyEntries

import org.datavec.api.records.reader.impl.csv.CSVRecordReader; //导入方法依赖的package包/类
@Test
public void testEmptyEntries() throws Exception {
    CSVRecordReader reader = new CSVRecordReader();
    reader.initialize(new StringSplit("1,1,8.0,,,,14.0,,,,15.0,,,,,,,,,,,,"));
    while (reader.hasNext()) {
        List<Writable> vals = reader.next();
        assertEquals("Entry count", 23, vals.size());
    }
}
 
开发者ID:deeplearning4j,项目名称:DataVec,代码行数:10,代码来源:CSVRecordReaderTest.java

示例14: testLineRecordReader

import org.datavec.api.records.reader.impl.csv.CSVRecordReader; //导入方法依赖的package包/类
@Test
public void testLineRecordReader() throws Exception {

    File dataFile = new ClassPathResource("iris.dat").getFile();
    List<String> lines = FileUtils.readLines(dataFile);

    JavaSparkContext sc = getContext();
    JavaRDD<String> linesRdd = sc.parallelize(lines);

    CSVRecordReader rr = new CSVRecordReader(0, ',');

    JavaRDD<List<Writable>> out = linesRdd.map(new LineRecordReaderFunction(rr));
    List<List<Writable>> outList = out.collect();


    CSVRecordReader rr2 = new CSVRecordReader(0, ',');
    rr2.initialize(new FileSplit(dataFile));
    Set<List<Writable>> expectedSet = new HashSet<>();
    int totalCount = 0;
    while (rr2.hasNext()) {
        expectedSet.add(rr2.next());
        totalCount++;
    }

    assertEquals(totalCount, outList.size());

    for (List<Writable> line : outList) {
        assertTrue(expectedSet.contains(line));
    }
}
 
开发者ID:deeplearning4j,项目名称:DataVec,代码行数:31,代码来源:TestLineRecordReaderFunction.java

示例15: testTabsAsSplit1

import org.datavec.api.records.reader.impl.csv.CSVRecordReader; //导入方法依赖的package包/类
@Test
public void testTabsAsSplit1() throws Exception {

    CSVRecordReader reader = new CSVRecordReader(0, '\t');
    reader.initialize(new FileSplit(new ClassPathResource("/tabbed.txt").getFile()));
    while (reader.hasNext()) {
        List<Writable> list = new ArrayList<>(reader.next());

        assertEquals(2, list.size());
    }
}
 
开发者ID:deeplearning4j,项目名称:DataVec,代码行数:12,代码来源:CSVRecordReaderTest.java


注:本文中的org.datavec.api.records.reader.impl.csv.CSVRecordReader.initialize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。