segmentation/bmoss/change_detec.py
def infer(self):
        """Return posterior probabilities OR sequence segmentation.

        If the MAX-PRODUCT algorithm is selected, this method returns the most
        likely sequence segmentation as a list of integers. Each integer in the
        list marks where a segment begins.

        If the SUM-PRODUCT algorithm is selected, this method returns the
        posterior probabilities of the segmentation hypotheses as a numpy
        array. Rows in the array represent hypotheses and columns in the array
        represent data points in the time-series.

        Returns:
            object: This method returns the inference results. In the case of
                    the MAX-PRODUCT algorithm, the method returns the most
                    likely segmentation. In the case of the SUM-PRODUCT
                    algorithm, this method returns the posterior probabilities
                    of the segmentation hypotheses.

        """

        # In the max-product algorithm, the most likely hypotheses are
        # tracked. Recover the most likely segment boundaries by performing a
        # back-trace.
        if self.__alg__ == 'maxprod':

            # Find the most likely hypothesis.
            max_hypothesis = max(self.__hypotheses,
                                 key=lambda dct: dct['log_probability'])

            # Find the best sequence segmentation given all the data so far.
            segment_boundaries = [len(self.__counts) - 1, ]
            index = segment_boundaries[0] - 1
            count = max_hypothesis['count'] - 1
            while index > 0:
                index -= count
                segment_boundaries.insert(0, index)
                count = self.__counts[index - 1]

            return segment_boundaries

        # In the sum-product algorithm, the segment probabilities are
        # tracked. Recover the segment probabilities by formatting the stored
        # history.
        else:
            k = len(self.__probabilities)
            segment_probabilities = np.zeros((k + 1, k + 1))
            segment_probabilities[0, 0] = 1.0

            # Update hypotheses probabilities.
            for i in range(len(self.__probabilities)):
                for (j, probability) in self.__probabilities[i]:
                    segment_probabilities[j, i + 1] = np.exp(probability)

            # A segment always occurs at the beginning of the dataset.
            segment_probabilities[0, 0] = 1.0

            return segment_probabilities
Return posterior probabilities OR sequence segmentation.

        If the MAX-PRODUCT algorithm is selected, this method returns the most
        likely sequence segmentation as a list of integers. Each integer in the
        list marks where a segment begins.

        If the SUM-PRODUCT algorithm is selected, this method returns the
        posterior probabilities of the segmentation hypotheses as a numpy
        array. Rows in the array represent hypotheses and columns in the array
        represent data points in the time-series.

        Returns:
            object: This method returns the inference results. In the case of
                    the MAX-PRODUCT algorithm, the method returns the most
                    likely segmentation. In the case of the SUM-PRODUCT
                    algorithm, this method returns the posterior probabilities
                    of the segmentation hypotheses.

        
Return posterior probabilities OR sequence segmentation.
If the MAX-PRODUCT algorithm is selected, this method returns the most
likely sequence segmentation as a list of integers. Each integer in the
list marks where a segment begins.

If the SUM-PRODUCT algorithm is selected, this method returns the
posterior probabilities of the segmentation hypotheses as a numpy
array. Rows in the array represent hypotheses and columns in the array
represent data points in the time-series.
Return posterior probabilities OR sequence segmentation . If the MAX - PRODUCT algorithm is selected this method returns the most likely sequence segmentation as a list of integers . Each integer in the list marks where a segment begins . If the SUM - PRODUCT algorithm is selected this method returns the posterior probabilities of the segmentation hypotheses as a numpy array . Rows in the array represent hypotheses and columns in the array represent data points in the time - series .
def infer(self):
        if self.__alg__ == 'maxprod':
            max_hypothesis = max(self.__hypotheses,
                                 key=lambda dct: dct['log_probability'])
            segment_boundaries = [len(self.__counts) - 1, ]
            index = segment_boundaries[0] - 1
            count = max_hypothesis['count'] - 1
            while index > 0:
                index -= count
                segment_boundaries.insert(0, index)
                count = self.__counts[index - 1]
            return segment_boundaries
        else:
            k = len(self.__probabilities)
            segment_probabilities = np.zeros((k + 1, k + 1))
            segment_probabilities[0, 0] = 1.0
            for i in range(len(self.__probabilities)):
                for (j, probability) in self.__probabilities[i]:
                    segment_probabilities[j, i + 1] = np.exp(probability)
            segment_probabilities[0, 0] = 1.0
            return segment_probabilities
def infer ( self ) : if self . __alg__ == 'maxprod' : max_hypothesis = max ( self . __hypotheses , key = lambda dct : dct [ 'log_probability' ] ) segment_boundaries = [ len ( self . __counts ) - 1 , ] index = segment_boundaries [ 0 ] - 1 count = max_hypothesis [ 'count' ] - 1 while index > 0 : index -= count segment_boundaries . insert ( 0 , index ) count = self . __counts [ index - 1 ] return segment_boundaries else : k = len ( self . __probabilities ) segment_probabilities = np . zeros ( ( k + 1 , k + 1 ) ) segment_probabilities [ 0 , 0 ] = 1.0 for i in range ( len ( self . __probabilities ) ) : for ( j , probability ) in self . __probabilities [ i ] : segment_probabilities [ j , i + 1 ] = np . exp ( probability ) segment_probabilities [ 0 , 0 ] = 1.0 return segment_probabilities
Return posterior probabilities OR sequence segmentation.
Return posterior probabilities OR sequence segmentation .
"""Return posterior probabilities OR sequence segmentation.

        If the MAX-PRODUCT algorithm is selected, this method returns the most
        likely sequence segmentation as a list of integers. Each integer in the
        list marks where a segment begins.

        If the SUM-PRODUCT algorithm is selected, this method returns the
        posterior probabilities of the segmentation hypotheses as a numpy
        array. Rows in the array represent hypotheses and columns in the array
        represent data points in the time-series.

        Returns:
            object: This method returns the inference results. In the case of
                    the MAX-PRODUCT algorithm, the method returns the most
                    likely segmentation. In the case of the SUM-PRODUCT
                    algorithm, this method returns the posterior probabilities
                    of the segmentation hypotheses.

        """ # In the max-product algorithm, the most likely hypotheses are # tracked. Recover the most likely segment boundaries by performing a # back-trace. # Find the most likely hypothesis. # Find the best sequence segmentation given all the data so far. # In the sum-product algorithm, the segment probabilities are # tracked. Recover the segment probabilities by formatting the stored # history. # Update hypotheses probabilities. # A segment always occurs at the beginning of the dataset.
This method returns the inference results. In the case of
the MAX-PRODUCT algorithm, the method returns the most
likely segmentation. In the case of the SUM-PRODUCT
algorithm, this method returns the posterior probabilities
of the segmentation hypotheses.
This method returns the inference results . In the case of the MAX - PRODUCT algorithm the method returns the most likely segmentation . In the case of the SUM - PRODUCT algorithm this method returns the posterior probabilities of the segmentation hypotheses .
object
self