<commit_before>"""Generate different kinds of driving rates, e.g. constant, oscillation,
and 'naturalistic'.
"""
from __future__ import division
import numpy as np
from scipy import signal


def renormalize(X, x_range, y_range):
    x1, x2 = x_range
    y1, y2 = y_range

    return (((X - x1) * (y2 - y1)) / (x2 - x1)) + y1


def create_times(t, dt):
    n_steps = int(t * (1.0 / dt))
    times = np.linspace(0, t, n_steps)

    return times


def osc(times, a, f, phase=0):
    """Sinusoidal oscillation"""

    rates = a + (a / 2.0) * np.sin(times * f * 2 * np.pi + phase)
    rates[rates < 0] = 0  # Rates must be positive

    return rates


def osc2(times, a, f, min_a=12, phase=0):
    """Continous bursting-type oscillation"""

    # Osc
    rates = np.cos((2 * np.pi * f * times) + phase)

    # Truncate negative half as a crude sim of spike bursts
    rates[rates < 0] = 0

    return renormalize(rates, (0, 1), (a, min_a))


def bursts(times, a, f, n_bursts=2, min_a=12, phase=0, offset=0, random=False):
    """Short bursts of oscillation"""

    if (not n_bursts) or (n_bursts is None):
        max_shift = int(1 / f / (times[1] - times[0]))
        rates = osc2(times, a, f, min_a, phase)
    else:
        if n_bursts < 1:
            raise ValueError("Must be at least 1 bursts.")

        # Is offset a range?
        try:
            if len(offset) == 2:<commit_msg>bugfix - fixing last fix<commit_after>"""Generate different kinds of driving rates, e.g. constant, oscillation,
and 'naturalistic'.
"""
from __future__ import division
import numpy as np
from scipy import signal


def renormalize(X, x_range, y_range):
    x1, x2 = x_range
    y1, y2 = y_range

    return (((X - x1) * (y2 - y1)) / (x2 - x1)) + y1


def create_times(t, dt):
    n_steps = int(t * (1.0 / dt))
    times = np.linspace(0, t, n_steps)

    return times


def osc(times, a, f, phase=0):
    """Sinusoidal oscillation"""

    rates = a + (a / 2.0) * np.sin(times * f * 2 * np.pi + phase)
    rates[rates < 0] = 0  # Rates must be positive

    return rates


def osc2(times, a, f, min_a=12, phase=0):
    """Continous bursting-type oscillation"""

    # Osc
    rates = np.cos((2 * np.pi * f * times) + phase)

    # Truncate negative half as a crude sim of spike bursts
    rates[rates < 0] = 0

    return renormalize(rates, (0, 1), (min_a, a))


def bursts(times, a, f, n_bursts=2, min_a=12, phase=0, offset=0, random=False):
    """Short bursts of oscillation"""

    if (not n_bursts) or (n_bursts is None):
        max_shift = int(1 / f / (times[1] - times[0]))
        rates = osc2(times, a, f, min_a, phase)
    else:
        if n_bursts < 1:
            raise ValueError("Must be at least 1 bursts.")

        # Is offset a range?
        try:
            if len(offset) == 2:
{'fraction_non_alphanumeric': 0.14203523912261776, 'fraction_numerical': 0.02876663070837828, 'mean_word_length': 2.5850515463917527, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2025103', 'n_tokens_mistral': 1082, 'n_tokens_neox': 1003, 'n_words': 330}