本文整理汇总了C#中Network.Pulse方法的典型用法代码示例。如果您正苦于以下问题:C# Network.Pulse方法的具体用法?C# Network.Pulse怎么用?C# Network.Pulse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Network
的用法示例。
在下文中一共展示了Network.Pulse方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Run
public static void Run()
{
var trainingSets = GenerateTrainingSets(100);
Network network;
double error = 0;
do
{
Console.WriteLine("Optimizing...");
network = new Network(trainingSets[0].Inputs.Length, 2, 10, trainingSets[0].Outputs.Length);
network.Weights = BruteOptimizer.OptimizeMulti(network, trainingSets);
error = network.Error(trainingSets, network.Weights);
Console.WriteLine("Error from last optimization attempt: " + error);
} while (error > 3);
Console.WriteLine("Optimization complete!");
while (true)
{
Console.Write("Enter space-separated inputs: ");
var inputs = Console.ReadLine().Split(' ');
if (inputs.Length == 1)
{
break;
}
var inputArray = new double[] { double.Parse(inputs[0].Trim()), double.Parse(inputs[1].Trim()) };
Console.WriteLine(network.Pulse(inputArray)[0]);
}
}
示例2: Delta
/// <summary>
/// Calculates the "delta value" for a specified neuron.
/// For output neurons, delta = (calculated - actual)*(calculated - calculated^2)
/// For hidden neurons in level l, delta = (calculated - calculated^2)* (sum n in neurons in l+1 [ delta((l+1)[n]) * weight(l[n] -> (l+1)[n]) ])
/// </summary>
/// <param name="network">The network to calculate the delta on</param>
/// <param name="set">The training set to calculate the delta on</param>
/// <param name="innerLayer">The inner layer index to calculate the training set on</param>
/// <param name="neuron">The neuron index to calculate the training set on</param>
/// <param name="deltas">The delta values for the L+1 layer</param>
/// <returns>The delta value for the specified neuron</returns>
public static double Delta(Network network, TrainingSet set, int innerLayer, int neuron, double[] deltas = null)
{
var isOutputLayer = innerLayer == network.Layers.Length - 1;
if (isOutputLayer)
{
var output = network.Pulse(set.Inputs)[neuron];
return (output - set.Outputs[neuron]) * (output - Math.Pow(output, 2));
}
else
{
var outputs = network.PulseDetailed(set.Inputs, false);
var actualOutput = outputs[innerLayer][neuron];
var summation = 0.0;
for (var n = 0; n < network.Weights[innerLayer + 1].Length; n++)
{
summation += deltas[n] * network.Weights[innerLayer + 1][n][neuron];
}
return (actualOutput - Math.Pow(actualOutput, 2)) * summation;
}
}
示例3: Run
public static void Run()
{
var trainingSets = LoadTrainingSets();
Network network = new Network(13, 1, 4, 3);
network.AddBiasNeuron(0);
double error = 0;
double deltaDrop = 0;
int tries = 0;
do
{
//if (tries % 5 == 0 && deltaDrop < 0.5)
//{
// Console.Write("Randomizing weights");
// network.RandomizeWeights();
//}
Console.WriteLine("Optimizing...");
//network.Weights = BruteOptimizer.OptimizeMulti(network, trainingSets);
network.Weights = BackPropOptimizer.Optimize(network, trainingSets, 2, 1);
var newError = network.Error(trainingSets, network.Weights);
deltaDrop = error - newError;
error = newError;
Console.WriteLine("Error from last optimization attempt: " + error);
tries++;
} while (error > 5 /*false || error > 10 || deltaDrop < 1*/);
Console.WriteLine("Optimization complete!");
while (true)
{
Console.Write("Enter comma-separated inputs: ");
var inputs = Console.ReadLine().Split(',');
if (inputs.Length == 1)
{
break;
}
var inputArray = new double[13];
for (var i = 0; i < 13; i++)
{
var minVal = RawTrainingSets.Min(set => set.Inputs[i]);
var maxVal = RawTrainingSets.Max(set => set.Inputs[i]);
inputArray[i] = Normalize(double.Parse(inputs[i].Trim()), minVal, maxVal);
}
var output = network.Pulse(inputArray);
Console.WriteLine(output[0] + " " + output[1] + " " + output[2]);
}
}
示例4: Run
public static void Run()
{
TrainingSets = new TrainingSet[0];
Network = new Network(9, 3, 10, 9);
Network.AddBiasNeuron(0);
Network.AddBiasNeuron(1);
Network.AddBiasNeuron(2);
double error = 0;
Console.WriteLine("Optimization complete!");
var beforePrompt = 10;
while (true)
{
beforePrompt--;
Console.WriteLine(beforePrompt);
var control = false;
if (beforePrompt <= 0)
{
Console.WriteLine("Take control? (Type TC)");
control = Console.ReadLine() == "TC";
if (control)
{
beforePrompt = 0;
}
else
{
beforePrompt = 30;
}
}
var board = GenerateBoard(0);
var lastMove = -1;
var lastComputerMove = -1;
do
{
Console.WriteLine("Board: ");
OutputBoard(board);
var spot = RandomMove(board);
if (control)
{
Console.Write("Pick to drop an X: ");
spot = int.Parse(Console.ReadLine());
}
board[spot] = -1;
lastMove = spot;
if (WinnerOfBoard(board) != -2)
{
break;
}
//var computerChoice = BestNextMove(board);
var output = Network.Pulse(board);
var computerChoice = -1;
double computerMax = -1;
for (var i = 0; i < output.Length; i++)
{
if (board[i] != 0)
{
continue;
}
if (output[i] > computerMax)
{
computerChoice = i;
computerMax = output[i];
}
}
if (computerChoice == -1) computerChoice = 0;
board[computerChoice] = 1;
lastComputerMove = computerChoice;
} while (WinnerOfBoard(board) == -2);
var winner = WinnerOfBoard(board);
switch (winner)
{
case 0:
Console.WriteLine("Tie!");
break;
case -1:
board[lastMove] = 0;
var output = new double[9];
output[lastMove] = 1;
Console.WriteLine("You win!");
Train(new TrainingSet(board, output), 1);
break;
case 1:
board[lastComputerMove] = 0;
output = new double[9];
output[lastComputerMove] = 1;
Console.WriteLine("Computer wins!");
Train(new TrainingSet(board, output), -1);
break;
}
Console.WriteLine("Final Board: ");
OutputBoard(board);
}
}