Ejemplo n.º 1
0
    def match_objects(self, set_a, set_b, time_a, time_b):
        """
        Match two sets of objects at particular times.

        Args:
            set_a: list of STObjects
            set_b: list of STObjects
            time_a: time at which set_a is being evaluated for matching
            time_b: time at which set_b is being evaluated for matching

        Returns:
            List of tuples containing (set_a index, set_b index) for each match
        """
        costs = self.cost_matrix(set_a, set_b, time_a, time_b) * 100
        min_row_costs = costs.min(axis=1)
        min_col_costs = costs.min(axis=0)
        good_rows = np.where(min_row_costs < 100)[0]
        good_cols = np.where(min_col_costs < 100)[0]
        assignments = []
        if len(good_rows) > 0 and len(good_cols) > 0:
            munk = Munkres()
            initial_assignments = munk.compute(costs[np.meshgrid(
                good_rows, good_cols, indexing='ij')].tolist())
            initial_assignments = [(good_rows[x[0]], good_cols[x[1]])
                                   for x in initial_assignments]
            for a in initial_assignments:
                if costs[a[0], a[1]] < 100:
                    assignments.append(a)
        return assignments
Ejemplo n.º 2
0
    def match_objects(self, set_a, set_b, time_a, time_b):
        """
        Match two sets of objects at particular times.

        Args:
            set_a: list of STObjects
            set_b: list of STObjects
            time_a: time at which set_a is being evaluated for matching
            time_b: time at which set_b is being evaluated for matching

        Returns:
            List of tuples containing (set_a index, set_b index) for each match
        """
        costs = self.cost_matrix(set_a, set_b, time_a, time_b) * 100
        min_row_costs = costs.min(axis=1)
        min_col_costs = costs.min(axis=0)
        good_rows = np.where(min_row_costs < 100)[0]
        good_cols = np.where(min_col_costs < 100)[0]
        assignments = []
        if len(good_rows) > 0 and len(good_cols) > 0:
            munk = Munkres()
            initial_assignments = munk.compute(costs[tuple(np.meshgrid(good_rows, good_cols, indexing='ij'))].tolist())
            initial_assignments = [(good_rows[x[0]], good_cols[x[1]]) for x in initial_assignments]
            for a in initial_assignments:
                if costs[a[0], a[1]] < 100:
                    assignments.append(a)
        return assignments
Ejemplo n.º 3
0
    def match_tracks(self, set_a, set_b, closest_matches=False):
        """
        Find the optimal set of matching assignments between set a and set b. This function supports optimal 1:1
        matching using the Munkres method and matching from every object in set a to the closest object in set b.
        In this situation set b accepts multiple matches from set a.

        Args:
            set_a:
            set_b:
            closest_matches:

        Returns:

        """
        costs = self.track_cost_matrix(set_a, set_b) * 100
        min_row_costs = costs.min(axis=1)
        min_col_costs = costs.min(axis=0)
        good_rows = np.where(min_row_costs < 100)[0]
        good_cols = np.where(min_col_costs < 100)[0]
        assignments = []
        if len(good_rows) > 0 and len(good_cols) > 0:
            if closest_matches:
                b_matches = costs[np.meshgrid(good_rows, good_cols, indexing='ij')].argmin(axis=1)
                a_matches = np.arange(b_matches.size)
                initial_assignments = [(good_rows[a_matches[x]], good_cols[b_matches[x]])
                                       for x in range(b_matches.size)]
            else:
                munk = Munkres()
                initial_assignments = munk.compute(costs[np.meshgrid(good_rows, good_cols, indexing='ij')].tolist())
                initial_assignments = [(good_rows[x[0]], good_cols[x[1]]) for x in initial_assignments]
            for a in initial_assignments:
                if costs[a[0], a[1]] < 100:
                    assignments.append(a)
        return assignments
Ejemplo n.º 4
0
    def match_tracks(self, set_a, set_b, closest_matches=False):
        """
        Find the optimal set of matching assignments between set a and set b. This function supports optimal 1:1
        matching using the Munkres method and matching from every object in set a to the closest object in set b.
        In this situation set b accepts multiple matches from set a.

        Args:
            set_a:
            set_b:
            closest_matches:

        Returns:

        """
        costs = self.track_cost_matrix(set_a, set_b) * 100
        min_row_costs = costs.min(axis=1)
        min_col_costs = costs.min(axis=0)
        good_rows = np.where(min_row_costs < 100)[0]
        good_cols = np.where(min_col_costs < 100)[0]
        assignments = []
        if len(good_rows) > 0 and len(good_cols) > 0:
            if closest_matches:
                b_matches = costs[np.meshgrid(good_rows, good_cols, indexing='ij')].argmin(axis=1)
                a_matches = np.arange(b_matches.size)
                initial_assignments = [(good_rows[a_matches[x]], good_cols[b_matches[x]])
                                       for x in range(b_matches.size)]
            else:
                munk = Munkres()
                initial_assignments = munk.compute(costs[np.meshgrid(good_rows, good_cols, indexing='ij')].tolist())
                initial_assignments = [(good_rows[x[0]], good_cols[x[1]]) for x in initial_assignments]
            for a in initial_assignments:
                if costs[a[0], a[1]] < 100:
                    assignments.append(a)
        return assignments
Ejemplo n.º 5
0
 def match_tracks(self, set_a, set_b):
     costs = self.track_cost_matrix(set_a, set_b) * 100
     min_row_costs = costs.min(axis=1)
     min_col_costs = costs.min(axis=0)
     good_rows = np.where(min_row_costs < 100)[0]
     good_cols = np.where(min_col_costs < 100)[0]
     assignments = []
     if len(good_rows) > 0 and len(good_cols) > 0:
         munk = Munkres()
         initial_assignments = munk.compute(costs[np.meshgrid(
             good_rows, good_cols, indexing='ij')].tolist())
         initial_assignments = [(good_rows[x[0]], good_cols[x[1]])
                                for x in initial_assignments]
         for a in initial_assignments:
             if costs[a[0], a[1]] < 100:
                 assignments.append(a)
     return assignments