Пример #1
0
def test_DARCDesign_delayed_and_risky_instantiation():
    D = DesignSpaceBuilder(DA=[0.],
                           DB=[7., 30, 30 * 6, 365],
                           PA=[1.],
                           PB=[0.1, 0.25, 0.5, 0.75, 0.8, 0.9, 0.99],
                           RA=list(100 * np.linspace(0.05, 0.95, 91)),
                           RB=[100.]).build()
    design_thing = BayesianAdaptiveDesignGeneratorDARC(D, max_trials=3)
    assert isinstance(design_thing, BayesianAdaptiveDesignGeneratorDARC)
Пример #2
0
def test_DARCDesign_risky_initial_design_space():
    D = DesignSpaceBuilder(DA=[0],
                           DB=[0],
                           PA=[1],
                           PB=[0.1, 0.25, 0.5, 0.75, 0.8, 0.9, 0.99],
                           RA=list(100 * np.linspace(0.05, 0.95, 91)),
                           RB=[100]).build()
    design_thing = BayesianAdaptiveDesignGeneratorDARC(D, max_trials=3)
    n_designs = design_thing.all_possible_designs.shape[0]
    assert n_designs > 10
Пример #3
0
def test_DARCDesign_delay_magnitude_effect_instantiation():
    '''When we are investigating the magnitide effect, we want to ask for a
    reasonable range of DB values. When we do this, we are going to provide
    a vector of proportions (RA_over_RB) which will be translated into
    actual RA values. '''
    D = DesignSpaceBuilder(RB=[10., 100., 1_000.],
                           RA_over_RB=np.linspace(0.05, 0.95,
                                                  19).tolist()).build()
    design_thing = BayesianAdaptiveDesignGeneratorDARC(D, max_trials=3)
    assert isinstance(design_thing, BayesianAdaptiveDesignGeneratorDARC)
def test_model_design_integration_delayed(model):
    '''Tests integration of model and design. Basically conducts Parameter
    Estimation'''

    D = DesignSpaceBuilder(RA=list(100 * np.linspace(0.05, 0.95, 19))).build()
    design_thing = BayesianAdaptiveDesignGeneratorDARC(D,
                                                       max_trials=max_trials)

    model = model(n_particles=n_particles)
    model = model.generate_faux_true_params()

    simulated_experiment_trial_loop(design_thing, model)
Пример #5
0
def test_DARCDesign_delay_instantiation():
    D = DesignSpaceBuilder(RA=list(100 * np.linspace(0.05, 0.95, 91)),
                           RB=[100.]).build()
    design_thing = BayesianAdaptiveDesignGeneratorDARC(D, max_trials=3)
    assert isinstance(design_thing, BayesianAdaptiveDesignGeneratorDARC)
Пример #6
0
def test_DARCDesign_default_instantiation():
    D = DesignSpaceBuilder(RA=list(100 * np.linspace(0.05, 0.95, 91))).build()
    design_thing = BayesianAdaptiveDesignGeneratorDARC(D)
    assert isinstance(design_thing, BayesianAdaptiveDesignGeneratorDARC)
Пример #7
0
def test_DARCDesign_delay_initial_design_space():
    D = DesignSpaceBuilder(RA=list(100 * np.linspace(0.05, 0.95, 91))).build()
    design_thing = BayesianAdaptiveDesignGeneratorDARC(D)
    n_designs = design_thing.all_possible_designs.shape[0]
    assert n_designs > 10
Пример #8
0
def test_DARC_BAD_alt_frontenddelay():
    D = DesignSpaceBuilder.frontend_delay().build()
    design_thing = BayesianAdaptiveDesignGeneratorDARC(D, max_trials=3)
    assert isinstance(design_thing, BayesianAdaptiveDesignGeneratorDARC)
Пример #9
0
def test_DARC_BAD_alt_delaymag():
    D = DesignSpaceBuilder.delay_magnitude_effect().build()
    design_thing = BayesianAdaptiveDesignGeneratorDARC(D, max_trials=3)
    assert isinstance(design_thing, BayesianAdaptiveDesignGeneratorDARC)
Пример #10
0
def act_on_choices(desired_experiment_type, desired_model, expInfo):

    # create desired experiment object ========================================

    if desired_experiment_type == 'delayed (Bayesian Adaptive Design)':
        from darc.designs import BayesianAdaptiveDesignGeneratorDARC, DesignSpaceBuilder
        # regular, or magnitude effect
        if (desired_model is 'HyperbolicMagnitudeEffect') or (desired_model is 'ExponentialMagnitudeEffect'):
            D = DesignSpaceBuilder.delay_magnitude_effect().build()
            design_thing = BayesianAdaptiveDesignGeneratorDARC(D,
                max_trials=expInfo['trials'])
        else:
            D = DesignSpaceBuilder.delayed().build()
            design_thing = BayesianAdaptiveDesignGeneratorDARC(D,
                max_trials=expInfo['trials'])

        # import the appropriate set of models
        from darc.delayed import models


    elif desired_experiment_type == 'delayed (Kirby 2009)':
        from darc.delayed.designs import Kirby2009
        design_thing = Kirby2009()
        from darc.delayed import models

    elif desired_experiment_type == 'delayed (Griskevicius et al, 2011)':
        from darc.delayed.designs import Griskevicius2011
        design_thing = Griskevicius2011()
        from darc.delayed import models

    elif desired_experiment_type == 'delayed (Frye et al, 2016)':
        from darc.delayed.designs import Frye
        design_thing = Frye()
        from darc.delayed import models

    elif desired_experiment_type == 'delayed (Du, Green, & Myerson, 2002)':
        from darc.delayed.designs import DuGreenMyerson2002
        design_thing = DuGreenMyerson2002()
        from darc.delayed import models

    elif desired_experiment_type == 'risky (Du, Green, & Myerson, 2002)':
        from darc.risky.designs import DuGreenMyerson2002
        design_thing = DuGreenMyerson2002()
        from darc.risky import models

    elif desired_experiment_type == 'risky (Griskevicius et al, 2011)':
        from darc.risky.designs import Griskevicius2011
        design_thing = Griskevicius2011()
        from darc.risky import models

    elif desired_experiment_type == 'risky (Bayesian Adaptive Design)':
        from darc.designs import BayesianAdaptiveDesignGeneratorDARC, DesignSpaceBuilder
        # create an appropriate design object
        D = DesignSpaceBuilder.risky().build()
        design_thing = BayesianAdaptiveDesignGeneratorDARC(D,
            max_trials=expInfo['trials'])
        # import the appropriate set of models
        from darc.risky import models

    elif desired_experiment_type == 'delayed and risky (Bayesian Adaptive Design)':
        from darc.designs import BayesianAdaptiveDesignGeneratorDARC
        # create an appropriate design object
        D = DesignSpaceBuilder.delayed_and_risky().build()
        design_thing = BayesianAdaptiveDesignGeneratorDARC(D,
            max_trials=expInfo['trials'])
        # import the appropriate set of models
        from darc.delayed_and_risky import models


    # chose the desired model here ============================================
    if desired_model is 'Hyperbolic':
        model = models.Hyperbolic(n_particles=expInfo['particles'])

    elif desired_model is 'Exponential':
        model = models.Exponential(n_particles=expInfo['particles'])

    elif desired_model is 'MyersonHyperboloid':
        model = models.MyersonHyperboloid(n_particles=expInfo['particles'])

    elif desired_model is 'ModifiedRachlin':
        model = models.ModifiedRachlin(n_particles=expInfo['particles'])

    elif desired_model is 'HyperbolicMagnitudeEffect':
        model = models.HyperbolicMagnitudeEffect(n_particles=expInfo['particles'])

    elif desired_model is 'ExponentialMagnitudeEffect':
        model = models.ExponentialMagnitudeEffect(
            n_particles=expInfo['particles'])

    elif desired_model is 'HyperbolicNonLinearUtility':
        model = models.HyperbolicNonLinearUtility(
            n_particles=expInfo['particles'])

    elif desired_model is 'MultiplicativeHyperbolic':
        model = models.MultiplicativeHyperbolic(
            n_particles=expInfo['particles'])

    elif desired_model is 'LinearInLogOdds':
        model = models.LinearInLogOdds(n_particles=expInfo['particles'])

    else:
        logging.error(f'Value of desired_model ({desired_model}) not recognised')
        raise ValueError('Filed to act on desired_model')


    return (design_thing, model)