private List <NGram <Chord>[]> RetrieveOkay()
        {
            NGramGraphMarkovChain <Chord>    graph        = new NGramGraphMarkovChain <Chord>(this.HomogenousWindowingData);
            NGramGraphChainRetriever <Chord> mostProbable = new NGramGraphChainRetriever <Chord>(graph);

            return(mostProbable
                   .FromEachNodeRandom(
                       (this.Assigner == null) ? new NGramIDWeightAssigner <Chord>(graph) : this.Assigner,
                       this.WindowSize - 1,
                       10));
        }
        public IReadOnlyCollection <NGram <Chord>[]> Themes(INGramWeightAssigner <Chord> assigner)
        {
            NGramGraphChainRetriever <Chord> mostProbable = new NGramGraphChainRetriever <Chord>(this.MarkovGraph);

            var chains = mostProbable.FromEachNodeRandom(assigner, this.WalkerDepth, 3);


            //KMeans<NGram<Chord>> cluster = new KMeans<NGram<Chord>>(chains.ToArray(), new LevenshteinDistance<NGram<Chord>>(), 500);
            //cluster.RunFrames(2);

            DiscreteNeuralNetworkByChord teacher = DiscreteNeuralNetworkByChord.Load(@"C:\Users\armen_000\Documents\Visual Studio 2013\Projects\Improvisation\Improvisation\bin\Debug\Learning\eminemNN.txt");

            ChordChainGeneticFunction function = new ChordChainGeneticFunction(
                teacher,
                this.MarkovGraph,
                assigner,
                ChordChainGeneticFunction.ChordRandomFunctionType.AllowRandomSelection,
                ChordChainGeneticFunction.ChordCrossFunctionType.DiscreteChoice)
            {
                RandomSelectionCoefficient = 0.3D
            };

            GeneticAlgorithm <NGram <Chord>[]> genetic = new GeneticAlgorithm <NGram <Chord>[]>(
                function,
                new GeneticSettings(0.1F, 0.05f, 5000, GeneticSettings.OrderOfEvolution.MutateCrossover),
                chains.Take(500));

            for (int i = 0; i < 3; i++)
            {
                try
                {
                    var l = genetic.SingleEvolutionaryCycle();
                }
                catch (Exception e)
                {
                    continue;
                }

                // KMeans<NGram<Chord>> chords = new KMeans<NGram<Chord>>(
                // genetic.CurrentPopulation.Select(x => x.Value).RandomValues(1000),
                // new GaussianNoiseDistance<NGram<Chord>>(new ChordHammingDistance(), 010F), 1000);

                // chords.RunFrames(3);
                // genetic.SubstitutePopulation(chords.Centers);
            }

            return(genetic.ToList().AsReadOnly());
        }
        private void GeneticSearch(object a)
        {
            var assigner = (INGramWeightAssigner <Chord>)(a);
            NGramGraphChainRetriever <Chord> mostProbable = new NGramGraphChainRetriever <Chord>(this.model)
            {
                Max = 200
            };

            var chains = mostProbable.FromEachNodeRandom(assigner, (int)this.walkerDepth.Value, (int)this.fromEachNode.Value);

            ChordChainGeneticFunction function = new ChordChainGeneticFunction(this.neuralNetwork, this.model, assigner,
                                                                               (this.allowRandomChordSelection.Checked) ?
                                                                               ChordChainGeneticFunction.ChordRandomFunctionType.AllowRandomSelection :
                                                                               ChordChainGeneticFunction.ChordRandomFunctionType.NoRandomSelection,
                                                                               (this.mergeChordsCheckBox.Checked) ?
                                                                               ChordChainGeneticFunction.ChordCrossFunctionType.Merge :
                                                                               ChordChainGeneticFunction.ChordCrossFunctionType.DiscreteChoice)
            {
                RandomSelectionCoefficient = 0.3D
            };

            GeneticAlgorithm <NGram <Chord>[]> genetic = new GeneticAlgorithm <NGram <Chord>[]>(function, new GeneticSettings(0.1F, 0.05f, (int)this.geneticInitialPopulation.Value,
                                                                                                                              (this.mutateCrossCheckBox.Checked) ?
                                                                                                                              GeneticSettings.OrderOfEvolution.MutateCrossover :
                                                                                                                              GeneticSettings.OrderOfEvolution.CrossoverMutate),
                                                                                                chains.Take(500));
            int iMax = (int)this.geneticEpochs.Value;

            this.progressBar1.Invoke((Action)(() => this.progressBar1.Maximum = iMax));

            for (int i = 0; i < iMax; i++)
            {
                this.progressBar1.Invoke((Action)(() => this.progressBar1.Value = i));

                var text = genetic.SingleEvolutionaryCycle().ToString();

                this.geneticErrorTextBox.Invoke((Action)(() => this.geneticErrorTextBox.Text = text));
            }

            this.progressBar1.Invoke((Action)(() => this.progressBar1.Value = this.progressBar1.Maximum));
            this.songListBox.Invoke((Action)(() => this.songListBox.Enabled = true));

            this.AddItemsToListBoxFromGenetic(genetic.CurrentPopulation);
        }
        private List<NGram<Chord>[]> RetrieveOkay()
        {
            NGramGraphMarkovChain<Chord> graph = new NGramGraphMarkovChain<Chord>(this.HomogenousWindowingData);
            NGramGraphChainRetriever<Chord> mostProbable = new NGramGraphChainRetriever<Chord>(graph);

            return mostProbable
                .FromEachNodeRandom(
                        (this.Assigner == null) ? new NGramIDWeightAssigner<Chord>(graph) : this.Assigner,
                        this.WindowSize - 1,
                        10);
        }