accord-net / framework

Machine learning, computer vision, statistics and general scientific computing for .NET
http://accord-framework.net
GNU Lesser General Public License v2.1
4.49k stars 1.99k forks source link

DoubleArrayChromosome CreateNew ignores Balancer properties #676

Closed lmrobins closed 7 years ago

lmrobins commented 7 years ago

In DoubleArrayChromosome.cs, the CreateNew function is used when initializing a genetic algorithm Population object, or when performing selection on an existing Population. The CreateNew function just creates a new instance of a DoubleArrayChromosome using the founding chromosome generator settings. Unfortunately it ignores the founding chromosome's CrossoverBalancer and MutationBalancer settings, so the entire population (and newly selected members of the population) will have the wrong Crossover and Mutation balancer settings.

The fix is easy (just update the CreateNew function), but I'm new to this project and keep getting an authorization error when trying to create a new branch for the change, so I thought I'd post about it here instead.

The CreateNew function should look like:

public override IChromosome CreateNew( )
        {
            var chromosome = new DoubleArrayChromosome( chromosomeGenerator, mutationMultiplierGenerator, mutationAdditionGenerator, length );
            chromosome.CrossoverBalancer = this.CrossoverBalancer;
            chromosome.MutationBalancer = this.MutationBalancer;

            return chromosome;
        }
cesarsouza commented 7 years ago

Hi @lmrobins

Thanks a lot for opening the issue! I haven't updated the .Genetics namespace since the merge with AForge.NET, so thanks a lot for the catch. If you see other problems, including inconsistent interfaces, or just things that do not work as you would have expected in the first try (even if they are not really bugs, just nuisances in the current API), please let me know.

Also, if you are still getting those authorization errors you mention, please let me know too - are they errors with git/GitHub, or errors within the project itself? Please feel free to open a new issue if you haven't been able to solve them yet.

Regards, Cesar

lmrobins commented 7 years ago

Hi Cesar, I know of at least one other issue with DoubleArrayChromosome but the fix isn't as straight forward, but I would be happy to submit a pull request for it when I get the git issue fixed. I have a feeling it's my own git setup conflicting with another non-github repository I use.

lmrobins commented 7 years ago

I got it worked out and was able to submit the request. I wasn't sure if it should be against development or master? I went with a single file change against the Master, but then the CI failed with an unrelated error.

cesarsouza commented 7 years ago

Hi @lmrobins,

If you can, please submit against development. Do whatever is easier for you, and then I can take care of the merging (even if this means attaching a .zip file with your changes to this thread).

Thanks a lot for the willingness to share your fixes!

Regards, Cesar

lmrobins commented 7 years ago

Ok thanks @cesarsouza, I created a new pull request against development.

cesarsouza commented 7 years ago

Added in v3.7.0.