def turnNoteOn(self, noteNum): if noteNum >= len(self.currNoteState) or noteNum < 0: return assert(self.currNoteState[noteNum] == 0) self.soundMapping[noteNum].play(loops=-1) self.currNoteState[noteNum] = 1 print noteNum, " : ", self.currNoteState[noteNum] print "current note: ", utils.midiNoteMapping[noteNum] if True in self.predictionState: predicted = self.predictionState.index(True) self.confMatrix[noteNum % 12, predicted % 12] += 1 self.mmConfMatrix[noteNum % 12, self.mmPreds[-1][0]] += 1 self.mm3ConfMatrix[noteNum % 12, self.mm3Preds[-1][0]] += 1 self.hmmConfMatrix[noteNum % 12, self.hmmPreds[-1][0]] += 1 self.qConfMatrix[noteNum % 12, self.qPreds[-1][0]] += 1 if self.predictor == "Q": print "begin reward sequence" reward = 0 if (noteNum % 12) == (predicted % 12): print "good reward!" reward = 1 prevNote = self.allNotes[-1][0] print "before learning: ", self.qModel.q self.qModel.learn(prevNote, predicted, reward, noteNum) print "after learning: ", self.qModel.q #learn q learning here note = [noteNum, pygame.time.get_ticks(), -1] print note self.noteRects.append(utils.makeNoteRect(noteNum, 1)) self.allNotes.append(note) if (len(self.allNotes) > 10): self.predictNotes()
def __init__(self, showPredictions=False, predictor="MM", dataFile="data/noteData_ex_random.pickle"): self.model = Model(dataFile) import utils self.showPredictions = showPredictions self.currNoteState = [0] * utils.numNotes self.predictionState = [False] * utils.numNotes self.keyRects = [] self.actionQueue = [] if predictor not in ["MM", "MM3", "HMM", "Q"]: predictor = "MM" self.predictor = predictor self.octave = 1 #assumes that note 48 is in the data... for note, val in enumerate(self.currNoteState): self.keyRects.append(utils.makeNoteRect(note, utils.numNotes)) self.allNotes = [] self.modelRects = [] #(note, (left, top, width, height)) self.noteRects = [] #(note, (left, top, width, height)) self.soundMapping = utils.initSoundMappings() self.confMatList = [] self.confMatrix = np.zeros((12, 12), dtype=np.int) self.avgF1s = [] self.memoryList = [] self.cpuList = [] self.mmPreds = [] self.mmConfMatList = [] self.mmConfMatrix = np.zeros((12, 12), dtype=np.int) self.mmAvgF1s = [] self.mm3Preds = [] self.mm3ConfMatList = [] self.mm3ConfMatrix = np.zeros((12, 12), dtype=np.int) self.mm3AvgF1s = [] self.hmmPreds = [] self.hmmConfMatList = [] self.hmmConfMatrix = np.zeros((12, 12), dtype=np.int) self.hmmAvgF1s = [] self.qPreds = [] self.qConfMatList = [] self.qConfMatrix = np.zeros((12, 12), dtype=np.int) self.qAvgF1s = [] #MODELS# mmModel, mmModel3, hmmModel, qModel = self.model.train() self.mmModel = mmModel self.mmModel3 = mmModel3 self.hmmModel = hmmModel self.qModel = qModel