cn.centipede.numpy.NDArray.subtract()

Here are the examples of the java api cn.centipede.numpy.NDArray.subtract() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

3 Examples 7

17 Source : LossFunction.java
with MIT License
from DRL-CASIA

public static NDArray MES_loss(NDArray y_pre, NDArray y) {
    // loss = np.sum((y_pre - y) ** 2)
    NDArray loss = np.abs(y_pre.subtract(y));
    return loss;
}

17 Source : LossFunction.java
with MIT License
from DRL-CASIA

public static NDArray Softmax_cross_loss(NDArray y_pre, NDArray y) {
    NDArray softmax = np.exp(y_pre).divide(np.sum(np.exp(y_pre), 0));
    // loss = - np.sum(y * np.log(softmax))
    NDArray loss = softmax.subtract(y);
    return loss;
}

14 Source : Softmax.java
with MIT License
from DRL-CASIA

public NDArray loss(NDArray predict, NDArray label) {
    int[] pdimens = predict.shape();
    int batchsize = pdimens[0];
    predict(predict);
    NDArray delta = np.zeros(pdimens);
    double loss = 0;
    for (int i = 0; i < batchsize; i++) {
        NDArray label_i = label.row(i);
        NDArray softmanx_i = this.softmax.row(i);
        delta.set(softmanx_i.subtract(label_i), i);
        loss -= np.sum(np.log(softmanx_i).multiply(label_i));
    }
    loss /= batchsize;
    System.out.printf("Softmax: loss=%f\n", loss);
    return delta;
}