コード例 #1
0
    public Neuron(BinaryReader aReader, SerializationContext <Neuron> aContext)
    {
        byte marker = aReader.ReadByte();

        if (marker != 0x3)
        {
            throw new System.Exception("Binarystream: expected neuron (0x3) got " + marker);
        }
        uint id = aReader.ReadUInt32();

        type           = (ENeuronType)aReader.ReadByte();
        activationType = (EActivationType)aReader.ReadByte();
        SigmoidBase    = aReader.ReadSingle();
        int count = aReader.ReadInt32();

        if (count >= 0)
        {
            inputs = new NeuronLink[count];
        }
        for (int i = 0; i < count; i++)
        {
            int index = i;
            aContext.GetObject(aReader.ReadUInt32(), (n) => inputs[index].neuron = n);
            inputs[i].weight = aReader.ReadSingle();
        }
        aContext.RegisterObject(id, this);
    }
コード例 #2
0
 public Layer AddLayer(int neuronCount, EActivationType method)
 {
     _lastLayer.IsMonitored = false;
     _lastLayer             = new Layer(_node.BuildChild(), neuronCount, _lastLayer);
     _lastLayer.BasicConfiguration.ActivationType.Value = method;
     _lastLayer.IsMonitored = true;
     return(_lastLayer);
 }
コード例 #3
0
 /// <summary>
 /// Mutates the neuron values based on the passed mutation rate
 /// </summary>
 public void Mutate(int aMutationRate)
 {
     if (aMutationRate == -1 || Random.Range(0, aMutationRate) == 1)
     {
         activationType = (EActivationType)Random.Range(0, (int)EActivationType.COUNT);
     }
     for (int i = 0; i < inputs.Length; i++)
     {
         if (aMutationRate == -1 || Random.Range(0, aMutationRate) == 1)
         {
             inputs[i].weight = Random.Range(-1f, 1f);
         }
     }
     if (aMutationRate == -1 || Random.Range(0, aMutationRate) == 1)
     {
         SigmoidBase = Random.Range(0f, 10.0f);
     }
 }
コード例 #4
0
    public Neuron(XmlNode aNode, SerializationContext <Neuron> aContext)
    {
        if (aNode.Name != "Neuron")
        {
            throw new System.Exception("Expected element 'Neuron' but got '" + aNode.Name + "'");
        }
        var id = uint.Parse(aNode.Attributes["id"].Value);

        type           = (ENeuronType)System.Enum.Parse(typeof(ENeuronType), aNode.Attributes["type"].Value);
        activationType = (EActivationType)System.Enum.Parse(typeof(EActivationType), aNode.Attributes["activationType"].Value);
        SigmoidBase    = float.Parse(aNode.Attributes["SigmoidBase"].Value);
        inputs         = new NeuronLink[aNode.ChildNodes.Count];
        for (int i = 0; i < inputs.Length; i++)
        {
            int index = i;
            var link  = aNode.ChildNodes.Item(i);
            inputs[i].weight = float.Parse(link.Attributes["weight"].Value);
            var neuronId = uint.Parse(link.Attributes["neuron"].Value);
            aContext.GetObject(neuronId, (n) => inputs[index].neuron = n);
        }
        aContext.RegisterObject(id, this);
    }
コード例 #5
0
ファイル: BasicConfig.cs プロジェクト: carlhuth/GenXSource
        public double Activate(double activity)
        {
            EActivationType at = ActivationType.Value;

            switch (at)
            {
            case EActivationType.Symmetric:
                return(Math.Tanh(activity));

            case EActivationType.Asymmetric:
                return(1.0 / (1.0 + Math.Exp(-activity / ActivationTemperature.Value)));

            case EActivationType.Threshold:
                return(activity >= ActivationThreshold.Value ? HighOutput.Value : LowOutput.Value);

            case EActivationType.Userdefined:
                return(ActivationFunction.Value(activity));

            default:      //case EActivationType.Linear:
                return(activity);
            }
        }
コード例 #6
0
ファイル: BasicConfig.cs プロジェクト: carlhuth/GenXSource
        public double ActivateDerivative(double activity, double output)
        {
            double          fe = FlatspotEliminationEnable.Value ? FlatspotElimination.Value : 0;
            EActivationType at = ActivationType.Value;

            switch (at)
            {
            case EActivationType.Symmetric:
                return(fe + 1 - output * output);

            case EActivationType.Asymmetric:
                return(fe + output * (1 - output));

            case EActivationType.Threshold:
                return(activity == ActivationThreshold.Value ? double.PositiveInfinity : fe);     //TODO: hardly useful ...

            case EActivationType.Userdefined:
                return(fe + ActivationFunctionDerivative.Value(activity, output));

            default:      //case EActivationType.Linear:
                return(1);
            }
        }