def probability(self, S, log=False, performance=False, name=None): if not S.hasLength(): if not S.tree() in self.allowed: return 0.0, 1 return 1.0, 1 # If time is greater than previous, all is fine, if time is smaller that previous, it becomes increasingly less probable # If time is smaller than next, all is fine, if time is greater than next, it becomes increasingly less probable start = S.downbeat() (pos, (previous, on, next)) = S.features length = len(S.children) * (S.beats[1] - S.beats[0]) if previous - start > 0.1 * length or\ (start + length) - next > 0.1 * length: return 0.0, 1 obs = expression.observations(S, performance=performance) if log: p = 0.0 for o in obs: if self.observation_likelihood(o, S.depth) == 0: print o, name, S.depth-o[0], self.expressionModel[(S.depth-o[0], )] p += math.log(1.0) else: p += math.log(self.observation_likelihood(o, S.depth)) else: p = 1.0 for o in obs: #if not (S.depth-o[0], ) in self.expressionModel: # print S.beats # S.view() # exit(0) p *= self.observation_likelihood(o, S.depth) return p, len(obs)
def probability(self, S, log=False, performance=False, name=None): if not S.hasLength(): if self.allowed == None: if S.depth > self.maxDepth: return 0.0, 1 elif not S.tree() in self.allowed: return 0.0, 1 return 1.0, 1 # If time is greater than previous, all is fine, if time is smaller that previous, it becomes increasingly less probable # If time is smaller than next, all is fine, if time is greater than next, it becomes increasingly less probable start = S.downbeat() (pos, (previous, on, next)) = S.features length = len(S.children) * (S.beats[1] - S.beats[0]) if previous - start > self.tieThreshold * length or\ (start + length) - next > self.tieThreshold * length: return 0.0, 1 obs = expression.observations(S, performance=performance) if len(obs) == 0: if S.beats[0] == 0 and S.beats[1] == 0: print S.beats print expression.observations(S.children[1]) expression.observations(S.children[1], verbose=2) S.view(showOnsets=True, showFeatures=True) exit(0) return 1.0, 1 if log: p = 0.0 for f, exp in obs: if self.observation_likelihood(f, exp) == 0: # print o, name, S.depth-o[0], self.expressionModel[(S.depth-o[0], )] p += math.log(1.0) else: p += math.log(self.observation_likelihood(f, exp)) else: p = 1.0 for f, exp in obs: #if not (S.depth-o[0], ) in self.expressionModel: # print S.beats # S.view() # exit(0) p *= self.observation_likelihood(f, exp) return p, len(obs)
def probability(self, S): if not S.hasLength(): if not S.tree() in self.allowed: return 0.0, 1 return 1.0, 1 # If time is greater than previous, all is fine, if time is smaller that previous, it becomes increasingly less probable # If time is smaller than next, all is fine, if time is greater than next, it becomes increasingly less probable start = S.downbeat() (pos, (previous, on, next)) = S.features length = len(S.children) * (S.beats[1] - S.beats[0]) if previous - start > 0.1 * length or\ (start + length) - next > 0.1 * length: return 0.0, 1 obs = expression.observations(S) p = 1.0 for o in obs: p *= self.observation_likelihood(o) return p, len(obs)