From c8767b102d2911812ef8e74dedc912c9fbd9ed0c Mon Sep 17 00:00:00 2001 From: Oceania2018 Date: Fri, 22 Feb 2019 00:11:14 -0600 Subject: [PATCH] doc updated. v0.4.0 released. --- docs/source/LinearRegression.md | 32 +++++++++++++++++++ docs/source/index.rst | 3 +- .../TensorFlowNET.Core.csproj | 9 +++--- .../LinearRegression.cs | 6 ++-- 4 files changed, 40 insertions(+), 10 deletions(-) create mode 100644 docs/source/LinearRegression.md diff --git a/docs/source/LinearRegression.md b/docs/source/LinearRegression.md new file mode 100644 index 00000000..025e60e6 --- /dev/null +++ b/docs/source/LinearRegression.md @@ -0,0 +1,32 @@ +# Chapter. Linear Regression + +```csharp +// Prepare training Data +var train_X = np.array(3.3f, 4.4f, 5.5f, 6.71f, 6.93f, 4.168f, 9.779f, 6.182f, 7.59f, 2.167f, 7.042f, 10.791f, 5.313f, 7.997f, 5.654f, 9.27f, 3.1f); +var train_Y = np.array(1.7f, 2.76f, 2.09f, 3.19f, 1.694f, 1.573f, 3.366f, 2.596f, 2.53f, 1.221f, 2.827f, 3.465f, 1.65f, 2.904f, 2.42f, 2.94f, 1.3f); +var n_samples = train_X.shape[0]; +``` + +```csharp +// tf Graph Input +var X = tf.placeholder(tf.float32); +var Y = tf.placeholder(tf.float32); + +// Set model weights +// We can set a fixed init value in order to debug +// var rnd1 = rng.randn(); +// var rnd2 = rng.randn(); +var W = tf.Variable(-0.06f, name: "weight"); +var b = tf.Variable(-0.73f, name: "bias"); + +// Construct a linear model +var pred = tf.add(tf.multiply(X, W), b); + +// Mean squared error +var cost = tf.reduce_sum(tf.pow(pred - Y, 2.0f)) / (2.0f * n_samples); + +// Gradient descent +// Note, minimize() knows to modify W and b because Variable objects are trainable=True by default +var optimizer = tf.train.GradientDescentOptimizer(learning_rate).minimize(cost); +``` + diff --git a/docs/source/index.rst b/docs/source/index.rst index 8ad5a091..298d2f92 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -28,4 +28,5 @@ Welcome to TensorFlow.NET's documentation! Gradient Train EagerMode - ImageRecognition \ No newline at end of file + ImageRecognition + LinearRegression \ No newline at end of file diff --git a/src/TensorFlowNET.Core/TensorFlowNET.Core.csproj b/src/TensorFlowNET.Core/TensorFlowNET.Core.csproj index 8a28fc73..c4e5891d 100644 --- a/src/TensorFlowNET.Core/TensorFlowNET.Core.csproj +++ b/src/TensorFlowNET.Core/TensorFlowNET.Core.csproj @@ -4,7 +4,7 @@ netstandard2.0 TensorFlow.NET Tensorflow - 0.3.0 + 0.4.0 Haiping Chen SciSharp STACK true @@ -16,12 +16,11 @@ TensorFlow, NumSharp, SciSharp, MachineLearning, TensorFlow.NET Google's TensorFlow binding in .NET Standard. Docs: https://tensorflownet.readthedocs.io - 0.3.0.0 - Added image prediction example. -Upgraded to TensorFlow 1.13 RC2. + 0.4.0.0 + Added Linear Regression example. 7.2 - 0.3.0.0 + 0.4.0.0 diff --git a/test/TensorFlowNET.Examples/LinearRegression.cs b/test/TensorFlowNET.Examples/LinearRegression.cs index 22f80d2e..e1f81f5d 100644 --- a/test/TensorFlowNET.Examples/LinearRegression.cs +++ b/test/TensorFlowNET.Examples/LinearRegression.cs @@ -28,8 +28,6 @@ namespace TensorFlowNET.Examples 2.827f, 3.465f, 1.65f, 2.904f, 2.42f, 2.94f, 1.3f); var n_samples = train_X.shape[0]; - var graph = tf.Graph().as_default(); - // tf Graph Input var X = tf.placeholder(tf.float32); var Y = tf.placeholder(tf.float32); @@ -47,7 +45,7 @@ namespace TensorFlowNET.Examples // Mean squared error var cost = tf.reduce_sum(tf.pow(pred - Y, 2.0f)) / (2.0f * n_samples); - // radient descent + // Gradient descent // Note, minimize() knows to modify W and b because Variable objects are trainable=True by default var optimizer = tf.train.GradientDescentOptimizer(learning_rate).minimize(cost); @@ -55,7 +53,7 @@ namespace TensorFlowNET.Examples var init = tf.global_variables_initializer(); // Start training - with(tf.Session(graph), sess => + with(tf.Session(), sess => { // Run the initializer sess.run(init);