All Downloads are FREE. Search and download functionalities are using the official Maven repository.
Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
org.nd4j.linalg.api.ops.impl.transforms.SoftPlus Maven / Gradle / Ivy
package org.nd4j.linalg.api.ops.impl.transforms;
import org.apache.commons.math3.util.FastMath;
import org.nd4j.linalg.api.complex.IComplexNumber;
import org.nd4j.linalg.api.ndarray.INDArray;
import org.nd4j.linalg.api.ops.BaseTransformOp;
import org.nd4j.linalg.api.ops.Op;
import org.nd4j.linalg.api.ops.TransformOp;
import org.nd4j.linalg.util.ComplexUtil;
/**
* @author Adam Gibson
*/
public class SoftPlus extends BaseTransformOp {
public SoftPlus(INDArray x, INDArray z) {
super(x, z);
}
public SoftPlus() {}
public SoftPlus(INDArray x, INDArray z, long n) {
super(x, z, n);
}
public SoftPlus(INDArray x, INDArray y, INDArray z, long n) {
super(x, y, z, n);
}
public SoftPlus(INDArray x) {
super(x);
}
@Override
public int opNum() {
return 13;
}
@Override
public String name() {
return "softplus";
}
@Override
public IComplexNumber op(IComplexNumber origin, double other) {
return ComplexUtil.log(ComplexUtil.exp(origin).add(1));
}
@Override
public IComplexNumber op(IComplexNumber origin, float other) {
return ComplexUtil.log(ComplexUtil.exp(origin).add(1));
}
@Override
public IComplexNumber op(IComplexNumber origin, IComplexNumber other) {
return ComplexUtil.log(ComplexUtil.exp(origin).add(1));
}
@Override
public float op(float origin, float other) {
return (float) FastMath.log(1 + FastMath.exp(origin));
}
@Override
public double op(double origin, double other) {
return FastMath.log(1 + FastMath.exp(origin));
}
@Override
public double op(double origin) {
return FastMath.log(1 + FastMath.exp(origin));
}
@Override
public float op(float origin) {
return (float) FastMath.log(1 + FastMath.exp(origin));
}
@Override
public IComplexNumber op(IComplexNumber origin) {
return ComplexUtil.log(ComplexUtil.exp(origin).add(1));
}
@Override
public Op opForDimension(int index, int dimension) {
INDArray xAlongDimension = x.vectorAlongDimension(index, dimension);
if (y() != null)
return new SoftPlus(xAlongDimension, y.vectorAlongDimension(index, dimension),
z.vectorAlongDimension(index, dimension), xAlongDimension.length());
else
return new SoftPlus(xAlongDimension, z.vectorAlongDimension(index, dimension), x.lengthLong());
}
@Override
public TransformOp derivative() {
return new Sigmoid(x, y, z, n);
}
@Override
public Op opForDimension(int index, int... dimension) {
INDArray xAlongDimension = x.tensorAlongDimension(index, dimension);
if (y() != null)
return new SoftPlus(xAlongDimension, y.tensorAlongDimension(index, dimension),
z.tensorAlongDimension(index, dimension), xAlongDimension.length());
else
return new SoftPlus(xAlongDimension, z.tensorAlongDimension(index, dimension), x.lengthLong());
}
}