# Import the necessary modules: import sys import numpy as np # Import the modules from the MCcubed package: sys.path.append("../MCcubed/") import MCcubed as mc3 sys.path.append("../MCcubed/examples/models/") from quadratic import quad # Create a synthetic dataset using a quadratic polynomial curve: x = np.linspace(0, 10, 100) # Independent variable of the model p0 = 3, -2.4, 0.5 # True-underlying model parameters y = quad(p0, x) # Noiseless model uncert = np.sqrt(np.abs(y)) # Data points uncertainty error = np.random.normal(0, uncert) # Noise for the data data = y + error # Noisy data set mu = mc3.utils mu.savebin([data, uncert], 'data.npz') # indparams contains additional arguments of func (if necessary). Each # additional argument is an item in the indparams tuple: mu.savebin([x], 'indp.npz') # Set the arguments to the file names: data = 'data.npz' indparams = 'indp.npz' # MCMC algorithm:
# working directory. # Import the necessary modules: import sys import numpy as np # Import the modules from the MCcubed package: sys.path.append("../MCcubed/") import MCcubed as mc3 sys.path.append("../MCcubed/examples/models/") from quadratic import quad # Create a synthetic dataset using a quadratic polynomial curve: x = np.linspace(0, 10, 1000) # Independent variable of the model p0 = [3, -2.4, 0.5] # True-underlying model parameters y = quad(p0, x) # Noiseless model uncert = np.sqrt(np.abs(y)) # Data points uncertainty error = np.random.normal(0, uncert) # Noise for the data data = y + error # Noisy data set # Define the modeling function as a callable: # The first argument of func() must be the fitting parameters sys.path.append("../MCcubed/examples/models/") from quadratic import quad func = quad # A three-elements tuple indicates the function name, the module # name (without the '.py' extension), and the path to the module. func = ("quad", "quadratic", "../MCcubed/examples/models/") # Alternatively, if the module is already within the scope of the
import sys import numpy as np import matplotlib.pyplot as plt sys.path.append("../../src") import mccubed as mc3 import mcplots as mp import mcutils as mu # Get function to model/sample. sys.path.append("../") from quadratic import quad # Create a synthetic dataset: x = np.linspace(0, 10, 100) # Independent model variable p0 = 3, -2.4, 0.5 # True-underlying model parameters y = quad(p0, x) # Noiseless model uncert = np.sqrt(np.abs(y)) # Data points uncertainty error = np.random.normal(0, uncert) # Noise for the data data = y + error # Noisy data set # Set the MCMC arguments: # ----------------------- help(mc3.mcmc) # Displays the MCMC function docstring. # Define the function to model the data in the MCMC: As a requirement, the # first argument of func must be the set of fitting parameters. # Define as callable: func = quad # Or by function name and module name: # func = ("quad", "quadratic")
def test_quad1(): my_quad = quad(a=2, b=3, c=1) assert my_quad(1) == 6
def test_quad3(): my_quad = quad(a=2, b=3, c=1) assert my_quad(3) == 28
def test_quad0(): my_quad = quad(a=2, b=3, c=1) assert my_quad(0) == 1
def test_quad2(): my_quad = quad(a=2, b=3, c=1) assert my_quad(2) == 15