From 4b6b9f84f8021bc40df7f56902b64cf0ea38963f Mon Sep 17 00:00:00 2001 From: Bo Peng Date: Wed, 27 Feb 2019 14:46:05 -0600 Subject: [PATCH 1/2] tf.nn.moments --- TensorFlow.NET.sln | 6 ++++ src/TensorFlowNET.Core/APIs/tf.nn.cs | 11 +++++++ .../Operations/math_ops.py.cs | 11 +++++++ .../Operations/nn_impl.py.cs | 32 +++++++++++++++++++ .../TensorFlowNET.Core.csproj | 4 +++ .../NaiveBayesClassifier.cs | 24 ++++++++++++-- .../TensorFlowNET.Examples.csproj | 1 + 7 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 src/TensorFlowNET.Core/APIs/tf.nn.cs create mode 100644 src/TensorFlowNET.Core/Operations/nn_impl.py.cs diff --git a/TensorFlow.NET.sln b/TensorFlow.NET.sln index 7f124824..827d18da 100644 --- a/TensorFlow.NET.sln +++ b/TensorFlow.NET.sln @@ -15,6 +15,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TensorFlowNET.Visualization EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "KerasNET.Core", "..\Keras.NET\src\KerasNET.Core\KerasNET.Core.csproj", "{E2F0C39C-D706-4CF5-AE00-81FB447F949D}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NumSharp.Core", "..\NumSharp\src\NumSharp.Core\NumSharp.Core.csproj", "{62360571-D1F7-473C-B81F-F03CA59E37DD}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -45,6 +47,10 @@ Global {E2F0C39C-D706-4CF5-AE00-81FB447F949D}.Debug|Any CPU.Build.0 = Debug|Any CPU {E2F0C39C-D706-4CF5-AE00-81FB447F949D}.Release|Any CPU.ActiveCfg = Release|Any CPU {E2F0C39C-D706-4CF5-AE00-81FB447F949D}.Release|Any CPU.Build.0 = Release|Any CPU + {62360571-D1F7-473C-B81F-F03CA59E37DD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {62360571-D1F7-473C-B81F-F03CA59E37DD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {62360571-D1F7-473C-B81F-F03CA59E37DD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {62360571-D1F7-473C-B81F-F03CA59E37DD}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/TensorFlowNET.Core/APIs/tf.nn.cs b/src/TensorFlowNET.Core/APIs/tf.nn.cs new file mode 100644 index 00000000..7ca290fd --- /dev/null +++ b/src/TensorFlowNET.Core/APIs/tf.nn.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Tensorflow +{ + public static partial class tf + { + public static nn_impl nn => new nn_impl(); + } +} diff --git a/src/TensorFlowNET.Core/Operations/math_ops.py.cs b/src/TensorFlowNET.Core/Operations/math_ops.py.cs index 8bfb51a7..a721c7bc 100644 --- a/src/TensorFlowNET.Core/Operations/math_ops.py.cs +++ b/src/TensorFlowNET.Core/Operations/math_ops.py.cs @@ -23,6 +23,17 @@ namespace Tensorflow return x; }); } + /// + /// + /// + /// + /// + /// + /// + public static void reduce_mean(Tensor input_tensor, int[] axes = null, bool keepdims = false, string name = null) + { + + } /// /// Helper function for reduction ops. diff --git a/src/TensorFlowNET.Core/Operations/nn_impl.py.cs b/src/TensorFlowNET.Core/Operations/nn_impl.py.cs new file mode 100644 index 00000000..56c4fb46 --- /dev/null +++ b/src/TensorFlowNET.Core/Operations/nn_impl.py.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Tensorflow +{ + public class nn_impl : Python + { + /// + /// Calculate the mean and variance of `x` + /// + /// + /// + /// + /// + /// + public (Tensor, Tensor) moments(Tensor x, + int[] axes, + string name = null, + bool keep_dims = false) + { + with(new ops.name_scope(name, "moments", new { x, axes }), scope => + { + var y = math_ops.cast(x, TF_DataType.TF_FLOAT); + // mean = math_ops.reduce_mean(y, axes, keepdims = True, name = "mean") + + }); + + throw new NotImplementedException(""); + } + } +} diff --git a/src/TensorFlowNET.Core/TensorFlowNET.Core.csproj b/src/TensorFlowNET.Core/TensorFlowNET.Core.csproj index ae1c5b8b..28637c9c 100644 --- a/src/TensorFlowNET.Core/TensorFlowNET.Core.csproj +++ b/src/TensorFlowNET.Core/TensorFlowNET.Core.csproj @@ -55,4 +55,8 @@ Docs: https://tensorflownet.readthedocs.io + + + + diff --git a/test/TensorFlowNET.Examples/NaiveBayesClassifier.cs b/test/TensorFlowNET.Examples/NaiveBayesClassifier.cs index 8f395ea9..948b9fff 100644 --- a/test/TensorFlowNET.Examples/NaiveBayesClassifier.cs +++ b/test/TensorFlowNET.Examples/NaiveBayesClassifier.cs @@ -2,6 +2,8 @@ using System.Collections.Generic; using System.Text; using Tensorflow; +using NumSharp.Core; +using System.Linq; namespace TensorFlowNET.Examples { @@ -9,10 +11,28 @@ namespace TensorFlowNET.Examples /// https://github.com/nicolov/naive_bayes_tensorflow /// public class NaiveBayesClassifier : Python, IExample - { + { public void Run() { - throw new NotImplementedException(); + // t/f.nn.moments() + } + + public void fit(NDArray X, NDArray y) + { + // separate training points by class + // shape : nb_class * nb_samples * nb_features + NDArray unique_y = y.unique(); + NDArray points_by_class = np.array(y.Data().Where(ys => unique_y.Data().Contains(ys))); + + foreach (long cls in unique_y) + { + + } + + + // estimate mean and variance for each class / feature + // shape : nb_classes * nb_features + } } } diff --git a/test/TensorFlowNET.Examples/TensorFlowNET.Examples.csproj b/test/TensorFlowNET.Examples/TensorFlowNET.Examples.csproj index d5986423..185903c4 100644 --- a/test/TensorFlowNET.Examples/TensorFlowNET.Examples.csproj +++ b/test/TensorFlowNET.Examples/TensorFlowNET.Examples.csproj @@ -12,6 +12,7 @@ + From 4e242b84cf5fea889fe003cb7afcc813083226af Mon Sep 17 00:00:00 2001 From: Bo Peng Date: Wed, 27 Feb 2019 15:00:12 -0600 Subject: [PATCH 2/2] remove numsharp --- TensorFlow.NET.sln | 12 ----------- .../Operations/math_ops.py.cs | 20 ++++++++++++++++++- .../TensorFlowNET.Core.csproj | 8 -------- .../TensorFlowNET.Examples.csproj | 1 - 4 files changed, 19 insertions(+), 22 deletions(-) diff --git a/TensorFlow.NET.sln b/TensorFlow.NET.sln index 01ba3a4d..880d886b 100644 --- a/TensorFlow.NET.sln +++ b/TensorFlow.NET.sln @@ -13,10 +13,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TensorFlowNET.Utility", "sr EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TensorFlowNET.Visualization", "TensorFlowNET.Visualization\TensorFlowNET.Visualization.csproj", "{4BB2ABD1-635E-41E4-B534-CB5B6A2D754D}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NumSharp.Core", "..\NumSharp\src\NumSharp.Core\NumSharp.Core.csproj", "{0AB4662E-7E3C-455F-BF0C-23D56CBE74F3}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NumSharp.Core", "..\NumSharp\src\NumSharp.Core\NumSharp.Core.csproj", "{62360571-D1F7-473C-B81F-F03CA59E37DD}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -43,14 +39,6 @@ Global {4BB2ABD1-635E-41E4-B534-CB5B6A2D754D}.Debug|Any CPU.Build.0 = Debug|Any CPU {4BB2ABD1-635E-41E4-B534-CB5B6A2D754D}.Release|Any CPU.ActiveCfg = Release|Any CPU {4BB2ABD1-635E-41E4-B534-CB5B6A2D754D}.Release|Any CPU.Build.0 = Release|Any CPU - {E2F0C39C-D706-4CF5-AE00-81FB447F949D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {E2F0C39C-D706-4CF5-AE00-81FB447F949D}.Debug|Any CPU.Build.0 = Debug|Any CPU - {E2F0C39C-D706-4CF5-AE00-81FB447F949D}.Release|Any CPU.ActiveCfg = Release|Any CPU - {E2F0C39C-D706-4CF5-AE00-81FB447F949D}.Release|Any CPU.Build.0 = Release|Any CPU - {62360571-D1F7-473C-B81F-F03CA59E37DD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {62360571-D1F7-473C-B81F-F03CA59E37DD}.Debug|Any CPU.Build.0 = Debug|Any CPU - {62360571-D1F7-473C-B81F-F03CA59E37DD}.Release|Any CPU.ActiveCfg = Release|Any CPU - {62360571-D1F7-473C-B81F-F03CA59E37DD}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/TensorFlowNET.Core/Operations/math_ops.py.cs b/src/TensorFlowNET.Core/Operations/math_ops.py.cs index a721c7bc..83ee4719 100644 --- a/src/TensorFlowNET.Core/Operations/math_ops.py.cs +++ b/src/TensorFlowNET.Core/Operations/math_ops.py.cs @@ -30,9 +30,27 @@ namespace Tensorflow /// /// /// - public static void reduce_mean(Tensor input_tensor, int[] axes = null, bool keepdims = false, string name = null) + public static Tensor reduce_mean(Tensor input_tensor, int[] axes = null, bool keepdims = false, string name = null) { + throw new NotFiniteNumberException(); + } + /// + /// Reduction Operation + /// + /// + /// + /// + public void _ReductionDims(Tensor x, int[] axis, int[] reduction_indices = null) + { + if (reduction_indices != null || reduction_indices.Length != 0) + { + if (axis != null) + { + + } + } + throw new NotSupportedException("Can't specify both axis' and 'reduction_indices'."); } /// diff --git a/src/TensorFlowNET.Core/TensorFlowNET.Core.csproj b/src/TensorFlowNET.Core/TensorFlowNET.Core.csproj index 2c99d5ad..c4e5891d 100644 --- a/src/TensorFlowNET.Core/TensorFlowNET.Core.csproj +++ b/src/TensorFlowNET.Core/TensorFlowNET.Core.csproj @@ -51,12 +51,4 @@ Docs: https://tensorflownet.readthedocs.io - - - - - - - - diff --git a/test/TensorFlowNET.Examples/TensorFlowNET.Examples.csproj b/test/TensorFlowNET.Examples/TensorFlowNET.Examples.csproj index 34a29361..e32a8092 100644 --- a/test/TensorFlowNET.Examples/TensorFlowNET.Examples.csproj +++ b/test/TensorFlowNET.Examples/TensorFlowNET.Examples.csproj @@ -11,7 +11,6 @@ -