diff --git a/src/TensorFlowNET.Core/Operations/Distributions/distribution.py.cs b/src/TensorFlowNET.Core/Operations/Distributions/distribution.py.cs index 2ac90fc8..68816963 100644 --- a/src/TensorFlowNET.Core/Operations/Distributions/distribution.py.cs +++ b/src/TensorFlowNET.Core/Operations/Distributions/distribution.py.cs @@ -27,6 +27,37 @@ namespace Tensorflow public List _graph_parents {get;set;} public string _name {get;set;} + + /// + /// Log probability density/mass function. + /// + /// `Tensor`. + /// Python `str` prepended to names of ops created by this function. + /// log_prob: a `Tensor` of shape `sample_shape(x) + self.batch_shape` with values of type `self.dtype`. + + /* + public Tensor log_prob(Tensor value, string name = "log_prob") + { + return _call_log_prob(value, name); + } + + private Tensor _call_log_prob (Tensor value, string name) + { + with(ops.name_scope(name, "moments", new { value }), scope => + { + value = _convert_to_tensor(value, "value", _dtype); + }); + + throw new NotImplementedException(); + + } + + private Tensor _convert_to_tensor(Tensor value, string name = null, TF_DataType preferred_dtype) + { + throw new NotImplementedException(); + } + */ + /// /// Constructs the `Distribution' /// **This is a private method for subclass use.** @@ -47,7 +78,7 @@ namespace Tensorflow /// Name prefixed to Ops created by this class. Default: subclass name. /// Two `Tensor` objects: `mean` and `variance`. - /* + /* private Distribution ( TF_DataType dtype, ReparameterizationType reparameterization_type, @@ -66,6 +97,10 @@ namespace Tensorflow this._name = name; } */ + + + + } /// diff --git a/src/TensorFlowNET.Core/Operations/Distributions/normal.py.cs b/src/TensorFlowNET.Core/Operations/Distributions/normal.py.cs index 4162ae25..6c77450a 100644 --- a/src/TensorFlowNET.Core/Operations/Distributions/normal.py.cs +++ b/src/TensorFlowNET.Core/Operations/Distributions/normal.py.cs @@ -78,5 +78,19 @@ namespace Tensorflow return array_ops.broadcast_static_shape(new Tensor(_loc.shape), new Tensor(_scale.shape)); } + private Tensor _log_prob(Tensor x) + { + return _log_unnormalized_prob(_z(x)); + } + + private Tensor _log_unnormalized_prob (Tensor x) + { + return -0.5 * math_ops.square(_z(x)); + } + + private Tensor _z (Tensor x) + { + return (x - this._loc) / this._scale; + } } } \ No newline at end of file diff --git a/src/TensorFlowNET.Core/Operations/math_ops.py.cs b/src/TensorFlowNET.Core/Operations/math_ops.py.cs index 9b16983e..d6b17509 100644 --- a/src/TensorFlowNET.Core/Operations/math_ops.py.cs +++ b/src/TensorFlowNET.Core/Operations/math_ops.py.cs @@ -55,6 +55,11 @@ namespace Tensorflow return m; } + public static Tensor square(Tensor x, string name = null) + { + throw new NotImplementedException(); + } + /// /// Helper function for reduction ops. /// diff --git a/test/TensorFlowNET.Examples/NaiveBayesClassifier.cs b/test/TensorFlowNET.Examples/NaiveBayesClassifier.cs index 05b7c0f2..131ab42c 100644 --- a/test/TensorFlowNET.Examples/NaiveBayesClassifier.cs +++ b/test/TensorFlowNET.Examples/NaiveBayesClassifier.cs @@ -15,13 +15,10 @@ namespace TensorFlowNET.Examples public void Run() { np.array(1.0f, 1.0f); - // var X = np.array(np.array(1.0f, 1.0f), np.array(2.0f, 2.0f), np.array(1.0f, -1.0f), np.array(2.0f, -2.0f), np.array(-1.0f, -1.0f), np.array(-1.0f, 1.0f),); - // var X = np.array(new float[][] { new float[] { 1.0f, 1.0f}, new float[] { 2.0f, 2.0f }, new float[] { -1.0f, -1.0f }, new float[] { -2.0f, -2.0f }, new float[] { 1.0f, -1.0f }, new float[] { 2.0f, -2.0f }, }); var X = np.array(new float[][] { new float[] { 1.0f, 1.0f }, new float[] { 2.0f, 2.0f }, new float[] { -1.0f, -1.0f }, new float[] { -2.0f, -2.0f }, new float[] { 1.0f, -1.0f }, new float[] { 2.0f, -2.0f }, }); var y = np.array(0,0,1,1,2,2); fit(X, y); // Create a regular grid and classify each point - } public void fit(NDArray X, NDArray y)