Esempio n. 1
0
def _I_hx_0_sin(model, n, t):
    """Compute the :math:`I_{0,n:\\sin}`, :math:`n>M`, integral."""
    omega = 2 * B.pi * (n - model.m_max) / (model.b - model.a)
    t_less_a = t - model.a
    return (
        model.alpha_t**2
        / (4 * model.alpha**2 + omega**2)
        * (
            omega * (B.exp(-2 * model.alpha * t_less_a) - B.cos(omega * t_less_a))
            + 2 * model.alpha * B.sin(omega * t_less_a)
        )
    )
Esempio n. 2
0
    def k_h(self):
        """Get the kernel function of the filter.

        Returns:
            :class:`mlkernels.Kernel`: Kernel for :math:`h`.
        """
        # Convert `self.gamma` to a regular length scale.
        gamma_scale = B.sqrt(1 / (2 * self.gamma))
        k_h = EQ().stretch(gamma_scale)  # Kernel of filter before window
        k_h *= lambda t: B.exp(-self.alpha * t**2)  # Window
        if self.causal:
            k_h *= lambda t: B.cast(self.dtype, t >= 0)  # Causality constraint
        return k_h
Esempio n. 3
0
def compute_K_u(model):
    """Covariance matrix of inducing variables :math:`u` associated with
    :math:`h`.

    Args:
        model (:class:`.gprv.GPRV`): Model.

    Returns:
        tensor: :math:`K_u`.
    """
    return Dense(
        (model.gamma_t**2 / (2 * model.gamma))
        * B.exp(-model.gamma * B.abs(model.t_u[:, None] - model.t_u[None, :]))
    )
Esempio n. 4
0
def _integral_luk_g_M(model, l, u, k):
    """Internal function :math:`I(l,u,k)` for :math:`k>M`. Assumes that :math:`a<l,u<b`.

    Note:
        This function gives :math:`-I(l,u,k)`, i.e. *minus* the integral in the paper!
    """
    ag = model.alpha - model.gamma
    om = 2 * B.pi * (k - model.m_max) / (model.b - model.a)
    return (-1 / (ag**2 + om**2)) * (
        (-ag * B.sin(om * (u - model.a)) + om * B.cos(om * (u - model.a)))
        - (
            B.exp(ag * (l - u))
            * (-ag * B.sin(om * (l - model.a)) + om * B.cos(om * (l - model.a)))
        )
    )
Esempio n. 5
0
    def _integrate_half1(self, name, **var_map):
        if self.poly.highest_power(name) != 2:
            raise RuntimeError(f'Dependency on "{name}" must be quadratic.')

        a = self.poly.collect_for(Factor(name, 2))
        b = self.poly.collect_for(Factor(name, 1))
        c = self.poly.reject(name)

        a = a.eval(**var_map)
        b = b.eval(**var_map)
        c = c.eval(**var_map)

        return (0.5 * self.const * safe_sqrt(-B.pi / a) *
                B.exp(-0.25 * b**2 / a + c) *
                (1 - B.erf(0.5 * b / safe_sqrt(-a))))
Esempio n. 6
0
def compute_i_hx(model, t1=None, t2=None):
    """Compute the :math:`I_{hx}` integral.

    Args:
        model (:class:`.gprv.GPRV`): Model.
        t1 (tensor, optional): First time input. Defaults to zero.
        t2 (tensor, optional): Second time input. Defaults to zero.

    Returns:
        tensor: Value of :math:`I_{hx}` for all `t1` and `t2`.
    """
    if t1 is None:
        t1 = B.zero(model.dtype)
    if t2 is None:
        t2 = B.zero(model.dtype)
    return model.alpha_t**2 / 2 / model.alpha * B.exp(-model.lam * B.abs(t1 - t2))
Esempio n. 7
0
    def positive(self, init=None, shape=None, dtype=None, name=None):
        # If nothing is specific, generate a scalar.
        if init is None and shape is None:
            shape = ()

        def generate_init(shape, dtype):
            return B.rand(dtype, *shape)

        return self._get_var(
            transform=lambda x: B.exp(x),
            inverse_transform=lambda x: B.log(x),
            init=init,
            generate_init=generate_init,
            shape=shape,
            shape_latent=shape,
            dtype=dtype,
            name=name,
        )
Esempio n. 8
0
def compute_I_ux(model, t1=None, t2=None):
    """Compute the :math:`I_{ux}` integral.

    Args:
        model (:class:`.gprv.GPRV`): Model.
        t1 (tensor, optional): First time input. Defaults to zero.
        t2 (tensor, optional): Second time input. Defaults to zero.

    Returns:
        tensor: Value of :math:`I_{ux}` for all `t1`, `t2`.
    """
    if t1 is None:
        t1 = B.zeros(model.dtype, 1)
        squeeze_t1 = True
    else:
        squeeze_t1 = False

    if t2 is None:
        t2 = B.zeros(model.dtype, 1)
        squeeze_t2 = True
    else:
        squeeze_t2 = False

    t1 = t1[:, None, None, None]
    t2 = t2[None, :, None, None]
    t_u_1 = model.t_u[None, None, :, None]
    t_u_2 = model.t_u[None, None, None, :]
    ga = model.gamma - model.alpha
    result = (
        model.alpha_t**2
        * model.gamma_t**2
        * B.exp(-model.gamma * (t_u_1 + t_u_2) + ga * (t1 + t2))
        * integral_abcd_lu(-t1, t_u_2 - t1, -t2, t_u_1 - t2, ga, model.lam)
    )

    if squeeze_t1 and squeeze_t2:
        return result[0, 0, :, :]
    elif squeeze_t1:
        return result[0, :, :, :]
    elif squeeze_t2:
        return result[:, 0, :, :]
    else:
        return result
Esempio n. 9
0
def f1(x):
    dists2 = (x - B.transpose(x))**2
    K = B.exp(-0.5 * dists2)
    K = K + B.epsilon * B.eye(t, n)
    L = B.cholesky(K)
    return B.matmul(L, B.ones(t, n, m))
Esempio n. 10
0
def test_inducing_points_extent_gprv():
    model = RGPCM(window=2, scale=1, n_u=10, t=(0, 10))
    t_u_max = max(model.t_u)
    approx(B.exp(-model.alpha * t_u_max), B.exp(-B.pi))
Esempio n. 11
0
def test_inducing_points_extent_gpcm(Model):
    model = Model(window=2, scale=1, n_u=10, t=(0, 10))
    approx(B.exp(-model.alpha * max(model.t_u)**2), B.exp(-B.pi))
Esempio n. 12
0
def _integral_lu0(model, l, u):
    """Compute :math:`I(l,u,k)` for :math:`k=0`."""
    ag = model.alpha - model.gamma
    return 1 / ag * (1 - B.exp(ag * (l - u)))
Esempio n. 13
0
 def transform(x):
     return lower + (upper - lower) / (1 + B.exp(x))
Esempio n. 14
0
 def transform(x):
     log_diag = x[:side]
     chol = B.vec_to_tril(x[side:], offset=-1) + B.diag(B.exp(log_diag))
     return B.matmul(chol, chol, tr_b=True)