src.analyse.simulations

Code for generating simulations using phase correction models

Functions

generate_phase_correction_simulations_for_coupling_parameters(...)

Create simulated performances across a range of artificial coupling parameters for every phase correction model

generate_phase_correction_simulations_for_individual_conditions(...)

Create simulated performances using the coupling within every individual performance.

Classes

Simulation(pcm[, num_simulations])

Creates X number (default 500) of simulated performances from a given phase correction model.

class src.analyse.simulations.Simulation(pcm: PhaseCorrectionModel, num_simulations: int = 500, **kwargs)

Bases: object

Creates X number (default 500) of simulated performances from a given phase correction model.

Number of simulations defaults to 500, the same number in Jacoby et al. (2021).

static _append_timestamps_to_latency_array(latency_array, offset: int = 8, resample_rate: float = 0.75) array

Appends timestamps showing the onset time for each value in the latency array applied to a performance

static _convert_musician_parameters_dict_to_numba(python_dict: dict) Dict

Converts a Python dictionary into a type that can be utilised by Numba

_create_summary_dictionary() dict

Creates a summary dictionary with important simulation parameters

_format_simulated_data(data: Dict) DataFrame

Formats data from one simulation by creating a dataframe, adding in the timedelta column, and resampling to get the mean IOI (defaults to every second)

static _get_average_var_for_one_simulation(all_perf: list[pandas.core.frame.DataFrame], var: str = 'my_next_ioi') DataFrame

Concatenate all simulations together and get the row-wise average (i.e. avg IOI every second)

static _get_number_of_beats_for_simulation(kp, dp) int

Averages the total number of beats across both keys and drums, then gets the upper ceiling.

static _get_raw_musician_parameters(init: DataFrame) dict

Gets necessary simulation parameters from pandas dataframe and converts to a dictionary

_get_rolling_standard_deviation_values(df: DataFrame, cols: tuple[str] = ('my_prev_ioi',)) DataFrame
_initialise_empty_data(iois: tuple[float] = (0.5, 0.5), onset: float = 8) Dict

Initialise an empty numba dictionary of string-array pairs, for storing data from one simulation in.

_modify_musician_parameters_by_simulation_type(input_data)

Modifies a simulated musician’s parameters according to the given simulation type

create_all_simulations() None

Run the simulations and create a list of dataframes for each individual performer

get_average_ioi_variability(func=<function nanmean>, **kwargs) float

Returns the average tempo slope for all simulations.

Method: — - For every simulation, get the median IOI standard deviation value over the window size - Calculate the mean of all of these values.

get_average_pairwise_asynchrony(func=<function nanmean>, async_col: str = 'asynchrony', **kwargs) float

Gets the average pairwise asynchrony (in milliseconds!) across all simulated performances

get_average_tempo_slope(func=<function nanmean>, **kwargs) float

Returns the average tempo slope for all simulations.

Method: — - For every simulation, zip the corresponding keys and drums performance together. - Then, get the average IOI for every second across both keys and drums.

  • This is straightforward, because we resampled to average IOI per second in _format_simulated_data

  • Convert average IOI to average BPM by dividing by 60, then regress against elapsed seconds

  • Extract the slope coefficient, take the median across all simulations, and return

get_simulation_data_for_plotting(plot_individual: bool = True, plot_average: bool = True, var: str = 'my_next_ioi', timespan: tuple = (7, 101)) tuple

Wrangles simulation data into a format that can be plotted and returns.

src.analyse.simulations.generate_phase_correction_simulations_for_coupling_parameters(mds: list[src.analyse.phase_correction_models.PhaseCorrectionModel], output_dir: str, logger=None, force_rebuild: bool = False, num_simulations: int = 500) tuple[list[src.analyse.simulations.Simulation], str]

Create simulated performances across a range of artificial coupling parameters for every phase correction model

src.analyse.simulations.generate_phase_correction_simulations_for_individual_conditions(mds: list[src.analyse.phase_correction_models.PhaseCorrectionModel], output_dir: str, logger=None, force_rebuild: bool = False, num_simulations: int = 500) list[src.analyse.simulations.Simulation]

Create simulated performances using the coupling within every individual performance.