use eye function
@@ -56,7 +56,7 @@ public class MultivariateGaussian extends ProbabilisticDouble {
* @param covariance the scale of the identity matrix
*/
public MultivariateGaussian(DoubleVertex mu, double covariance) {
- this(mu, createIdentityMatrixFromScalar(mu, covariance));
+ this(mu, new ConstantDoubleVertex(Nd4jDoubleTensor.eye(mu.getShape()[0])).times(covariance));
}
public MultivariateGaussian(double mu, double covariance) {
@@ -81,13 +81,6 @@ public class MultivariateGaussian extends ProbabilisticDouble {
return TensorMultivariateGaussian.sample(mu.getValue(), covariance.getValue(), variates, random);
}
- private static DoubleVertex createIdentityMatrixFromScalar(DoubleVertex mu, double covariance) {
- int dimensions = mu.getShape()[0];
- RealMatrix identityMatrix = MatrixUtils.createRealIdentityMatrix(dimensions).scalarMultiply(covariance);
- Nd4jDoubleTensor identityTensor = Nd4jDoubleTensor.create(identityMatrix);
- return new ConstantDoubleVertex(identityTensor);
- }
-
private static int[] checkValidMultivariateShape(int[] muShape, int[] covarianceShape) {
if (covarianceShape.length != 2
|| muShape.length != 2
