Exemple #1
0
        public override INeuralNetChromosome Clone()
        {
            var clone = new RMP_Chromosome();

            clone.InhibitoryConnectionChance = InhibitoryConnectionChance;
            clone.ConnectionChance           = ConnectionChance;

            clone.NewConnectionsCanForm = NewConnectionsCanForm;
            clone.ConnectionsCanDie     = ConnectionsCanDie;
            clone.NewNeuronsCanForm     = NewNeuronsCanForm;
            clone.NeuronsCanDie         = NeuronsCanDie;

            clone.EyeRNeuronGenes.AddRange(EyeRNeuronGenes.Select(n => (RMP_NeuronGene)n.Clone()));
            clone.EyeGNeuronGenes.AddRange(EyeGNeuronGenes.Select(n => (RMP_NeuronGene)n.Clone()));
            clone.EyeBNeuronGenes.AddRange(EyeBNeuronGenes.Select(n => (RMP_NeuronGene)n.Clone()));
            clone.DistanceNeuronGenes.AddRange(DistanceNeuronGenes.Select(n => (RMP_NeuronGene)n.Clone()));

            clone.HiddenNeuronGenes.AddRange(HiddenNeuronGenes.Select(n => (RMP_NeuronGene)n.Clone()));
            clone.InputNeuronGenes.AddRange(InputNeuronGenes.Select(n => (RMP_NeuronGene)n.Clone()));
            clone.OutputNeuronGenes.AddRange(OutputNeuronGenes.Select(n => (RMP_NeuronGene)n.Clone()));

            clone.MutationGenes.AddRange(MutationGenes.Select(n => (DoubleGene)n.Clone()));

            clone.GlobalSigmoidFunction       = (SigmoidFunction)GlobalSigmoidFunction.Clone();
            clone.GlobalOutputSigmoidFunction = (SigmoidFunction)GlobalOutputSigmoidFunction.Clone();

            return(clone);
        }
Exemple #2
0
        public override INeuralNetChromosome CrossoverWith(INeuralNetChromosome netC2, CrossoverFunction crossoverFunction)
        {
            var c2    = (RMP_Chromosome)netC2;
            var child = new RMP_Chromosome();

            crossoverFunction.Crossover(MutationGenes, c2.MutationGenes, child.MutationGenes);

            crossoverFunction.Crossover(EyeRNeuronGenes, c2.EyeRNeuronGenes, child.EyeRNeuronGenes);
            crossoverFunction.Crossover(EyeGNeuronGenes, c2.EyeGNeuronGenes, child.EyeGNeuronGenes);
            crossoverFunction.Crossover(EyeBNeuronGenes, c2.EyeBNeuronGenes, child.EyeBNeuronGenes);
            crossoverFunction.Crossover(DistanceNeuronGenes, c2.DistanceNeuronGenes, child.DistanceNeuronGenes);

            crossoverFunction.Crossover(HiddenNeuronGenes, c2.HiddenNeuronGenes, child.HiddenNeuronGenes);
            crossoverFunction.Crossover(InputNeuronGenes, c2.InputNeuronGenes, child.InputNeuronGenes);
            crossoverFunction.Crossover(OutputNeuronGenes, c2.OutputNeuronGenes, child.OutputNeuronGenes);

            child.GlobalSigmoidFunction       = (SigmoidFunction)GlobalSigmoidFunction.CrossoverModule(c2.GlobalSigmoidFunction, crossoverFunction);
            child.GlobalOutputSigmoidFunction = (SigmoidFunction)GlobalOutputSigmoidFunction.CrossoverModule(c2.GlobalOutputSigmoidFunction, crossoverFunction);

            return(child);
        }
Exemple #3
0
        public static Func <bool> GUI_Edit(SingleSlotBox container, RMP_Chromosome chromosome)
        {
            var builder = new FieldBuilder();

            builder.BuildSessionStart(container);

            Dictionary <string, object> valueHolder = new Dictionary <string, object>();

            valueHolder.Add("RMP_Chromosome", chromosome);

            var inhibitoryConnectionChance = builder.AddDoubleField("Inhibitory Connection-Chance: ");

            inhibitoryConnectionChance.Value = chromosome.InhibitoryConnectionChance;
            var connectionChance = builder.AddDoubleField("Connection-Chance: ");

            connectionChance.Value = chromosome.ConnectionChance;

            var newConnectionsCanForm = builder.AddCheckBoxField("NewConnectionsCanForm: ");

            newConnectionsCanForm.Checked = chromosome.NewConnectionsCanForm;
            var connectionsCanDie = builder.AddCheckBoxField("ConnectionsCanDie: ");

            connectionsCanDie.Checked = chromosome.ConnectionsCanDie;
            var newNeuronsCanForm = builder.AddCheckBoxField("NewNeuronsCanForm: ");

            newNeuronsCanForm.Checked = chromosome.NewNeuronsCanForm;
            var neuronsCanDie = builder.AddCheckBoxField("NeuronsCanDie: ");

            neuronsCanDie.Checked = chromosome.NeuronsCanDie;

            Action reloadChromosome = delegate()
            {
                chromosome.InhibitoryConnectionChance = inhibitoryConnectionChance.Value;
                chromosome.ConnectionChance           = connectionChance.Value;

                chromosome.NewConnectionsCanForm = newConnectionsCanForm.Checked;
                chromosome.ConnectionsCanDie     = connectionsCanDie.Checked;
                chromosome.NewNeuronsCanForm     = newNeuronsCanForm.Checked;
                chromosome.NeuronsCanDie         = neuronsCanDie.Checked;
            };

            if (chromosome.MutationGenes.Count == 0)
            {
                //Mutation Genes
                chromosome.MutationGenes.Add(new DoubleGene("NeuronAddChance", 0, 1, 0.1));
                chromosome.MutationGenes.Add(new DoubleGene("NeuronRemoveChance", 0, 1, 0.1));
                chromosome.MutationGenes.Add(new DoubleGene("MaxNeuronRemoving", 0, 1, 0.1));
                chromosome.MutationGenes.Add(new DoubleGene("MaxNeuronAdding", 0, 1, 0.1));
                chromosome.MutationGenes.Add(new DoubleGene("ConnectionAddChance", 0, 1, 0.05));
                chromosome.MutationGenes.Add(new DoubleGene("ConnectionRemoveChance", 0, 1, 0.05));
            }
            builder.AddResizableButtonField("Edit Mutation Genes", delegate(object sender)
            {
                EditDoubleGeneListForm.ShowDialogue(container.Parent, chromosome.MutationGenes);
            });

            var sigmoidTypes = Globals.GetAllTypesDeriving(typeof(SigmoidFunction), Assembly.GetExecutingAssembly());
            var sigmoidNames = new List <string>(sigmoidTypes.Select(s => s.Name));

            var globalSigmoidComboBox = builder.AddComboBoxField("GlobalSigmoid: ", sigmoidNames);

            if (chromosome.GlobalSigmoidFunction != null)
            {
                var globalSigmoidType = chromosome.GlobalSigmoidFunction.GetType();
                foreach (var type in sigmoidTypes)
                {
                    if (type.IsEquivalentTo(globalSigmoidType))
                    {
                        globalSigmoidComboBox.Index = sigmoidTypes.IndexOf(type);
                    }
                }
            }

            globalSigmoidComboBox.SelectedItemChanged += delegate(object sender, int newItemIndex, int oldItemIndex)
            {
                chromosome.GlobalSigmoidFunction = (SigmoidFunction)Activator.CreateInstance(sigmoidTypes[newItemIndex]);
            };
            var globalSigmoidEditButton = builder.AddResizableButtonField("Edit GlobalSigmoid", delegate(object sender)
            {
                if (chromosome.GlobalSigmoidFunction == null)
                {
                    return;
                }

                var sigmoid = chromosome.GlobalSigmoidFunction;
                sigmoidTypes[globalSigmoidComboBox.Index].InvokeMember("GUI_Edit", BindingFlags.Default | BindingFlags.InvokeMethod, null, null, new object[] { container.Parent, sigmoid });
            });

            var globalOutputSigmoidComboBox = builder.AddComboBoxField("GlobalOutputSigmoid: ", sigmoidNames);

            if (chromosome.GlobalOutputSigmoidFunction != null)
            {
                var globalOutputSigmoidType = chromosome.GlobalOutputSigmoidFunction.GetType();
                foreach (var type in sigmoidTypes)
                {
                    if (type.IsEquivalentTo(globalOutputSigmoidType))
                    {
                        globalOutputSigmoidComboBox.Index = sigmoidTypes.IndexOf(type);
                    }
                }
            }

            globalOutputSigmoidComboBox.SelectedItemChanged += delegate(object sender, int newItemIndex, int oldItemIndex)
            {
                chromosome.GlobalOutputSigmoidFunction = (SigmoidFunction)Activator.CreateInstance(sigmoidTypes[newItemIndex]);
            };
            var globalOutputSigmoidEditButton = builder.AddResizableButtonField("Edit GlobalOutputSigmoid", delegate(object sender)
            {
                if (chromosome.GlobalOutputSigmoidFunction == null)
                {
                    return;
                }

                var sigmoid = chromosome.GlobalOutputSigmoidFunction;
                sigmoidTypes[globalOutputSigmoidComboBox.Index].InvokeMember("GUI_Edit", BindingFlags.Default | BindingFlags.InvokeMethod, null, null, new object[] { container.Parent, sigmoid });
            });

            builder.AddResizableButtonField("Randomize", delegate(object sender)
            {
                reloadChromosome();

                if (chromosome.GlobalSigmoidFunction == null ||
                    chromosome.GlobalOutputSigmoidFunction == null)
                {
                    AlertForm.ShowDialogue(container.Parent, null, "Can't randomize before choosing a sigmoid function.");
                }
                else
                {
                    RandomizeForm.ShowDialogue(container.Parent, chromosome);
                }
            });

            builder.AddResizableButtonField("Edit Neuron-genes", delegate(object sender)
            {
                reloadChromosome();

                EditChromosomeNeuronsForm.ShowDialogue(container.Parent, valueHolder);
            });

            container.IsClosing += delegate(object sender)
            {
                reloadChromosome();
            };

            builder.BuildSessionEnd();

            return(delegate()
            {
                return chromosome.GlobalSigmoidFunction != null && chromosome.GlobalOutputSigmoidFunction != null;
            });
        }