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


Java FeatureUtil类代码示例

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


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

示例1: convertMat

import org.nd4j.linalg.util.FeatureUtil; //导入依赖的package包/类
public Pair<INDArray, opencv_core.Mat> convertMat(byte[] byteFeature) {
    INDArray label = FeatureUtil.toOutcomeVector(byteFeature[0], NUM_LABELS);; // first value in the 3073 byte array
    opencv_core.Mat image = new opencv_core.Mat(HEIGHT, WIDTH, CV_8UC(CHANNELS)); // feature are 3072
    ByteBuffer imageData = image.createBuffer();

    for (int i = 0; i < HEIGHT * WIDTH; i++) {
        imageData.put(3 * i, byteFeature[i + 1 + 2 * HEIGHT * WIDTH]); // blue
        imageData.put(3 * i + 1, byteFeature[i + 1 + HEIGHT * WIDTH]); // green
        imageData.put(3 * i + 2, byteFeature[i + 1]); // red
    }
    //        if (useSpecialPreProcessCifar) {
    //            image = convertCifar(image);
    //        }

    return new Pair<>(label, image);
}
 
开发者ID:deeplearning4j,项目名称:DataVec,代码行数:17,代码来源:CifarLoader.java

示例2: testSplitTestAndTrain

import org.nd4j.linalg.util.FeatureUtil; //导入依赖的package包/类
@Test
public void testSplitTestAndTrain() throws Exception {
    INDArray labels = FeatureUtil.toOutcomeMatrix(new int[] {0, 0, 0, 0, 0, 0, 0, 0}, 1);
    DataSet data = new DataSet(Nd4j.rand(8, 1), labels);

    SplitTestAndTrain train = data.splitTestAndTrain(6, new Random(1));
    assertEquals(train.getTrain().getLabels().length(), 6);

    SplitTestAndTrain train2 = data.splitTestAndTrain(6, new Random(1));
    assertEquals(getFailureMessage(), train.getTrain().getFeatureMatrix(), train2.getTrain().getFeatureMatrix());

    DataSet x0 = new IrisDataSetIterator(150, 150).next();
    SplitTestAndTrain testAndTrain = x0.splitTestAndTrain(10);
    assertArrayEquals(new int[] {10, 4}, testAndTrain.getTrain().getFeatureMatrix().shape());
    assertEquals(x0.getFeatureMatrix().getRows(ArrayUtil.range(0, 10)), testAndTrain.getTrain().getFeatureMatrix());
    assertEquals(x0.getLabels().getRows(ArrayUtil.range(0, 10)), testAndTrain.getTrain().getLabels());


}
 
开发者ID:deeplearning4j,项目名称:nd4j,代码行数:20,代码来源:DataSetTest.java

示例3: testStringListLabels

import org.nd4j.linalg.util.FeatureUtil; //导入依赖的package包/类
@Test
public void testStringListLabels() {
    INDArray trueOutcome = FeatureUtil.toOutcomeVector(0, 2);
    INDArray predictedOutcome = FeatureUtil.toOutcomeVector(0, 2);

    List<String> labelsList = new ArrayList<>();
    labelsList.add("hobbs");
    labelsList.add("cal");

    Evaluation eval = new Evaluation(labelsList);

    eval.eval(trueOutcome, predictedOutcome);
    assertEquals(1, eval.classCount(0));
    assertEquals(labelsList.get(0), eval.getClassLabel(0));

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

示例4: testStringHashLabels

import org.nd4j.linalg.util.FeatureUtil; //导入依赖的package包/类
@Test
public void testStringHashLabels() {
    INDArray trueOutcome = FeatureUtil.toOutcomeVector(0, 2);
    INDArray predictedOutcome = FeatureUtil.toOutcomeVector(0, 2);

    Map<Integer, String> labelsMap = new HashMap<>();
    labelsMap.put(0, "hobbs");
    labelsMap.put(1, "cal");

    Evaluation eval = new Evaluation(labelsMap);

    eval.eval(trueOutcome, predictedOutcome);
    assertEquals(1, eval.classCount(0));
    assertEquals(labelsMap.get(0), eval.getClassLabel(0));

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

示例5: convert

import org.nd4j.linalg.util.FeatureUtil; //导入依赖的package包/类
@Override
public DataSet convert(Collection<Collection<Writable>> records, int numLabels) {
    //all but last label
    DataSet ret = new DataSet(Nd4j.create(records.size(), records.iterator().next().size() - 1),
                    Nd4j.create(records.size(), numLabels));
    //  INDArray ret = Nd4j.create(records.size(),records.iterator().next().size() - 1);
    int count = 0;
    for (Collection<Writable> record : records) {
        List<Writable> list;
        if (record instanceof List) {
            list = (List<Writable>) record;
        } else
            list = new ArrayList<>(record);
        DataSet d = new DataSet(Nd4j.create(record.size() - 1),
                        FeatureUtil.toOutcomeVector(list.get(list.size() - 1).toInt(), numLabels));
        ret.addRow(d, count++);

    }


    return ret;
}
 
开发者ID:deeplearning4j,项目名称:deeplearning4j,代码行数:23,代码来源:CSVRecordToDataSet.java

示例6: setOutcome

import org.nd4j.linalg.util.FeatureUtil; //导入依赖的package包/类
/**
 * Sets the outcome of a particular example
 * @param example the example to applyTransformToDestination
 * @param label the label of the outcome
 */
@Override
public void setOutcome(int example, int label) {
    if(example > numExamples())
        throw new IllegalArgumentException("No example at " + example);
    if(label > numOutcomes() || label < 0)
        throw new IllegalArgumentException("Illegal label");

    INDArray outcome = FeatureUtil.toOutcomeVector(label, numOutcomes());
    getLabels().putRow(example,outcome);
}
 
开发者ID:wlin12,项目名称:JNN,代码行数:16,代码来源:DataSet.java

示例7: setOutcome

import org.nd4j.linalg.util.FeatureUtil; //导入依赖的package包/类
/**
 * Sets the outcome of a particular example
 *
 * @param example the example to transform
 * @param label   the label of the outcome
 */
@Override
public void setOutcome(int example, int label) {
    if (example > numExamples())
        throw new IllegalArgumentException("No example at " + example);
    if (label > numOutcomes() || label < 0)
        throw new IllegalArgumentException("Illegal label");

    INDArray outcome = FeatureUtil.toOutcomeVector(label, numOutcomes());
    getLabels().putRow(example, outcome);
}
 
开发者ID:deeplearning4j,项目名称:nd4j,代码行数:17,代码来源:DataSet.java

示例8: getDataFor

import org.nd4j.linalg.util.FeatureUtil; //导入依赖的package包/类
public DataSet getDataFor(int i) {
    File image = new File(images.get(i));
    int outcome = outcomes.indexOf(image.getParentFile().getAbsolutePath());
    try {
        return new DataSet(loader.asRowVector(image), FeatureUtil.toOutcomeVector(outcome, outcomes.size()));
    } catch (Exception e) {
        throw new IllegalStateException("Unable to getFromOrigin data for image " + i + " for path " + images.get(i));
    }
}
 
开发者ID:jpatanooga,项目名称:Canova,代码行数:10,代码来源:LFWLoader.java

示例9: fit

import org.nd4j.linalg.util.FeatureUtil; //导入依赖的package包/类
/**
 * Fit the model
 *
 * @param examples the examples to classify (one example in each row)
 * @param labels   the labels for each example (the number of labels must match
 */
@Override
public void fit(INDArray examples, int[] labels) {
    INDArray outcomeMatrix = FeatureUtil.toOutcomeMatrix(labels, numLabels());
    fit(examples, outcomeMatrix);

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

示例10: fit

import org.nd4j.linalg.util.FeatureUtil; //导入依赖的package包/类
/**
 * Fit the model
 *
 * @param examples the examples to classify (one example in each row)
 * @param labels   the labels for each example (the number of labels must match
 */
@Override
public void fit(INDArray examples, int[] labels) {
    org.deeplearning4j.nn.conf.layers.OutputLayer layerConf =
                    (org.deeplearning4j.nn.conf.layers.OutputLayer) getOutputLayer().conf().getLayer();
    fit(examples, FeatureUtil.toOutcomeMatrix(labels, layerConf.getNOut()));
}
 
开发者ID:deeplearning4j,项目名称:deeplearning4j,代码行数:13,代码来源:MultiLayerNetwork.java

示例11: fromCache

import org.nd4j.linalg.util.FeatureUtil; //导入依赖的package包/类
private DataSet fromCache() {
    INDArray outcomes = null;
    INDArray input = null;
    input = Nd4j.create(batch, vec.lookupTable().layerSize() * vec.getWindow());
    outcomes = Nd4j.create(batch, labels.size());
    for (int i = 0; i < batch; i++) {
        input.putRow(i, WindowConverter.asExampleMatrix(cache.get(i), vec));
        int idx = labels.indexOf(cache.get(i).getLabel());
        if (idx < 0)
            idx = 0;
        outcomes.putRow(i, FeatureUtil.toOutcomeVector(idx, labels.size()));
    }
    return new DataSet(input, outcomes);

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

示例12: toLabelMatrix

import org.nd4j.linalg.util.FeatureUtil; //导入依赖的package包/类
public static INDArray toLabelMatrix(List<String> labels, List<Window> windows) {
    int columns = labels.size();
    INDArray ret = Nd4j.create(windows.size(), columns);
    for (int i = 0; i < ret.rows(); i++) {
        ret.putRow(i, FeatureUtil.toOutcomeVector(labels.indexOf(windows.get(i).getLabel()), labels.size()));
    }
    return ret;
}
 
开发者ID:deeplearning4j,项目名称:deeplearning4j,代码行数:9,代码来源:WordConverter.java

示例13: vectorize

import org.nd4j.linalg.util.FeatureUtil; //导入依赖的package包/类
/**
 * Vectorizes the passed in text treating it as one document
 *
 * @param text  the text to vectorize
 * @param label the label of the text
 * @return a dataset with a transform of weights(relative to impl; could be word counts or tfidf scores)
 */
@Override
public DataSet vectorize(String text, String label) {
    INDArray input = transform(text);
    INDArray labelMatrix = FeatureUtil.toOutcomeVector(labelsSource.indexOf(label), labelsSource.size());

    return new DataSet(input, labelMatrix);
}
 
开发者ID:deeplearning4j,项目名称:deeplearning4j,代码行数:15,代码来源:TfidfVectorizer.java

示例14: vectorize

import org.nd4j.linalg.util.FeatureUtil; //导入依赖的package包/类
@Override
public DataSet vectorize(String text, String label) {
    INDArray input = transform(text);
    INDArray labelMatrix = FeatureUtil.toOutcomeVector(labelsSource.indexOf(label), labelsSource.size());

    return new DataSet(input, labelMatrix);
}
 
开发者ID:deeplearning4j,项目名称:deeplearning4j,代码行数:8,代码来源:BagOfWordsVectorizer.java

示例15: testEval

import org.nd4j.linalg.util.FeatureUtil; //导入依赖的package包/类
@Test
public void testEval() {
    int classNum = 5;
    Evaluation eval = new Evaluation(classNum);

    // Testing the edge case when some classes do not have true positive
    INDArray trueOutcome = FeatureUtil.toOutcomeVector(0, 5); //[1,0,0,0,0]
    INDArray predictedOutcome = FeatureUtil.toOutcomeVector(0, 5); //[1,0,0,0,0]
    eval.eval(trueOutcome, predictedOutcome);
    assertEquals(1, eval.classCount(0));
    assertEquals(1.0, eval.f1(), 1e-1);

    // Testing more than one sample. eval() does not reset the Evaluation instance
    INDArray trueOutcome2 = FeatureUtil.toOutcomeVector(1, 5); //[0,1,0,0,0]
    INDArray predictedOutcome2 = FeatureUtil.toOutcomeVector(0, 5); //[1,0,0,0,0]
    eval.eval(trueOutcome2, predictedOutcome2);
    // Verified with sklearn in Python
    // from sklearn.metrics import classification_report
    // classification_report(['a', 'a'], ['a', 'b'], labels=['a', 'b', 'c', 'd', 'e'])
    assertEquals(eval.f1(), 0.6, 1e-1);
    // The first entry is 0 label
    assertEquals(1, eval.classCount(0));
    // The first entry is 1 label
    assertEquals(1, eval.classCount(1));
    // Class 0: one positive, one negative -> (one true positive, one false positive); no true/false negatives
    assertEquals(1, eval.positive().get(0), 0);
    assertEquals(1, eval.negative().get(0), 0);
    assertEquals(1, eval.truePositives().get(0), 0);
    assertEquals(1, eval.falsePositives().get(0), 0);
    assertEquals(0, eval.trueNegatives().get(0), 0);
    assertEquals(0, eval.falseNegatives().get(0), 0);


    // The rest are negative
    assertEquals(1, eval.negative().get(0), 0);
    // 2 rows and only the first is correct
    assertEquals(0.5, eval.accuracy(), 0);
}
 
开发者ID:deeplearning4j,项目名称:deeplearning4j,代码行数:39,代码来源:EvalTest.java


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