Ejemplo n.º 1
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.0, 100.0, 1_000.0],
                           RA_over_RB=np.linspace(0.05, 0.95,
                                                  19).tolist()).build()
    design_thing = BayesianAdaptiveDesignGenerator(D, max_trials=3)
    assert isinstance(design_thing, BayesianAdaptiveDesignGenerator)
Ejemplo n.º 2
0
def test_DARCDesign_delayed_and_risky_instantiation():
    D = DesignSpaceBuilder(
        DA=[0.0],
        DB=[7.0, 30, 30 * 6, 365],
        PA=[1.0],
        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.0],
    ).build()
    design_thing = BayesianAdaptiveDesignGenerator(D, max_trials=3)
    assert isinstance(design_thing, BayesianAdaptiveDesignGenerator)
Ejemplo n.º 3
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 = BayesianAdaptiveDesignGenerator(D, max_trials=3)
    n_designs = design_thing.all_possible_designs.shape[0]
    assert n_designs > 10
Ejemplo n.º 4
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_toolbox.designs import BayesianAdaptiveDesignGeneratorDARC, DesignSpaceBuilder
        # regular, or magnitude effect
        if (desired_model == 'HyperbolicMagnitudeEffect') or (
                desired_model == '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_toolbox.delayed import models

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

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

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

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

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

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

    elif desired_experiment_type == 'risky (Bayesian Adaptive Design)':
        from darc_toolbox.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_toolbox.risky import models

    elif desired_experiment_type == 'delayed and risky (Bayesian Adaptive Design)':
        from darc_toolbox.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_toolbox.delayed_and_risky import models

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

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

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

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

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

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

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

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

    elif desired_model == '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)
Ejemplo n.º 5
0
def test_DARCDesign_delay_instantiation():
    D = DesignSpaceBuilder(RA=list(100 * np.linspace(0.05, 0.95, 91)),
                           RB=[100.0]).build()
    design_thing = BayesianAdaptiveDesignGenerator(D, max_trials=3)
    assert isinstance(design_thing, BayesianAdaptiveDesignGenerator)
Ejemplo n.º 6
0
def test_DARCDesign_default_instantiation():
    D = DesignSpaceBuilder(RA=list(100 * np.linspace(0.05, 0.95, 91))).build()
    design_thing = BayesianAdaptiveDesignGenerator(D)
    assert isinstance(design_thing, BayesianAdaptiveDesignGenerator)
Ejemplo n.º 7
0
def test_DARCDesign_delay_initial_design_space():
    D = DesignSpaceBuilder(RA=list(100 * np.linspace(0.05, 0.95, 91))).build()
    design_thing = BayesianAdaptiveDesignGenerator(D)
    n_designs = design_thing.all_possible_designs.shape[0]
    assert n_designs > 10
Ejemplo n.º 8
0
def test_DARC_BAD_alt_frontenddelay():
    D = DesignSpaceBuilder.frontend_delay().build()
    design_thing = BayesianAdaptiveDesignGenerator(D, max_trials=3)
    assert isinstance(design_thing, BayesianAdaptiveDesignGenerator)
Ejemplo n.º 9
0
def test_DARC_BAD_alt_delaymag():
    D = DesignSpaceBuilder.delay_magnitude_effect().build()
    design_thing = BayesianAdaptiveDesignGenerator(D, max_trials=3)
    assert isinstance(design_thing, BayesianAdaptiveDesignGenerator)