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());
        }
Exemplo n.º 2
0
        private void loadNeuralNetworkButton_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();
            DialogResult   result          = openFileDialog1.ShowDialog(); // Show the dialog.

            if (result == DialogResult.OK)                                 // Test result.
            {
                string file = openFileDialog1.FileName;
                try
                {
                    this.neuralNetwork = DiscreteNeuralNetworkByChord.Load(file);
                    this.loadNeuralNetworkTextbox.Text = FinalUIHelperMethods.FileFriendlyString(openFileDialog1.FileName);
                }

                catch (Exception ex)
                {
                    MessageBox.Show("Could Not Load NN", ex.Message);
                }
            }
        }
Exemplo n.º 3
0
        private void loadNeuralNetworkButton_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            // Test result.
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                string file = openFileDialog1.FileName;

                try
                {
                    this.neuralNetwork = DiscreteNeuralNetworkByChord.Load(file);
                    this.loadNeuralNetworkTextbox.Text = Path.GetFileName(openFileDialog1.FileName);
                }

                catch (Exception ex)
                {
                    MessageBox.Show("Could Not Load Neural Network", ex.Message);
                }
            }
        }
Exemplo n.º 4
0
        private void trainingButton_Click(object sender, EventArgs e)
        {
            var retriever  = new PianoNoteRetriever();
            var midiEvents = new InstrumentMidiEventProducer(this.files.Select(x => new Sequence(x)));
            IReadOnlyList <MidiEvent> midi = midiEvents.GetOrderedMessages(GeneralMidiInstrument.AcousticGrandPiano);

            Chord.AllowForComplexSimplification = this.checkBox.Checked;
            var accords = Chord.RetrieveChords(midi, retriever);

            DiscreteDataRetriever data = new DiscreteDataRetriever(accords.ToList());

            DiscreteNeuralNetworkByChord.OkayWeight      = (double)this.okayWeight.Value;
            DiscreteNeuralNetworkByChord.HiddenLayerSize = (int)hiddelLayerSize.Value;

            if (this.okayFiles != null)
            {
                var midiEvents1 = new InstrumentMidiEventProducer(this.okayFiles.Select(x => new Sequence(x)));
                var midi1       = midiEvents1.GetOrderedMessages(GeneralMidiInstrument.AcousticGrandPiano);
                Chord.AllowForComplexSimplification = this.checkBox.Checked;
                var accords1 = Chord.RetrieveChords(midi1, retriever);
                DiscreteDataRetriever data1 = new DiscreteDataRetriever(accords1.ToList());

                this.nnByChord = new DiscreteNeuralNetworkByChord(data.Good, data1.Good, data.Bad.Union(data1.Bad).Take(data.Bad.Count).ToList(),
                                                                  new AForge.Neuro.BipolarSigmoidFunction());
            }
            else
            {
                this.nnByChord = new DiscreteNeuralNetworkByChord(data.Good, data.Okay, data.Bad, new AForge.Neuro.SigmoidFunction());
            }

            foreach (var item in this.Controls.OfType <Control>())
            {
                item.Enabled = false;
            }

            threadTrain = new Thread(Start);
            threadTrain.Start();
        }