예제 #1
0
파일: HMM.py 프로젝트: kuleshov/ProbHap
    def get_posterior_code_y_only(self,k,block,y):
        N = 2**len(self.segments_at_position[block[k]])
        if y == (0,1): slice = range(0,N)
        else: slice = range(N,2*N)

        return logsumexp(self.fwd_values[block[k]][slice] +
                         self.bwd_values[block[k]][slice]) - \
                         self.log_data_prob
예제 #2
0
    def get_posterior_code_y_only(self, k, block, y):
        N = 2**len(self.segments_at_position[block[k]])
        if y == (0, 1): slice = range(0, N)
        else: slice = range(N, 2 * N)

        return logsumexp(self.fwd_values[block[k]][slice] +
                         self.bwd_values[block[k]][slice]) - \
                         self.log_data_prob
예제 #3
0
파일: HMM.py 프로젝트: kuleshov/ProbHap
    def run_forwards(self,block):
        start, end = block[0], block[-1]
        block_length = len(block)

        fwd_values = dict()
        fwd, fwd_prev = np.array([]), np.array([])
        N, N_prev = 0, 0

        with open(self.dir + "/c/forwards.c") as code_file:
            forwards_code = code_file.read()

        # compute probabilities and pointers:
        for j, j_prev in ((block[k], block[(k-1) % block_length])
                          for k in xrange(len(block))):

            N = len(self.segments_at_position[j])
            N_prev = len(self.segments_at_position[j_prev])
            np_free_indices = self.get_free_indices(j, j_prev)
            N_free = len(np_free_indices)

            fwd_prev = fwd
            fwd = np.zeros(2**(N+1))

            np_prob0, np_prob1 = self.get_prob_vectors(j)
            np_current_to_prev_pos = self.get_position_map(j, j_prev)
            np_clouds_at_position = self.get_clouds_at_position(j)
            Nclouds = len(np_clouds_at_position)

            start_position = int(j == start)

            inline(forwards_code,
                ['j', 'fwd', 'fwd_prev',
                 'np_prob0', 'np_prob1',
                 'np_current_to_prev_pos', 'np_clouds_at_position',
                 'np_free_indices',
                 'N', 'N_prev', 'Nclouds', 'N_free', 'start_position'],
                headers = ["<math.h>",
                           "\"" + self.dir + "/c/common.h\""],
                type_converters = converters.blitz,
                compiler = "gcc")

            fwd_values[j] = fwd

        self.fwd_values = fwd_values
        self.log_data_prob = logsumexp(fwd)
예제 #4
0
    def run_forwards(self, block):
        start, end = block[0], block[-1]
        block_length = len(block)

        fwd_values = dict()
        fwd, fwd_prev = np.array([]), np.array([])
        N, N_prev = 0, 0

        with open(self.dir + "/c/forwards.c") as code_file:
            forwards_code = code_file.read()

        # compute probabilities and pointers:
        for j, j_prev in ((block[k], block[(k - 1) % block_length])
                          for k in xrange(len(block))):

            N = len(self.segments_at_position[j])
            N_prev = len(self.segments_at_position[j_prev])
            np_free_indices = self.get_free_indices(j, j_prev)
            N_free = len(np_free_indices)

            fwd_prev = fwd
            fwd = np.zeros(2**(N + 1))

            np_prob0, np_prob1 = self.get_prob_vectors(j)
            np_current_to_prev_pos = self.get_position_map(j, j_prev)
            np_clouds_at_position = self.get_clouds_at_position(j)
            Nclouds = len(np_clouds_at_position)

            start_position = int(j == start)

            inline(forwards_code, [
                'j', 'fwd', 'fwd_prev', 'np_prob0', 'np_prob1',
                'np_current_to_prev_pos', 'np_clouds_at_position',
                'np_free_indices', 'N', 'N_prev', 'Nclouds', 'N_free',
                'start_position'
            ],
                   headers=["<math.h>", "\"" + self.dir + "/c/common.h\""],
                   type_converters=converters.blitz,
                   compiler="gcc")

            fwd_values[j] = fwd

        self.fwd_values = fwd_values
        self.log_data_prob = logsumexp(fwd)