示例#1
0
    public IEnumerator LTW255ToZero()
    {
        var          LTWGainRate  = 16;
        var          Start        = 255;
        var          End          = 3;
        var          DynamicsGene = new DendriteDynamicsGene(LTWGainRate, 0, 0, null, 0, null, 0, null, null, 0);
        DendriteGene DendriteGene = new DendriteGene(0, 0, DendriteGene.SpreadType.Flat, 0, new Vector2Int(0, 0), new Vector2Int(Start, Start), new Vector2Int(1, 1), DynamicsGene);
        TestDendrite Dendrite     = new TestDendrite(0, 0, DendriteGene);

        Dendrite.MockSTW(1);
        // Process assumes it is being called in FixedUpdate
        // i.e. 10 times a second
        foreach (var i in Enumerable.Range(0, 10))
        {
            Dendrite.Process(null, false, false);
        }
        Assert.AreEqual(End, Mathf.RoundToInt(Dendrite.LTW));

        yield return(null);
    }
示例#2
0
 public LobeGene(
     BrainLobeID lobeID,
     Vector2Int location,
     Vector2Int dimension,
     DendriteGene dendrite0,
     DendriteGene dendrite1,
     NeuronGene neuronGene,
     int copyToPerceptionLobe,
     int winnerTakesAll
     )
 {
     LobeID               = lobeID;
     Location             = location;
     Dimension            = dimension;
     Dendrite0            = dendrite0;
     Dendrite1            = dendrite1;
     NeuronGene           = neuronGene;
     CopyToPerceptionLobe = copyToPerceptionLobe > 0 ? true : false;
     WinnerTakesAll       = winnerTakesAll == 1 ? true : false;
 }
示例#3
0
    public IEnumerator GetValue()
    {
        var          DynamicsGene = new DendriteDynamicsGene(1, 0, 0, null, 0, null, 0, null, null, 0);
        DendriteGene DendriteGene = new DendriteGene(0, 0, DendriteGene.SpreadType.Flat, 0, new Vector2Int(0, 0), new Vector2Int(5, 5), new Vector2Int(1, 1), DynamicsGene);
        TestDendrite Dendrite     = new TestDendrite(0, 0, DendriteGene);
        NeuronGene   NeuronGene   = new NeuronGene(0, 0, 0, null);
        Lobe         lobe         = new Lobe(0, null, new Vector2Int(0, 0), new Vector2Int(5, 5), Enumerable.Range(0, 25).Select(n => new Neuron(n, NeuronGene)).ToList(), false, false);

        lobe.FireNeuron(0);
        Dendrite.SetSourceLobe(lobe);
        Dendrite.MockSTW(1);
        var DendriteValue = Dendrite.GetValue();

        Assert.AreEqual(1, DendriteValue);

        Dendrite.MockSTW(255);
        DendriteValue = Dendrite.GetValue();
        Assert.AreEqual(255, DendriteValue);

        yield return(null);
    }
示例#4
0
    public static List <Dendrite> BuildFromGene(DendriteGene gene, int sourceLobeSize, int destinationCellIndex)
    {
        List <Dendrite> Dendrites = new List <Dendrite>();
        // In C2, it appears that the spread doesn't really make any difference
        // and it's the fanout that actually alters the distribution
        // also, fanout may wrap round (e.g. in a 5-cell lobe, a fanout 1 dendrite may go to cell 4 and cell 0)

        //hard coding for perception lobe
        bool Drive = false;
        bool Verb  = false;

        foreach (var r in Enumerable.Range(0, gene.NumDendrites))
        {
            int SourceNeuronIndex = Random.Range(destinationCellIndex - gene.Fanout, destinationCellIndex + gene.Fanout) % sourceLobeSize;
            SourceNeuronIndex = (int)Mathf.Repeat(SourceNeuronIndex, sourceLobeSize);
            // Hard code perception lobe for now
            if (gene.SourceLobeIndex == BrainLobeType.Perception)
            {
                if (SourceNeuronIndex >= 0 && SourceNeuronIndex <= 15)
                {
                    Dendrites.Add(new Dendrite(gene.SourceLobeIndex, SourceNeuronIndex, gene, !Drive));
                    Drive = true;
                }
                else if (SourceNeuronIndex >= 16 && SourceNeuronIndex <= 31)
                {
                    Dendrites.Add(new Dendrite(gene.SourceLobeIndex, SourceNeuronIndex, gene, !Verb));
                    Verb = true;
                }
                else
                {
                    Dendrites.Add(new Dendrite(gene.SourceLobeIndex, SourceNeuronIndex, gene));
                }
            }
            else
            {
                Dendrites.Add(new Dendrite(gene.SourceLobeIndex, SourceNeuronIndex, gene));
            }
        }
        return(Dendrites);
    }
    public static Chromosome CreateCrossover(Chromosome ch1, Chromosome ch2)
    {
        Gene[] genes = CrossoverManager.Crossover(ch1.Genes, ch2.Genes);


        var neuralComparableGenes = CrossoverManager.Crossover(ch1.neuralChromosome.GetComparableGenes(), ch2.neuralChromosome.GetComparableGenes());

        DendriteGene[] dendriteGenes = new DendriteGene[neuralComparableGenes.Length];
        for (int i = 0; i < dendriteGenes.Length; i++)
        {
            dendriteGenes[i] = neuralComparableGenes[i].GetGene();
        }


        NeuralChromosome neuralChromosome = new NeuralChromosome(dendriteGenes);

        ChromosomeParameters parameters = CrossoverManager.CrossParameters(ch1.Parameters, ch2.Parameters);

        Chromosome chromosome = new Chromosome(genes, neuralChromosome, ch1.MutationTracker + "CR", parameters);

        return(chromosome);
    }
示例#6
0
 public static List <Neuron> SetUpDendrites(List <Neuron> neurons, DendriteGene d0, DendriteGene d1, int numSourceNeurons0, int numSourceNeurons1)
 {
     foreach (var Neuron in neurons)
     {
         if (d0 == null || d1 == null)
         {
             return(neurons);
         }
         if (d0.NumDendrites > 0)
         {
             Neuron.Dendrites0 = DendriteBuilder.BuildFromGene(d0, numSourceNeurons0, Neuron.Index);
         }
         else
         {
             Neuron.Dendrites0 = new List <Dendrite>(0);
         }
         if (d1.NumDendrites > 0)
         {
             Neuron.Dendrites1 = DendriteBuilder.BuildFromGene(d1, numSourceNeurons1, Neuron.Index);
         }
         else
         {
             Neuron.Dendrites1 = new List <Dendrite>(0);
         }
     }
     return(neurons);
 }
示例#7
0
 public ComparableGene(DendriteGene dendrite)
 {
     this.startNeuron = dendrite.startNeuron;
     this.endNeuron   = dendrite.endNeuron;
     this.dendrite    = dendrite;
 }
示例#8
0
 public TestDendrite(BrainLobeType sourceLobeIndex, int sourceNeuronIndex, DendriteGene gene) : base(sourceLobeIndex, sourceNeuronIndex, gene)
 {
 }