def calculateMostLikely(self): """ Calculates the indices of the most likely trajectory. The result alternates between point indices and path indices and correspond to the candidate points and candidate paths. """ # a LearningTrajectory is the basic data structure that stores the # features (scores candidate states candidate paths), and transitions # (indices to look up those states or paths). traj = LearningTrajectory(self.features, self.transitions) # The viterbi is a specific algorithm that calculates the most likely # states and most likley paths. The key output are the indices noted # below, which can be used to look up the specific candidate states # and candidate paths (although those must be stored externally. # There is one index for each feature. viterbi = TrajectoryViterbi1(traj, self.THETA) try: viterbi.computeAssignments() except (ValueError): for f in self.features: print(f) for t in self.transitions: print(t) print(self.THETA) raise # The indexes of the most likely elements of the trajectory # Point indexes and path indexes are interleaved. self.most_likely_indices = viterbi.assignments
def simple_traj2(): """ Simple trajectory, tests correct indices. """ features = [ [[0.0, 2.0]], [[2.0, 0.0], [-1.0, 0.0]], ] connections = [[(0, 0), (0, 1)]] traj = LearningTrajectory(features, connections) return traj
def simple_traj1(): """ Simple trajectory. """ features = [ [[1.0, 0.0], [-2.0, 0.0]], [[0.0, 1.0]], ] connections = [[(1, 0), (0, 0)]] traj = LearningTrajectory(features, connections) return traj
def simple_traj3(): """ Simple trajectory with large features, breaks non log-based implementations. """ features = [ [[0, 200]], [[200, 0], [-100, 0]], ] connections = [[(0, 0), (0, 1)]] traj = LearningTrajectory(features, connections) return traj
def simple_traj10(): """ Simple trajectory, with a single feature and feature values that are very big. Should cause some underflow problems. """ features = [ [[1000.0, 0.0], [2000.0, 0.0]], [[500.0, 0.0], [3000.0, 0.0]], ] connections = [[(0, 0), (0, 1), (1, 1)]] traj = LearningTrajectory(features, connections) return traj
def simple_traj7(): """ Simple trajectory, with a disconnected point. This case should be properly handled. """ features = [ [[1.0], [-2.0]], [[-1.0], [-2.0]], ] connections = [[(0, 0)]] traj = LearningTrajectory(features, connections) return traj
def simple_traj9(): """ Simple trajectory, with a single feature and feature values that are all zeros. Feature values are small enough to be safe against underflows. """ features = [ [[1.0], [2.0]], [[1.0], [2.0]], ] connections = [[(0, 0), (0, 1), (1, 1)]] traj = LearningTrajectory(features, connections) return traj
def calculateProbabilities(self): """ Calculates the probabilities for all possible options. The result alternates between point indices and path indices and correspond to the candidate points and candidate paths. Returns the probabilities. """ # The smoother is a different algorithm that gives probabilities instead # of the most likley. traj = LearningTrajectory(self.features, self.transitions) smoother = TrajectorySmoother1(traj, self.THETA) smoother.computeProbabilities() return smoother.probabilities
def simple_traj6(): """ Simple trajectory with more than 3 elements. """ features = [ [[1.0, 0.0], [-2.0, 0.0]], [[0.0, 1.0]], [[0.0, -1.0], [0.0, 2.0], [0.5, 0.5]], [[0.0, -1.0], [0.0, 2.0], [0.5, 0.5]], ] connections = [ [(1, 0), (0, 0)], [(0, 0), (0, 1), (0, 2)], [(1, 0), (2, 1), (0, 2)], ] traj = LearningTrajectory(features, connections) return traj
# NOTES (gde): fill up the data structures used by the algoritms transitions.append(trans1) paths_features = [] for path_ in ps: paths_features.append(path_feature_vector(path_, tt_)) features.append(paths_features) transitions.append(trans2) features.append(point_feature_vector(sc2)) """ We can build a trajectory. """ # NOTES (gde): # # a LearningTrajectory is the basic data structure that stores the # features (scores candidate states candidate paths), and transitions # (indices to look up those states or paths). traj = LearningTrajectory(features, transitions) """ *** Running filters *** """ """ Weight vector of the model. Note: these weights have not be tuned in any way and are here for demonstration only. """ # NOTES (gde): # # theta determines the relative weights of the pathscores versus # the pointscores. What are recommended values? # Also beware of units! theta = np.array([1, 1]) """ Viterbi filter (most likely elements) """ # NOTES (gde):