################################################################################
# Compute the sensitivity matrix for a given model
J = tdp.sensitivity(mod)
plt.figure()
_ = np.abs(J).pcolor(equalize=True, log=10, flipY=True)

################################################################################
# Attaching statistical descriptors to the datapoint
# ++++++++++++++++++++++++++++++++++++++++++++++++++
#
# Set values of relative and additive error for both systems.
tdp.relErr = 0.05
tdp.addErr = 1e-8
# Define a multivariate log normal distribution as the prior on the predicted data.
tdp.predictedData.prior = Distribution('MvLogNormal', tdp.data[tdp.active],
                                       tdp.std[tdp.active]**2.0)

################################################################################
# This allows us to evaluate the likelihood of the predicted data
print(tdp.likelihood(log=True))
# Or the misfit
print(tdp.dataMisfit())

################################################################################
# We can perform a quick search for the best fitting half space
halfspace = tdp.find_best_halfspace()
print('Best half space conductivity is {} $S/m$'.format(halfspace.par))
plt.figure()
_ = tdp.plot()
_ = tdp.plotPredicted()
Exemple #2
0
#
# * Prior Distribution
#     The prior represents how the user believes the variable should
#     behave from a statistical standpoint.
#     The values of the variable can be evaluated against the attached prior,
#     to determine how likely they are to have occured https://en.wikipedia.org/wiki/Prior_probability
#
# * Proposal Distribution
#     The proposal describes a probability distribution from which to
#     sample when we wish to perturb the variable
#     https://en.wikipedia.org/wiki/Metropolis%E2%80%93Hastings_algorithm

# Obtain an instantiation of a random number generator.
# This is optional, but is an important consideration for parallel programming.
prng = np.random.RandomState()
Density.prior = Distribution('Uniform', -2.0, 2.0, prng=prng)

#%%
# We can also attach a proposal distribution
Density.proposal = Distribution('Normal', 0.0, 1.0, prng=prng)
print(Density.summary)
print("Class type of the prior: ", type(Density.prior))
print("Class type of the proposal: ", type(Density.proposal))

#%%
# The values in the variable can be evaluated against the prior.
# In this case, we have 3 elements in the variable, and a univariate Normal for the prior.
# Therefore each element is evaluated to get 3 probabilities, one for each element.
print(Density.probability(log=False))

################################################################################
Exemple #3
0
# Set relative errors for the primary fields, and secondary fields.
tdp.relErr = np.r_[0.01, 0.05]

# Set the additive errors for
tdp.addErr = np.hstack([[
    0.011474, 0.012810, 0.008507, 0.005154, 0.004742, 0.004477, 0.004168,
    0.003539, 0.003352, 0.003213, 0.003161, 0.003122, 0.002587, 0.002038,
    0.002201
],
                        [
                            0.007383, 0.005693, 0.005178, 0.003659, 0.003426,
                            0.003046, 0.003095, 0.003247, 0.002775, 0.002627,
                            0.002460, 0.002178, 0.001754, 0.001405, 0.001283
                        ]])
# Define a multivariate log normal distribution as the prior on the predicted data.
tdp.predictedData.prior = Distribution('MvLogNormal', tdp.data[tdp.active],
                                       tdp.std[tdp.active]**2.0)

################################################################################
# This allows us to evaluate the likelihood of the predicted data
print(tdp.likelihood(log=True))
# Or the misfit
print(tdp.dataMisfit())

################################################################################
# Plot the misfits for a range of half space conductivities
plt.figure()
plt.subplot(1, 2, 1)
_ = tdp.plotHalfSpaceResponses(-6.0, 4.0, 200)
plt.title("Halfspace responses")

################################################################################
Exemple #4
0
################################################################################
# Compute the sensitivity matrix for a given model
J = fdp.sensitivity(mod)

plt.figure()
_ = np.abs(J).pcolor(equalize=True, log=10, flipY=True)

################################################################################
# Attaching statistical descriptors to the datapoint
# ++++++++++++++++++++++++++++++++++++++++++++++++++
#
# Set values of relative and additive error for both systems.
fdp.relErr = 0.05
fdp.addErr = 10.0
# Define a multivariate log normal distribution as the prior on the predicted data.
fdp.predictedData.prior = Distribution('MvLogNormal', fdp.data[fdp.active],
                                       fdp.std[fdp.active]**2.0)

################################################################################
# This allows us to evaluate the likelihood of the predicted data
print(fdp.likelihood(log=True))
# Or the misfit
print(fdp.dataMisfit())

################################################################################
# Plot the misfits for a range of half space conductivities
plt.figure()
_ = fdp.plotHalfSpaceResponses(-6.0, 4.0, 200)

plt.title("Halfspace responses")

################################################################################
Exemple #5
0
Distribution Class
++++++++++++++++++

Handles the initialization of different statistical distribution
"""

#%%
from geobipy import Distribution
from geobipy import plotting as cP
import matplotlib.pyplot as plt
import numpy as np

#%%
# Univariate Normal Distribution
# ++++++++++++++++++++++++++++++
D = Distribution('Normal', 0.0, 1.0)

# Get the bins of the Distribution from +- 4 standard deviations of the mean
bins = D.bins()

# Grab random samples from the distribution
D.rng(10)

# We can then get the Probability Density Function for those bins
pdf = D.probability(bins, log=False)

# And we can plot that PDF
# sphinx_gallery_thumbnail_number = 1
plt.figure()
_ = cP.plot(bins,pdf)
Exemple #6
0
prng = np.random.RandomState()
# Set the priors
mod.setPriors(halfSpaceValue=0.01,
              minDepth=1.0,
              maxDepth=150.0,
              maxLayers=30,
              parameterPrior=True,
              gradientPrior=True,
              prng=prng)

################################################################################
# To propose new models, we specify the probabilities of creating, removing, perturbing, and not changing
# a layer interface
pProposal = Distribution('LogNormal',
                         0.01,
                         np.log(2.0)**2.0,
                         linearSpace=True,
                         prng=prng)
mod.setProposals(probabilities=[0.25, 0.25, 0.25, 0.25],
                 parameterProposal=pProposal,
                 prng=prng)

################################################################################
# We can then perturb the layers of the model
# perturbed = mod.perturbStructure()
remapped, perturbed = mod.perturb()

################################################################################
fig = plt.figure(figsize=(8, 6))
ax = plt.subplot(121)
mod.pcolor(grid=True)
Exemple #7
0
# Plot the misfits for a range of half space conductivities
plt.figure()
_ = tdp.plotHalfSpaceResponses(-6.0, 4.0, 200)
plt.title("Halfspace responses")

################################################################################
# We can attach priors to the height of the datapoint,
# the relative error multiplier, and the additive error noise floor

# Set values of relative and additive error for both systems.
tdp.relErr = [0.05, 0.05]
tdp.addErr = [1e-11, 1e-12]

# Define the distributions used as priors.
heightPrior = Distribution('Uniform',
                           min=np.float64(tdp.z) - 2.0,
                           max=np.float64(tdp.z) + 2.0)
relativePrior = Distribution('Uniform',
                             min=np.r_[0.01, 0.01],
                             max=np.r_[0.5, 0.5])
additivePrior = Distribution('Uniform',
                             min=np.r_[1e-12, 1e-13],
                             max=np.r_[1e-10, 1e-11],
                             log=True)
tdp.set_priors(height_prior=heightPrior,
               relative_error_prior=relativePrior,
               additive_error_prior=additivePrior)

################################################################################
# In order to perturb our solvable parameters, we need to attach proposal distributions
heightProposal = Distribution('Normal', mean=tdp.z, variance=0.01)