You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

BasicLinearModel.cs 950 B

1234567891011121314151617181920212223242526272829303132
  1. using Microsoft.VisualStudio.TestTools.UnitTesting;
  2. using NumSharp;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Text;
  6. using Tensorflow;
  7. using static Tensorflow.Binding;
  8. namespace TensorFlowNET.UnitTest.Training
  9. {
  10. [TestClass]
  11. public class BasicLinearModel
  12. {
  13. int NUM_EXAMPLES = 1000;
  14. [TestMethod]
  15. public void FitLinear()
  16. {
  17. // Initialize the weights to `5.0` and the bias to `0.0`
  18. // In practice, these should be initialized to random values (for example, with `tf.random.normal`)
  19. var W = tf.Variable(5.0f);
  20. var b = tf.Variable(0.0);
  21. // define linear model
  22. Func<NDArray, Tensor> model = (x) => W * x + b;
  23. // var inputs = tf.random.normal(shape =[NUM_EXAMPLES]);
  24. // noise = tf.random.normal(shape =[NUM_EXAMPLES])
  25. // outputs = inputs * TRUE_W + TRUE_b + noise
  26. }
  27. }
  28. }