Skip to content

Instantly share code, notes, and snippets.

@ZviBaratz
Last active November 23, 2022 09:41
Show Gist options
  • Save ZviBaratz/c29884a9ed8ce56ae78d7435b8209897 to your computer and use it in GitHub Desktop.
Save ZviBaratz/c29884a9ed8ce56ae78d7435b8209897 to your computer and use it in GitHub Desktop.
Buggy oddball debugging exercise solution

Buggy Oddball

This list details the bugs found in buggy_oddball.py. For the correct version, see oddball.py.

  • normalize_distance_parameters()
  1. Incorrect weights normalization, should be divided by sum() rather than mean().

  2. The function returns only weights, instead of distances, weights.

  3. The expression:

    distances = np.array(
        [distances]
        if isinstance(distances, (int, float))
        else list([distances]),
        dtype=int,
    )

    should be fixed to:

    distances = np.array(
        [distances]
        if isinstance(distances, (int, float))
        else list(distances),
        dtype=int,
    )
  • generate_oddball_indices()
  1. The line:

    oddball_indices = oddball_indices[distances < duration]

    Should be replaced with:

    oddball_indices = oddball_indices[np.cumsum(distances) < duration]
  • infer_stimulus_timings()
  1. n_clicks is undefined, should be calculated as:

    n_clicks = int(click_frequency * duration)
  • create_oddball_audio()
  1. Missing click_duration and oddball_duration parameters in function signature.
  2. Return value should be click_train + oddball_train, rather than click_train, oddball_train.
  3. librosa.clicks accepts a click_freq parameter rather than click_tone.
  4. The oddball_train creation should include length=click_train.size to return an equally sized array.
  • generate_oddball_stimulus()
  1. click_duration and oddball_duration should be provided in seconds, rather than milliseconds.
  2. output_path is not implemented.
  3. The call to create_oddball_audio() has a typo.
  • General
  1. typing.List is imported but unused.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment