forked from mathigatti/midi2foxdot
-
Notifications
You must be signed in to change notification settings - Fork 1
/
train.py
50 lines (36 loc) · 1.25 KB
/
train.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import json, pickle
import sys
import os.path as ospath
from FoxDot import *
import pykov
def main(args):
pickleFile = args.file
print("Loading "+pickleFile)
with open(pickleFile,'rb') as j:
data = pickle.load( j)
#print(data)
matr = pykov.Matrix()
T = pykov.Chain()
transitions= {}
for notes in data['degree']:
for i in range(len(notes)-1):
A = notes[i]# % 12
B = notes[i+1]# % 12
if not A in transitions:
transitions[A] = pykov.Vector()
if not B in transitions[A]:
transitions[A][B] = 0
transitions[A][B] += 1
for k in transitions.keys():
transitions[k].normalize()
T[k] = transitions[k]
#matr[(A,B)] += 1
#T[(A,B)] += 1
#matr.normalize()
print (T.steady())
if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser(description='Process files into the data format for learning.')
parser.add_argument('--file', help='file to learn from', default='output/bad_guy.pickle')
args = parser.parse_args()
main(args)