📄 program.cs
字号:
using System;
using System.Collections.Generic;
using System.Text;
namespace NeuralNetCS
{
class Program
{
static double[] GetExamples()
{
double[] examples = new double[101];
for( int x = 0; x < examples.Length; ++x )
{
double input = x / 100.0f;
if( input > 0.20 && input < 0.25 ||
input > 0.50 && input < 0.55 ||
input > 0.75 && input < 0.80 )
{
// This simulates noise in the input data
examples[x] = 0.3;
}
else
{
// The example function
examples[x] = 0.1 + (300 * Math.Sin((100 * input * input) / 3) + 95 *
Math.Cos(100 * input) + (100 * input - 40) * (100 * input - 40) + 5) / 4000.0;
}
}
return examples;
}
static bool HiddenNodesRangeFunc(int value)
{
return value > 0 && value <= 40;
}
static void Main()
{
Console.WriteLine("Artificial Intelligence: Neural Networks in C#");
Console.WriteLine("Sven Groot");
Console.WriteLine();
int nodes = Util.InputValue<int>("Give the number of hidden nodes (1-40) (<enter> = 3): ", new Util.RangeFunc<int>(HiddenNodesRangeFunc), "The value must be between 1 and 40.", 3);
uint epochs = Util.InputValue<uint>("Give the number of epochs (<enter> = 100000): ", new Util.RangeFunc<uint>(Util.Positive<uint>), "The value must be larger than 0.", 100000);
double learningRate = Util.InputValue<double>("Give the learning rate (<enter> = 0.9): ", new Util.RangeFunc<double>(Util.Positive<double>), "The value must be larger than 0.", 0.9);
Console.Write("Give the output file name (<enter> = 'net.out'): ");
string fileName = Console.ReadLine().Trim();
if( fileName.Length == 0 )
fileName = "net.out";
Net net = new Net(nodes, learningRate, GetExamples());
net.Learn(epochs, fileName);
Console.WriteLine();
Console.WriteLine("Done!");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -