Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,37 @@ public class Distribution : _BaseDistribution
public List<Tensor> _graph_parents {get;set;}
public string _name {get;set;}


/// <summary>
/// Log probability density/mass function.
/// </summary>
/// <param name="value"> `Tensor`.</param>
/// <param name="name"> Python `str` prepended to names of ops created by this function.</param>
/// <returns>log_prob: a `Tensor` of shape `sample_shape(x) + self.batch_shape` with values of type `self.dtype`.</returns>

/*
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();
}
*/

/// <summary>
/// Constructs the `Distribution'
/// **This is a private method for subclass use.**
Expand All @@ -47,7 +78,7 @@ public class Distribution : _BaseDistribution
/// <param name = "name"> Name prefixed to Ops created by this class. Default: subclass name.</param>
/// <returns> Two `Tensor` objects: `mean` and `variance`.</returns>

/*
/*
private Distribution (
TF_DataType dtype,
ReparameterizationType reparameterization_type,
Expand All @@ -66,6 +97,10 @@ private Distribution (
this._name = name;
}
*/




}

/// <summary>
Expand Down
14 changes: 14 additions & 0 deletions src/TensorFlowNET.Core/Operations/Distributions/normal.py.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,19 @@ public Tensor _batch_shape()
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;
}
}
}
5 changes: 5 additions & 0 deletions src/TensorFlowNET.Core/Operations/math_ops.py.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ public static Tensor square_difference(Tensor x, Tensor y, string name = null)
return m;
}

public static Tensor square(Tensor x, string name = null)
{
throw new NotImplementedException();
}

/// <summary>
/// Helper function for reduction ops.
/// </summary>
Expand Down
3 changes: 0 additions & 3 deletions test/TensorFlowNET.Examples/NaiveBayesClassifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,10 @@ public class NaiveBayesClassifier : Python, IExample
public void Run()
{
np.array<float>(1.0f, 1.0f);
// var X = np.array<float>(np.array<float>(1.0f, 1.0f), np.array<float>(2.0f, 2.0f), np.array<float>(1.0f, -1.0f), np.array<float>(2.0f, -2.0f), np.array<float>(-1.0f, -1.0f), np.array<float>(-1.0f, 1.0f),);
// var X = np.array<float[]>(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<float>(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<int>(0,0,1,1,2,2);
fit(X, y);
// Create a regular grid and classify each point

}

public void fit(NDArray X, NDArray y)
Expand Down