Skip to main content

CUQIpy plugin for FEniCS

Project description

CUQIpy-FEniCS

CUQIpy-FEniCS is a plugin for CUQIpy software package. It provides an interface between FEniCS PDE models and CUQIpy modules.

Installation

First install FEniCS (we recommend using Anaconda from the available installation options). Then install CUQIpy-FEniCS with pip:

pip install cuqipy-fenics

If CUQIpy is not installed, it will be installed automatically.

Quickstart

import numpy as np
import matplotlib.pyplot as plt
import cuqi
import cuqipy_fenics

# Load a fenics forward model and data from testproblem library
model, y_data, info = cuqipy_fenics.testproblem.FEniCSDiffusion1D.get_components(
    dim=20,
    endpoint=1,
    exactSolution='smooth_step',
    mapping='exponential',
    SNR=10000,
    left_bc=0,
    right_bc=8
)

# Set up Bayesian model
x = cuqi.distribution.GMRF(np.zeros(model.domain_dim),
                           25, 1, 'zero', geometry=model.domain_geometry)
# y ~ N(model(x), 0.01^2)
y = cuqi.distribution.Gaussian(mean=model(x), cov=0.05**2)

# Set up Bayesian Problem object
BP = cuqi.problem.BayesianProblem(y, x).set_data(y=y_data)

# Sample from the posterior
samples = BP.sample_posterior(5000)

# Analyze the samples
samples.burnthin(1000).plot_ci(95, plot_par=True,
                               exact=info.exactSolution, linestyle='-', marker='.')

For more examples, see the demos folder.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

CUQIpy-FEniCS-0.2.1.post0.dev7.tar.gz (51.8 kB view hashes)

Uploaded Source

Built Distribution

CUQIpy_FEniCS-0.2.1.post0.dev7-py3-none-any.whl (38.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page