Skip to content

Commit ae5a109

Browse files
authored
Merge pull request SciSharp#178 from PppBr/master
tf.nn.moments
2 parents 031670b + 4e242b8 commit ae5a109

7 files changed

Lines changed: 94 additions & 13 deletions

File tree

‎TensorFlow.NET.sln‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TensorFlowNET.Utility", "sr
1313
EndProject
1414
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TensorFlowNET.Visualization", "TensorFlowNET.Visualization\TensorFlowNET.Visualization.csproj", "{4BB2ABD1-635E-41E4-B534-CB5B6A2D754D}"
1515
EndProject
16-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NumSharp.Core", "..\NumSharp\src\NumSharp.Core\NumSharp.Core.csproj", "{0AB4662E-7E3C-455F-BF0C-23D56CBE74F3}"
17-
EndProject
1816
Global
1917
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2018
Debug|Any CPU = Debug|Any CPU
@@ -41,10 +39,6 @@ Global
4139
{4BB2ABD1-635E-41E4-B534-CB5B6A2D754D}.Debug|Any CPU.Build.0 = Debug|Any CPU
4240
{4BB2ABD1-635E-41E4-B534-CB5B6A2D754D}.Release|Any CPU.ActiveCfg = Release|Any CPU
4341
{4BB2ABD1-635E-41E4-B534-CB5B6A2D754D}.Release|Any CPU.Build.0 = Release|Any CPU
44-
{0AB4662E-7E3C-455F-BF0C-23D56CBE74F3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
45-
{0AB4662E-7E3C-455F-BF0C-23D56CBE74F3}.Debug|Any CPU.Build.0 = Debug|Any CPU
46-
{0AB4662E-7E3C-455F-BF0C-23D56CBE74F3}.Release|Any CPU.ActiveCfg = Release|Any CPU
47-
{0AB4662E-7E3C-455F-BF0C-23D56CBE74F3}.Release|Any CPU.Build.0 = Release|Any CPU
4842
EndGlobalSection
4943
GlobalSection(SolutionProperties) = preSolution
5044
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: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,35 @@ 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 Tensor reduce_mean(Tensor input_tensor, int[] axes = null, bool keepdims = false, string name = null)
34+
{
35+
throw new NotFiniteNumberException();
36+
}
37+
/// <summary>
38+
/// Reduction Operation
39+
/// </summary>
40+
/// <param name="x"></param>
41+
/// <param name="axis"></param>
42+
/// <param name="reduction_indices"></param>
43+
public void _ReductionDims(Tensor x, int[] axis, int[] reduction_indices = null)
44+
{
45+
if (reduction_indices != null || reduction_indices.Length != 0)
46+
{
47+
if (axis != null)
48+
{
49+
50+
}
51+
}
52+
53+
throw new NotSupportedException("Can't specify both axis' and 'reduction_indices'.");
54+
}
2655

2756
/// <summary>
2857
/// 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: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,4 @@ Docs: https://tensorflownet.readthedocs.io</Description>
5151
<Content CopyToOutputDirectory="PreserveNewest" Include="./runtimes/win-x64/native/tensorflow.dll" Link="tensorflow.dll" Pack="true" PackagePath="runtimes/win-x64/native/tensorflow.dll" />
5252
</ItemGroup>
5353

54-
<ItemGroup>
55-
<ProjectReference Include="..\..\..\NumSharp\src\NumSharp.Core\NumSharp.Core.csproj" />
56-
</ItemGroup>
57-
5854
</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: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
</ItemGroup>
1212

1313
<ItemGroup>
14-
<ProjectReference Include="..\..\..\NumSharp\src\NumSharp.Core\NumSharp.Core.csproj" />
1514
<ProjectReference Include="..\..\src\TensorFlowNET.Core\TensorFlowNET.Core.csproj" />
1615
<ProjectReference Include="..\..\src\TensorFlowNET.Utility\TensorFlowNET.Utility.csproj" />
1716
</ItemGroup>

0 commit comments

Comments
 (0)