/// <summary> /// Override that randomly assigns activation functions to neuron's from an activation function library /// based on each library item's selection probability. /// </summary> public override NeuronGene CreateNeuronGene(uint innovationId, NodeType neuronType) { switch (neuronType) { case NodeType.Bias: case NodeType.Input: { // Use the ID of the first function. By convention this will be the a sigmoid function in nEAT and RBF-NEAT // but in actual fact bias and input neurons don't use their activation function. int activationFnId = _activationFnLibrary.GetFunctionList()[0].Id; return(new NeuronGene(innovationId, neuronType, activationFnId)); } default: { ActivationFunctionInfo fnInfo = _activationFnLibrary.GetRandomFunction(_rng); IActivationFunction actFn = fnInfo.ActivationFunction; double[] auxArgs = null; if (actFn.AcceptsAuxArgs) { auxArgs = actFn.GetRandomAuxArgs(_rng, _neatGenomeParamsCurrent.ConnectionWeightRange); } return(new NeuronGene(innovationId, neuronType, fnInfo.Id, auxArgs)); } } }
private void PaintLegend(PaintState state) { const int LineHeight = 16; const int Margin = 10; IList <ActivationFunctionInfo> fnList = _activationFnLibrary.GetFunctionList(); int count = fnList.Count; // Determine y position of first line. int yCurr = Math.Max(Margin, state._viewportArea.Height - ((count * LineHeight) + Margin)); for (int i = 0; i < count; i++, yCurr += LineHeight) { ActivationFunctionInfo fnInfo = fnList[i]; const int X = Margin; // Paint an example node as part of the legend item. Point p = new Point(X, yCurr); Size s = new Size(state._nodeDiameter, state._nodeDiameter); Rectangle r = new Rectangle(p, s); // Paint the node. Fill first and then border, this gives a clean border. Graphics g = state._g; Brush fillBrush = _brushNodeFillArr[fnInfo.Id % _brushNodeFillArr.Length]; g.FillRectangle(fillBrush, r); g.DrawRectangle(__penBlack, r); // Write the activation function string ID. g.DrawString(fnList[i].ActivationFunction.FunctionId, __fontNodeTag, __brushBlack, X + 12, yCurr - 1); } }
/// <summary> /// Construct with a single IActivationFunction. /// </summary> /// <param name="activationFn"></param> public NeatActivationFunctionLibrary(IActivationFunction activationFn) { _activationFn = activationFn; _activationFnInfo = new ActivationFunctionInfo(0, 1.0, activationFn); _activationFnInfoList = new List <ActivationFunctionInfo>(1); _activationFnInfoList.Add(_activationFnInfo); }