Skip to content

Commit 4b6b9f8

Browse files
committed
tf.nn.moments
1 parent d7cb00f commit 4b6b9f8

7 files changed

Lines changed: 87 additions & 2 deletions

File tree

‎TensorFlow.NET.sln‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TensorFlowNET.Visualization
1515
EndProject
1616
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "KerasNET.Core", "..\Keras.NET\src\KerasNET.Core\KerasNET.Core.csproj", "{E2F0C39C-D706-4CF5-AE00-81FB447F949D}"
1717
EndProject
18+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NumSharp.Core", "..\NumSharp\src\NumSharp.Core\NumSharp.Core.csproj", "{62360571-D1F7-473C-B81F-F03CA59E37DD}"
19+
EndProject
1820
Global
1921
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2022
Debug|Any CPU = Debug|Any CPU
@@ -45,6 +47,10 @@ Global
4547
{E2F0C39C-D706-4CF5-AE00-81FB447F949D}.Debug|Any CPU.Build.0 = Debug|Any CPU
4648
{E2F0C39C-D706-4CF5-AE00-81FB447F949D}.Release|Any CPU.ActiveCfg = Release|Any CPU
4749
{E2F0C39C-D706-4CF5-AE00-81FB447F949D}.Release|Any CPU.Build.0 = Release|Any CPU
50+
{62360571-D1F7-473C-B81F-F03CA59E37DD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
51+
{62360571-D1F7-473C-B81F-F03CA59E37DD}.Debug|Any CPU.Build.0 = Debug|Any CPU
52+
{62360571-D1F7-473C-B81F-F03CA59E37DD}.Release|Any CPU.ActiveCfg = Release|Any CPU
53+
{62360571-D1F7-473C-B81F-F03CA59E37DD}.Release|Any CPU.Build.0 = Release|Any CPU
4854
EndGlobalSection
4955
GlobalSection(SolutionProperties) = preSolution
5056
HideSolutionNode = FALSE
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace Tensorflow
6+
{
7+
public static partial class tf
8+
{
9+
public static nn_impl nn => new nn_impl();
10+
}
11+
}

‎src/TensorFlowNET.Core/Operations/math_ops.py.cs‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,17 @@ public static Tensor cast(Tensor x, TF_DataType dtype = TF_DataType.DtInvalid, s
2323
return x;
2424
});
2525
}
26+
/// <summary>
27+
///
28+
/// </summary>
29+
/// <param name="input_tensor"></param>
30+
/// <param name="axes"></param>
31+
/// <param name="keepdims"></param>
32+
/// <param name="name"></param>
33+
public static void reduce_mean(Tensor input_tensor, int[] axes = null, bool keepdims = false, string name = null)
34+
{
35+
36+
}
2637

2738
/// <summary>
2839
/// Helper function for reduction ops.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace Tensorflow
6+
{
7+
public class nn_impl : Python
8+
{
9+
/// <summary>
10+
/// Calculate the mean and variance of `x`
11+
/// </summary>
12+
/// <param name="x"></param>
13+
/// <param name="axes"></param>
14+
/// <param name="name"></param>
15+
/// <param name="keep_dims"></param>
16+
/// <returns></returns>
17+
public (Tensor, Tensor) moments(Tensor x,
18+
int[] axes,
19+
string name = null,
20+
bool keep_dims = false)
21+
{
22+
with<ops.name_scope>(new ops.name_scope(name, "moments", new { x, axes }), scope =>
23+
{
24+
var y = math_ops.cast(x, TF_DataType.TF_FLOAT);
25+
// mean = math_ops.reduce_mean(y, axes, keepdims = True, name = "mean")
26+
27+
});
28+
29+
throw new NotImplementedException("");
30+
}
31+
}
32+
}

‎src/TensorFlowNET.Core/TensorFlowNET.Core.csproj‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,8 @@ Docs: https://tensorflownet.readthedocs.io</Description>
5555
<Folder Include="APIs\Keras\" />
5656
</ItemGroup>
5757

58+
<ItemGroup>
59+
<ProjectReference Include="..\..\..\NumSharp\src\NumSharp.Core\NumSharp.Core.csproj" />
60+
</ItemGroup>
61+
5862
</Project>

‎test/TensorFlowNET.Examples/NaiveBayesClassifier.cs‎

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,37 @@
22
using System.Collections.Generic;
33
using System.Text;
44
using Tensorflow;
5+
using NumSharp.Core;
6+
using System.Linq;
57

68
namespace TensorFlowNET.Examples
79
{
810
/// <summary>
911
/// https://github.com/nicolov/naive_bayes_tensorflow
1012
/// </summary>
1113
public class NaiveBayesClassifier : Python, IExample
12-
{
14+
{
1315
public void Run()
1416
{
15-
throw new NotImplementedException();
17+
// t/f.nn.moments()
18+
}
19+
20+
public void fit(NDArray X, NDArray y)
21+
{
22+
// separate training points by class
23+
// shape : nb_class * nb_samples * nb_features
24+
NDArray unique_y = y.unique<long>();
25+
NDArray points_by_class = np.array(y.Data<long>().Where(ys => unique_y.Data<long>().Contains(ys)));
26+
27+
foreach (long cls in unique_y)
28+
{
29+
30+
}
31+
32+
33+
// estimate mean and variance for each class / feature
34+
// shape : nb_classes * nb_features
35+
1636
}
1737
}
1838
}

‎test/TensorFlowNET.Examples/TensorFlowNET.Examples.csproj‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
<ItemGroup>
1414
<ProjectReference Include="..\..\..\Keras.NET\src\KerasNET.Core\KerasNET.Core.csproj" />
15+
<ProjectReference Include="..\..\..\NumSharp\src\NumSharp.Core\NumSharp.Core.csproj" />
1516
<ProjectReference Include="..\..\src\TensorFlowNET.Core\TensorFlowNET.Core.csproj" />
1617
<ProjectReference Include="..\..\src\TensorFlowNET.Utility\TensorFlowNET.Utility.csproj" />
1718
</ItemGroup>

0 commit comments

Comments
 (0)