Exemplo n.º 1
0
def surrogate_model(n, dim, fun, fun_base, theta, X, y, F):

    R, inv_R = correl.compute_R(theta, X)
    beta_hat = np.linalg.inv(F.T @ inv_R @ F) @ F.T @ inv_R @ y
    sigma2_hat = (y - F @ beta_hat).T @ inv_R @ (y - F @ beta_hat) / n

    return R, inv_R, beta_hat, sigma2_hat
Exemplo n.º 2
0
def logML(theta):
    F = fun_base(X)
    R, inv_R = correl.compute_R(theta, X)
    beta_hat = np.linalg.inv(F.T @ inv_R @ F) @ F.T @ inv_R @ y
    sigma2_hat = (y - F @ beta_hat).T @ inv_R @ (y - F @ beta_hat) / n
    criterion = -0.5 * (n * np.log(sigma2_hat) + np.log(np.linalg.det(R)))
    return -criterion
Exemplo n.º 3
0
def distribFixe(theta):
    """ compute the density of theta|sigma,X,beta"""
    F = fun_base(X)
    R, inv_R = correl.compute_R(theta, X)
    More = (y - F @ beta).T @ inv_R @ (y - F @ beta) / (2 * sigma2_hat
                                                        )  #beta is fixed here
    P = np.exp(-(np.linalg.norm(theta - bias, 2)**2) /
               (2 * V) - More) / np.sqrt(np.linalg.det(R))
    return P
Exemplo n.º 4
0
def distrib(theta):
    """ compute the density of theta|sigma,X, here we compute beta as a deterministic function of the other parameter"""
    F = fun_base(X)
    R, inv_R = correl.compute_R(theta, X)
    beta_hat = np.linalg.inv(
        F.T @ inv_R @ F
    ) @ F.T @ inv_R @ y  # beta is computed, he is not supposed to be fixed here
    More = (y - F @ beta_hat).T @ inv_R @ (y - F @ beta_hat) / (2 * sigma2_hat)
    P = np.exp(-(np.linalg.norm(theta - bias, 2)**2) /
               (2 * V) - More) / np.sqrt(np.linalg.det(R))
    return P
Exemplo n.º 5
0
def logbayes(theta):
    """(alpha,delta) parameter for the invGammma prior on sigma, 
    (b,invGamma) parameter for the Gaussian prior on beta, 
    (th,V) for the standard gaussian prior on (th,V>0)"""
    F = fun_base(X)
    R, inv_R = correl.compute_R(theta, X)
    beta_hat = np.linalg.inv(F.T @ inv_R @ F) @ F.T @ inv_R @ y
    sigma2_hat = ((y - F @ beta_hat).T @ inv_R @ (y - F @ beta_hat) +
                  2 * delta) / (n + 2 * (alpha - 1))  #INVGAMA

    beta_hat = np.linalg.inv(F.T @ inv_R @ F / sigma2_hat**2 + invGamma) @ (
        invGamma @ b + F.T @ inv_R @ y / sigma2_hat**2)
    More = 0.5 * (y - F @ beta_hat).T @ inv_R @ (
        y - F @ beta_hat
    ) / sigma2_hat  # we have to add this term because the expression of sigma2_hat does not imply further simplification as previouly whit the frequentist estimation of sigma2_hat
    criterion = -0.5 * (n * np.log(sigma2_hat) + np.log(np.linalg.det(R)) +
                        np.linalg.norm(theta - th, 2)**2 / V) - More
    return -criterion