private NGramGraphMarkovChain(bool het)
 {
     this.graph          = new Dictionary <NGram <T>, List <NonRecursiveNGramProbabilisticEdge <T> > >();
     this.IsHeterogenous = het;
     this.Distrubution   = new NGramDistribution <T>(new NGram <T> [0]);
     this.Grams          = HomogenousNGrams <T> .DirectBuiltUnsafe(new NGram <T> [0], 1);
 }
Пример #2
0
        private void beginGenerationButton_Click(object sender, EventArgs e)
        {
            try
            {
                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.checkBox1.Checked;
                var accords = Chord.RetrieveChords(midi, retriever);

                INGrams <Chord> grams = null;
                if (this.homogeneous)
                {
                    grams = HomogenousNGrams <Chord> .BuildNGrams((int)this.leftRangeNumericUpDown.Value, accords);
                }
                else
                {
                    grams = HeterogenousNGrams <Chord> .BuildNGrams((int)this.leftRangeNumericUpDown.Value, (int)this.rightRangeNumericUpDown.Value, accords);
                }

                NGramGraphMarkovChain <Chord> graph = new NGramGraphMarkovChain <Chord>(grams);
                this.Save(graph);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void BuildFromHomogenousNGrams(INGrams <T> grams, NGram <T>[] array, NGramDistribution <T> distrubution)
        {
            var blockedGrams = NGramHomogenousMatrixMarkovChainHelper <T> .BuildBlockedNGrams(grams.ToArray());

            var transitionMatrix = Matrix <float> .Build.Sparse(
                array.Length,
                array.Length,
                new Func <int, int, float>(
                    (x, y) => NGramHomogenousMatrixMarkovChainHelper <T> .CalculateProbability(blockedGrams, distrubution, array, x, y)));

            int rowIndex = 0;

            foreach (var row in transitionMatrix.EnumerateRows())
            {
                this.graph.Add(array[rowIndex], new List <NonRecursiveNGramProbabilisticEdge <T> >());

                for (int i = 0; i < row.Count; i++)
                {
                    if (row[i] != 0)
                    {
                        this.graph[array[rowIndex]].Add(new NonRecursiveNGramProbabilisticEdge <T>(row[i], array[i]));
                    }
                }
                rowIndex++;
            }
        }
        public DiscreteDataRetriever(List <Chord> chordsInOrder, int clusterSize = 2, int windowSize = 20)
        {
            chordsInOrder.NullCheck();
            chordsInOrder.Any().AssertTrue();

            this.Chords = chordsInOrder.AsReadOnly();

            this.WindowSize = windowSize;
            this.NGramSize  = clusterSize;

            this.HomogenousWindowingData = HomogenousNGrams <Chord> .BuildNGrams(this.NGramSize, this.Chords.ToList());

            this.badOkayGoodChords = Tuple.Create <List <NGram <Chord>[]>, List <NGram <Chord>[]>, List <NGram <Chord>[]> >(this.RetrieveBad(), this.RetrieveOkay(), this.RetrieveGood());
        }
        public DiscreteDataRetriever(List<Chord> chordsInOrder, int clusterSize = 2, int windowSize = 20)
        {
            chordsInOrder.NullCheck();
            chordsInOrder.Any().AssertTrue();

            this.Chords = chordsInOrder.AsReadOnly();

            this.WindowSize = windowSize;
            this.NGramSize = clusterSize;

            this.HomogenousWindowingData = HomogenousNGrams<Chord>.BuildNGrams(this.NGramSize, this.Chords.ToList());

            this.badOkayGoodChords = Tuple.Create<List<NGram<Chord>[]>, List<NGram<Chord>[]>, List<NGram<Chord>[]>>(this.RetrieveBad(), this.RetrieveOkay(), this.RetrieveGood());
        }
        public NGramGraphMarkovChain(INGrams <T> grams)
        {
            grams.NullCheck();


            var array = new HashSet <NGram <T> >(grams).ToArray();

            this.Distrubution = new NGramDistribution <T>(grams);
            var typeOfNGram = (grams as IHeterogenousNGrams <T>);

            this.IsHeterogenous = typeOfNGram != null;
            this.graph          = new Dictionary <NGram <T>, List <NonRecursiveNGramProbabilisticEdge <T> > >();
            this.Grams          = grams;
            if (!this.IsHeterogenous)
            {
                this.BuildFromHomogenousNGrams(grams, array, this.Distrubution);
            }
            else
            {
                this.BuildFromHeterogenousNGrams(typeOfNGram, array, this.Distrubution);
            }
        }
 public NGramDistribution(INGrams <T> ngrams)
     : this(ngrams.AsEnumerable())
 {
 }