本文整理汇总了C#中Encog.Neural.Networks.Training.Propagation.Resilient.ResilientPropagation.Iteration方法的典型用法代码示例。如果您正苦于以下问题:C# ResilientPropagation.Iteration方法的具体用法?C# ResilientPropagation.Iteration怎么用?C# ResilientPropagation.Iteration使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Encog.Neural.Networks.Training.Propagation.Resilient.ResilientPropagation
的用法示例。
在下文中一共展示了ResilientPropagation.Iteration方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestRPROPCont
public void TestRPROPCont()
{
IMLDataSet trainingSet = XOR.CreateXORDataSet();
BasicNetwork net1 = XOR.CreateUnTrainedXOR();
BasicNetwork net2 = XOR.CreateUnTrainedXOR();
ResilientPropagation rprop1 = new ResilientPropagation(net1, trainingSet);
ResilientPropagation rprop2 = new ResilientPropagation(net2, trainingSet);
rprop1.Iteration();
rprop1.Iteration();
rprop2.Iteration();
rprop2.Iteration();
TrainingContinuation cont = rprop2.Pause();
ResilientPropagation rprop3 = new ResilientPropagation(net2, trainingSet);
rprop3.Resume(cont);
rprop1.Iteration();
rprop3.Iteration();
for (int i = 0; i < net1.Flat.Weights.Length; i++)
{
Assert.AreEqual(net1.Flat.Weights[i], net2.Flat.Weights[i], 0.0001);
}
}
示例2: TestRPROPContPersistEG
public void TestRPROPContPersistEG()
{
IMLDataSet trainingSet = XOR.CreateXORDataSet();
BasicNetwork net1 = XOR.CreateUnTrainedXOR();
BasicNetwork net2 = XOR.CreateUnTrainedXOR();
ResilientPropagation rprop1 = new ResilientPropagation(net1, trainingSet);
ResilientPropagation rprop2 = new ResilientPropagation(net2, trainingSet);
rprop1.Iteration();
rprop1.Iteration();
rprop2.Iteration();
rprop2.Iteration();
TrainingContinuation cont = rprop2.Pause();
EncogDirectoryPersistence.SaveObject(EG_FILENAME, cont);
TrainingContinuation cont2 = (TrainingContinuation)EncogDirectoryPersistence.LoadObject(EG_FILENAME);
ResilientPropagation rprop3 = new ResilientPropagation(net2, trainingSet);
rprop3.Resume(cont2);
rprop1.Iteration();
rprop3.Iteration();
for (int i = 0; i < net1.Flat.Weights.Length; i++)
{
Assert.AreEqual(net1.Flat.Weights[i], net2.Flat.Weights[i], 0.0001);
}
}
示例3: Main
static void Main(string[] args)
{
//create a neural network withtout using a factory
var network = new BasicNetwork();
network.AddLayer(new BasicLayer(null, true, 2));
network.AddLayer(new BasicLayer(new ActivationSigmoid(), true, 2));
network.AddLayer(new BasicLayer(new ActivationSigmoid(), false, 1));
network.Structure.FinalizeStructure();
network.Reset();
IMLDataSet trainingSet = new BasicMLDataSet(XORInput, XORIdeal);
IMLTrain train = new ResilientPropagation(network, trainingSet);
int epoch = 1;
do
{
train.Iteration();
Console.WriteLine($"Epoch #{epoch} Error: {train.Error}");
epoch++;
} while (train.Error > 0.01);
train.FinishTraining();
Console.WriteLine("Neural Network Results:");
foreach (IMLDataPair iPair in trainingSet)
{
IMLData output = network.Compute(iPair.Input);
Console.WriteLine($"{iPair.Input[0]}, {iPair.Input[0]}, actual={output[0]}, ideal={iPair.Ideal[0]}");
}
EncogFramework.Instance.Shutdown();
Console.ReadKey();
}
示例4: Main
static void Main(string[] args)
{
var network = new BasicNetwork();
network.AddLayer(new BasicLayer(null, true, 2));
network.AddLayer(new BasicLayer(new ActivationSigmoid(), true, 3));
network.AddLayer(new BasicLayer(new ActivationSigmoid(), false, 1));
network.Structure.FinalizeStructure();
network.Reset();
var trainingSet = new BasicMLDataSet(XORInput, XORIdeal);
var train = new ResilientPropagation(network, trainingSet);
var epoch = 1;
do
{
train.Iteration();
} while (train.Error > 0.01);
train.FinishTraining();
foreach (var pair in trainingSet)
{
var output = network.Compute(pair.Input);
Console.WriteLine(pair.Input[0] + @", " + pair.Input[1] + @" , actual=" + output[0] + @", ideal=" + pair.Ideal[0]);
}
EncogFramework.Instance.Shutdown();
Console.ReadLine();
}
示例5: Preprocessing_Completed
private void Preprocessing_Completed(object sender, RunWorkerCompletedEventArgs e)
{
worker.ReportProgress(0, "Creating Network...");
BasicNetwork Network = new BasicNetwork();
Network.AddLayer(new BasicLayer(new ActivationSigmoid(), true, DataContainer.NeuralNetwork.Data.InputSize));
Network.AddLayer(new BasicLayer(new ActivationSigmoid(), true, 50));
Network.AddLayer(new BasicLayer(new ActivationSigmoid(), true, DataContainer.NeuralNetwork.Data.IdealSize));
Network.Structure.FinalizeStructure();
Network.Reset();
DataContainer.NeuralNetwork.Network = Network;
ResilientPropagation training = new ResilientPropagation(DataContainer.NeuralNetwork.Network, DataContainer.NeuralNetwork.Data);
worker.ReportProgress(0, "Running Training: Epoch 0");
for(int i = 0; i < 200; i++)
{
training.Iteration();
worker.ReportProgress(0, "Running Training: Epoch " + (i+1).ToString() + " Current Training Error : " + training.Error.ToString());
if(worker.CancellationPending == true)
{
completed = true;
return;
}
}
completed = true;
}
示例6: TestRPROPConsistency
public void TestRPROPConsistency()
{
IMLDataSet training = EncoderTrainingFactory.generateTraining(4, false);
var network = EncogUtility.SimpleFeedForward(4, 2, 0, 4, true);
(new ConsistentRandomizer(-1, 1, 50)).Randomize(network);
var rprop = new ResilientPropagation(network, training);
for (var i = 0; i < 5; i++)
{
rprop.Iteration();
}
Assert.IsTrue(CompareArray.Compare(ExpectedWeights1, network.Flat.Weights,0.00001));
for (var i = 0; i < 5; i++)
{
rprop.Iteration();
}
Assert.IsTrue(CompareArray.Compare(ExpectedWeights2, network.Flat.Weights, 0.00001));
var e = network.CalculateError(training);
Assert.AreEqual(0.0767386807494191, e, 0.00001);
}
示例7: TrainNetwork
public ResilientPropagation TrainNetwork(BasicNetwork network, BasicMLDataSet trainingData)
{
var trainedNetwork = new ResilientPropagation(network, trainingData);
var epoch = 0;
do
{
trainedNetwork.Iteration();
epoch++;
Console.WriteLine("Epoch:{0}, Error{1}", epoch, trainedNetwork.Error);
} while (trainedNetwork.Error > 0.01);
return trainedNetwork;
}
示例8: EvaluateTrain
/// <summary>
/// Evaluate how long it takes to calculate the error for the network. This
/// causes each of the training pairs to be run through the network. The
/// network is evaluated 10 times and the lowest time is reported.
/// </summary>
/// <param name="network">The training data to use.</param>
/// <param name="training">The number of seconds that it took.</param>
/// <returns></returns>
public static int EvaluateTrain(BasicNetwork network, IMLDataSet training)
{
// train the neural network
IMLTrain train = new ResilientPropagation(network, training);
int iterations = 0;
var watch = new Stopwatch();
watch.Start();
while (watch.ElapsedMilliseconds < (10*Milis))
{
iterations++;
train.Iteration();
}
return iterations;
}
示例9: EvaluateMPROP
public double EvaluateMPROP(BasicNetwork network, IMLDataSet data)
{
var train = new ResilientPropagation(network, data);
long start = DateTime.Now.Ticks;
Console.WriteLine(@"Training 20 Iterations with MPROP");
for (int i = 1; i <= 20; i++)
{
train.Iteration();
Console.WriteLine("Iteration #" + i + " Error:" + train.Error);
}
//train.finishTraining();
long stop = DateTime.Now.Ticks;
double diff = new TimeSpan(stop - start).Seconds;
Console.WriteLine("MPROP Result:" + diff + " seconds.");
Console.WriteLine("Final MPROP error: " + network.CalculateError(data));
return diff;
}
示例10: EvaluateTrain
public static int EvaluateTrain(BasicNetwork network, IMLDataSet training)
{
int num;
IMLTrain train = new ResilientPropagation(network, training);
if (0 == 0)
{
num = 0;
}
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
while (stopwatch.ElapsedMilliseconds < 0x2710L)
{
num++;
train.Iteration();
}
return num;
}
示例11: Main
static void Main(string[] args)
{
double[][] XOR_Input =
{
new[] {0.0,0.0},
new[] {1.0,0.0},
new[] {0.0,1.0},
new[] {1.0,1.0}
};
double[][] XOR_Ideal =
{
new[] {0.0},
new[] {1.0},
new[] {1.0},
new[] {0.0}
};
var trainingSet = new BasicMLDataSet(XOR_Input, XOR_Ideal);
BasicNetwork network = CreateNetwork();
var train = new ResilientPropagation(network, trainingSet);
int epoch = 1;
do
{
train.Iteration();
epoch++;
Console.WriteLine("Iteration No :{0}, Error: {1}", epoch, train.Error);
} while (train.Error > 0.001);
foreach (var item in trainingSet)
{
var output = network.Compute(item.Input);
Console.WriteLine("Input : {0}, {1} Ideal : {2} Actual : {3}", item.Input[0], item.Input[1], item.Ideal[0], output[0]);
}
Console.WriteLine("press any key to exit...");
Console.ReadLine();
}
示例12: EvaluateTrain
/// <summary>
/// Evaluate how long it takes to calculate the error for the network. This
/// causes each of the training pairs to be run through the network. The
/// network is evaluated 10 times and the lowest time is reported.
/// </summary>
/// <param name="network">The training data to use.</param>
/// <param name="training">The number of seconds that it took.</param>
/// <returns></returns>
public static int EvaluateTrain(BasicNetwork network, IMLDataSet training)
{
// train the neural network
IMLTrain train = new ResilientPropagation(network, training);
int iterations = 0;
const int milis10 = Milis * 10;
var watch = new Stopwatch();
watch.Start();
while (true)
{
iterations++;
train.Iteration();
if((iterations & 0xff) == 0 && watch.ElapsedMilliseconds < milis10) break;
}
return iterations;
}
示例13: Run
public double Run(List<int> topoplogy, int iterations)
{
_Network = new BasicNetwork();
_Network.AddLayer(new BasicLayer(new ActivationSigmoid(), true, _Features));
foreach (int layer in topoplogy)
{
_Network.AddLayer(new BasicLayer(new ActivationSigmoid(), true, layer));
}
_Network.AddLayer(new BasicLayer(new ActivationSigmoid(), true, 1));
_Network.Structure.FinalizeStructure();
_Network.Reset();
//Encog.Neural.Networks.Training.Propagation.Gradient.
ITrain train = new ResilientPropagation(_Network, _TrainingSet);
for (int i = 0; i < iterations; i++)
{
train.Iteration();
}
return train.Error;
}
示例14: Evaluate
public static int Evaluate(BasicNetwork network, IMLDataSet training)
{
ResilientPropagation rprop = new ResilientPropagation(network, training);
int iterations = 0;
for (; ; )
{
rprop.Iteration();
iterations++;
if (rprop.Error < TARGET_ERROR)
{
return iterations;
}
if (iterations > 1000)
{
iterations = 0;
return -1;
}
}
}
示例15: XORTest
private static void XORTest()
{
double[][] XOR_Input =
{
new[] {0.0, 0.0},
new[] {1.0, 0.0},
new[] {0.0, 1.0},
new[] {1.0, 1.0}
};
double[][] XOR_Ideal =
{
new[] {0.0},
new[] {1.0},
new[] {1.0},
new[] {0.0}
};
var trainingSet = new BasicMLDataSet(XOR_Input, XOR_Ideal);
var network = CreateNetwork();
var train = new ResilientPropagation(network, trainingSet);
int epoch = 1;
do
{
train.Iteration();
epoch++;
Console.WriteLine($"Iteration No: {epoch}, Error: {train.Error}");
} while (train.Error > 0.001);
foreach (var item in trainingSet)
{
var output = network.Compute(item.Input);
Console.WriteLine($"Input : {item.Input[0]}, {item.Input[1]}, Ideal: {item.Ideal[0]}, Actual : {output[0]}");
}
}