code
stringlengths
11
173k
docstring
stringlengths
2
593k
func_name
stringlengths
2
189
language
stringclasses
1 value
repo
stringclasses
833 values
path
stringlengths
11
294
url
stringlengths
60
339
license
stringclasses
4 values
public static TensorDataType fromProtoValue(String value) { String valueReplace = value.replace("DT_",""); return TensorDataType.valueOf(valueReplace); }
Map a tensor data type to a proto value found in tensorflow. Generally, this is just replacing DT_ with empty and returning enum.valueOf(string) @param value the input string @return the associated {@link TensorDataType}
TensorDataType::fromProtoValue
java
deeplearning4j/deeplearning4j
nd4j/nd4j-tensorflow/src/main/java/org/nd4j/tensorflow/conversion/TensorDataType.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-tensorflow/src/main/java/org/nd4j/tensorflow/conversion/TensorDataType.java
Apache-2.0
public static String toPythonName(TensorDataType tensorDataType) { switch(tensorDataType) { case DOUBLE: return "float64"; case FLOAT: return "float32"; case HALF: return "float16"; default: return tensorDataType.name().toLowerCase(); } }
Get the python name for the given data type @param tensorDataType the python name for the given data type @return float64 for double, float32 for double, float16 for half, otherwise the type's name converted to lower case
TensorDataType::toPythonName
java
deeplearning4j/deeplearning4j
nd4j/nd4j-tensorflow/src/main/java/org/nd4j/tensorflow/conversion/TensorDataType.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-tensorflow/src/main/java/org/nd4j/tensorflow/conversion/TensorDataType.java
Apache-2.0
public static TensorflowConversion getInstance() { if(INSTANCE == null) INSTANCE = new TensorflowConversion(); return INSTANCE; }
Get a singleton instance @return
TensorflowConversion::getInstance
java
deeplearning4j/deeplearning4j
nd4j/nd4j-tensorflow/src/main/java/org/nd4j/tensorflow/conversion/TensorflowConversion.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-tensorflow/src/main/java/org/nd4j/tensorflow/conversion/TensorflowConversion.java
Apache-2.0
public TF_Tensor tensorFromNDArray(INDArray ndArray) { if(ndArray == null) { throw new IllegalArgumentException("NDArray must not be null!"); } //we infer data type from the ndarray.databuffer() //for now we throw an exception if(ndArray.data() == null) { throw new IllegalArgumentException("Unable to infer data type from null databuffer"); } if(ndArray.isView() || ndArray.ordering() != 'c') { ndArray = ndArray.dup('c'); } long[] ndShape = ndArray.shape(); long[] tfShape = new long[ndShape.length]; System.arraycopy(ndShape, 0, tfShape, 0, ndShape.length); int type; DataBuffer data = ndArray.data(); DataType dataType = data.dataType(); switch (dataType) { case DOUBLE: type = DT_DOUBLE; break; case FLOAT: type = DT_FLOAT; break; case INT: type = DT_INT32; break; case HALF: type = DT_HALF; break; case COMPRESSED: CompressedDataBuffer compressedData = (CompressedDataBuffer)data; CompressionDescriptor desc = compressedData.getCompressionDescriptor(); String algo = desc.getCompressionAlgorithm(); switch (algo) { case "FLOAT16": type = DT_HALF; break; case "INT8": type = DT_INT8; break; case "UINT8": type = DT_UINT8; break; case "INT16": type = DT_INT16; break; case "UINT16": type = DT_UINT16; break; default: throw new IllegalArgumentException("Unsupported compression algorithm: " + algo); } break; case SHORT: type = DT_INT16; break; case LONG: type = DT_INT64; break; case UTF8: type = DT_STRING; break; case BYTE: type = DT_INT8; break; case UBYTE: type = DT_UINT8; break; case UINT16: type = DT_UINT16; break; case UINT32: type = DT_UINT32; break; case UINT64: type = DT_UINT64; break; case BFLOAT16: type = DT_BFLOAT16; break; case BOOL: type = DT_BOOL; break; default: throw new IllegalArgumentException("Unsupported data type: " + dataType); } try { Nd4j.getAffinityManager().ensureLocation(ndArray, AffinityManager.Location.HOST); } catch (Exception e) { // ND4J won't let us access compressed data in GPU memory, so we'll leave TensorFlow do the conversion instead ndArray.getDouble(0); // forces decompression and data copy to host data = ndArray.data(); dataType = data.dataType(); switch (dataType) { case DOUBLE: type = DT_DOUBLE; break; case FLOAT: type = DT_FLOAT; break; case INT: type = DT_INT32; break; case LONG: type = DT_INT64; break; case UTF8: type = DT_STRING; break; default: throw new IllegalArgumentException("Unsupported data type: " + dataType); } } LongPointer longPointer = new LongPointer(tfShape); TF_Tensor tf_tensor = null; if (type == DT_STRING) { long size = 0; long length = ndArray.length(); BytePointer[] strings = new BytePointer[(int)length]; for (int i = 0; i < length; i++) { strings[i] = new BytePointer(ndArray.getString(i)); size += TF_StringEncodedSize(strings[i].capacity()); } tf_tensor = TF_AllocateTensor( type, longPointer, tfShape.length, 8 * length + size); long offset = 0; BytePointer tf_data = new BytePointer(TF_TensorData(tf_tensor)).capacity(TF_TensorByteSize(tf_tensor)); TF_Status status = TF_NewStatus(); for (int i = 0; i < length; i++) { tf_data.position(8 * i).putLong(offset); offset += TF_StringEncode(strings[i], strings[i].capacity() - 1, tf_data.position(8 * length + offset), tf_data.capacity() - tf_data.position(), status); if (TF_GetCode(status) != TF_OK) { throw new IllegalStateException("ERROR: Unable to convert tensor " + TF_Message(status).getString()); } } TF_DeleteStatus(status); } else { tf_tensor = TF_NewTensor( type, longPointer, tfShape.length, data.pointer(), data.length() * data.getElementSize(), calling,null); } return tf_tensor; }
Convert an {@link INDArray} to a {@link TF_Tensor} with zero copy. Uses a direct pointer to the underlying ndarray's data @param ndArray the ndarray to use @return the equivalent {@link TF_Tensor}
TensorflowConversion::tensorFromNDArray
java
deeplearning4j/deeplearning4j
nd4j/nd4j-tensorflow/src/main/java/org/nd4j/tensorflow/conversion/TensorflowConversion.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-tensorflow/src/main/java/org/nd4j/tensorflow/conversion/TensorflowConversion.java
Apache-2.0
public INDArray ndArrayFromTensor(TF_Tensor tensor) { int rank = TF_NumDims(tensor); int[] ndShape; if (rank == 0) { // scalar ndShape = new int[] {}; } else { ndShape = new int[rank]; for (int i = 0; i < ndShape.length; i++) { ndShape[i] = (int) TF_Dim(tensor,i); } } int tfType = TF_TensorType(tensor); DataType nd4jType = typeFor(tfType); //scalars are technically length 1 but of rank 0 int length = Math.max(1,ArrayUtil.prod(ndShape)); INDArray array; if (nd4jType == DataType.UTF8) { String[] strings = new String[length]; BytePointer data = new BytePointer(TF_TensorData(tensor)).capacity(TF_TensorByteSize(tensor)); BytePointer str = new BytePointer((Pointer)null); SizeTPointer size = new SizeTPointer(1); TF_Status status = TF_NewStatus(); for (int i = 0; i < length; i++) { long offset = data.position(8 * i).getLong(); TF_StringDecode(data.position(8 * length + offset), data.capacity() - data.position(), str, size, status); if (TF_GetCode(status) != TF_OK) { throw new IllegalStateException("ERROR: Unable to convert tensor " + TF_Message(status).getString()); } strings[i] = str.position(0).capacity(size.get()).getString(); } TF_DeleteStatus(status); array = Nd4j.create(strings); } else { Pointer pointer = TF_TensorData(tensor).capacity(length); Indexer indexer = indexerForType(nd4jType,pointer); DataBuffer d = Nd4j.createBuffer(indexer.pointer(),nd4jType,length,indexer); array = Nd4j.create(d,ndShape); } // we don't need this in this case. Device memory will be updated right in the constructor //Nd4j.getAffinityManager().tagLocation(array, AffinityManager.Location.HOST); return array; }
Convert a {@link INDArray} to a {@link TF_Tensor} using zero copy. It will use the underlying pointer with in nd4j. @param tensor the tensor to use @return
TensorflowConversion::ndArrayFromTensor
java
deeplearning4j/deeplearning4j
nd4j/nd4j-tensorflow/src/main/java/org/nd4j/tensorflow/conversion/TensorflowConversion.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-tensorflow/src/main/java/org/nd4j/tensorflow/conversion/TensorflowConversion.java
Apache-2.0
public TF_Graph loadGraph(String filePath, TF_Status status) throws IOException { byte[] bytes = Files.readAllBytes(Paths.get(filePath)); return loadGraph(bytes, status); }
Get an initialized {@link TF_Graph} based on the passed in file (the file must be a binary protobuf/pb file) The graph will be modified to be associated with the device associated with this current thread. Depending on the active {@link Nd4j#getBackend()} the device will either be the gpu pinned to the current thread or the cpu @param filePath the path to the file to read @return the initialized graph @throws IOException
TensorflowConversion::loadGraph
java
deeplearning4j/deeplearning4j
nd4j/nd4j-tensorflow/src/main/java/org/nd4j/tensorflow/conversion/TensorflowConversion.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-tensorflow/src/main/java/org/nd4j/tensorflow/conversion/TensorflowConversion.java
Apache-2.0
public static String defaultDeviceForThread() { Integer deviceForThread = Nd4j.getAffinityManager().getDeviceForCurrentThread(); String deviceName = null; //gpu if(Nd4j.getBackend().getClass().getName().contains("JCublasBackend")) { deviceName = "/device:gpu:" + deviceForThread; } else { deviceName = "/device:cpu:" + deviceForThread; } return deviceName; }
Infers the device for the given thread based on the {@link Nd4j#getAffinityManager()} Usually, this will either be a gpu or cpu reserved for the current device. You can think of the "current thread" as a worker. This is mainly useful with multiple gpus @return
TensorflowConversion::defaultDeviceForThread
java
deeplearning4j/deeplearning4j
nd4j/nd4j-tensorflow/src/main/java/org/nd4j/tensorflow/conversion/TensorflowConversion.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-tensorflow/src/main/java/org/nd4j/tensorflow/conversion/TensorflowConversion.java
Apache-2.0
public TF_Session loadSavedModel(SavedModelConfig savedModelConfig, TF_SessionOptions options, TF_Buffer runOptions, TF_Graph graph, Map<String, String> inputsMap, Map<String, String> outputsMap, TF_Status status) { TF_Buffer metaGraph = TF_Buffer.newBuffer(); TF_Session session = TF_LoadSessionFromSavedModel(options, runOptions, new BytePointer(savedModelConfig.getSavedModelPath()), new BytePointer(savedModelConfig.getModelTag()), 1, graph, metaGraph, status); if (TF_GetCode(status) != TF_OK) { throw new IllegalStateException("ERROR: Unable to import model " + TF_Message(status).getString()); } MetaGraphDef metaGraphDef; try { metaGraphDef = MetaGraphDef.parseFrom(metaGraph.data().capacity(metaGraph.length()).asByteBuffer()); } catch (InvalidProtocolBufferException ex) { throw new IllegalStateException("ERROR: Unable to import model " + ex); } Map<String, SignatureDef> signatureDefMap = metaGraphDef.getSignatureDefMap(); SignatureDef signatureDef = signatureDefMap.get(savedModelConfig.getSignatureKey()); Map<String, TensorInfo> inputs = signatureDef.getInputsMap(); for (Map.Entry<String, TensorInfo> e : inputs.entrySet()) { inputsMap.put(e.getKey(), e.getValue().getName()); } Map<String, TensorInfo> outputs = signatureDef.getOutputsMap(); for (Map.Entry<String, TensorInfo> e : outputs.entrySet()) { outputsMap.put(e.getKey(), e.getValue().getName()); } return session; }
Load a session based on the saved model @param savedModelConfig the configuration for the saved model @param options the session options to use @param runOptions the run configuration to use @param graph the tf graph to use @param inputsMap the input map @param outputsMap the output names @param status the status object to use for verifying the results @return
TensorflowConversion::loadSavedModel
java
deeplearning4j/deeplearning4j
nd4j/nd4j-tensorflow/src/main/java/org/nd4j/tensorflow/conversion/TensorflowConversion.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-tensorflow/src/main/java/org/nd4j/tensorflow/conversion/TensorflowConversion.java
Apache-2.0
public Map<String, TF_Tensor> recastInputs(Map<String, TF_Tensor> inputs) { return recastInputs(inputs,inputOrder,inputDataTypes); }
Cast inputs from the original data type to the target resulting input data type. This is for when there's a disconnect from the inputs to the target input data type. This runs a pre cast automatically. @param inputs the inputs to cast @return the re casted input
GraphRunner::recastInputs
java
deeplearning4j/deeplearning4j
nd4j/nd4j-tensorflow/src/main/java/org/nd4j/tensorflow/conversion/graphrunner/GraphRunner.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-tensorflow/src/main/java/org/nd4j/tensorflow/conversion/graphrunner/GraphRunner.java
Apache-2.0
public Map<String, TF_Tensor> recastInputs(Map<String, TF_Tensor> inputs, List<String> inputOrder, Map<String,TensorDataType> inputDataTypes) { if(inputDataTypes == null || inputDataTypes.isEmpty()) { inputDataTypes = new LinkedHashMap<>(); if(inputOrder != null) for(int i = 0; i < inputOrder.size(); i++) { TensorDataType tensorDataType = TensorDataType.values()[TF_TensorType(inputs.get(inputOrder.get(i)))]; Preconditions.checkNotNull(tensorDataType,"Data type of " + TF_TensorType(inputs.get(inputOrder.get(i))) + " was null!"); inputDataTypes.put(inputOrder.get(i),tensorDataType); } } Map<String, TF_Tensor> ret = new HashMap<>(); if(inputOrder != null) for(int i = 0; i < inputOrder.size(); i++) { TF_Tensor currInput = inputs.get(inputOrder.get(i)); TensorDataType fromDType = TensorDataType.values()[TF_TensorType(currInput)]; if(fromDType != inputDataTypes.get(inputOrder.get(i))) { TF_Tensor oldTensor = currInput; currInput = castTensor(currInput, fromDType, inputDataTypes.get(inputOrder.get(i))); TF_DeleteTensor(oldTensor); } ret.put(inputOrder.get(i),currInput); } return ret; }
Automatically recast the input arrays as the specified types @param inputs the input tensors to recast @param inputOrder the order of the input tensors @param inputDataTypes the data types to cast to (null means stay the same) @return the new values
GraphRunner::recastInputs
java
deeplearning4j/deeplearning4j
nd4j/nd4j-tensorflow/src/main/java/org/nd4j/tensorflow/conversion/graphrunner/GraphRunner.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-tensorflow/src/main/java/org/nd4j/tensorflow/conversion/graphrunner/GraphRunner.java
Apache-2.0
public Map<String, TF_Tensor> runTfTensor(Map<String, TF_Tensor> inputs) { if(graph == null) { throw new IllegalStateException("Graph not initialized."); } if(!inputs.isEmpty() && inputOrder != null && inputs.size() != inputOrder.size()) { throw new IllegalArgumentException("Number of inputs specified do not match number of arrays specified."); } if(inputDataTypes == null) { inputDataTypes = new LinkedHashMap<>(); if(inputOrder != null) for(int i = 0; i < inputOrder.size(); i++) { inputDataTypes.put(inputOrder.get(i),TensorDataType.values()[TF_TensorType(inputs.get(inputOrder.get(i)))]); } } for(Map.Entry<String, org.bytedeco.tensorflow.TF_Tensor> entry : inputs.entrySet()) { Preconditions.checkNotNull(entry.getValue(),"Entry " + entry.getKey() + " was null!"); } //recast for adapting input inputs = recastInputs(inputs); if(savedModelConfig != null) { Map<String, TF_Tensor> outputArrays = new LinkedHashMap<>(); Map<String, org.bytedeco.tensorflow.TF_Operation> opsByName = new HashMap<>(); org.bytedeco.tensorflow.TF_Output inputOut = new org.bytedeco.tensorflow.TF_Output(savedModelConfig.getSavedModelInputOrder().size()); TF_Tensor[] inputTensors = new TF_Tensor[savedModelConfig.getSavedModelInputOrder().size()]; for(int i = 0; i < savedModelConfig.getSavedModelInputOrder().size(); i++) { String[] name = savedModelConfig.getSavedModelInputOrder().get(i).split(":"); org.bytedeco.tensorflow.TF_Operation inputOp = TF_GraphOperationByName(graph, name[0]); opsByName.put(savedModelConfig.getSavedModelInputOrder().get(i),inputOp); inputOut.position(i).oper(inputOp).index(name.length > 1 ? Integer.parseInt(name[1]) : 0); TF_Tensor tfTensor = inputs.get(inputOrder != null && !inputOrder.isEmpty() ? inputOrder.get(i) : savedModelConfig.getSavedModelInputOrder().get(i)); inputTensors[i] = tfTensor; } //reset the position of the pointer for execution inputOut.position(0); org.bytedeco.tensorflow.TF_Output outputOut = new org.bytedeco.tensorflow.TF_Output(savedModelConfig.getSaveModelOutputOrder().size()); //only setup the output ops for(int i = 0; i < savedModelConfig.getSaveModelOutputOrder().size(); i++) { String[] name = savedModelConfig.getSaveModelOutputOrder().get(i).split(":"); org.bytedeco.tensorflow.TF_Operation outputOp = TF_GraphOperationByName(graph, name[0]); opsByName.put(savedModelConfig.getSaveModelOutputOrder().get(i),outputOp); outputOut.position(i).oper(outputOp).index(name.length > 1 ? Integer.parseInt(name[1]) : 0); } //reset the position of the pointer for execution outputOut.position(0); //these are references to the nd4j ndarrays wrapped for tensorflow PointerPointer<TF_Tensor> inputTensorsPointer = new PointerPointer<>(inputTensors); //note that these are the result pointers //the result pointers are null, and will be populated automatically by the session run PointerPointer<TF_Tensor> outputTensorsPointer = new PointerPointer<>(savedModelConfig.getSaveModelOutputOrder().size()); long start = System.nanoTime(); TF_SessionRun( session, null, //inputs inputOut, inputTensorsPointer, inputTensors.length, //outputSchema outputOut, outputTensorsPointer, savedModelConfig.getSaveModelOutputOrder().size(), //targets null, 0, null, status); long end = System.nanoTime(); long diff = TimeUnit.NANOSECONDS.toMillis((end - start)); log.debug("Session runtime: {} ms", diff); if (TF_GetCode(status) != TF_OK) { throw new IllegalStateException("ERROR: Unable to run session " + TF_Message(status).getString()); } else { for(int i = 0; i < outputOrder.size(); i++) { outputArrays.put(outputOrder != null && !outputOrder.isEmpty() ? outputOrder.get(i) : savedModelConfig.getSaveModelOutputOrder().get(i),new TF_Tensor(outputTensorsPointer.get(i))); } } return outputArrays; } else { Map<String, TF_Tensor> outputArrays = new LinkedHashMap<>(); int inputOrderSize = inputOrder == null ? 0 : inputOrder.size(); Map<String, org.bytedeco.tensorflow.TF_Operation> opsByName = new HashMap<>(); org.bytedeco.tensorflow.TF_Output inputOut = new org.bytedeco.tensorflow.TF_Output(inputOrderSize); TF_Tensor[] inputTensors = new TF_Tensor[inputOrderSize]; for(int i = 0; i < inputOrderSize; i++) { String[] name = inputOrder.get(i).split(":"); org.bytedeco.tensorflow.TF_Operation inputOp = TF_GraphOperationByName(graph, name[0]); opsByName.put(inputOrder.get(i),inputOp); inputOut.position(i).oper(inputOp).index(name.length > 1 ? Integer.parseInt(name[1]) : 0); TF_Tensor tf_tensor = inputs.get(inputOrder.get(i)); inputTensors[i] = tf_tensor; } //reset the position of the pointer for execution inputOut.position(0); int outputOrderSize = outputOrder == null ? 0 : outputOrder.size(); org.bytedeco.tensorflow.TF_Output outputOut = new org.bytedeco.tensorflow.TF_Output(outputOrder.size()); //only setup the output ops for(int i = 0; i < outputOrderSize; i++) { String[] name = outputOrder.get(i).split(":"); org.bytedeco.tensorflow.TF_Operation outputOp = TF_GraphOperationByName(graph, name[0]); if(outputOp == null) { throw new IllegalArgumentException("Illegal output found " + outputOrder.get(i) + " - no op found! Mis specified name perhaps?"); } opsByName.put(outputOrder.get(i),outputOp); outputOut.position(i).oper(outputOp).index(name.length > 1 ? Integer.parseInt(name[1]) : 0); } //reset the position of the pointer for execution outputOut.position(0); //these are references to the nd4j ndarrays wrapped for tensorflow PointerPointer<TF_Tensor> inputTensorsPointer = new PointerPointer<>(inputTensors); //note that these are the result pointers //the result pointers are null, and will be populated automatically by the session run PointerPointer<TF_Tensor> outputTensorsPointer = new PointerPointer<>(outputOrderSize); long start = System.nanoTime(); TF_SessionRun( session, null, //inputs inputOut, inputTensorsPointer, inputOrderSize, //output outputOut, outputTensorsPointer, outputOrderSize, //targets null, 0, null, status); long end = System.nanoTime(); long diff = TimeUnit.NANOSECONDS.toMillis((end - start)); log.debug("Session runtime: {} ms", diff); if (TF_GetCode(status) != TF_OK) { throw new IllegalStateException("ERROR: Unable to run session " + TF_Message(status).getString()); } else { for(int i = 0; i < outputOrder.size(); i++) { outputArrays.put(outputOrder.get(i),new TF_Tensor(outputTensorsPointer.get(i))); } } return outputArrays; } }
Run the graph definition with the given inputs in native tensorflow @param inputs the inputs to run @return the outputSchema from the native tensorflow wrapper
GraphRunner::runTfTensor
java
deeplearning4j/deeplearning4j
nd4j/nd4j-tensorflow/src/main/java/org/nd4j/tensorflow/conversion/graphrunner/GraphRunner.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-tensorflow/src/main/java/org/nd4j/tensorflow/conversion/graphrunner/GraphRunner.java
Apache-2.0
public static org.tensorflow.framework.ConfigProto fromJson(String json) { org.tensorflow.framework.ConfigProto.Builder builder = org.tensorflow.framework.ConfigProto.newBuilder(); try { org.nd4j.shade.protobuf.util.JsonFormat.parser().merge(json,builder); org.tensorflow.framework.ConfigProto build = builder.build(); org.nd4j.shade.protobuf.ByteString serialized = build.toByteString(); byte[] binaryString = serialized.toByteArray(); org.tensorflow.framework.ConfigProto configProto = org.tensorflow.framework.ConfigProto.parseFrom(binaryString); return configProto; } catch (Exception e) { log.error("",e); } return null; }
Convert a json string written out by {@link org.nd4j.shade.protobuf.util.JsonFormat} to a {@link org.bytedeco.tensorflow.ConfigProto} @param json the json to read @return the config proto to use
GraphRunner::fromJson
java
deeplearning4j/deeplearning4j
nd4j/nd4j-tensorflow/src/main/java/org/nd4j/tensorflow/conversion/graphrunner/GraphRunner.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-tensorflow/src/main/java/org/nd4j/tensorflow/conversion/graphrunner/GraphRunner.java
Apache-2.0
public static TF_Tensor castTensor(TF_Tensor input, TensorDataType from, TensorDataType to) { if(from.equals(to)) return input; Map<String, TF_Tensor> inputMap = new HashMap<>(); inputMap.put("input",input); GraphRunner graphRunner = getRunner(from,to); try { Map<String, TF_Tensor> output = graphRunner.runTfTensor(inputMap); return output.get("cast_output"); } catch(Exception e) { throw new IllegalStateException("Unable to run graph",e); } }
Cast a tensor to another type using the tensorflow c api. This method loads a graph from the classpath from cast_graph/cast_(name of datatype lower case).pb which contains a simple protobuf file with a variant data type tensorflow input place holder named place holder and an output named cast_output. @param input the input data @param from the input data type to cast from @param to the output data type to @return the casted tensor
GraphRunner::castTensor
java
deeplearning4j/deeplearning4j
nd4j/nd4j-tensorflow/src/main/java/org/nd4j/tensorflow/conversion/graphrunner/GraphRunner.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-tensorflow/src/main/java/org/nd4j/tensorflow/conversion/graphrunner/GraphRunner.java
Apache-2.0
public String sessionOptionsToJson() { if(sessionOptionsConfigProto == null) return null; try { return org.nd4j.shade.protobuf.util.JsonFormat.printer().print(sessionOptionsConfigProto); } catch (Exception e) { log.error("",e); } return null; }
Write out the session options used by this {@link org.nd4j.tensorflow.conversion.graphrunner.GraphRunner} a s a json string using the {@link org.nd4j.shade.protobuf.util.JsonFormat} @return the session options as json (mainly for debugging)
GraphRunner::sessionOptionsToJson
java
deeplearning4j/deeplearning4j
nd4j/nd4j-tensorflow/src/main/java/org/nd4j/tensorflow/conversion/graphrunner/GraphRunner.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-tensorflow/src/main/java/org/nd4j/tensorflow/conversion/graphrunner/GraphRunner.java
Apache-2.0
public static INDArray[] ndarraysFromSequence(Value outValue,OrtAllocator ortAllocator) { Preconditions.checkState(outValue.HasValue(),"No value found in specified value!"); INDArray[] ret = new INDArray[(int) outValue.GetCount()]; for(int i = 0; i < ret.length; i++) { INDArray retValue = getArray(outValue.GetValue(i,ortAllocator)); ret[i] = retValue; } return ret; }
Return the {@link INDArray} from a sequence @param outValue the input sequence to get the ndarrays from @param ortAllocator the allocator to use to retrieve relevant memory @return the equivalent arrays
ONNXUtils::ndarraysFromSequence
java
deeplearning4j/deeplearning4j
nd4j/nd4j-onnxruntime/src/main/java/org/nd4j/onnxruntime/util/ONNXUtils.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-onnxruntime/src/main/java/org/nd4j/onnxruntime/util/ONNXUtils.java
Apache-2.0
public static ValueVector getSequence(List<INDArray> sequence,MemoryInfo memoryInfo) { ValueVector valueVector = new ValueVector(sequence.size()); for(int i = 0; i < sequence.size(); i++) { valueVector.put(getTensor(sequence.get(i),memoryInfo)); } return valueVector; }
Create a sequence from a list of tensors returning a {@link ValueVector} equivalent using {@link #getTensor(INDArray, MemoryInfo)} @param sequence the sequence to get @param memoryInfo the memory info to use for allocation @return
ONNXUtils::getSequence
java
deeplearning4j/deeplearning4j
nd4j/nd4j-onnxruntime/src/main/java/org/nd4j/onnxruntime/util/ONNXUtils.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-onnxruntime/src/main/java/org/nd4j/onnxruntime/util/ONNXUtils.java
Apache-2.0
public static ONNXType getTypeForOutput(Session session,int i) { TypeInfo typeInfo = session.GetOutputTypeInfo(i); return ONNXType.values()[typeInfo.GetONNXType()]; }
Get the onnx type of the output @param session the session to get the input for @param i the index of the output @return
ONNXUtils::getTypeForOutput
java
deeplearning4j/deeplearning4j
nd4j/nd4j-onnxruntime/src/main/java/org/nd4j/onnxruntime/util/ONNXUtils.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-onnxruntime/src/main/java/org/nd4j/onnxruntime/util/ONNXUtils.java
Apache-2.0
public static ONNXType getTypeForInput(Session session,long i) { TypeInfo typeInfo = session.GetInputTypeInfo(i); return ONNXType.values()[typeInfo.GetONNXType()]; }
Get the onnx type of the input @param session the session to get the output type info from @param i the index of the input @return the relevant type information
ONNXUtils::getTypeForInput
java
deeplearning4j/deeplearning4j
nd4j/nd4j-onnxruntime/src/main/java/org/nd4j/onnxruntime/util/ONNXUtils.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-onnxruntime/src/main/java/org/nd4j/onnxruntime/util/ONNXUtils.java
Apache-2.0
public static INDArray getSampleForValueInfo(Onnx.ValueInfoProto valueInfoProto) { Preconditions.checkState(valueInfoProto.hasType(),"Value info must have a type!"); Onnx.TypeProto.Tensor tensorType = valueInfoProto.getType().getTensorType(); long[] shape = Longs.toArray(tensorType.getShape().getDimList().stream().map(input -> input.getDimValue()).collect(Collectors.toList())); DataType type = dataTypeForOnnxType(tensorType.getElemType()); return Nd4j.create(type,shape); }
Returns a zeroed array of the input data. This array's shape and data type are determined from {@link Onnx.ValueInfoProto#getType()} tensor field. given the value type. Mainly used for quick debugging/ testing. @param valueInfoProto the value info proto to get the shape information from @return the sample tensor
ONNXUtils::getSampleForValueInfo
java
deeplearning4j/deeplearning4j
nd4j/nd4j-onnxruntime/src/main/java/org/nd4j/onnxruntime/util/ONNXUtils.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-onnxruntime/src/main/java/org/nd4j/onnxruntime/util/ONNXUtils.java
Apache-2.0
public static void validateType(DataType expected, INDArray array) { if (!array.dataType().equals(expected)) throw new RuntimeException("INDArray data type (" + array.dataType() + ") does not match required ONNX data type (" + expected + ")"); }
@param expected @param array
ONNXUtils::validateType
java
deeplearning4j/deeplearning4j
nd4j/nd4j-onnxruntime/src/main/java/org/nd4j/onnxruntime/util/ONNXUtils.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-onnxruntime/src/main/java/org/nd4j/onnxruntime/util/ONNXUtils.java
Apache-2.0
public static DataType dataTypeForOnnxType(int dataType) { if(dataType == dataType) { return FLOAT; } else if(dataType == ONNX_TENSOR_ELEMENT_DATA_TYPE_INT8) { return INT8; } else if(dataType == ONNX_TENSOR_ELEMENT_DATA_TYPE_DOUBLE) { return DOUBLE; } else if(dataType == ONNX_TENSOR_ELEMENT_DATA_TYPE_BOOL) { return BOOL; } else if(dataType == ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT8) { return UINT8; } else if(dataType == ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT16) { return UINT16; } else if(dataType == ONNX_TENSOR_ELEMENT_DATA_TYPE_INT16) { return INT16; } else if(dataType == ONNX_TENSOR_ELEMENT_DATA_TYPE_INT32) { return INT32; } else if(dataType == ONNX_TENSOR_ELEMENT_DATA_TYPE_INT64) { return INT64; } else if(dataType == ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT16) { return FLOAT16; } else if(dataType == ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT32) { return UINT32; } else if(dataType == ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT64) { return UINT64; } else if(dataType == ONNX_TENSOR_ELEMENT_DATA_TYPE_BFLOAT16) { return BFLOAT16; } else throw new IllegalArgumentException("Illegal data type " + dataType); }
Return a {@link DataType} for the onnx data type @param dataType the equivalent nd4j data type @return
ONNXUtils::dataTypeForOnnxType
java
deeplearning4j/deeplearning4j
nd4j/nd4j-onnxruntime/src/main/java/org/nd4j/onnxruntime/util/ONNXUtils.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-onnxruntime/src/main/java/org/nd4j/onnxruntime/util/ONNXUtils.java
Apache-2.0
public static int onnxTypeForDataType(DataType dataType) { if(dataType == FLOAT) { return ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT; } else if(dataType == INT8) { return ONNX_TENSOR_ELEMENT_DATA_TYPE_INT8; } else if(dataType == DOUBLE) { return ONNX_TENSOR_ELEMENT_DATA_TYPE_DOUBLE; } else if(dataType == BOOL) { return ONNX_TENSOR_ELEMENT_DATA_TYPE_BOOL; } else if(dataType == UINT8) { return ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT8; } else if(dataType == UINT16) { return ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT16; } else if(dataType == INT16) { return ONNX_TENSOR_ELEMENT_DATA_TYPE_INT16; } else if(dataType == INT32) { return ONNX_TENSOR_ELEMENT_DATA_TYPE_INT32; } else if(dataType == INT64) { return ONNX_TENSOR_ELEMENT_DATA_TYPE_INT64; } else if(dataType == FLOAT16) { return ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT16; } else if(dataType == UINT32) { return ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT32; } else if(dataType == UINT64) { return ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT64; } else if(dataType == BFLOAT16) { return ONNX_TENSOR_ELEMENT_DATA_TYPE_BFLOAT16; } else throw new IllegalArgumentException("Illegal data type " + dataType); }
Convert the onnx type for the given data type @param dataType @return
ONNXUtils::onnxTypeForDataType
java
deeplearning4j/deeplearning4j
nd4j/nd4j-onnxruntime/src/main/java/org/nd4j/onnxruntime/util/ONNXUtils.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-onnxruntime/src/main/java/org/nd4j/onnxruntime/util/ONNXUtils.java
Apache-2.0
public static INDArray getArray(Value value) { DataType dataType = dataTypeForOnnxType(value.GetTypeInfo().GetONNXType()); LongVector shape = value.GetTensorTypeAndShapeInfo().GetShape(); long[] shapeConvert; if(shape != null) { shapeConvert = new long[(int) value.GetTensorTypeAndShapeInfo().GetDimensionsCount()]; for(int j = 0; j < shapeConvert.length; j++) { shapeConvert[j] = shape.get(j); } } else { shapeConvert = new long[]{1}; } DataBuffer getBuffer = getDataBuffer(value); Preconditions.checkState(dataType.equals(getBuffer.dataType()),"Data type must be equivalent as specified by the onnx metadata."); return Nd4j.create(getBuffer,shapeConvert,Nd4j.getStrides(shapeConvert),0); }
Convert an onnx {@link Value} in to an {@link INDArray} @param value the value to convert @return
ONNXUtils::getArray
java
deeplearning4j/deeplearning4j
nd4j/nd4j-onnxruntime/src/main/java/org/nd4j/onnxruntime/util/ONNXUtils.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-onnxruntime/src/main/java/org/nd4j/onnxruntime/util/ONNXUtils.java
Apache-2.0
public static int getOnnxLogLevelFromLogger(Logger logger) { if(logger.isTraceEnabled() || logger.isDebugEnabled()) { return ORT_LOGGING_LEVEL_VERBOSE; } else if(logger.isInfoEnabled()) { return ORT_LOGGING_LEVEL_INFO; } else if(logger.isWarnEnabled()) { return ORT_LOGGING_LEVEL_WARNING; } else if(logger.isErrorEnabled()) { return ORT_LOGGING_LEVEL_ERROR; } return ORT_LOGGING_LEVEL_INFO; }
Get the onnx log level relative to the given slf4j logger. Trace or debug will return ORT_LOGGING_LEVEL_VERBOSE Info will return: ORT_LOGGING_LEVEL_INFO Warn returns ORT_LOGGING_LEVEL_WARNING Error returns error ORT_LOGGING_LEVEL_ERROR The default is info @param logger the slf4j logger to get the onnx log level for @return
ONNXUtils::getOnnxLogLevelFromLogger
java
deeplearning4j/deeplearning4j
nd4j/nd4j-onnxruntime/src/main/java/org/nd4j/onnxruntime/util/ONNXUtils.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-onnxruntime/src/main/java/org/nd4j/onnxruntime/util/ONNXUtils.java
Apache-2.0
public static Value getTensor(INDArray ndArray, MemoryInfo memoryInfo) { if(ndArray == null || ndArray.isEmpty()) { /** * static Value CreateTensor(const OrtMemoryInfo* info, void* p_data, size_t p_data_byte_count, const int64_t* shape, size_t shape_len, * ONNXTensorElementDataType type) */ LongPointer dims = new LongPointer(0); Value ret = Value.CreateTensor( memoryInfo.asOrtMemoryInfo(), new FloatPointer(), 0, dims, 0, onnxTypeForDataType(FLOAT)); return ret; } Pointer inputTensorValuesPtr = ndArray.data().pointer(); Pointer inputTensorValues = inputTensorValuesPtr; long sizeInBytes = ndArray.length() * ndArray.data().getElementSize(); /** * static Value CreateTensor(const OrtMemoryInfo* info, void* p_data, size_t p_data_byte_count, const int64_t* shape, size_t shape_len, * ONNXTensorElementDataType type) */ LongPointer dims = new LongPointer(ndArray.shape()); Value ret = Value.CreateTensor( memoryInfo.asOrtMemoryInfo(), inputTensorValues, sizeInBytes, dims, ndArray.rank(), onnxTypeForDataType(ndArray.dataType())); return ret; }
Get an onnx tensor from an ndarray. @param ndArray the ndarray to get the value from @param memoryInfo the {@link MemoryInfo} to use. Can be created with: MemoryInfo memoryInfo = MemoryInfo.CreateCpu(OrtArenaAllocator, OrtMemTypeDefault); @return
ONNXUtils::getTensor
java
deeplearning4j/deeplearning4j
nd4j/nd4j-onnxruntime/src/main/java/org/nd4j/onnxruntime/util/ONNXUtils.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-onnxruntime/src/main/java/org/nd4j/onnxruntime/util/ONNXUtils.java
Apache-2.0
public static void checkVersions(){ boolean doCheck = Boolean.parseBoolean(System.getProperty(ND4JSystemProperties.VERSION_CHECK_PROPERTY, "true")); if(!doCheck){ return; } if(ND4JClassLoading.classPresentOnClasspath(ND4J_JBLAS_CLASS)) { //nd4j-jblas is ancient and incompatible log.error("Found incompatible/obsolete backend and version (nd4j-jblas) on classpath. ND4J is unlikely to" + " function correctly with nd4j-jblas on the classpath. JVM will now exit."); System.exit(1); } if(ND4JClassLoading.classPresentOnClasspath(CANOVA_CLASS)) { //Canova is ancient and likely to pull in incompatible dependencies log.error("Found incompatible/obsolete library Canova on classpath. ND4J is unlikely to" + " function correctly with this library on the classpath. JVM will now exit."); System.exit(1); } List<VersionInfo> dependencies = getVersionInfos(); if(dependencies.size() <= 2){ //No -properties.git files were found on the classpath. This may be due to a misconfigured uber-jar // or maybe running in IntelliJ with "dynamic.classpath" set to true (in workspace.xml). Either way, // we can't check versions and don't want to log an error, which will more often than not be wrong if(dependencies.size() == 0){ return; } //Another edge case: no -properties.git files were found, but DL4J and/or DataVec were inferred // by class names. If these "inferred by opName" versions were the only things found, we should also // not log a warning, as we can't check versions in this case boolean dl4jViaClass = false; boolean datavecViaClass = false; for(VersionInfo vi : dependencies ){ if(DL4J_GROUPID.equals(vi.getGroupId()) && DL4J_ARTIFACT.equals(vi.getArtifactId()) && (UNKNOWN_VERSION.equals(vi.getBuildVersion()))){ dl4jViaClass = true; } else if(DATAVEC_GROUPID.equals(vi.getGroupId()) && DATAVEC_ARTIFACT.equals(vi.getArtifactId()) && (UNKNOWN_VERSION.equals(vi.getBuildVersion()))){ datavecViaClass = true; } } if(dependencies.size() == 1 && (dl4jViaClass || datavecViaClass)){ return; } else if(dependencies.size() == 2 && dl4jViaClass && datavecViaClass){ return; } } Set<String> foundVersions = new HashSet<>(); for(VersionInfo vi : dependencies){ String g = vi.getGroupId(); if(g != null && GROUPIDS_TO_CHECK.contains(g)){ String version = vi.getBuildVersion(); if(version.contains("_spark_")){ //Normalize spark versions: // "0.9.1_spark_1" to "0.9.1" and "0.9.1_spark_1-SNAPSHOT" to "0.9.1-SNAPSHOT" version = version.replaceAll("_spark_1",""); version = version.replaceAll("_spark_2",""); } foundVersions.add(version); } } boolean logVersions = false; if(foundVersions.size() > 1){ log.warn("*** ND4J VERSION CHECK FAILED - INCOMPATIBLE VERSIONS FOUND ***"); log.warn("Incompatible versions (different version number) of DL4J, ND4J, RL4J, DataVec, Arbiter are unlikely to function correctly"); logVersions = true; } //Also: check for mixed scala versions - but only for our dependencies... These are in the artifact ID, // scored like dl4j-spack_2.10 and deeplearning4j-ui_2.11 //And check for mixed spark versions (again, just DL4J/DataVec etc dependencies for now) boolean scala210 = false; boolean scala211 = false; boolean spark1 = false; boolean spark2 = false; for(VersionInfo vi : dependencies){ String artifact = vi.getArtifactId(); if(!scala210 && artifact.contains(SCALA_210_SUFFIX)){ scala210 = true; } if(!scala211 && artifact.contains(SCALA_211_SUFFIX)){ scala211 = true; } String version = vi.getBuildVersion(); if(!spark1 && version.contains(SPARK_1_VER_STRING)){ spark1 = true; } if(!spark2 && version.contains(SPARK_2_VER_STRING)){ spark2 = true; } } if(scala210 && scala211){ log.warn("*** ND4J VERSION CHECK FAILED - FOUND BOTH SCALA VERSION 2.10 AND 2.11 ARTIFACTS ***"); log.warn("Projects with mixed Scala versions (2.10/2.11) are unlikely to function correctly"); logVersions = true; } if(spark1 && spark2){ log.warn("*** ND4J VERSION CHECK FAILED - FOUND BOTH SPARK VERSION 1 AND 2 ARTIFACTS ***"); log.warn("Projects with mixed Spark versions (1 and 2) are unlikely to function correctly"); logVersions = true; } if(logVersions){ log.info("Versions of artifacts found on classpath:"); logVersionInfo(); } }
Perform a check of the versions of ND4J, DL4J, DataVec, RL4J and Arbiter dependencies, logging a warning if necessary.
Detail::checkVersions
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/versioncheck/VersionCheck.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/versioncheck/VersionCheck.java
Apache-2.0
public NDArrayList(int size) { this(DataType.DOUBLE, size); }
Initialize with the desired size. This will set the list.size() to be equal to the passed in size @param size the initial size of the array
NDArrayList::NDArrayList
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/list/NDArrayList.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/list/NDArrayList.java
Apache-2.0
public NDArrayList(@NonNull INDArray container,int size) { Preconditions.checkState(container == null || container.rank() == 1, "Container must be rank 1: is rank %s", container == null ? 0 : container.rank()); this.container = container; this.size = size; }
Specify the underlying ndarray for this list. @param container the underlying array. @param size the initial size of the array. This will set list.size() to be equal to the passed in size.
NDArrayList::NDArrayList
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/list/NDArrayList.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/list/NDArrayList.java
Apache-2.0
public NDArrayList(@NonNull INDArray container) { this(container,0); }
Specify the underlying ndarray for this list. @param container the underlying array.
NDArrayList::NDArrayList
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/list/NDArrayList.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/list/NDArrayList.java
Apache-2.0
public INDArray array() { return container.get(NDArrayIndex.interval(0,size)).reshape(1,size); }
Get a view of the underlying array relative to the size of the actual array. (Sometimes there are overflows in the internals but you want to use the internal INDArray for computing something directly, this gives you the relevant subset that reflects the content of the list) @return the view of the underlying ndarray relative to the collection's real size
BaseNDArrayList::array
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/list/BaseNDArrayList.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/list/BaseNDArrayList.java
Apache-2.0
public String memoryPerDevice() { StringBuilder stringBuilder = new StringBuilder(); for(int i = 0; i < Nd4j.getAffinityManager().getNumberOfDevices(); i++) { stringBuilder.append("------Device: " + i + "---------------\n"); stringBuilder.append("Allocated on device: " + allocatedPerDevice.get(i).get() + "\n"); stringBuilder.append("Total workspace memory allocated for device: " + workspacesPerDevice.get(i).get() + "\n"); stringBuilder.append("Cached memory for device: " + cachedPerDevice.get(i).get() + "\n"); stringBuilder.append("Total device memory available: " + totalPerDevice.get(i).get() + "\n"); stringBuilder.append("Free total memory for device: " + freePerDevice.get(i).get() + "\n"); stringBuilder.append("-----------------------------------------\n"); } return stringBuilder.toString(); }
toString() overview of every device's current status including available memory, number of workspaces per device, free memory per device, total memory available for a device @return
MemoryTracker::memoryPerDevice
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/allocator/impl/MemoryTracker.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/allocator/impl/MemoryTracker.java
Apache-2.0
public long getCachedHostAmount() { return cachedHost.get(); }
This method returns number of bytes currently cached from host memory @return
MemoryTracker::getCachedHostAmount
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/allocator/impl/MemoryTracker.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/allocator/impl/MemoryTracker.java
Apache-2.0
public long getAllocatedHostAmount() { return allocatedHost.get(); }
This method returns number of bytes currently allocated from host memory @return
MemoryTracker::getAllocatedHostAmount
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/allocator/impl/MemoryTracker.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/allocator/impl/MemoryTracker.java
Apache-2.0
public long getActiveHostAmount() { return getAllocatedHostAmount() + getCachedHostAmount(); }
This method returns number of bytes allocated and cached in host ram @return
MemoryTracker::getActiveHostAmount
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/allocator/impl/MemoryTracker.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/allocator/impl/MemoryTracker.java
Apache-2.0
public long getApproximateFreeMemory(int deviceId) { val externalAllocations = getTotalMemory(deviceId) - getFreeMemory(deviceId); val active = getActiveMemory(deviceId); val free = getTotalMemory(deviceId) - (active + externalAllocations); return free; }
This method returns approximate free memory on specified device @param deviceId @return
MemoryTracker::getApproximateFreeMemory
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/allocator/impl/MemoryTracker.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/allocator/impl/MemoryTracker.java
Apache-2.0
public long getPreciseFreeMemory(int deviceId) { // we refresh free memory on device val extFree =Nd4j.getNativeOps().getDeviceFreeMemory(deviceId); return extFree; }
This method returns precise amount of free memory on specified device @param deviceId @return
MemoryTracker::getPreciseFreeMemory
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/allocator/impl/MemoryTracker.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/allocator/impl/MemoryTracker.java
Apache-2.0
public long getUsableMemory(int deviceId) { return getTotalMemory(deviceId) - getFreeMemory(deviceId); }
This method returns delta between total memory and free memory @param deviceId @return
MemoryTracker::getUsableMemory
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/allocator/impl/MemoryTracker.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/allocator/impl/MemoryTracker.java
Apache-2.0
public long getActiveMemory(int deviceId) { return getWorkspaceAllocatedAmount(deviceId) + getAllocatedAmount(deviceId) + getCachedAmount(deviceId); }
This method returns total amount of device memory allocated on specified device Includes: workspace memory, cached memory, regular memory @param deviceId @return
MemoryTracker::getActiveMemory
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/allocator/impl/MemoryTracker.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/allocator/impl/MemoryTracker.java
Apache-2.0
public long getManagedMemory(int deviceId) { return getAllocatedAmount(deviceId) + getCachedAmount(deviceId); }
This method returns amount of memory that relies on JVM GC Includes: cached memory, regular allocated memory @param deviceId @return
MemoryTracker::getManagedMemory
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/allocator/impl/MemoryTracker.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/allocator/impl/MemoryTracker.java
Apache-2.0
public void incrementAllocatedAmount(int deviceId, long memoryAdded) { allocatedPerDevice.get(deviceId).getAndAdd(matchBlock(memoryAdded)); }
This method increments amount of regular allocated memory @param deviceId @param memoryAdded
MemoryTracker::incrementAllocatedAmount
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/allocator/impl/MemoryTracker.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/allocator/impl/MemoryTracker.java
Apache-2.0
public void incrementCachedAmount(int deviceId, long memoryAdded) { cachedPerDevice.get(deviceId).getAndAdd(matchBlock(memoryAdded)); }
This method increments amount of cached memory @param deviceId @param memoryAdded
MemoryTracker::incrementCachedAmount
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/allocator/impl/MemoryTracker.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/allocator/impl/MemoryTracker.java
Apache-2.0
public void decrementAllocatedAmount(int deviceId, long memorySubtracted) { allocatedPerDevice.get(deviceId).getAndAdd(-matchBlock(memorySubtracted)); }
This method decrements amount of regular allocated memory @param deviceId @param memorySubtracted
MemoryTracker::decrementAllocatedAmount
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/allocator/impl/MemoryTracker.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/allocator/impl/MemoryTracker.java
Apache-2.0
public void decrementCachedAmount(int deviceId, long memorySubtracted) { cachedPerDevice.get(deviceId).getAndAdd(-matchBlock(memorySubtracted)); }
This method decrements amount of cached memory @param deviceId @param memorySubtracted
MemoryTracker::decrementCachedAmount
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/allocator/impl/MemoryTracker.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/allocator/impl/MemoryTracker.java
Apache-2.0
public void incrementWorkspaceAllocatedAmount(int deviceId, long memoryAdded) { workspacesPerDevice.get(deviceId).getAndAdd(matchBlock(memoryAdded)); }
This method increments amount of memory allocated within workspaces @param deviceId @param memoryAdded
MemoryTracker::incrementWorkspaceAllocatedAmount
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/allocator/impl/MemoryTracker.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/allocator/impl/MemoryTracker.java
Apache-2.0
public void decrementWorkspaceAmount(int deviceId, long memorySubtracted) { workspacesPerDevice.get(deviceId).getAndAdd(-matchBlock(memorySubtracted)); }
This method decrements amount of memory allocated within workspaces @param deviceId @param memorySubtracted
MemoryTracker::decrementWorkspaceAmount
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/allocator/impl/MemoryTracker.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/allocator/impl/MemoryTracker.java
Apache-2.0
public static <T extends IEvaluation> T fromYaml(String yaml, Class<T> clazz) { try { return JsonMappers.getYamlMapper().readValue(yaml, clazz); } catch (IOException e) { throw new RuntimeException(e); } }
@param yaml YAML representation @param clazz Class @param <T> Type to return @return Evaluation instance
BaseEvaluation::fromYaml
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/BaseEvaluation.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/BaseEvaluation.java
Apache-2.0
public static <T extends IEvaluation> T fromJson(String json, Class<T> clazz) { try { return JsonMappers.getMapper().readValue(json, clazz); } catch (InvalidTypeIdException e) { if (e.getMessage().contains("Could not resolve type id")) { try { return (T) attempFromLegacyFromJson(json, e); } catch (Throwable t) { throw new RuntimeException("Cannot deserialize from JSON - JSON is invalid?", t); } } throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } }
@param json Jason representation of the evaluation instance @param clazz Class @param <T> Type to return @return Evaluation instance
BaseEvaluation::fromJson
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/BaseEvaluation.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/BaseEvaluation.java
Apache-2.0
protected static <T extends IEvaluation> T attempFromLegacyFromJson(String json, InvalidTypeIdException originalException) throws InvalidTypeIdException { if (json.contains("org.deeplearning4j.eval.Evaluation")) { String newJson = json.replaceAll("org.deeplearning4j.eval.Evaluation", "org.nd4j.evaluation.classification.Evaluation"); return (T) fromJson(newJson, Evaluation.class); } if (json.contains("org.deeplearning4j.eval.EvaluationBinary")) { String newJson = json.replaceAll("org.deeplearning4j.eval.EvaluationBinary", "org.nd4j.evaluation.classification.EvaluationBinary") .replaceAll("org.deeplearning4j.eval.ROC", "org.nd4j.evaluation.classification.ROC") .replaceAll("org.deeplearning4j.eval.curves.", "org.nd4j.evaluation.curves."); return (T) fromJson(newJson, EvaluationBinary.class); } if (json.contains("org.deeplearning4j.eval.EvaluationCalibration")) { String newJson = json.replaceAll("org.deeplearning4j.eval.EvaluationCalibration", "org.nd4j.evaluation.classification.EvaluationCalibration") .replaceAll("org.deeplearning4j.eval.curves.", "org.nd4j.evaluation.curves."); return (T) fromJson(newJson, EvaluationCalibration.class); } if (json.contains("org.deeplearning4j.eval.ROCBinary")) { String newJson = json.replaceAll("org.deeplearning4j.eval.ROCBinary", "org.nd4j.evaluation.classification.ROCBinary") .replaceAll("org.deeplearning4j.eval.ROC", "org.nd4j.evaluation.classification.ROC") //Nested ROC instances internally .replaceAll("org.deeplearning4j.eval.curves.", "org.nd4j.evaluation.curves."); return (T) fromJson(newJson, ROCBinary.class); } if (json.contains("org.deeplearning4j.eval.ROCMultiClass")) { String newJson = json.replaceAll("org.deeplearning4j.eval.ROCMultiClass", "org.nd4j.evaluation.classification.ROCMultiClass") .replaceAll("org.deeplearning4j.eval.ROC", "org.nd4j.evaluation.classification.ROC") //Nested ROC instances internally .replaceAll("org.deeplearning4j.eval.curves.", "org.nd4j.evaluation.curves."); return (T) fromJson(newJson, ROCMultiClass.class); } if (json.contains("org.deeplearning4j.eval.ROC")) { //Has to be checked after ROCBinary/ROCMultiClass due to it being a prefix String newJson = json.replaceAll("org.deeplearning4j.eval.ROC", "org.nd4j.evaluation.classification.ROC") .replaceAll("org.deeplearning4j.eval.curves.", "org.nd4j.evaluation.curves."); return (T) fromJson(newJson, ROC.class); } if (json.contains("org.deeplearning4j.eval.RegressionEvaluation")) { String newJson = json.replaceAll("org.deeplearning4j.eval.RegressionEvaluation", "org.nd4j.evaluation.regression.RegressionEvaluation"); return (T) fromJson(newJson, RegressionEvaluation.class); } throw originalException; }
Attempt to load DL4J IEvaluation JSON from 1.0.0-beta2 or earlier. Given IEvaluation classes were moved to ND4J with no major changes, a simple "find and replace" for the class names is used. @param json JSON to attempt to deserialize @param originalException Original exception to be re-thrown if it isn't legacy JSON
BaseEvaluation::attempFromLegacyFromJson
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/BaseEvaluation.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/BaseEvaluation.java
Apache-2.0
public static double precision(long tpCount, long fpCount, double edgeCase) { //Edge case if (tpCount == 0 && fpCount == 0) { return edgeCase; } return tpCount / (double) (tpCount + fpCount); }
Calculate the precision from true positive and false positive counts @param tpCount True positive count @param fpCount False positive count @param edgeCase Edge case value use to avoid 0/0 @return Precision
EvaluationUtils::precision
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/EvaluationUtils.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/EvaluationUtils.java
Apache-2.0
public static double recall(long tpCount, long fnCount, double edgeCase) { //Edge case if (tpCount == 0 && fnCount == 0) { return edgeCase; } return tpCount / (double) (tpCount + fnCount); }
Calculate the recall from true positive and false negative counts @param tpCount True positive count @param fnCount False negative count @param edgeCase Edge case values used to avoid 0/0 @return Recall
EvaluationUtils::recall
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/EvaluationUtils.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/EvaluationUtils.java
Apache-2.0
public static double falsePositiveRate(long fpCount, long tnCount, double edgeCase) { //Edge case if (fpCount == 0 && tnCount == 0) { return edgeCase; } return fpCount / (double) (fpCount + tnCount); }
Calculate the false positive rate from the false positive count and true negative count @param fpCount False positive count @param tnCount True negative count @param edgeCase Edge case values are used to avoid 0/0 @return False positive rate
EvaluationUtils::falsePositiveRate
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/EvaluationUtils.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/EvaluationUtils.java
Apache-2.0
public static double falseNegativeRate(long fnCount, long tpCount, double edgeCase) { //Edge case if (fnCount == 0 && tpCount == 0) { return edgeCase; } return fnCount / (double) (fnCount + tpCount); }
Calculate the false negative rate from the false negative counts and true positive count @param fnCount False negative count @param tpCount True positive count @param edgeCase Edge case value to use to avoid 0/0 @return False negative rate
EvaluationUtils::falseNegativeRate
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/EvaluationUtils.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/EvaluationUtils.java
Apache-2.0
public static double fBeta(double beta, long tp, long fp, long fn) { double prec = tp / ((double) tp + fp); double recall = tp / ((double) tp + fn); return fBeta(beta, prec, recall); }
Calculate the F beta value from counts @param beta Beta of value to use @param tp True positive count @param fp False positive count @param fn False negative count @return F beta
EvaluationUtils::fBeta
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/EvaluationUtils.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/EvaluationUtils.java
Apache-2.0
public static double fBeta(double beta, double precision, double recall) { if (precision == 0.0 || recall == 0.0) return 0; double numerator = (1 + beta * beta) * precision * recall; double denominator = beta * beta * precision + recall; return numerator / denominator; }
Calculate the F-beta value from precision and recall @param beta Beta value to use @param precision Precision @param recall Recall @return F-beta value
EvaluationUtils::fBeta
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/EvaluationUtils.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/EvaluationUtils.java
Apache-2.0
public static double gMeasure(double precision, double recall) { return Math.sqrt(precision * recall); }
Calculate the G-measure from precision and recall @param precision Precision value @param recall Recall value @return G-measure
EvaluationUtils::gMeasure
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/EvaluationUtils.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/EvaluationUtils.java
Apache-2.0
public static double matthewsCorrelation(long tp, long fp, long fn, long tn) { double numerator = ((double) tp) * tn - ((double) fp) * fn; double denominator = Math.sqrt(((double) tp + fp) * (tp + fn) * (tn + fp) * (tn + fn)); return numerator / denominator; }
Calculate the binary Matthews correlation coefficient from counts @param tp True positive count @param fp False positive counts @param fn False negative counts @param tn True negative count @return Matthews correlation coefficient
EvaluationUtils::matthewsCorrelation
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/EvaluationUtils.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/EvaluationUtils.java
Apache-2.0
protected double calculateArea() { return calculateArea(getX(), getY()); }
@return Area under the curve
BaseCurve::calculateArea
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/curves/BaseCurve.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/curves/BaseCurve.java
Apache-2.0
public String toJson() { try { return JsonMappers.getMapper().writeValueAsString(this); } catch (JsonProcessingException e) { throw new RuntimeException(e); } }
@return JSON representation of the curve
BaseCurve::toJson
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/curves/BaseCurve.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/curves/BaseCurve.java
Apache-2.0
public String toYaml() { try { return JsonMappers.getYamlMapper().writeValueAsString(this); } catch (JsonProcessingException e) { throw new RuntimeException(e); } }
@return YAML representation of the curve
BaseCurve::toYaml
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/curves/BaseCurve.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/curves/BaseCurve.java
Apache-2.0
public static <T extends BaseCurve> T fromJson(String json, Class<T> curveClass) { try { return JsonMappers.getMapper().readValue(json, curveClass); } catch (IOException e) { throw new RuntimeException(e); } }
@param json JSON representation @param curveClass Class for the curve @param <T> Type @return Instance of the curve
BaseCurve::fromJson
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/curves/BaseCurve.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/curves/BaseCurve.java
Apache-2.0
public static <T extends BaseCurve> T fromYaml(String yaml, Class<T> curveClass) { try { return JsonMappers.getYamlMapper().readValue(yaml, curveClass); } catch (IOException e) { throw new RuntimeException(e); } }
@param yaml YAML representation @param curveClass Class for the curve @param <T> Type @return Instance of the curve
BaseCurve::fromYaml
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/curves/BaseCurve.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/curves/BaseCurve.java
Apache-2.0
public double getThreshold(int i) { Preconditions.checkArgument(i >= 0 && i < threshold.length, "Invalid index: " + i); return threshold[i]; }
@param i Point number, 0 to numPoints()-1 inclusive @return Threshold of a given point
RocCurve::getThreshold
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/curves/RocCurve.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/curves/RocCurve.java
Apache-2.0
public double getTruePositiveRate(int i) { Preconditions.checkArgument(i >= 0 && i < tpr.length, "Invalid index: " + i); return tpr[i]; }
@param i Point number, 0 to numPoints()-1 inclusive @return True positive rate of a given point
RocCurve::getTruePositiveRate
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/curves/RocCurve.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/curves/RocCurve.java
Apache-2.0
public double getFalsePositiveRate(int i) { Preconditions.checkArgument(i >= 0 && i < fpr.length, "Invalid index: " + i); return fpr[i]; }
@param i Point number, 0 to numPoints()-1 inclusive @return False positive rate of a given point
RocCurve::getFalsePositiveRate
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/curves/RocCurve.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/curves/RocCurve.java
Apache-2.0
public double calculateAUC() { if (auc != null) { return auc; } auc = calculateArea(); return auc; }
Calculate and return the area under ROC curve
RocCurve::calculateAUC
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/curves/RocCurve.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/curves/RocCurve.java
Apache-2.0
public double getPrecision(int i) { Preconditions.checkArgument(i >= 0 && i < precision.length, "Invalid index: " + i); return precision[i]; }
@param i Point number, 0 to numPoints()-1 inclusive @return Precision of a given point
PrecisionRecallCurve::getPrecision
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/curves/PrecisionRecallCurve.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/curves/PrecisionRecallCurve.java
Apache-2.0
public double getRecall(int i) { Preconditions.checkArgument(i >= 0 && i < recall.length, "Invalid index: " + i); return recall[i]; }
@param i Point number, 0 to numPoints()-1 inclusive @return Recall of a given point
PrecisionRecallCurve::getRecall
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/curves/PrecisionRecallCurve.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/curves/PrecisionRecallCurve.java
Apache-2.0
public double calculateAUPRC() { if (area != null) { return area; } area = calculateArea(); return area; }
@return The area under the precision recall curve
PrecisionRecallCurve::calculateAUPRC
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/curves/PrecisionRecallCurve.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/curves/PrecisionRecallCurve.java
Apache-2.0
public Point getPointAtThreshold(double threshold) { //Return (closest) point number, precision, recall, whether it's interpolated or not //Binary search to find closest threshold int idx = Arrays.binarySearch(this.threshold, threshold); if (idx < 0) { //Not found (usual case). binarySearch javadoc: /* index of the search key, if it is contained in the array; otherwise, (-(insertion point) - 1). The insertion point is defined as the point at which the key would be inserted into the array: the index of the first element greater than the key, or a.length if all elements in the array are less than the specified key. */ idx = -idx - 1; } //At this point: idx = exact, on the next highest double thr = this.threshold[idx]; double pr = precision[idx]; double rec = recall[idx]; return new Point(idx, thr, pr, rec); }
Get the point (index, threshold, precision, recall) at the given threshold.<br> Note that if the threshold is not found exactly, the next highest threshold exceeding the requested threshold is returned @param threshold Threshold to get the point for @return point (index, threshold, precision, recall) at the given threshold
PrecisionRecallCurve::getPointAtThreshold
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/curves/PrecisionRecallCurve.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/curves/PrecisionRecallCurve.java
Apache-2.0
public Point getPointAtPrecision(double precision) { //Find the LOWEST threshold that gives the specified precision for (int i = 0; i < this.precision.length; i++) { if (this.precision[i] >= precision) { return new Point(i, threshold[i], this.precision[i], recall[i]); } } //Not found, return last point. Should never happen though... int i = threshold.length - 1; return new Point(i, threshold[i], this.precision[i], this.recall[i]); }
Get the point (index, threshold, precision, recall) at the given precision.<br> Specifically, return the points at the lowest threshold that has precision equal to or greater than the requested precision. @param precision Precision to get the point for @return point (index, threshold, precision, recall) at (or closest exceeding) the given precision
PrecisionRecallCurve::getPointAtPrecision
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/curves/PrecisionRecallCurve.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/curves/PrecisionRecallCurve.java
Apache-2.0
public Point getPointAtRecall(double recall) { Point foundPoint = null; //Find the HIGHEST threshold that gives the specified recall for (int i = this.recall.length - 1; i >= 0; i--) { if (this.recall[i] >= recall) { if (foundPoint == null ||(this.recall[i] == foundPoint.getRecall() && this.precision[i] >= foundPoint.getPrecision())) { foundPoint = new Point(i, threshold[i], precision[i], this.recall[i]); } } } if (foundPoint == null){ //Not found - return first point. Should never happen... foundPoint = new Point(0, threshold[0], precision[0], this.recall[0]); } return foundPoint; }
Get the point (index, threshold, precision, recall) at the given recall.<br> Specifically, return the points at the highest threshold that has recall equal to or greater than the requested recall. @param recall Recall to get the point for @return point (index, threshold, precision, recall) at (or closest exceeding) the given recall
PrecisionRecallCurve::getPointAtRecall
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/curves/PrecisionRecallCurve.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/curves/PrecisionRecallCurve.java
Apache-2.0
public Confusion getConfusionMatrixAtThreshold(double threshold) { Point p = getPointAtThreshold(threshold); int idx = p.idx; int tn = totalCount - (tpCount[idx] + fpCount[idx] + fnCount[idx]); return new Confusion(p, tpCount[idx], fpCount[idx], fnCount[idx], tn); }
Get the binary confusion matrix for the given threshold. As per {@link #getPointAtThreshold(double)}, if the threshold is not found exactly, the next highest threshold exceeding the requested threshold is returned @param threshold Threshold at which to get the confusion matrix @return Binary confusion matrix
PrecisionRecallCurve::getConfusionMatrixAtThreshold
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/curves/PrecisionRecallCurve.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/curves/PrecisionRecallCurve.java
Apache-2.0
public Confusion getConfusionMatrixAtPoint(int point) { return getConfusionMatrixAtThreshold(threshold[point]); }
Get the binary confusion matrix for the given position. As per {@link #getPointAtThreshold(double)}. @param point Position at which to get the binary confusion matrix @return Binary confusion matrix
PrecisionRecallCurve::getConfusionMatrixAtPoint
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/curves/PrecisionRecallCurve.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/curves/PrecisionRecallCurve.java
Apache-2.0
public static Histogram fromJson(String json) { return BaseHistogram.fromJson(json, Histogram.class); }
@param json JSON representation @return Instance of the histogram
Histogram::fromJson
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/curves/Histogram.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/curves/Histogram.java
Apache-2.0
public RegressionEvaluation(long nColumns) { this(createDefaultColumnNames(nColumns), DEFAULT_PRECISION); }
Create a regression evaluation object with the specified number of columns, and default precision for the stats() method. @param nColumns Number of columns
JsonDeserialize::RegressionEvaluation
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/regression/RegressionEvaluation.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/regression/RegressionEvaluation.java
Apache-2.0
public RegressionEvaluation(long nColumns, long precision) { this(createDefaultColumnNames(nColumns), precision); }
Create a regression evaluation object with the specified number of columns, and specified precision for the stats() method. @param nColumns Number of columns
JsonDeserialize::RegressionEvaluation
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/regression/RegressionEvaluation.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/regression/RegressionEvaluation.java
Apache-2.0
public RegressionEvaluation(String... columnNames) { this(columnNames == null || columnNames.length == 0 ? null : Arrays.asList(columnNames), DEFAULT_PRECISION); }
Create a regression evaluation object with default precision for the stats() method @param columnNames Names of the columns
JsonDeserialize::RegressionEvaluation
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/regression/RegressionEvaluation.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/regression/RegressionEvaluation.java
Apache-2.0
public RegressionEvaluation(List<String> columnNames, long precision) { this.precision = precision; if (columnNames == null || columnNames.isEmpty()) { initialized = false; } else { this.columnNames = columnNames; initialize(columnNames.size()); } }
Create a regression evaluation object with specified precision for the stats() method @param columnNames Names of the columns
JsonDeserialize::RegressionEvaluation
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/regression/RegressionEvaluation.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/regression/RegressionEvaluation.java
Apache-2.0
public void setAxis(int axis){ this.axis = axis; }
Set the axis for evaluation - this is the dimension along which the probability (and label classes) are present.<br> For DL4J, this can be left as the default setting (axis = 1).<br> Axis should be set as follows:<br> For 2D (OutputLayer), shape [minibatch, numClasses] - axis = 1<br> For 3D, RNNs/CNN1D (DL4J RnnOutputLayer), NCW format, shape [minibatch, numClasses, sequenceLength] - axis = 1<br> For 3D, RNNs/CNN1D (DL4J RnnOutputLayer), NWC format, shape [minibatch, sequenceLength, numClasses] - axis = 2<br> For 4D, CNN2D (DL4J CnnLossLayer), NCHW format, shape [minibatch, channels, height, width] - axis = 1<br> For 4D, CNN2D, NHWC format, shape [minibatch, height, width, channels] - axis = 3<br> @param axis Axis to use for evaluation
JsonDeserialize::setAxis
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/regression/RegressionEvaluation.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/regression/RegressionEvaluation.java
Apache-2.0
public int getAxis(){ return axis; }
Get the axis - see {@link #setAxis(int)} for details
JsonDeserialize::getAxis
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/regression/RegressionEvaluation.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/regression/RegressionEvaluation.java
Apache-2.0
public double pearsonCorrelation(int column) { double sumxiyi = sumOfProducts.getDouble(column); double predictionMean = currentPredictionMean.getDouble(column); double labelMean = currentMean.getDouble(column); double sumSquaredLabels = this.sumSquaredLabels.getDouble(column); double sumSquaredPredicted = this.sumSquaredPredicted.getDouble(column); double exampleCount = exampleCountPerColumn.getDouble(column); double r = sumxiyi - exampleCount * predictionMean * labelMean; r /= Math.sqrt(sumSquaredLabels - exampleCount * labelMean * labelMean) * Math.sqrt(sumSquaredPredicted - exampleCount * predictionMean * predictionMean); return r; }
Pearson Correlation Coefficient for samples @param column Column to evaluate @return Pearson Correlation Coefficient for column with index {@code column} @see <a href="https://en.wikipedia.org/wiki/Pearson_correlation_coefficient#For_a_sample">Wikipedia</a>
JsonDeserialize::pearsonCorrelation
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/regression/RegressionEvaluation.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/regression/RegressionEvaluation.java
Apache-2.0
public double rSquared(int column) { //ss_tot = sum_i (label_i - mean(labels))^2 // = (sum_i label_i^2) + mean(labels) * (n * mean(labels) - 2 * sum_i label_i) double sumLabelSquared = sumSquaredLabels.getDouble(column); double meanLabel = currentMean.getDouble(column); double sumLabel = sumLabels.getDouble(column); double n = exampleCountPerColumn.getDouble(column); double sstot = sumLabelSquared + meanLabel * (n * meanLabel - 2 * sumLabel); double ssres = sumSquaredErrorsPerColumn.getDouble(column); return (sstot - ssres) / sstot; }
Coefficient of Determination (R^2 Score) @param column Column to evaluate @return R^2 score for column with index {@code column} @see <a href="https://en.wikipedia.org/wiki/Coefficient_of_determination">Wikipedia</a>
JsonDeserialize::rSquared
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/regression/RegressionEvaluation.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/regression/RegressionEvaluation.java
Apache-2.0
public double averageMeanSquaredError() { double ret = 0.0; for (int i = 0; i < numColumns(); i++) { ret += meanSquaredError(i); } return ret / (double) numColumns(); }
Average MSE across all columns @return
JsonDeserialize::averageMeanSquaredError
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/regression/RegressionEvaluation.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/regression/RegressionEvaluation.java
Apache-2.0
public double averageMeanAbsoluteError() { double ret = 0.0; for (int i = 0; i < numColumns(); i++) { ret += meanAbsoluteError(i); } return ret / (double) numColumns(); }
Average MAE across all columns @return
JsonDeserialize::averageMeanAbsoluteError
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/regression/RegressionEvaluation.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/regression/RegressionEvaluation.java
Apache-2.0
public double averagerootMeanSquaredError() { double ret = 0.0; for (int i = 0; i < numColumns(); i++) { ret += rootMeanSquaredError(i); } return ret / (double) numColumns(); }
Average RMSE across all columns @return
JsonDeserialize::averagerootMeanSquaredError
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/regression/RegressionEvaluation.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/regression/RegressionEvaluation.java
Apache-2.0
public double averagerelativeSquaredError() { double ret = 0.0; for (int i = 0; i < numColumns(); i++) { ret += relativeSquaredError(i); } return ret / (double) numColumns(); }
Average RSE across all columns @return
JsonDeserialize::averagerelativeSquaredError
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/regression/RegressionEvaluation.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/regression/RegressionEvaluation.java
Apache-2.0
public double averagePearsonCorrelation() { double ret = 0.0; for (int i = 0; i < numColumns(); i++) { ret += pearsonCorrelation(i); } return ret / (double) numColumns(); }
Average Pearson Correlation Coefficient across all columns @return Pearson Correlation Coefficient across all columns
JsonDeserialize::averagePearsonCorrelation
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/regression/RegressionEvaluation.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/regression/RegressionEvaluation.java
Apache-2.0
public double averageRSquared() { double ret = 0.0; for (int i = 0; i < numColumns(); i++) { ret += rSquared(i); } return ret / (double) numColumns(); }
Average R2 across all columns @return R2 score accross all columns
JsonDeserialize::averageRSquared
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/regression/RegressionEvaluation.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/regression/RegressionEvaluation.java
Apache-2.0
public <T> T getRecordMetaData(Class<T> recordMetaDataClass) { return (T) recordMetaData; }
Convenience method for getting the record meta data as a particular class (as an alternative to casting it manually). NOTE: This uses an unchecked cast inernally. @param recordMetaDataClass Class of the record metadata @param <T> Type to return
Prediction::getRecordMetaData
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/meta/Prediction.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/meta/Prediction.java
Apache-2.0
public EvaluationCalibration() { this(DEFAULT_RELIABILITY_DIAG_NUM_BINS, DEFAULT_HISTOGRAM_NUM_BINS, true); }
Create an EvaluationCalibration instance with the default number of bins
JsonDeserialize::EvaluationCalibration
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/classification/EvaluationCalibration.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/classification/EvaluationCalibration.java
Apache-2.0
public EvaluationCalibration(int reliabilityDiagNumBins, int histogramNumBins) { this(reliabilityDiagNumBins, histogramNumBins, true); }
Create an EvaluationCalibration instance with the specified number of bins @param reliabilityDiagNumBins Number of bins for the reliability diagram (usually 10) @param histogramNumBins Number of bins for the histograms
JsonDeserialize::EvaluationCalibration
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/classification/EvaluationCalibration.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/classification/EvaluationCalibration.java
Apache-2.0
public EvaluationCalibration(@JsonProperty("reliabilityDiagNumBins") int reliabilityDiagNumBins, @JsonProperty("histogramNumBins") int histogramNumBins, @JsonProperty("excludeEmptyBins") boolean excludeEmptyBins) { this.reliabilityDiagNumBins = reliabilityDiagNumBins; this.histogramNumBins = histogramNumBins; this.excludeEmptyBins = excludeEmptyBins; }
Create an EvaluationCalibration instance with the specified number of bins @param reliabilityDiagNumBins Number of bins for the reliability diagram (usually 10) @param histogramNumBins Number of bins for the histograms @param excludeEmptyBins For the reliability diagram, whether empty bins should be excluded
JsonDeserialize::EvaluationCalibration
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/classification/EvaluationCalibration.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/classification/EvaluationCalibration.java
Apache-2.0
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); }
Get the reliability diagram for the specified class @param classIdx Index of the class to get the reliability diagram for
JsonDeserialize::getReliabilityDiagram
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/classification/EvaluationCalibration.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/classification/EvaluationCalibration.java
Apache-2.0
public int[] getLabelCountsEachClass() { return labelCountsEachClass == null ? null : labelCountsEachClass.data().asInt(); }
@return The number of observed labels for each class. For N classes, be returned array is of length N, with out[i] being the number of labels of class i
JsonDeserialize::getLabelCountsEachClass
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/classification/EvaluationCalibration.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/classification/EvaluationCalibration.java
Apache-2.0
public int[] getPredictionCountsEachClass() { return predictionCountsEachClass == null ? null : predictionCountsEachClass.data().asInt(); }
@return The number of network predictions for each class. For N classes, be returned array is of length N, with out[i] being the number of predicted values (max probability) for class i
JsonDeserialize::getPredictionCountsEachClass
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/classification/EvaluationCalibration.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/classification/EvaluationCalibration.java
Apache-2.0
public Histogram getResidualPlotAllClasses() { String title = "Residual Plot - All Predictions and Classes"; int[] counts = residualPlotOverall.data().asInt(); return new Histogram(title, 0.0, 1.0, counts); }
Get the residual plot for all classes combined. The residual plot is defined as a histogram of<br> |label_i - prob(class_i | input)| for all classes i and examples.<br> In general, small residuals indicate a superior classifier to large residuals. @return Residual plot (histogram) - all predictions/classes
JsonDeserialize::getResidualPlotAllClasses
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/classification/EvaluationCalibration.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/classification/EvaluationCalibration.java
Apache-2.0
public Histogram getResidualPlot(int labelClassIdx) { Preconditions.checkState(rDiagBinPosCount != null, "Unable to get residual plot: no evaluation has been performed (no data)"); String title = "Residual Plot - Predictions for Label Class " + labelClassIdx; int[] counts = residualPlotByLabelClass.getColumn(labelClassIdx).dup().data().asInt(); return new Histogram(title, 0.0, 1.0, counts); }
Get the residual plot, only for examples of the specified class.. The residual plot is defined as a histogram of<br> |label_i - prob(class_i | input)| for all and examples; for this particular method, only predictions where i == labelClassIdx are included.<br> In general, small residuals indicate a superior classifier to large residuals. @param labelClassIdx Index of the class to get the residual plot for @return Residual plot (histogram) - all predictions/classes
JsonDeserialize::getResidualPlot
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/classification/EvaluationCalibration.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/classification/EvaluationCalibration.java
Apache-2.0
public Histogram getProbabilityHistogramAllClasses() { String title = "Network Probabilities Histogram - All Predictions and Classes"; int[] counts = probHistogramOverall.data().asInt(); return new Histogram(title, 0.0, 1.0, counts); }
Return a probability histogram for all predictions/classes. @return Probability histogram
JsonDeserialize::getProbabilityHistogramAllClasses
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/classification/EvaluationCalibration.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/classification/EvaluationCalibration.java
Apache-2.0
public Histogram getProbabilityHistogram(int labelClassIdx) { Preconditions.checkState(rDiagBinPosCount != null, "Unable to get probability histogram: no evaluation has been performed (no data)"); String title = "Network Probabilities Histogram - P(class " + labelClassIdx + ") - Data Labelled Class " + labelClassIdx + " Only"; int[] counts = probHistogramByLabelClass.getColumn(labelClassIdx).dup().data().asInt(); return new Histogram(title, 0.0, 1.0, counts); }
Return a probability histogram of the specified label class index. That is, for label class index i, a histogram of P(class_i | input) is returned, only for those examples that are labelled as class i. @param labelClassIdx Index of the label class to get the histogram for @return Probability histogram
JsonDeserialize::getProbabilityHistogram
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/classification/EvaluationCalibration.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/classification/EvaluationCalibration.java
Apache-2.0
public ROCBinary(int thresholdSteps) { this(thresholdSteps, true); }
@param thresholdSteps Number of threshold steps to use for the ROC calculation. Set to 0 for exact ROC calculation
private::ROCBinary
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/classification/ROCBinary.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/evaluation/classification/ROCBinary.java
Apache-2.0