Python_modules.mmcomplexity Module

Python module to analyze mental model complexity in our Auditory change-point task

To generate a block of trials with fixed hazard rate on the sources, use the StimulusBlock class.

To build your own decision-making model, base your class on BinaryDecisionMaker.

Pre-existing sequential-update decision-making models are provided in this module:

KnownHazard: UnknownHazard

To initialize the models, you must provide a stimulus block and call the observe method.
>>> stim = StimulusBlock(100, .2)  # stimulus block with hazard rate 0.2 and 100 trials
>>> dm = KnownHazard(stim)
>>> dm.observe()
To run the decision making algorithm on a sequence of trials, we use generators:
>>> gen1 = dm.process(target='source', filter_step=1)  # predict the next source
>>> dec1 = list(gen1)  # list of tuples (log-posterior odds, decision)
>>> gen2 = dm.process(target='source', filter_step=0)  # infer the current source
>>> dec2 = list(gen2)  # list of tuples (log-posterior odds, decision)
>>> gen3 = dm.process(hazard=.9, filter_step=1)  # prediction model where we force believed hazard rate to be 0.9
>>> dec3 = list(gen3)

To produce a sequence of trials with hazards that vary according to their own meta-hazard rate, use the class Audio2AFCSimulation. Below, we generate 400 trials with hazards being either 0.1 or 0.9, a meta hazard rate of 0.01 and flat prior on the hazard values.

>>> sim = Audio2AFCSimulation(400, [0.1, 0.9], .01, [0.5,0.5])
>>> sim.data.head()  # trial info is contained in a pandas.DataFrame

– Technical note – to activate warnings in interactive Shell, type:

>>> import warnings
>>> import mmcomplexity as mmx
>>> warnings.filterwarnings("default", category=DeprecationWarning, module=mmx.get("__name__"))

Functions

check_reasonable_log_odds(l)

check_valid_probability_distribution(dist_array)

checks that sum of elements in array is 1, up to TOLERANCE level

check_valid_sequence_of_sides(sides)

Check that all elements in sides are valid sides

check_valid_side(side)

Check that side is in the allowed set of sides

flag_change_points(seq)

iterate through seq and flag change points with False boolean.

get_next_change_point(p)

Sample from geometric distribution to tell us when the next change point will occur

infer_bernoulli_bayes(num_successes, num_trials)

Given num_trials independent observations from a Bernoulli random variable with num_successes successes, returns the posterior distribution over the Bernoulli parameter in the form of a Beta distribution.

log_odds_to_posterior(log_odds)

returns posterior over sources, given the log-posterior odds

normalize(array)

Args:

posterior_to_log_odds(posterior)

Args:

propagate_posterior(post, hazard[, llh, …])

Args:

switch_side(side)

Args:

Classes

Audio2AFCSimulation(tot_trials, h_values, …)

Use this class to launch simulations of our models

BinaryDecisionMaker(stimulus_object[, …])

Base class to simulate an observer performing our Auditory change-point 2AFC task.

KnownHazard(stimulus_object[, sources_prior])

Binary decision maker which is an ideal observer who knows the true hazard rate value and assumes it fixed.

StimulusBlock(num_trials, hazard[, …])

Define stimulus for a block of trials in which hazard rate is fixed

UnknownHazard(stimulus_object[, sources_prior])

Variables

MAX_LOG_ODDS

int([x]) -> integer int(x, base=10) -> integer

SIDES

set of allowed sides

TOLERANCE

under this threshold, a probability is deemed to be 0

bernoulli

A Bernoulli discrete random variable.

beta

A beta continuous random variable.

Class Inheritance Diagram

Inheritance diagram of Python_modules.mmcomplexity.Audio2AFCSimulation, Python_modules.mmcomplexity.BinaryDecisionMaker, Python_modules.mmcomplexity.KnownHazard, Python_modules.mmcomplexity.StimulusBlock, Python_modules.mmcomplexity.UnknownHazard

Python_modules.tests_mmcomplexity Module

This is a test module to test the mmcomplexity module with unittest Main reference: https://docs.python.org/3/library/unittest.html#unittest.TestCase.setUp

Classes

TestBinaryDecisionMaker([methodName])

TestKnownHazard([methodName])

TestModuleFunctions([methodName])

TestSimulation([methodName])

TestStimulusBlock([methodName])

Class Inheritance Diagram

Inheritance diagram of Python_modules.tests_mmcomplexity.TestBinaryDecisionMaker, Python_modules.tests_mmcomplexity.TestKnownHazard, Python_modules.tests_mmcomplexity.TestModuleFunctions, Python_modules.tests_mmcomplexity.TestSimulation, Python_modules.tests_mmcomplexity.TestStimulusBlock