本文整理汇总了Java中org.nd4j.linalg.util.FeatureUtil.toOutcomeMatrix方法的典型用法代码示例。如果您正苦于以下问题:Java FeatureUtil.toOutcomeMatrix方法的具体用法?Java FeatureUtil.toOutcomeMatrix怎么用?Java FeatureUtil.toOutcomeMatrix使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.nd4j.linalg.util.FeatureUtil
的用法示例。
在下文中一共展示了FeatureUtil.toOutcomeMatrix方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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());
}
示例2: 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);
}
示例3: testDenseToOutputLayer
import org.nd4j.linalg.util.FeatureUtil; //导入方法依赖的package包/类
@Test
public void testDenseToOutputLayer() {
final int numRows = 76;
final int numColumns = 76;
int nChannels = 3;
int outputNum = 6;
int seed = 123;
//setup the network
MultiLayerConfiguration.Builder builder = new NeuralNetConfiguration.Builder().seed(seed)
.l1(1e-1).l2(2e-4).dropOut(0.5).miniBatch(true)
.optimizationAlgo(OptimizationAlgorithm.CONJUGATE_GRADIENT).list()
.layer(0, new ConvolutionLayer.Builder(5, 5).nOut(5).dropOut(0.5).weightInit(WeightInit.XAVIER)
.activation(Activation.RELU).build())
.layer(1, new SubsamplingLayer.Builder(SubsamplingLayer.PoolingType.MAX, new int[] {2, 2})
.build())
.layer(2, new ConvolutionLayer.Builder(3, 3).nOut(10).dropOut(0.5).weightInit(WeightInit.XAVIER)
.activation(Activation.RELU).build())
.layer(3, new SubsamplingLayer.Builder(SubsamplingLayer.PoolingType.MAX, new int[] {2, 2})
.build())
.layer(4, new DenseLayer.Builder().nOut(100).activation(Activation.RELU).build())
.layer(5, new OutputLayer.Builder(LossFunctions.LossFunction.NEGATIVELOGLIKELIHOOD)
.nOut(outputNum).weightInit(WeightInit.XAVIER).activation(Activation.SOFTMAX)
.build())
.backprop(true).pretrain(false)
.setInputType(InputType.convolutional(numRows, numColumns, nChannels));
DataSet d = new DataSet(Nd4j.rand(12345, 10, nChannels, numRows, numColumns),
FeatureUtil.toOutcomeMatrix(new int[] {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 6));
MultiLayerNetwork network = new MultiLayerNetwork(builder.build());
network.init();
network.fit(d);
}
示例4: getData
import org.nd4j.linalg.util.FeatureUtil; //导入方法依赖的package包/类
private static INDArray getData() {
Random r = new Random(1);
int[] result = new int[window];
for (int i = 0; i < window; i++) {
result[i] = r.nextInt(nIn);
}
return FeatureUtil.toOutcomeMatrix(result, nIn);
}
示例5: testFilterAndStrip
import org.nd4j.linalg.util.FeatureUtil; //导入方法依赖的package包/类
@Test
public void testFilterAndStrip() {
INDArray labels = FeatureUtil.toOutcomeMatrix(new int[]{0,1,2,1,2,2,0,1,2,1},3);
DataSet d = new org.nd4j.linalg.dataset.DataSet(Nd4j.ones(10, 2),labels);
//strip the dataset down to just these labels. Rearrange them such that each label is in the specified position.
d.filterAndStrip(new int[]{1,2});
for(int i = 0; i < d.numExamples(); i++) {
int outcome = d.get(i).outcome();
assertTrue(outcome == 0 || outcome == 1);
}
}