| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -27,6 +27,37 @@ public class Distribution : _BaseDistribution | |||
| 27 | 27 | public List<Tensor> _graph_parents {get;set;} | |
| 28 | 28 | public string _name {get;set;} | |
| 29 | 29 | ||
| 30 | + | ||
| 31 | + /// <summary> | ||
| 32 | + /// Log probability density/mass function. | ||
| 33 | + /// </summary> | ||
| 34 | + /// <param name="value"> `Tensor`.</param> | ||
| 35 | + /// <param name="name"> Python `str` prepended to names of ops created by this function.</param> | ||
| 36 | + /// <returns>log_prob: a `Tensor` of shape `sample_shape(x) + self.batch_shape` with values of type `self.dtype`.</returns> | ||
| 37 | + | ||
| 38 | + /* | ||
| 39 | + public Tensor log_prob(Tensor value, string name = "log_prob") | ||
| 40 | + { | ||
| 41 | + return _call_log_prob(value, name); | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | + private Tensor _call_log_prob (Tensor value, string name) | ||
| 45 | + { | ||
| 46 | + with(ops.name_scope(name, "moments", new { value }), scope => | ||
| 47 | + { | ||
| 48 | + value = _convert_to_tensor(value, "value", _dtype); | ||
| 49 | + }); | ||
| 50 | + | ||
| 51 | + throw new NotImplementedException(); | ||
| 52 | + | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + private Tensor _convert_to_tensor(Tensor value, string name = null, TF_DataType preferred_dtype) | ||
| 56 | + { | ||
| 57 | + throw new NotImplementedException(); | ||
| 58 | + } | ||
| 59 | + */ | ||
| 60 | + | ||
| 30 | 61 | /// <summary> | |
| 31 | 62 | /// Constructs the `Distribution' | |
| 32 | 63 | /// **This is a private method for subclass use.** | |
@@ -47,7 +78,7 @@ public class Distribution : _BaseDistribution | |||
| 47 | 78 | /// <param name = "name"> Name prefixed to Ops created by this class. Default: subclass name.</param> | |
| 48 | 79 | /// <returns> Two `Tensor` objects: `mean` and `variance`.</returns> | |
| 49 | 80 | ||
| 50 | - /* | ||
| 81 | + /* | ||
| 51 | 82 | private Distribution ( | |
| 52 | 83 | TF_DataType dtype, | |
| 53 | 84 | ReparameterizationType reparameterization_type, | |
@@ -66,6 +97,10 @@ private Distribution ( | |||
| 66 | 97 | this._name = name; | |
| 67 | 98 | } | |
| 68 | 99 | */ | |
| 100 | + | ||
| 101 | + | ||
| 102 | + | ||
| 103 | + | ||
| 69 | 104 | } | |
| 70 | 105 | ||
| 71 | 106 | /// <summary> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -78,5 +78,19 @@ public Tensor _batch_shape() | |||
| 78 | 78 | return array_ops.broadcast_static_shape(new Tensor(_loc.shape), new Tensor(_scale.shape)); | |
| 79 | 79 | } | |
| 80 | 80 | ||
| 81 | + private Tensor _log_prob(Tensor x) | ||
| 82 | + { | ||
| 83 | + return _log_unnormalized_prob(_z(x)); | ||
| 84 | + } | ||
| 85 | + | ||
| 86 | + private Tensor _log_unnormalized_prob (Tensor x) | ||
| 87 | + { | ||
| 88 | + return -0.5 * math_ops.square(_z(x)); | ||
| 89 | + } | ||
| 90 | + | ||
| 91 | + private Tensor _z (Tensor x) | ||
| 92 | + { | ||
| 93 | + return (x - this._loc) / this._scale; | ||
| 94 | + } | ||
| 81 | 95 | } | |
| 82 | 96 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -55,6 +55,11 @@ public static Tensor square_difference(Tensor x, Tensor y, string name = null) | |||
| 55 | 55 | return m; | |
| 56 | 56 | } | |
| 57 | 57 | ||
| 58 | + public static Tensor square(Tensor x, string name = null) | ||
| 59 | + { | ||
| 60 | + throw new NotImplementedException(); | ||
| 61 | + } | ||
| 62 | + | ||
| 58 | 63 | /// <summary> | |
| 59 | 64 | /// Helper function for reduction ops. | |
| 60 | 65 | /// </summary> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,13 +15,10 @@ public class NaiveBayesClassifier : Python, IExample | |||
| 15 | 15 | public void Run() | |
| 16 | 16 | { | |
| 17 | 17 | np.array<float>(1.0f, 1.0f); | |
| 18 | - // 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),); | ||
| 19 | - // 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 }, }); | ||
| 20 | 18 | 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 }, }); | |
| 21 | 19 | var y = np.array<int>(0,0,1,1,2,2); | |
| 22 | 20 | fit(X, y); | |
| 23 | 21 | // Create a regular grid and classify each point | |
| 24 | - | ||
| 25 | 22 | } | |
| 26 | 23 | ||
| 27 | 24 | public void fit(NDArray X, NDArray y) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments