Browse Source

implemented naive bayes predict API

tags/v0.8.0
Bo Peng 6 years ago
parent
commit
f8b618cba9
3 changed files with 32 additions and 6 deletions
  1. +13
    -0
      src/TensorFlowNET.Core/APIs/tf.exp.cs
  2. +15
    -0
      src/TensorFlowNET.Core/APIs/tf.reduce_logsumexp.cs
  3. +4
    -6
      test/TensorFlowNET.Examples/NaiveBayesClassifier.cs

+ 13
- 0
src/TensorFlowNET.Core/APIs/tf.exp.cs View File

@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Tensorflow
{
public static partial class tf
{
public static Tensor exp(Tensor x,
string name = null) => gen_math_ops.exp(x, name);

}
}

+ 15
- 0
src/TensorFlowNET.Core/APIs/tf.reduce_logsumexp.cs View File

@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Tensorflow
{
public static partial class tf
{
public static Tensor reduce_logsumexp(Tensor input_tensor,
int[] axis = null,
bool keepdims = false,
string name = null) => math_ops.reduce_logsumexp(input_tensor, axis, keepdims, name);

}
}

+ 4
- 6
test/TensorFlowNET.Examples/NaiveBayesClassifier.cs View File

@@ -76,7 +76,7 @@ namespace TensorFlowNET.Examples
this.dist = dist;
}

public void predict (NDArray X)
public Tensor predict (NDArray X)
{
if (dist == null)
{
@@ -96,13 +96,11 @@ namespace TensorFlowNET.Examples
// posterior log probability, log P(c) + log P(x|c)
var joint_likelihood = tf.add(new Tensor(priors), cond_probs);
// normalize to get (log)-probabilities
/*
var norm_factor = tf.reduce_logsumexp(joint_likelihood, axis = 1, keep_dims = True)
var norm_factor = tf.reduce_logsumexp(joint_likelihood, new int[] { 1 }, true);
var log_prob = joint_likelihood - norm_factor;
// exp to get the actual probabilities
return tf.exp(log_prob)
*/
throw new NotImplementedException();
return tf.exp(log_prob);
}
}
}

Loading…
Cancel
Save