public void DeltawertBerechen(double[] outputSoll) { if (outputSoll.Length != NeuronDeltaValue.Last().Length) { throw new Exception("Der gewollte Output hat die Falsche länge"); } for (int i = 0; i < NeuronValue.Last().Length; ++i) { NeuronDeltaValue[NeuronDeltaValue.Length - 1][i] = 0; NeuronDeltaValue[NeuronDeltaValue.Length - 1][i] = NeuroMaths.Ableitung(NeuronArt.Last(), NeuronValue.Last()[i], ArtT.Last()) * (outputSoll[i] - NeuronValue.Last()[i]); } for (int i0 = NeuronValue.Length - 2; i0 > 0; --i0) { Parallel.For(0, NeuronValue[i0].Length, i1 => { NeuronDeltaValue[i0][i1] = 0; for (int i2 = 0; i2 < NeuronValue[i0 + 1].Length; ++i2) { NeuronDeltaValue[i0][i1] += Weights[i0][i1][i2] * NeuronDeltaValue[i0 + 1][i2]; } NeuronDeltaValue[i0][i1] *= NeuroMaths.Ableitung(NeuronArt[i0], NeuronValue[i0][i1], ArtT[i0]); }); } }
public virtual void ReinforcementLearning3(double reward, bool useAbleitung) { if (useAbleitung) { for (int i = 0; i < NeuronValue.Last().Length; ++i) { NeuronDeltaValue[NeuronDeltaValue.Length - 1][i] = 0; NeuronDeltaValue[NeuronDeltaValue.Length - 1][i] = (NeuronValue.Last()[i] * reward) * NeuroMaths.Ableitung(NeuronArt.Last(), NeuronValue.Last()[i], ArtT.Last()); } } else { for (int i = 0; i < NeuronValue.Last().Length; ++i) { NeuronDeltaValue[NeuronDeltaValue.Length - 1][i] = 0; NeuronDeltaValue[NeuronDeltaValue.Length - 1][i] = (NeuronValue.Last()[i] * reward); } } for (int i0 = NeuronValue.Length - 2; i0 > 0; --i0) { for (int i1 = 0; i1 < NeuronValue[i0].Length; ++i1) { NeuronDeltaValue[i0][i1] = 0; for (int i2 = 0; i2 < NeuronValue[i0 + 1].Length; ++i2) { NeuronDeltaValue[i0][i1] += Weights[i0][i1][i2] * NeuronDeltaValue[i0 + 1][i2]; } NeuronDeltaValue[i0][i1] *= NeuroMaths.Ableitung(NeuronArt[i0], NeuronValue[i0][i1], ArtT[i0]); } } }
public virtual void OutputBerechnen() { for (int i0 = 1; i0 < NeuronValue.Length; ++i0) { Parallel.For(0, NeuronValue[i0].Length, i1 => { NeuronValue[i0][i1] = 0; for (int i2 = 0; i2 < NeuronValue[i0 - 1].Length; ++i2) { NeuronValue[i0][i1] += NeuronValue[i0 - 1][i2] * Weights[i0 - 1][i2][i1]; } NeuronValue[i0][i1] += Weights[i0 - 1][NeuronValue[i0 - 1].Length][i1]; NeuronValue[i0][i1] = NeuroMaths.Formel(NeuronArt[i0], NeuronValue[i0][i1], ArtT[i0]); }); } }