Gibbs

class psynet.trial.gibbs.GibbsNetwork(*args, **kwargs)[source]

Bases: ChainNetwork

A Network class for Gibbs sampler chains.

creation_time

the time at which the Network was created.

details

a generic column for storing structured JSON data

failed

boolean indicating whether the Network has failed which prompts Dallinger to ignore it unless specified otherwise. Objects are usually failed to indicate something has gone wrong.

failed_reason

an optional reason the object was failed. If the object is failed as part of a cascading failure triggered from another object, the chain of objects will be captured in this field.

full

Whether the network is currently full

id

a unique number for every entry. 1, 2, 3 and so on…

make_definition()[source]

Derives the definition for the network. This definition represents some collection of attributes that is shared by all nodes/trials in a network, but that may differ between networks.

Suppose one wishes to have multiple networks in the experiment, each characterised by a different value of an attribute (e.g. a different color). One approach would be to sample randomly; however, this would not guarantee an even distribution of attribute values. In this case, a better approach is to use the psynet.trial.chain.ChainNetwork.balance_across_networks() method, as follows:

colors = ["red", "green", "blue"]
return {
    "color": self.balance_across_networks(colors)
}

See psynet.trial.chain.ChainNetwork.balance_across_networks() for details on how this balancing works.

Returns:

  • object – By default this returns an empty dictionary, but this can be customised by subclasses. The object should be suitable for serialisation to JSON.

max_size

How big the network can get, this number is used by the full() method to decide whether the network is full

property1

a generic column that can be used to store experiment-specific details in String form.

property2

a generic column that can be used to store experiment-specific details in String form.

property3

a generic column that can be used to store experiment-specific details in String form.

property4

a generic column that can be used to store experiment-specific details in String form.

property5

a generic column that can be used to store experiment-specific details in String form.

role

The role of the network. By default dallinger initializes all networks as either “practice” or “experiment”

time_of_death

the time at which failing occurred

type

A String giving the name of the class. Defaults to “network”. This allows subclassing.

vars
class psynet.trial.gibbs.GibbsNode(*args, **kwargs)[source]

Bases: ChainNode

A Node class for Gibbs sampler chains.

vector_length

Must be overridden with the length of the free parameter vector that is manipulated during the Gibbs sampling procedure.

Type:

int

create_definition_from_seed(seed, experiment, participant)[source]

Creates a GibbsNode definition from the seed passed by the previous GibbsNode or GibbsSource in the chain. The vector of parameters is preserved from the seed, but the ‘active index’ is increased by 1 modulo the length of the vector, meaning that the next parameter in the vector is chosen as the current free parameter. This method will typically not need to be overridden.

Returns:

  • dict – A dictionary of the following form:

    {
        "vector": vector,
        "initial_index": initial_index
        "active_index": active_index
    }
    

    where vector is the vector passed by the seed, initial_index identifies the dimension of the first iteration, and active_index identifies the position of the new free parameter.

create_initial_seed(experiment, participant)[source]

Generates the seed for the GibbsSource. By default the method samples the vector of parameters by repeatedly applying random_sample(), and randomly chooses one of these parameters to be the initial free parameter ("initial_index"). Note that the source itself doesn’t receive trials, and the first proper node in the chain will actually have the free parameter after this one, see GibbsNode.create_definition_from_seed for the implementation. This method will not normally need to be overridden.

Parameters:
Returns:

  • dict – A dictionary of the following form:

    {
        "vector": vector,
        "initial_index": initial_index
    }
    

    where vector is the initial vector and initial_index identifies the initial position of the free parameter.

creation_time

the time at which the Network was created.

details

a generic column for storing structured JSON data

failed

boolean indicating whether the Network has failed which prompts Dallinger to ignore it unless specified otherwise. Objects are usually failed to indicate something has gone wrong.

failed_reason

an optional reason the object was failed. If the object is failed as part of a cascading failure triggered from another object, the chain of objects will be captured in this field.

id

a unique number for every entry. 1, 2, 3 and so on…

network

the network the node is in

network_id

the id of the network that this node is a part of

participant

the participant the node is associated with

participant_id

the id of the participant whose node this is

property1

a generic column that can be used to store experiment-specific details in String form.

property2

a generic column that can be used to store experiment-specific details in String form.

property3

a generic column that can be used to store experiment-specific details in String form.

property4

a generic column that can be used to store experiment-specific details in String form.

property5

a generic column that can be used to store experiment-specific details in String form.

random_sample(i)[source]

(Abstract method, to be overridden) Randomly samples a new value for the ith element of the free parameter vector. This is used for initialising the participant’s response options.

Parameters:

i (int) – The index of the element that is being resampled.

Returns:

  • float – The new parameter value.

summarize_trials(trials, experiment, participant)[source]

This method summarizes the answers to the provided trials. The default method averages over all the provided parameter vectors, and will typically not need to be overridden.

Parameters:
  • trials (list) – Trials to be summarized. By default only trials that are completed (i.e. have received a response) and processed (i.e. aren’t waiting for an asynchronous process) are provided here.

  • experiment – An instantiation of psynet.experiment.Experiment, corresponding to the current experiment.

  • participant – The participant who initiated the creation of the node.

Returns:

  • dict – A dictionary of the following form:

    {
        "vector": summary_vector,
        "initial_index": initial_index
        "active_index": active_index
    }
    

    where summary_vector is the summary of all the vectors, and active_index is an integer identifying which was the free parameter. The initial index is also passed on, as it is used to identify the current dimension in the chain.

time_of_death

the time at which failing occurred

type

A String giving the name of the class. Defaults to node. This allows subclassing.

vars
class psynet.trial.gibbs.GibbsTrial(*args, **kwargs)[source]

Bases: ChainTrial

A Trial class for Gibbs sampler chains.

resample_free_parameter

If True (default), the starting value of the free parameter is resampled on each trial. Disable this behaviour by setting this parameter to False in the definition of the custom GibbsTrial class.

Type:

bool

initial_vector

The starting vector that is presented to the participant at the beginning of the trial.

Type:

list

initial_index

The initial index of the parameter that the participant manipulates on the first trial.

Type:

int

active_index

The index of the parameter that the participant manipulates on this trial.

Type:

int

reverse_scale

Whether the response scale should be reversed. This reversal should be implemented on the front-end, with the correct numbers still being reported to the back-end.

Type:

bool

updated_vector

The updated vector after the participant has responded.

Type:

list

complete

whether the info is ‘complete’, i.e. has received its contents

creation_time

the time at which the Network was created.

details

a generic column for storing structured JSON data

failed

boolean indicating whether the Network has failed which prompts Dallinger to ignore it unless specified otherwise. Objects are usually failed to indicate something has gone wrong.

failed_reason

an optional reason the object was failed. If the object is failed as part of a cascading failure triggered from another object, the chain of objects will be captured in this field.

id

a unique number for every entry. 1, 2, 3 and so on…

make_definition(experiment, participant)[source]

In the Gibbs sampler, a trial’s definition is created by taking the definition from the source GibbsNode, modifying it such that the free parameter has a randomised starting value, and adding a randomised Boolean determining whether the corresponding slider (or similar) has its direction reversed. Note that different trials at the same GibbsNode will have the same free parameters but different starting values for those free parameters.

Parameters:
  • experiment – An instantiation of psynet.experiment.Experiment, corresponding to the current experiment.

  • participant – Optional participant with which to associate the trial.

Returns:

  • object – The trial’s definition, equal to the node’s definition with the free parameter randomised.

network

the network the info is in

network_id

the id of the network the info is in

origin

the Node that created the info.

origin_id

the id of the Node that created the info

property1

a generic column that can be used to store experiment-specific details in String form.

property2

a generic column that can be used to store experiment-specific details in String form.

property3

a generic column that can be used to store experiment-specific details in String form.

property4

a generic column that can be used to store experiment-specific details in String form.

property5

a generic column that can be used to store experiment-specific details in String form.

time_of_death

the time at which failing occurred

type

a String giving the name of the class. Defaults to “info”. This allows subclassing.

vars
class psynet.trial.gibbs.GibbsTrialMaker(*, id_, trial_class, node_class, network_class=None, chain_type, expected_trials_per_participant, max_trials_per_participant=<class 'psynet.utils.NoArgumentProvided'>, max_trials_per_block=None, max_nodes_per_chain=None, chains_per_participant=None, chains_per_experiment=None, trials_per_node=1, n_repeat_trials=0, target_n_participants=None, balance_across_chains=False, start_nodes=None, check_performance_at_end=False, check_performance_every_trial=False, recruit_mode='n_participants', fail_trials_on_premature_exit=False, fail_trials_on_participant_performance_check=False, propagate_failure=True, wait_for_networks=False, allow_revisiting_networks_in_across_chains=False, assets=None, choose_participant_group=None, sync_group_type=None, sync_group_max_wait_time=45.0)[source]

Bases: ChainTrialMaker

A TrialMaker class for Gibbs sampler chains; see the documentation for ChainTrialMaker for usage instructions.