| @@ -122,13 +122,14 @@ namespace Tensorflow.Gradients | |||||
| [RegisterGradient("SquaredDifference")] | [RegisterGradient("SquaredDifference")] | ||||
| public static Tensor[] _SquaredDifferenceGrad(Operation op, Tensor[] grads) | public static Tensor[] _SquaredDifferenceGrad(Operation op, Tensor[] grads) | ||||
| { | { | ||||
| //"""Returns the gradient for (x-y)^2.""" | |||||
| Tensor x = op.inputs[0]; | Tensor x = op.inputs[0]; | ||||
| Tensor y = op.inputs[1]; | Tensor y = op.inputs[1]; | ||||
| var scale = ops.convert_to_tensor(2.0f, dtype: x.dtype); | |||||
| var x_grad = math_ops.scalar_mul(scale, grads[0]) * (x - y); | |||||
| return new Tensor[] | return new Tensor[] | ||||
| { | { | ||||
| x, | |||||
| y | |||||
| x_grad, | |||||
| -x_grad | |||||
| }; | }; | ||||
| } | } | ||||
| /// <summary> | /// <summary> | ||||
| @@ -272,6 +272,9 @@ namespace Tensorflow | |||||
| public static Tensor mul_no_nan<Tx, Ty>(Tx x, Ty y, string name = null) | public static Tensor mul_no_nan<Tx, Ty>(Tx x, Ty y, string name = null) | ||||
| => gen_math_ops.mul_no_nan(x, y, name: name); | => gen_math_ops.mul_no_nan(x, y, name: name); | ||||
| public static Tensor scalar_mul<Tscale, Tx>(Tscale scale, Tx x, string name = null) | |||||
| => tf.Context.ExecuteOp("Mul", name, new ExecuteOpArgs(scale, x)); | |||||
| public static Tensor real(Tensor input, string name = null) | public static Tensor real(Tensor input, string name = null) | ||||
| { | { | ||||
| return tf_with(ops.name_scope(name, "Real", new[] { input }), scope => | return tf_with(ops.name_scope(name, "Real", new[] { input }), scope => | ||||
| @@ -48,7 +48,7 @@ namespace Tensorflow | |||||
| public tensorflow() | public tensorflow() | ||||
| { | { | ||||
| Logger = new LoggerConfiguration() | Logger = new LoggerConfiguration() | ||||
| .MinimumLevel.Error() | |||||
| .MinimumLevel.Debug() | |||||
| .WriteTo.Console() | .WriteTo.Console() | ||||
| .CreateLogger(); | .CreateLogger(); | ||||
| @@ -25,7 +25,6 @@ namespace TensorFlowNET.UnitTest.Gradient | |||||
| Assert.AreEqual((float)grad, 3.0f); | Assert.AreEqual((float)grad, 3.0f); | ||||
| } | } | ||||
| [Ignore] | |||||
| [TestMethod] | [TestMethod] | ||||
| public void SquaredDifference_Constant() | public void SquaredDifference_Constant() | ||||
| { | { | ||||