Java Code Examples for org.nd4j.linalg.factory.Nd4j#EPS_THRESHOLD
The following examples show how to use
org.nd4j.linalg.factory.Nd4j#EPS_THRESHOLD .
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: ShufflesTests.java From nd4j with Apache License 2.0 | 6 votes |
public boolean compareRow(INDArray newData) { float[] newMap = measureState(newData); if (newMap.length != map.length) { System.out.println("Different map lengths"); return false; } if (Arrays.equals(map, newMap)) { System.out.println("Maps are equal"); return false; } for (int x = 0; x < newData.rows(); x++) { INDArray row = newData.getRow(x); for (int y = 0; y < row.lengthLong(); y++ ) { if (Math.abs(row.getFloat(y) - newMap[x]) > Nd4j.EPS_THRESHOLD) { System.out.print("Different data in a row"); return false; } } } return true; }
Example 2
Source File: StableNumber.java From nd4j with Apache License 2.0 | 6 votes |
@Override public Number apply(Number number) { switch (type) { case DOUBLE: if (Double.isInfinite(number.doubleValue())) return -Double.MAX_VALUE; if (Double.isNaN(number.doubleValue())) return Nd4j.EPS_THRESHOLD; case FLOAT: if (Float.isInfinite(number.floatValue())) return -Float.MAX_VALUE; if (Float.isNaN(number.floatValue())) return Nd4j.EPS_THRESHOLD; default: throw new IllegalStateException("Illegal opType"); } }
Example 3
Source File: TFGraphTestAllHelper.java From nd4j with Apache License 2.0 | 6 votes |
public static void checkIntermediate(Map<String, INDArray> inputs, String modelName, String baseDir, ExecuteWith execType) throws IOException { Nd4j.EPS_THRESHOLD = 1e-3; Nd4j.getExecutioner().enableDebugMode(true); Nd4j.getExecutioner().enableVerboseMode(true); val graph = getGraphAfterExec(baseDir, modelName, inputs, execType); if (!execType.equals(ExecuteWith.JUST_PRINT)) { for (String varName : graph.variableMap().keySet()) { if (!inputs.containsKey(varName)) { //avoiding placeholders INDArray tfValue = intermediateVars(modelName, baseDir, varName); if (tfValue == null) { continue; } if (skipNode(modelName, varName)) { log.info("\n\tFORCING no check on " + varName); } else { assertEquals("Shape not equal on node " + varName, ArrayUtils.toString(tfValue.shape()), ArrayUtils.toString(graph.getVariable(varName).getShape())); assertEquals("Value not equal on node " + varName, tfValue, graph.getVariable(varName).getArr()); log.info("\n\tShapes equal for " + varName); log.info("\n\tValues equal for " + varName); } } } } }
Example 4
Source File: MatchCondition.java From deeplearning4j with Apache License 2.0 | 5 votes |
public MatchCondition(SameDiff sameDiff, SDVariable in, Condition condition, boolean keepDims, int... dimensions) { super(sameDiff, in, dimensions, keepDims); this.compare = condition.getValue(); this.mode = condition.condtionNum(); this.eps = Nd4j.EPS_THRESHOLD; this.extraArgs = new Object[] {compare, eps, (double) mode}; }
Example 5
Source File: ShufflesTests.java From nd4j with Apache License 2.0 | 5 votes |
public boolean compareSlice(INDArray data) { float[] newMap = measureState(data); if (newMap.length != map.length) { System.out.println("Different map lengths"); return false; } if (Arrays.equals(map, newMap)) { System.out.println("Maps are equal"); return false; } for (int x = 0; x < data.shape()[0]; x++) { INDArray slice = data.slice(x); for (int y = 0; y < slice.length(); y++) { if (Math.abs(slice.getFloat(y) - newMap[x]) > Nd4j.EPS_THRESHOLD) { System.out.print("Different data in a row"); return false; } } } return true; }
Example 6
Source File: BaseNDArray.java From deeplearning4j with Apache License 2.0 | 5 votes |
@Override public INDArray subi(Number n, INDArray result) { validateNumericalArray("subi", false); if (Double.isNaN(n.doubleValue())) n = Nd4j.EPS_THRESHOLD; Nd4j.getExecutioner().exec(new ScalarSubtraction(this, null, result, n)); return result; }
Example 7
Source File: ShufflesTests.java From nd4j with Apache License 2.0 | 5 votes |
public boolean compareSlice(INDArray data) { float[] newMap = measureState(data); if (newMap.length != map.length) { System.out.println("Different map lengths"); return false; } if (Arrays.equals(map, newMap)) { System.out.println("Maps are equal"); return false; } for (int x = 0; x < data.shape()[0]; x++) { INDArray slice = data.slice(x); for (int y = 0; y < slice.length(); y++) { if (Math.abs(slice.getFloat(y) - newMap[x]) > Nd4j.EPS_THRESHOLD) { System.out.print("Different data in a row"); return false; } } } return true; }
Example 8
Source File: BaseNDArray.java From deeplearning4j with Apache License 2.0 | 5 votes |
@Override public INDArray rdivi(Number n, INDArray result) { validateNumericalArray("rdivi", false); if (Double.isNaN(n.doubleValue())) n = Nd4j.EPS_THRESHOLD; Nd4j.getExecutioner().exec(new ScalarReverseDivision(this, null, result, n)); return result; }
Example 9
Source File: BaseNDArray.java From deeplearning4j with Apache License 2.0 | 5 votes |
@Override public INDArray addi(Number n, INDArray result) { validateNumericalArray("addi", false); if (Double.isNaN(n.doubleValue())) n = Nd4j.EPS_THRESHOLD; Nd4j.getExecutioner().exec(new ScalarAdd(this, null, result, n)); return result; }
Example 10
Source File: BaseComplexNDArray.java From nd4j with Apache License 2.0 | 5 votes |
/** * In place epsilon equals than comparison: * If the given number is less than the * comparison number the item is 0 otherwise 1 * * @param other the number to compare * @return */ @Override public IComplexNDArray epsi(INDArray other) { IComplexNDArray linear = linearView(); if (other instanceof IComplexNDArray) { IComplexNDArray otherComplex = (IComplexNDArray) other; IComplexNDArray otherComplexLinear = otherComplex.linearView(); for (int i = 0; i < linearView().length(); i++) { IComplexNumber n = linear.getComplex(i); IComplexNumber otherComplexNumber = otherComplexLinear.getComplex(i); double real = n.absoluteValue().doubleValue(); double otherAbs = otherComplexNumber.absoluteValue().doubleValue(); double diff = Math.abs(real - otherAbs); if (diff <= Nd4j.EPS_THRESHOLD) linear.putScalar(i, Nd4j.createDouble(1, 0)); else linear.putScalar(i, Nd4j.createDouble(0, 0)); } } return this; }
Example 11
Source File: BaseNDArray.java From deeplearning4j with Apache License 2.0 | 5 votes |
@Override public INDArray divi(Number n, INDArray result) { validateNumericalArray("divi", false); if (Double.isNaN(n.doubleValue())) n = Nd4j.EPS_THRESHOLD; Nd4j.getExecutioner().exec(new ScalarDivision(this, null, result, n)); return result; }
Example 12
Source File: MatchConditionTransform.java From nd4j with Apache License 2.0 | 4 votes |
public MatchConditionTransform(@NonNull INDArray x, @NonNull INDArray z, @NonNull Condition condition) { this(x, z, Nd4j.EPS_THRESHOLD, condition); }
Example 13
Source File: BaseCondition.java From deeplearning4j with Apache License 2.0 | 4 votes |
@Override public double epsThreshold() { return Nd4j.EPS_THRESHOLD; }
Example 14
Source File: MatchCondition.java From deeplearning4j with Apache License 2.0 | 4 votes |
public MatchCondition(INDArray x, Condition condition, int... dimensions) { this(x, Nd4j.EPS_THRESHOLD, condition, dimensions); }
Example 15
Source File: LocallyConnectedLayerTest.java From deeplearning4j with Apache License 2.0 | 4 votes |
@Before public void before() { DataTypeUtil.setDTypeForContext(DataType.DOUBLE); Nd4j.factory().setDType(DataType.DOUBLE); Nd4j.EPS_THRESHOLD = 1e-4; }
Example 16
Source File: EqualsWithEps.java From deeplearning4j with Apache License 2.0 | 4 votes |
public EqualsWithEps(INDArray x, INDArray y, INDArray z) { this(x, y, z, Nd4j.EPS_THRESHOLD, null); }
Example 17
Source File: LastIndex.java From nd4j with Apache License 2.0 | 4 votes |
public LastIndex(INDArray x, @NonNull Condition condition) { this(x, condition, Nd4j.EPS_THRESHOLD); }
Example 18
Source File: FirstIndex.java From nd4j with Apache License 2.0 | 4 votes |
public FirstIndex(INDArray x, @NonNull Condition condition) { this(x, condition, Nd4j.EPS_THRESHOLD); }
Example 19
Source File: MatchConditionTransform.java From deeplearning4j with Apache License 2.0 | 4 votes |
public MatchConditionTransform(@NonNull INDArray x, @NonNull INDArray y, @NonNull INDArray z, @NonNull Condition condition) { this(x, z, Nd4j.EPS_THRESHOLD, condition); this.y = y; }
Example 20
Source File: CudaGridExecutioner.java From nd4j with Apache License 2.0 | 4 votes |
protected void buildZ(Accumulation op, int... dimension) { Arrays.sort(dimension); for (int i = 0; i < dimension.length; i++) { if (dimension[i] < 0) dimension[i] += op.x().rank(); } //do op along all dimensions if (dimension.length == op.x().rank()) dimension = new int[] {Integer.MAX_VALUE}; long[] retShape = Shape.wholeArrayDimension(dimension) ? new long[] {1, 1} : ArrayUtil.removeIndex(op.x().shape(), dimension); //ensure vector is proper shape if (retShape.length == 1) { if (dimension[0] == 0) retShape = new long[] {1, retShape[0]}; else retShape = new long[] {retShape[0], 1}; } else if (retShape.length == 0) { retShape = new long[] {1, 1}; } /* if(op.x().isVector() && op.x().length() == ArrayUtil.prod(retShape)) return op.noOp(); */ INDArray ret = null; if (op.z() == null || op.z() == op.x()) { if (op.isComplexAccumulation()) { val xT = op.x().tensorssAlongDimension(dimension); val yT = op.y().tensorssAlongDimension(dimension); ret = Nd4j.create(xT, yT); } else { if (Math.abs(op.zeroDouble()) < Nd4j.EPS_THRESHOLD) { ret = Nd4j.zeros(retShape); } else { ret = Nd4j.valueArrayOf(retShape, op.zeroDouble()); } } op.setZ(ret); } else { // compare length if (op.z().lengthLong() != ArrayUtil.prodLong(retShape)) throw new ND4JIllegalStateException("Shape of target array for reduction [" + Arrays.toString(op.z().shape()) + "] doesn't match expected [" + Arrays.toString(retShape) + "]"); if (op.x().data().dataType() == DataBuffer.Type.DOUBLE) { op.z().assign(op.zeroDouble()); } else if (op.x().data().dataType() == DataBuffer.Type.FLOAT) { op.z().assign(op.zeroFloat()); } else if (op.x().data().dataType() == DataBuffer.Type.HALF) { op.z().assign(op.zeroHalf()); } ret = op.z(); } }