Reshape reverse first attempt
package io.improbable.keanu.vertices.dbl.nonprobabilistic.operators.unary;
-import java.util.Map;
-
import io.improbable.keanu.tensor.dbl.DoubleTensor;
import io.improbable.keanu.vertices.Vertex;
import io.improbable.keanu.vertices.dbl.DoubleVertex;
import io.improbable.keanu.vertices.dbl.nonprobabilistic.diff.DualNumber;
import io.improbable.keanu.vertices.dbl.nonprobabilistic.diff.PartialDerivatives;
+import java.util.HashMap;
+import java.util.Map;
+
public class ReshapeVertex extends DoubleUnaryOpVertex {
public ReshapeVertex(DoubleVertex inputVertex, int... proposedShape) {
@@ -26,8 +27,10 @@ public class ReshapeVertex extends DoubleUnaryOpVertex {
@Override
public Map<Vertex, PartialDerivatives> reverseModeAutoDifferentiation(PartialDerivatives derivativeOfOutputsWithRespectToSelf) {
-
- return null;
+ Map<Vertex, PartialDerivatives> partials = new HashMap<>();
+ PartialDerivatives reshaped = derivativeOfOutputsWithRespectToSelf.reshape(getShape().length, inputVertex.getShape());
+ partials.put(inputVertex, reshaped);
+ return partials;
}
}
