Skip to main content

Utilities to generate realistic movement time distributions for various user strategies

Project description

Utilities for generating realistic movement time and index of difficulty joint distributions. Example usage

import scipy.stats as stats
import numpy
import polars
import matplotlib.pyplot as plt
import seaborn

import gen_joint_mtide as gen


# === loading some data
df = polars.read_csv(gen.example_data)

############### generate EMG data

# -- infer emg model
# off the shelf fitter should work. If not, refer to fit_emg_arbitrary_variance_model
x, fit = gen.compute_emg_regression_linear_expo_mean(
    numpy.asarray(df["IDe(2d)"]), numpy.asarray(df["Duration"])
)
beta = x[:2]
sigma = x[2]
lambda_emg = x[3:]
# -- end infer model

# without specifying ide levels
emg_x, emg_y = gen.gen_emg(
    beta, sigma, lambda_emg, block_levels=None, ntrials=50, rng=None, seed=None
)

# with ide levels specified:
ide_levels = df["IDe(2d)"].unique()
emg_x, emg_y = gen.gen_emg(
    beta,
    sigma,
    lambda_emg,
    block_levels=numpy.asarray(ide_levels),
    ntrials=50,
    rng=None,
    seed=None,
)

############### generate EMG data with r(mean(MT), IDe) control
df_mean = df.group_by("IDe(2d)").mean()
# -- infer mu, cov for mean MT, mean IDe using scipy.stats
mu, cov = stats.multivariate_normal.fit(df_mean.select(["IDe(2d)", "Duration"]))
block_levels = df_mean["IDe(2d)"]

emg_control_x, emg_control_y = gen.gen_emg_control(
    beta,
    sigma,
    lambda_emg,
    mu,
    cov,
    block_levels=block_levels,
    ntrials=50,
    rng=None,
    seed=None,
)

############### generate data with t-copula

rho1, df = gen.fit_t_copula(
    df["IDe(2d)"], df["Duration"]
)  # rho1 can be estimated by sin(pi/2 tau) where tau is kendall's tau

# fit id and mt marginals
u_loc, u_scale = stats.uniform.fit(df_mean.select("IDe(2d)"))
K, loc, scale = stats.exponnorm.fit(df_mean.select("Duration"))

id_params = {"distribution": "unif", "params": dict(min=u_loc, max=u_loc + u_scale)}
mt_params = {
    "distribution": "emg",
    "params": {
        "mu": float(loc),
        "sigma": float(scale),
        "lambda": float(1 / (scale * K)),
    },
}

block_levels = stats.uniform(loc=(u_loc - 1e-3), scale=(u_scale + 2e-3)).cdf(
    block_levels
)

cop_x, cop_y = gen.gen_t_copula(
    rho1,
    df,
    id_params,
    mt_params,  # for the marginals, pass things that make sense to R
    trials=15,
    block_levels=block_levels,
    cdf_block=False,
    rng=None,
    seed=None,
)

fig, axs = plt.subplots(1, 3)
seaborn.scatterplot(x=emg_x, y=emg_y, ax=axs[0])
seaborn.scatterplot(x=emg_control_x, y=emg_control_y, ax=axs[1])
seaborn.scatterplot(x=cop_x, y=cop_y, ax=axs[2])
plt.ion()
plt.tight_layout()
plt.show()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gen_joint_mtide-0.2.0.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gen_joint_mtide-0.2.0-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file gen_joint_mtide-0.2.0.tar.gz.

File metadata

  • Download URL: gen_joint_mtide-0.2.0.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.14

File hashes

Hashes for gen_joint_mtide-0.2.0.tar.gz
Algorithm Hash digest
SHA256 4a9d9273ee8f7e0574919fd359a9a5fcc68b1403c3f475f6f56067a954dde7ea
MD5 94a9695102ad5aee3e912cd3f265bebf
BLAKE2b-256 f17b8002f8828b0d384a09ebf50ba38c1d611bc417e70a5a42bbf309b467de6c

See more details on using hashes here.

File details

Details for the file gen_joint_mtide-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for gen_joint_mtide-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cba51798772cf8e7009779563f78c8d2895a58c15275a51ef45f7bf1936b03fb
MD5 9b1e71b28ecac155e2990fab20d634d8
BLAKE2b-256 521dff9afdbe1164bd29a6a16bfb7282311b52239aa3edffdbee37c62850dcd2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page