def classifyForShot(block, context, classifiers, scaler): """ Constructs a feature-line from the block and the history in context. There needs to be a correctly constructed context for this function to work. The feature-line is scaled using the scaler. Then the distribution for all classifiers is compted and a single mixed distribution is returned. """ feature_line = getFeatureLine(context, block, True, -1) feature_line.pop() feature_line = scaler.transform(feature_line) return distributionOfClassification(feature_line, classifiers, dist=[0, 0, 0, 0, 0, 0, 0])
def classifyForCut(block, context, classifiers, scaler): """ Constructs a feature-line from the block and the history in context. There needs to be a correctly constructed context for this function to work. The feature-line is scaled using the scaler. Then the distribution for all classifiers is compted and a single mixed distribution is returned. This function is for computing the decision if there should be a cut or not. """ if len(context["BygoneBlocks"]) >= 1: last_shot_id = context["BygoneBlocks"][-1][-1].shotId else: last_shot_id = 0 feature_line = getFeatureLine(context, block, True, last_shot_id) feature_line.pop() feature_line = scaler.transform(feature_line) return distributionOfClassification(feature_line, classifiers, dist=[0, 0])
def onlineFeatureLineCreator(filename, use_classified_shot = False, use_history = True): # load context and complete beatlist from file context, beatList = getContextAndBeatListFromFile(filename) Features.initializeContextVars(context) blockList = coalesceBeats(beatList) context["BygoneBlocks"] = [] for block in blockList: shot_true = block[-1].shot # get current feature line and true shot class featureLine = getFeatureLine(context, block, True, -1) features = np.array(featureLine[:-1], dtype=np.float64) shot_classified = yield features, shot_true # update block and lastShotId if use_classified_shot: for beat in block: beat.shot = shot_classified if use_history: context["BygoneBlocks"].append(block)