Skip to content

Commit 2cdbdaf

Browse files
committed
implemented 1)tf.sqrt 2) tf.distributions.normal
1 parent c77ee07 commit 2cdbdaf

7 files changed

Lines changed: 22 additions & 9 deletions

File tree

‎src/TensorFlowNET.Core/APIs/tf.distributions.cs‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@
22
using System.Collections.Generic;
33
using System.Text;
44

5-
namespace Tensorflow.APIs
5+
namespace Tensorflow
66
{
77
public static partial class tf
88
{
99
public static class distributions
1010
{
11-
public static Normal(Tensor loc, Tensor scale, bool validate_args = false, bool allow_nan_stats = true, string name = "Normal") => Normal(loc, scale, validate_args = false, allow_nan_stats = true, "Normal");
11+
public static Normal Normal(Tensor loc,
12+
Tensor scale,
13+
bool validate_args = false,
14+
bool allow_nan_stats = true,
15+
string name = "Normal") => new Normal(loc, scale, validate_args = false, allow_nan_stats = true, "Normal");
1216
}
1317
}
1418
}

‎src/TensorFlowNET.Core/APIs/tf.layers.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Text;
4-
using Tensorflow.Layers;
4+
using Tensorflow.Keras.Layers;
55
using Tensorflow.Operations.Activation;
66

77
namespace Tensorflow

‎src/TensorFlowNET.Core/APIs/tf.math.cs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ public static partial class tf
1010

1111
public static Tensor sub(Tensor a, Tensor b) => gen_math_ops.sub(a, b);
1212

13+
public static Tensor sqrt(Tensor a, string name = null) => gen_math_ops.sqrt(a, name);
14+
1315
public static Tensor subtract<T>(Tensor x, T[] y, string name = null) where T : struct
1416
=> gen_math_ops.sub(x, ops.convert_to_tensor(y, dtype: x.dtype.as_base_dtype(), name: "y"), name);
1517

‎src/TensorFlowNET.Core/Operations/Distributions/distribution.py.cs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace Tensorflow
99
{
10-
class _BaseDistribution : Python
10+
public class _BaseDistribution : Python
1111
{
1212
// Abstract base class needed for resolving subclass hierarchy.
1313
}
@@ -17,10 +17,10 @@ class _BaseDistribution : Python
1717
/// Distribution is a base class for constructing and organizing properties
1818
/// (e.g., mean, variance) of random variables (e.g, Bernoulli, Gaussian).
1919
/// </summary>
20-
class Distribution : _BaseDistribution
20+
public class Distribution : _BaseDistribution
2121
{
2222
public TF_DataType _dtype {get;set;}
23-
public static ReparameterizationType _reparameterization_type {get;set;}
23+
//public ReparameterizationType _reparameterization_type {get;set;}
2424
public bool _validate_args {get;set;}
2525
public bool _allow_nan_stats {get;set;}
2626
public Dictionary<string, object> _parameters {get;set;}

‎src/TensorFlowNET.Core/Operations/Distributions/normal.py.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace Tensorflow
55
{
6-
class Normal : Distribution
6+
public class Normal : Distribution
77
{
88
public Tensor _loc { get; set; }
99
public Tensor _scale { get; set; }
@@ -25,7 +25,7 @@ class Normal : Distribution
2525
/// <param name="validate_args"></param>
2626
/// <param name="allow_nan_stats"></param>
2727
/// <param name="name"></param>
28-
Normal (Tensor loc, Tensor scale, bool validate_args=false, bool allow_nan_stats=true, string name="Normal")
28+
public Normal (Tensor loc, Tensor scale, bool validate_args=false, bool allow_nan_stats=true, string name="Normal")
2929
{
3030
parameters.Add("name", name);
3131
parameters.Add("loc", loc);

‎src/TensorFlowNET.Core/Operations/gen_math_ops.cs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ public static Tensor neg(Tensor x, string name = null)
6262
return _op.outputs[0];
6363
}
6464

65+
public static Tensor sqrt(Tensor x, string name = null)
66+
{
67+
var _op = _op_def_lib._apply_op_helper("Sqrt", name, args: new { x });
68+
69+
return _op.outputs[0];
70+
}
71+
6572
public static Tensor sub<Tx, Ty>(Tx x, Ty y, string name = null)
6673
{
6774
var _op = _op_def_lib._apply_op_helper("Sub", name, args: new { x, y });

‎test/TensorFlowNET.Examples/NaiveBayesClassifier.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public void fit(NDArray X, NDArray y)
7474

7575
// Create a 3x2 univariate normal distribution with the
7676
// Known mean and variance
77-
var dist = tf.distributions.Normal(loc=mean, scale=tf.sqrt(variance));
77+
var dist = tf.distributions.Normal(mean, tf.sqrt(variance));
7878

7979
}
8080

0 commit comments

Comments
 (0)