コード例 #1
0
ファイル: obe_lockin.py プロジェクト: rishirelan/optbayesexpt
    def __init__(self, model_function, setting_values, parameter_samples,
                 constants):

        OptBayesExpt.__init__(self, model_function, setting_values,
                              parameter_samples, constants)

        self.VALUES_PER_MEASUREMENT = 2
        self.cost_of_changing_setting = 5.
        self.noise_parameter_index = 3
コード例 #2
0
    def __init__(self, model_function, setting_values, parameter_samples,
                 constants):
        OptBayesExpt.__init__(self, model_function, setting_values,
                              parameter_samples, constants)

        self.noise_parameter_index = 3

        self.sweep_settings = setting_values[0]
        self.cost_of_new_sweep = 5.
        self.start_stop_subsample = 3
        self.start_stop_indices = self._generate_start_stop_indices()
        self.start_stop_values = self.sweep_settings[self.start_stop_indices]
コード例 #3
0
def setup():
    pars = (np.array([0, 1, 2, 3]), np.array([1, 3, 2, 4]))
    settings = (np.array([0, 1, 2]), )
    cons = ()

    def fakefunc(sets, pars, cons):
        x, = sets
        a, b = pars
        return a + b * x

    an_obe = OptBayesExpt(fakefunc, settings, pars, cons)

    return an_obe
コード例 #4
0
 def __init__(self):
     OptBayesExpt.__init__(self)
コード例 #5
0
b_min = -1
b_max = 1
b_draws = np.random.uniform(b_min, b_max, n_particles)
# Pack the parameters into a tuple and incorporate it
pars = (x0_draws, a_draws, b_draws)
# note that the parameter order must correspond to how the
# values are unpacked in the model_function

# constant parameters -- just linewidth here.
dtrue = 0.15
cons = (dtrue, )

# Settings, parameters, constants and model all defined, so set it all up
myOBE = OptBayesExpt(my_model_function,
                     sets,
                     pars,
                     cons,
                     n_draws=30,
                     scale=False)

initial_pars = myOBE.parameters

#################################################################
# Measurement simulation
#################################################################

# secret stuff - to be used only by the measurement simulator
# pick the parameters of the true resonance
x0true = 2.5  # pick a random resonance x0
Atrue = 1
Btrue = 0
truevals = (x0true, Atrue, Btrue, dtrue)
コード例 #6
0
b_samples = rng.normal(b_mean, b_sigma, n_samples)
# Pack the parameters into a tuple.
# Note that the order must correspond to how the values are unpacked in
# the model_function.
parameters = (x0_samples, a_samples, b_samples)
param_labels = ['Center', 'Amplitude', 'Background']
# Define Constants
#
dtrue = .1
constants = (dtrue, )

# make an instance of OptBayesExpt
#
my_obe = OptBayesExpt(my_model_function,
                      settings,
                      parameters,
                      constants,
                      scale=False,
                      use_jit=use_jit)

########################################################################
#           MEASUREMENT LOOP
########################################################################

# Set up measurement simulator
#
# Randomly select "true" parameter values for simulation
true_pars = tuple([np.random.choice(param) for param in parameters])
# MeasurementSimulator.simdata() provides simulated data
# See optbayesexpt/obe_utils.py.
my_sim = MeasurementSimulator(my_model_function,
                              true_pars,
コード例 #7
0
from optbayesexpt import OptBayesExpt

# Global variables
# number of measurement iterations to simulate
Nmeasure = 100
# use optbayesexpt (False uses least-squares fitting
smartmeasure = True
# optimum = True --> always measure at the maximum utility
# optimum = False --> select a high value of utility using the pickiness factor
optimum = False
pickiness = 6
"""
Create an instance of the OptBayesExpt class for our use
"""
myOBE = OptBayesExpt()
"""
Establish the experimental model -- a Lorentzian peak
"""


def lorentz_peak(x, x0, A, B, d):
    """
    Calculate a Lorentzian function of x
    All parameters may be scalars or they may be arrays
        - as long as the arrays interact nicely
    :param x:  measurement setting
    :param A:  Amplitude parameter
    :param B:  background parameter
    :param d:  half-width at half-max parameter
    :param x0: peak center value parameter
コード例 #8
0
 def __init__(self, model_function, setting_values, parameter_samples,
              constants):
     OptBayesExpt.__init__(self, model_function, setting_values,
                           parameter_samples, constants)
     # identify the measurement noise parameter.
     self.noise_parameter_index = 3
コード例 #9
0
"""
Pi pulse tuner

"""

import numpy as np
import matplotlib.pyplot as plt

from optbayesexpt import OptBayesExpt

# make the instance that we'll use
myOBE = OptBayesExpt()
"""
Establish the experimental model
"""


def mxplusb(x, m, b):
    # a straight line
    return m * x + b


def mxplsub_wrapper(sets, pars, cons):
    # unpack the experimental settings
    x = sets[0]
    # unpack model parameters
    m = pars[0]
    b = pars[1]
    # unpack model constants
    # N/A
    return mxplusb(x, m, b)
コード例 #10
0
"""
Pi pulse tuner

"""

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec

from optbayesexpt import OptBayesExpt

myOBE = OptBayesExpt()
"""
ESTABLISH THE EXPERIMENTAL MODEL
"""


# this is the model of our experiment
def rabicounts(pulsetime, delta_f, B1, f_center, baseline, contrast, T1):
    """
    A model of Rabi chevrons
    :param pulsetime:  Duration of microwave pulse
    :param delta_f:    detuning relative to a reference frequency
    :param B1:         Rabi frequency
    :param f_center:   true center of resonance relative to reference frequency
    :param baseline:   background signal
    :param contrast:   Maximum fractional change in signal for pi pulse
    :param T1:         coherence time
    :return:
    """
    zz = ((delta_f - f_center) / B1)**2
コード例 #11
0
 def __init__(self, model_function, settings, parameters, constants):
     OptBayesExpt.__init__(self, model_function, settings,
                           parameters, constants)
コード例 #12
0
a_draws = np.random.exponential(a_scale, n_particles)
# background
b_min = -1
b_max = 1
b_draws = np.random.uniform(b_min, b_max, n_particles)
# Pack the parameters into a tuple and incorporate it
pars = (x0_draws, a_draws, b_draws)
# note that the parameter order must correspond to how the
# values are unpacked in the model_function

# constant parameters -- just linewidth here.
dtrue = 0.15
cons = (dtrue, )

# Settings, parameters, constants and model all defined, so set it all up
myOBE = OptBayesExpt(my_model_function, sets, pars, cons)
myOBE.N_DRAWS = 30
initial_pars = myOBE.parameters

#################################################################
# Measurement simulation
#################################################################

# secret stuff - to be used only by the measurement simulator
# pick the parameters of the true resonance
x0true = 2.5  # pick a random resonance x0
Atrue = 1
Btrue = 0
truevals = (x0true, Atrue, Btrue, dtrue)