mercredi 5 février 2020

How do I use a markov chain matrix to generate music?

I have a matrix (square - nxn) <--Depends on how many chords there are.

------------------------------------------
            Transition Matrix: (FROM)
------------------------------------------
 A     Bm   C#m    D     E    F#m    G#   
------------------------------------------
0.07  0.00  0.00  0.00  0.66  0.14  0.86 | A   | 
0.15  0.17  0.00  0.05  0.07  0.30  0.00 | Bm  | 
0.00  0.00  0.00  0.00  0.00  0.37  0.00 | C#m | 
0.19  0.00  0.39  0.16  0.14  0.00  0.00 | D   | (TO)
0.52  0.83  0.29  0.43  0.00  0.19  0.00 | E   | 
0.07  0.00  0.32  0.36  0.14  0.00  0.14 | F#m | 
0.00  0.00  0.00  0.00  0.00  0.00  0.00 | G#  | 

This matrix gets multiplied by another matrix which is:

1
0
0
0
0
0
0

This means the starting note is an A (1st row corresponds to A).

The next note is determined by the column of the Markov Transition Matrix which says there is a:

7% chance to become A

15% chance to become Bm

0% chance to become C#m, etc. etc.

(Done by matrix multiplication, using numPy).

So the resulting matrix is a 1col x nrows matrix.

This matrix will look like this:

0.07
0.15
0.00
0.19
0.52
0.07
0.00

^ This means that there is a 0.07% that the next note is an A, etc.

^ Using these probabilities can I play back those notes? Or generate a midi file based on it?

I should only get back one note (plus the first one), and based on the probability it should be an E.




Aucun commentaire:

Enregistrer un commentaire