Browse Source

implemented 1)tf.sqrt 2) tf.distributions.normal

tags/v0.8.0
Bo Peng 6 years ago
parent
commit
2cdbdaf7a5
7 changed files with 22 additions and 9 deletions
  1. +6
    -2
      src/TensorFlowNET.Core/APIs/tf.distributions.cs
  2. +1
    -1
      src/TensorFlowNET.Core/APIs/tf.layers.cs
  3. +2
    -0
      src/TensorFlowNET.Core/APIs/tf.math.cs
  4. +3
    -3
      src/TensorFlowNET.Core/Operations/Distributions/distribution.py.cs
  5. +2
    -2
      src/TensorFlowNET.Core/Operations/Distributions/normal.py.cs
  6. +7
    -0
      src/TensorFlowNET.Core/Operations/gen_math_ops.cs
  7. +1
    -1
      test/TensorFlowNET.Examples/NaiveBayesClassifier.cs

+ 6
- 2
src/TensorFlowNET.Core/APIs/tf.distributions.cs View File

@@ -2,13 +2,17 @@
using System.Collections.Generic;
using System.Text;

namespace Tensorflow.APIs
namespace Tensorflow
{
public static partial class tf
{
public static class distributions
{
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");
public static Normal Normal(Tensor loc,
Tensor scale,
bool validate_args = false,
bool allow_nan_stats = true,
string name = "Normal") => new Normal(loc, scale, validate_args = false, allow_nan_stats = true, "Normal");
}
}
}

+ 1
- 1
src/TensorFlowNET.Core/APIs/tf.layers.cs View File

@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
using System.Text;
using Tensorflow.Layers;
using Tensorflow.Keras.Layers;
using Tensorflow.Operations.Activation;

namespace Tensorflow


+ 2
- 0
src/TensorFlowNET.Core/APIs/tf.math.cs View File

@@ -10,6 +10,8 @@ namespace Tensorflow

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

public static Tensor sqrt(Tensor a, string name = null) => gen_math_ops.sqrt(a, name);

public static Tensor subtract<T>(Tensor x, T[] y, string name = null) where T : struct
=> gen_math_ops.sub(x, ops.convert_to_tensor(y, dtype: x.dtype.as_base_dtype(), name: "y"), name);



+ 3
- 3
src/TensorFlowNET.Core/Operations/Distributions/distribution.py.cs View File

@@ -7,7 +7,7 @@ using System.Text;

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


+ 2
- 2
src/TensorFlowNET.Core/Operations/Distributions/normal.py.cs View File

@@ -3,7 +3,7 @@ using Tensorflow;

namespace Tensorflow
{
class Normal : Distribution
public class Normal : Distribution
{
public Tensor _loc { get; set; }
public Tensor _scale { get; set; }
@@ -25,7 +25,7 @@ namespace Tensorflow
/// <param name="validate_args"></param>
/// <param name="allow_nan_stats"></param>
/// <param name="name"></param>
Normal (Tensor loc, Tensor scale, bool validate_args=false, bool allow_nan_stats=true, string name="Normal")
public Normal (Tensor loc, Tensor scale, bool validate_args=false, bool allow_nan_stats=true, string name="Normal")
{
parameters.Add("name", name);
parameters.Add("loc", loc);


+ 7
- 0
src/TensorFlowNET.Core/Operations/gen_math_ops.cs View File

@@ -62,6 +62,13 @@ namespace Tensorflow
return _op.outputs[0];
}
public static Tensor sqrt(Tensor x, string name = null)
{
var _op = _op_def_lib._apply_op_helper("Sqrt", name, args: new { x });
return _op.outputs[0];
}
public static Tensor sub<Tx, Ty>(Tx x, Ty y, string name = null)
{
var _op = _op_def_lib._apply_op_helper("Sub", name, args: new { x, y });


+ 1
- 1
test/TensorFlowNET.Examples/NaiveBayesClassifier.cs View File

@@ -74,7 +74,7 @@ namespace TensorFlowNET.Examples

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

}



Loading…
Cancel
Save