Java Code Examples for org.nd4j.linalg.api.ndarray.INDArray#min()

The following examples show how to use org.nd4j.linalg.api.ndarray.INDArray#min() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PreProcessor3D4DTest.java    From nd4j with Apache License 2.0 6 votes vote down vote up
public Construct4dDataSet(int nExamples, int nChannels, int height, int width) {

            INDArray allImages = Nd4j.rand(new int[] {nExamples, nChannels, height, width});
            allImages.get(NDArrayIndex.all(), NDArrayIndex.point(1), NDArrayIndex.all(), NDArrayIndex.all()).muli(100)
                            .addi(200);
            allImages.get(NDArrayIndex.all(), NDArrayIndex.point(2), NDArrayIndex.all(), NDArrayIndex.all()).muli(0.001)
                            .subi(10);

            INDArray labels = Nd4j.linspace(1, nChannels, nChannels).reshape(nChannels, 1);
            sampleDataSet = new DataSet(allImages, labels);

            expectedMean = allImages.mean(0, 2, 3);
            expectedStd = allImages.std(0, 2, 3);

            expectedLabelMean = labels.mean(0);
            expectedLabelStd = labels.std(0);

            expectedMin = allImages.min(0, 2, 3);
            expectedMax = allImages.max(0, 2, 3);
        }
 
Example 2
Source File: SpTree.java    From deeplearning4j with Apache License 2.0 6 votes vote down vote up
public SpTree(INDArray data, Collection<INDArray> indices, String similarityFunction) {
    this.indices = indices;
    this.N = data.rows();
    this.D = data.columns();
    this.similarityFunction = similarityFunction;
    data = data.dup();
    INDArray meanY = data.mean(0);
    INDArray minY = data.min(0);
    INDArray maxY = data.max(0);
    INDArray width = Nd4j.create(data.dataType(), meanY.shape());
    for (int i = 0; i < width.length(); i++) {
        width.putScalar(i, Math.max(maxY.getDouble(i) - meanY.getDouble(i),
                meanY.getDouble(i) - minY.getDouble(i)) + Nd4j.EPS_THRESHOLD);
    }

    try(MemoryWorkspace ws = Nd4j.getMemoryManager().scopeOutOfWorkspaces()) {
        init(null, data, meanY, width, indices, similarityFunction);
        fill(N);
    }
}
 
Example 3
Source File: DistributionStats.java    From nd4j with Apache License 2.0 5 votes vote down vote up
/**
 * @param mean row vector of means
 * @param std  row vector of standard deviations
 */
public DistributionStats(@NonNull INDArray mean, @NonNull INDArray std) {
    Transforms.max(std, Nd4j.EPS_THRESHOLD, false);
    if (std.min(1) == Nd4j.scalar(Nd4j.EPS_THRESHOLD)) {
        logger.info("API_INFO: Std deviation found to be zero. Transform will round up to epsilon to avoid nans.");
    }

    this.mean = mean;
    this.std = std;
}
 
Example 4
Source File: MinMaxStats.java    From nd4j with Apache License 2.0 5 votes vote down vote up
/**
 * Add rows of data to the statistics
 *
 * @param data the matrix containing multiple rows of data to include
 * @param mask (optionally) the mask of the data, useful for e.g. time series
 */
public MinMaxStats.Builder add(@NonNull INDArray data, INDArray mask) {
    data = DataSetUtil.tailor2d(data, mask);
    if (data == null) {
        // Nothing to add. Either data is empty or completely masked. Just skip it, otherwise we will get
        // null pointer exceptions.
        return this;
    }

    INDArray tad = data.javaTensorAlongDimension(0, 0);
    INDArray batchMin = data.min(0);
    INDArray batchMax = data.max(0);
    if (!Arrays.equals(batchMin.shape(), batchMax.shape()))
        throw new IllegalStateException(
                        "Data min and max must be same shape. Likely a bug in the operation changing the input?");
    if (runningLower == null) {
        // First batch
        // Create copies because min and max are views to the same data set, which will cause problems with the
        // side effects of Transforms.min and Transforms.max
        runningLower = batchMin.dup();
        runningUpper = batchMax.dup();
    } else {
        // Update running bounds
        Transforms.min(runningLower, batchMin, false);
        Transforms.max(runningUpper, batchMax, false);
    }

    return this;
}
 
Example 5
Source File: FeatureUtil.java    From nd4j with Apache License 2.0 5 votes vote down vote up
/**
 * Scales the ndarray columns
 * to the given min/max values
 *
 * @param min the minimum number
 * @param max the max number
 */
public static void scaleMinMax(double min, double max, INDArray toScale) {
    //X_std = (X - X.min(axis=0)) / (X.max(axis=0) - X.min(axis=0)) X_scaled = X_std * (max - min) + min

    INDArray min2 = toScale.min(0);
    INDArray max2 = toScale.max(0);

    INDArray std = toScale.subRowVector(min2).diviRowVector(max2.sub(min2));

    INDArray scaled = std.mul(max - min).addi(min);
    toScale.assign(scaled);
}
 
Example 6
Source File: FeatureUtil.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
/**
 * Scales the ndarray columns
 * to the given min/max values
 *
 * @param min the minimum number
 * @param max the max number
 */
public static void scaleMinMax(double min, double max, INDArray toScale) {
    //X_std = (X - X.min(axis=0)) / (X.max(axis=0) - X.min(axis=0)) X_scaled = X_std * (max - min) + min

    INDArray min2 = toScale.min(0);
    INDArray max2 = toScale.max(0);

    INDArray std = toScale.subRowVector(min2).diviRowVector(max2.sub(min2));

    INDArray scaled = std.mul(max - min).addi(min);
    toScale.assign(scaled);
}
 
Example 7
Source File: QuadTree.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
/**
 * Pass in a matrix
 * @param data
 */
public QuadTree(INDArray data) {
    INDArray meanY = data.mean(0);
    INDArray minY = data.min(0);
    INDArray maxY = data.max(0);
    init(data, meanY.getDouble(0), meanY.getDouble(1),
                    max(maxY.getDouble(0) - meanY.getDouble(0), meanY.getDouble(0) - minY.getDouble(0))
                                    + Nd4j.EPS_THRESHOLD,
                    max(maxY.getDouble(1) - meanY.getDouble(1), meanY.getDouble(1) - minY.getDouble(1))
                                    + Nd4j.EPS_THRESHOLD);
    fill();
}