Пример #1
0
def uncertainty_quantification(
    x_sol,
    data,
    sigma,
    weights,
    wav,
    levels,
    gamma,
    options={
        'alpha': 0.99,
        "top": 1e3,
        "bottom": 0,
        "region_size": 16,
        "iters": 10,
        "tol": 1e-3
    }):
    psi = linear_operators.dictionary(wav, levels, x_sol.shape)
    W = weights
    obj = lambda data_sol, data_mask, wav_sol, wav_mask: gamma * np.sum(
        np.abs(wav_sol + wav_mask)) + np.sum(
            np.abs(W * (data_sol + data_mask) - W * data)**2) / (2 * sigma**2)
    bound = obj(x_sol, 0, psi.dir_op(x_sol), 0) + float(len(
        np.ravel(x_sol))) + np.sqrt(
            float(len(np.ravel(x_sol))) * 16. * np.log(3. / options['alpha']))
    print(obj(x_sol, 0, psi.dir_op(x_sol), 0))
    print(
        np.sqrt(
            float(len(np.ravel(x_sol))) * 16. * np.log(3. / options['alpha'])))
    phi = linear_operators.identity()
    return map_uncertainty.create_local_credible_interval_fast(
        x_sol, phi, psi, options['region_size'], obj, bound, options['iters'],
        options['tol'], options['bottom'], options['top'])
Пример #2
0
    def __init__(self, data, background, Phi=None):

        self.data = data
        self.background = background
        self.beta = 1.
        if (Phi is None):
            self.Phi = linear_operators.identity()
        else:
            self.Phi = Phi
Пример #3
0
def test_id_op():
    id_op = linear_operators.identity()
    inp = np.random.normal(0, 10., (10, 10))
    out = inp
    forward_operator(id_op, inp, out)
    adjoint_operator(id_op, inp, out)
    inp = np.random.normal(0, 10., (10))
    out = inp
    forward_operator(id_op, inp, out)
    adjoint_operator(id_op, inp, out)
Пример #4
0
    def __init__(self, epsilon, data, Phi=None):

        if np.any(epsilon <= 0):
            raise Exception("'epsilon' must be positive")
        self.epsilon = epsilon
        self.data = data
        self.beta = 1.
        if (Phi is None):
            self.Phi = linear_operators.identity()
        else:
            self.Phi = Phi
Пример #5
0
    def __init__(self, tau, l2axis=0, Phi=None):

        if np.any(tau <= 0):
            raise Exception("'tau' must be positive")
        self.tau = tau
        self.l2axis = l2axis
        self.beta = 1.
        if (Phi is None):
            self.Phi = linear_operators.identity()
        else:
            self.Phi = Phi
Пример #6
0
    def __init__(self, sigma, Psi=None):

        if np.any(sigma <= 0):
            raise Exception("'gamma' must be positive")

        self.sigma = sigma
        self.beta = 1.

        if (Psi is None):
            self.Psi = linear_operators.identity()
        else:
            self.Psi = Psi
Пример #7
0
 def __init__(self, epsilon, data, background, iters=20, Phi=None):
     if np.any(epsilon <= 0):
         raise Exception("'epsilon' must be positive")
     self.epsilon = epsilon
     self.data = data
     self.background = background
     self.beta = 1.
     if (Phi is None):
         self.Phi = linear_operators.identity()
     else:
         self.Phi = Phi
     self.loglike = lambda x, mask: np.sum(x[mask] - self.data[
         mask] - self.data[mask] * np.log(x[mask]) + self.data[mask] * np.
                                           log(self.data[mask]))
     # below are functions needed for newtons method to find the root for the prox
     self.f = lambda x, delta, mask: self.loglike(
         np.abs(x - delta + np.sqrt((x - delta)**2 + 4 * delta * self.data))
         / 2., mask) - epsilon / 2.
     self.df = lambda x, delta, mask: np.sum(
         ((delta - x[mask] + 2 * self.data[mask]) / np.sqrt(
             (x[mask] - delta)**2 + 4 * delta * self.data[mask]) - 1) *
         (1 - 2 * self.data[mask] / (x[mask] - delta + np.sqrt(
             (x[mask] - delta)**2 + 4 * delta * self.data[mask])))) / 2.
     self.iters = iters