Geplaatst: 09 okt 2007, 09:59
Geledu, van harte man.....nog vele jaren toegewenst.............
Raden maar... (ik zeg het niet :mrgreen: )helma schreef:Van harte Geledu!! (en ik ben toch wel benieuwd naar je leeftijd....)
oké dan: 35 :idea:BJD schreef:Raden maar... (ik zeg het niet :mrgreen: )helma schreef:Van harte Geledu!! (en ik ben toch wel benieuwd naar je leeftijd....)
welk topic rens? 8)Rens schreef:........ik de boosaardige neiging nauwelijks kan onderdrukken om een hele oude topic nieuw leven in te blazen?
........die oude topic heet: veel kijkers, weinigen reageren?
........die topic ongelofelijk veel postings heeft opgeleverd?
........ik er met plezier de boel weer zal opstarten?
Code: Selecteer alles
struct NeuralConst
{
public static float learningRate = 0.2f;
}
class Perceptron
{
float weight;
Neuron child;
Neuron parent;
public Perceptron(Neuron child, Neuron parent)
{
this.child = child;
this.parent = parent;
child.addPerceptron(this);
parent.addPerceptron(this);
weight = 1;
}
public float think()
{
child.think();
return child.value * weight;
}
public void learn()
{
weight += NeuralConst.learningRate * parent.getError() * child.value;
child.learn();
}
public float getError()
{
return weight * parent.getError();
}
public bool youAreTheParent(Neuron you)
{
return parent.Equals(you);
}
public static float F(float x)
{
return (1 / (1 + (float)Math.Exp(-x)));
}
}
class Neuron
{
Perceptron[] childs;
Perceptron[] parents;
public float target = 0;
public float value;
public float delta = 0;
public bool functionsAsInput;
public bool functionsAsOutput;
public bool functionsAsBias;
public Neuron(bool functionsAsInput, bool functionsAsOutput, bool functionsAsBias)
{
childs = new Perceptron[0];
parents = new Perceptron[0];
this.functionsAsInput = functionsAsInput;
this.functionsAsOutput = functionsAsOutput;
this.functionsAsBias = functionsAsBias;
value = 1;
}
public void think()
{
if ((!functionsAsBias)&&(!functionsAsInput))
{
if (childs.Length > 0)
{
float sum = 0;
foreach (Perceptron child in childs)
sum += child.think();
value = Perceptron.F(sum);
}
}
}
public void learn()
{
if ((!functionsAsOutput) && (!functionsAsBias) && (!functionsAsInput))
{
float error = 0.0f;
foreach (Perceptron parent in parents)
{
error += parent.getError();
}
delta = value * (1.0f - value) * error;
}
if (functionsAsOutput)
delta = value * (1.0f - value) * (target - value);
if ((!functionsAsBias) && (!functionsAsInput))
{
foreach (Perceptron child in childs)
{
child.learn();
}
}
}
public float getError()
{
return delta;
}
public void addPerceptron(Perceptron perceptron)
{
if (perceptron.youAreTheParent(this))
{
Array.Resize(ref childs, childs.Length + 1);
childs[childs.Length - 1] = perceptron;
}
else
{
Array.Resize(ref parents, parents.Length + 1);
parents[parents.Length - 1] = perceptron;
}
}
}