Java Code Examples for org.nd4j.linalg.indexing.conditions.Conditions#equals()
The following examples show how to use
org.nd4j.linalg.indexing.conditions.Conditions#equals() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TransformOpValidation.java From deeplearning4j with Apache License 2.0 | 6 votes |
@Test public void testReplaceWhereScalar() { for (Condition c : new Condition[]{Conditions.lessThan(0.5), Conditions.greaterThan(0.5), Conditions.equals(0.5)}) { log.info("Testing condition: " + c.getClass().getSimpleName()); INDArray inArr = Nd4j.rand(DataType.DOUBLE, 3, 4); SameDiff sd = SameDiff.create(); SDVariable in = sd.var("in", inArr); SDVariable where = sd.replaceWhere(in, 10, c); INDArray exp = inArr.dup(); BooleanIndexing.replaceWhere(exp, 10, c); SDVariable loss = where.std(true); TestCase tc = new TestCase(sd); String err = OpValidation.validate(tc); assertNull(err); } }
Example 2
Source File: TransformOpValidation.java From deeplearning4j with Apache License 2.0 | 6 votes |
@Test public void testReplaceWhereArray() { for (Condition c : new Condition[]{Conditions.lessThan(0.5), Conditions.greaterThan(0.5), Conditions.equals(0.5)}) { INDArray inArr = Nd4j.rand(3, 4); INDArray inArr2 = Nd4j.valueArrayOf(3, 4, 10); SameDiff sd = SameDiff.create(); SDVariable in = sd.var("in", inArr); SDVariable in2 = sd.var("in2", inArr2); SDVariable where = sd.replaceWhere(in, in2, c); INDArray exp = inArr.dup(); BooleanIndexing.replaceWhere(exp, inArr2, c); SDVariable loss = where.std(true); TestCase tc = new TestCase(sd); String err = OpValidation.validate(tc); assertNull(err); } }
Example 3
Source File: CustomOpsTests.java From deeplearning4j with Apache License 2.0 | 6 votes |
@Test public void testMatch_1() { INDArray x = Nd4j.ones(DataType.FLOAT, 3,3); INDArray y = Nd4j.linspace(DataType.FLOAT, -5, 9, 1).reshape(3, 3); val c = Conditions.equals(0.0); // System.out.println("Y:\n" + y); INDArray z = x.match(y, c); INDArray exp = Nd4j.createFromArray(new boolean[][]{ {false, false, false}, {false, false, false}, {true, false, false} }); assertEquals(exp, z); }
Example 4
Source File: ShufflesTest.java From nd4j with Apache License 2.0 | 5 votes |
@Test public void testBinomial() { Distribution distribution = Nd4j.getDistributions().createBinomial(3, Nd4j.create(10).putScalar(1, 0.00001)); for (int x = 0; x < 10000; x++) { INDArray z = distribution.sample(new int[]{1, 10}); System.out.println(); MatchCondition condition = new MatchCondition(z, Conditions.equals(0.0)); int match = Nd4j.getExecutioner().exec(condition, Integer.MAX_VALUE).getInt(0); assertEquals(z.length(), match); } }
Example 5
Source File: SpecialTests.java From deeplearning4j with Apache License 2.0 | 5 votes |
@Test public void testMatchCondition(){ INDArray x = Nd4j.valueArrayOf(new long[]{10,10}, 2.0, DataType.DOUBLE); val op = new MatchCondition(x, Conditions.equals(2)); INDArray z = Nd4j.getExecutioner().exec(op); int count = z.getInt(0); assertEquals(100, count); }
Example 6
Source File: EvaluationCalibration.java From deeplearning4j with Apache License 2.0 | 5 votes |
/** * Get the reliability diagram for the specified class * * @param classIdx Index of the class to get the reliability diagram for */ public ReliabilityDiagram getReliabilityDiagram(int classIdx) { Preconditions.checkState(rDiagBinPosCount != null, "Unable to get reliability diagram: no evaluation has been performed (no data)"); INDArray totalCountBins = rDiagBinTotalCount.getColumn(classIdx); INDArray countPositiveBins = rDiagBinPosCount.getColumn(classIdx); double[] meanPredictionBins = rDiagBinSumPredictions.getColumn(classIdx).castTo(DataType.DOUBLE) .div(totalCountBins.castTo(DataType.DOUBLE)).data().asDouble(); double[] fracPositives = countPositiveBins.castTo(DataType.DOUBLE).div(totalCountBins.castTo(DataType.DOUBLE)).data().asDouble(); if (excludeEmptyBins) { val condition = new MatchCondition(totalCountBins, Conditions.equals(0)); int numZeroBins = Nd4j.getExecutioner().exec(condition).getInt(0); if (numZeroBins != 0) { double[] mpb = meanPredictionBins; double[] fp = fracPositives; meanPredictionBins = new double[(int) (totalCountBins.length() - numZeroBins)]; fracPositives = new double[meanPredictionBins.length]; int j = 0; for (int i = 0; i < mpb.length; i++) { if (totalCountBins.getDouble(i) != 0) { meanPredictionBins[j] = mpb[i]; fracPositives[j] = fp[i]; j++; } } } } String title = "Reliability Diagram: Class " + classIdx; return new ReliabilityDiagram(title, meanPredictionBins, fracPositives); }