Ejemplo n.º 1
0
    def build_poe(self, b_frames, tau_frames, win_mats, sdw=None):
        """
            Computes natural parameters for a Gaussian product-of-experts model.
            The natural parameters (b-value vector and precision matrix) are returned.
            The returned precision matrix is stored as a BandMat.
                Mathematically the b-value vector is given as:
            b = \sum_d \transpose{W_d} \tilde{b}_d
                and the precision matrix is given as:
            P = \sum_d \transpose{W_d} \text{diag}(\tilde{tau}_d) W_d
                where $W_d$ is the window matrix for window $d$ as specified by an element
             of `win_mats`, $\tilde{b}_d$ is the sequence over time of b-value
                parameters for window $d$ as given by a column of `b_frames`, and
                $\tilde{\tau}_d$ is the sequence over time of precision parameters for
                window $d$ as given by a column of `tau_frames`.
        """
        if sdw is None:
            sdw = max([win_mat.l + win_mat.u for win_mat in win_mats])
        num_windows = len(win_mats)
        frames = len(b_frames)
        assert np.shape(b_frames) == (frames, num_windows)
        assert np.shape(tau_frames) == (frames, num_windows)
        assert all([win_mat.l + win_mat.u <= sdw for win_mat in win_mats])

        b = np.zeros((frames, ))
        prec = bm.zeros(sdw, sdw, frames)

        for win_index, win_mat in enumerate(win_mats):
            bm.dot_mv_plus_equals(win_mat.T, b_frames[:, win_index], target=b)
            bm.dot_mm_plus_equals(win_mat.T,
                                  win_mat,
                                  target_bm=prec,
                                  diag=float64(tau_frames[:, win_index]))

        return b, prec
Ejemplo n.º 2
0
    def test_dot_mv_plus_equals(self, its=100):
        for it in range(its):
            size = random.choice([0, 1, randint(0, 10), randint(0, 100)])
            a_bm = gen_BandMat(size)
            b = randn(size)
            c = randn(size)
            a_full = a_bm.full()
            c_good = c.copy()
            array_mem = get_array_mem(a_bm.data, b, c)

            bm.dot_mv_plus_equals(a_bm, b, c)
            c_good += np.dot(a_full, b)
            assert_allclose(c, c_good)
            assert get_array_mem(a_bm.data, b, c) == array_mem
Ejemplo n.º 3
0
    def test_dot_mv_plus_equals(self, its=100):
        for it in range(its):
            size = random.choice([0, 1, randint(0, 10), randint(0, 100)])
            a_bm = gen_BandMat(size)
            b = randn(size)
            c = randn(size)
            a_full = a_bm.full()
            c_good = c.copy()
            array_mem = get_array_mem(a_bm.data, b, c)

            bm.dot_mv_plus_equals(a_bm, b, c)
            c_good += np.dot(a_full, b)
            assert_allclose(c, c_good)
            assert get_array_mem(a_bm.data, b, c) == array_mem
Ejemplo n.º 4
0
    def build_poe(self, b_frames, tau_frames, win_mats, sdw=None):
        if sdw is None:
            sdw = max([win_mat.l + win_mat.u for win_mat in win_mats])
        num_windows = len(win_mats)
        frames = len(b_frames)
        assert np.shape(b_frames) == (frames, num_windows)
        assert np.shape(tau_frames) == (frames, num_windows)
        assert all([win_mat.l + win_mat.u <= sdw for win_mat in win_mats])

        b = np.zeros((frames,))
        prec = bm.zeros(sdw, sdw, frames)

        for win_index, win_mat in enumerate(win_mats):
            bm.dot_mv_plus_equals(win_mat.T, b_frames[:, win_index], target=b)
            bm.dot_mm_plus_equals(win_mat.T, win_mat, target_bm=prec, diag=float64(tau_frames[:, win_index]))
        return b, prec
Ejemplo n.º 5
0
    def build_poe(self, b_frames, tau_frames, win_mats, sdw=None):
#        tau_frames.astype('float64')

        if sdw is None:
            sdw = max([ win_mat.l + win_mat.u for win_mat in win_mats ])
        num_windows = len(win_mats)
        frames = len(b_frames)
        assert np.shape(b_frames) == (frames, num_windows)
        assert np.shape(tau_frames) == (frames, num_windows)
        assert all([ win_mat.l + win_mat.u <= sdw for win_mat in win_mats ])

        b = np.zeros((frames,))
        prec = bm.zeros(sdw, sdw, frames)

        for win_index, win_mat in enumerate(win_mats):
            bm.dot_mv_plus_equals(win_mat.T, b_frames[:, win_index], target=b)
            bm.dot_mm_plus_equals(win_mat.T, win_mat, target_bm=prec,
                                  diag=float64(tau_frames[:, win_index]))

        return b, prec
Ejemplo n.º 6
0
def build_poe(b_frames, tau_frames, win_mats, sdw=None):
    if sdw is None:

        sdw = max([win_mat.l + win_mat.u for win_mat in win_mats])

    num_windows = len(win_mats)

    frames = len(b_frames)

    b = numpy.zeros((frames, ))

    prec = bandmat.zeros(sdw, sdw, frames)

    for win_index, win_mat in enumerate(win_mats):

        bandmat.dot_mv_plus_equals(win_mat.T, b_frames[:, win_index], target=b)

        bandmat.dot_mm_plus_equals(win_mat.T,
                                   win_mat,
                                   target_bm=prec,
                                   diag=tau_frames[:, win_index])

    return b, prec
Ejemplo n.º 7
0
def build_poe(b_frames, tau_frames, win_mats, sdw=None):
    r"""Computes natural parameters for a Gaussian product-of-experts model.

    The natural parameters (b-value vector and precision matrix) are returned.
    The returned precision matrix is stored as a BandMat.
    Mathematically the b-value vector is given as:

        b = \sum_d \transpose{W_d} \tilde{b}_d

    and the precision matrix is given as:

        P = \sum_d \transpose{W_d} \text{diag}(\tilde{tau}_d) W_d

    where $W_d$ is the window matrix for window $d$ as specified by an element
    of `win_mats`, $\tilde{b}_d$ is the sequence over time of b-value
    parameters for window $d$ as given by a column of `b_frames`, and
    $\tilde{\tau}_d$ is the sequence over time of precision parameters for
    window $d$ as given by a column of `tau_frames`.
    """
    if sdw is None:
        sdw = max([ win_mat.l + win_mat.u for win_mat in win_mats ])
    num_windows = len(win_mats)
    frames = len(b_frames)
    assert np.shape(b_frames) == (frames, num_windows)
    assert np.shape(tau_frames) == (frames, num_windows)
    assert all([ win_mat.l + win_mat.u <= sdw for win_mat in win_mats ])

    b = np.zeros((frames,))
    prec = bm.zeros(sdw, sdw, frames)

    for win_index, win_mat in enumerate(win_mats):
        bm.dot_mv_plus_equals(win_mat.T, b_frames[:, win_index], target=b)
        bm.dot_mm_plus_equals(win_mat.T, win_mat, target_bm=prec,
                              diag=tau_frames[:, win_index])

    return b, prec