<commit_before>"""The stressmodels module contains all the transforms that can be added to the simulation of a model.

"""
import numpy as np
import pandas as pd
from .model import Model


class ThresholdTransform:
    _name = "ThresholdTransform"
    def __init__(self, value=0.0, vmin=np.nan, vmax = np.nan, name='ThresholdTransform', nparam=2):
        if isinstance(value, Model):
            # determine the initial parameter from the model
            ml = value
            value = ml.oseries.mean()
            if np.isnan(vmin):
                vmin = ml.oseries.min()
            if np.isnan(vmax):
                vmax = ml.oseries.max()
        self.value = value
        self.vmin = vmin
        self.vmax = vmax
        self.name = name
        self.nparam = nparam
        self.set_init_parameters()

    def set_init_parameters(self):
        self.parameters = pd.DataFrame(
            columns=['initial', 'pmin', 'pmax', 'vary', 'name'])
        self.parameters.loc[self.name + '_1'] = (self.value, self.vmin, self.vmax, 1, self.name)
        if self.nparam==2:
            self.parameters.loc[self.name + '_2'] = (0.5, 0., 1., 1, self.name)

    def simulate(self, h, p):
        if self.nparam == 1:
            # value above a threshold p[0] are equal to the threshold
            h[h > p[0]] = p[0]
        elif self.nparam == 2:<commit_msg>Improve starting conditions of ThesholdTransform<commit_after>"""The stressmodels module contains all the transforms that can be added to the simulation of a model.

"""
import numpy as np
import pandas as pd
from .model import Model


class ThresholdTransform:
    _name = "ThresholdTransform"
    def __init__(self, value=0.0, vmin=np.nan, vmax = np.nan, name='ThresholdTransform', nparam=2):
        if isinstance(value, Model):
            # determine the initial parameter from the model
            ml = value
            value = ml.oseries.min() + 0.75*(ml.oseries.max()-ml.oseries.min())
            if np.isnan(vmin):
                vmin = ml.oseries.min() + 0.5*(ml.oseries.max()-ml.oseries.min())
            if np.isnan(vmax):
                vmax = ml.oseries.max()
        self.value = value
        self.vmin = vmin
        self.vmax = vmax
        self.name = name
        self.nparam = nparam
        self.set_init_parameters()

    def set_init_parameters(self):
        self.parameters = pd.DataFrame(
            columns=['initial', 'pmin', 'pmax', 'vary', 'name'])
        self.parameters.loc[self.name + '_1'] = (self.value, self.vmin, self.vmax, 1, self.name)
        if self.nparam==2:
            self.parameters.loc[self.name + '_2'] = (0.5, 0., 1., 1, self.name)

    def simulate(self, h, p):
        if self.nparam == 1:
            # value above a threshold p[0] are equal to the threshold
            h[h > p[0]] = p[0]
        elif self.nparam == 2:
{'fraction_non_alphanumeric': 0.1265377855887522, 'fraction_numerical': 0.013708260105448155, 'mean_word_length': 2.1657397107897665, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '4892889', 'n_tokens_mistral': 915, 'n_tokens_neox': 880, 'n_words': 249}