Browse Source

doc updated.

v0.4.0 released.
tags/v0.8.0
Oceania2018 6 years ago
parent
commit
c8767b102d
4 changed files with 40 additions and 10 deletions
  1. +32
    -0
      docs/source/LinearRegression.md
  2. +2
    -1
      docs/source/index.rst
  3. +4
    -5
      src/TensorFlowNET.Core/TensorFlowNET.Core.csproj
  4. +2
    -4
      test/TensorFlowNET.Examples/LinearRegression.cs

+ 32
- 0
docs/source/LinearRegression.md View File

@@ -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<float>();
// var rnd2 = rng.randn<float>();
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);
```


+ 2
- 1
docs/source/index.rst View File

@@ -28,4 +28,5 @@ Welcome to TensorFlow.NET's documentation!
Gradient
Train
EagerMode
ImageRecognition
ImageRecognition
LinearRegression

+ 4
- 5
src/TensorFlowNET.Core/TensorFlowNET.Core.csproj View File

@@ -4,7 +4,7 @@
<TargetFramework>netstandard2.0</TargetFramework>
<AssemblyName>TensorFlow.NET</AssemblyName>
<RootNamespace>Tensorflow</RootNamespace>
<Version>0.3.0</Version>
<Version>0.4.0</Version>
<Authors>Haiping Chen</Authors>
<Company>SciSharp STACK</Company>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
@@ -16,12 +16,11 @@
<PackageTags>TensorFlow, NumSharp, SciSharp, MachineLearning, TensorFlow.NET</PackageTags>
<Description>Google's TensorFlow binding in .NET Standard.
Docs: https://tensorflownet.readthedocs.io</Description>
<AssemblyVersion>0.3.0.0</AssemblyVersion>
<PackageReleaseNotes>Added image prediction example.
Upgraded to TensorFlow 1.13 RC2.
<AssemblyVersion>0.4.0.0</AssemblyVersion>
<PackageReleaseNotes>Added Linear Regression example.
</PackageReleaseNotes>
<LangVersion>7.2</LangVersion>
<FileVersion>0.3.0.0</FileVersion>
<FileVersion>0.4.0.0</FileVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">


+ 2
- 4
test/TensorFlowNET.Examples/LinearRegression.cs View File

@@ -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<Session>(tf.Session(graph), sess =>
with<Session>(tf.Session(), sess =>
{
// Run the initializer
sess.run(init);


Loading…
Cancel
Save