<commit_before>function standard_deviation(power, median, cv, multiplier) {
    /**
     * Return the standard deviation for a given lms parameters and multiplier.
     * @param lms {Hash}: a dictionary containing the lms values:
     *     'power': the Box-Cox power (L),
     *     'median': the median value (M),
     *     'cv': the coefficient of variation (S).
     * @param multiplier {Number}: the standard deviation to be retrieved.
     * @return {Number}
     */
    return median * Math.pow(1 + power * cv * multiplier, 1 / power);
}

function standard_deviation_3_pos(power, median, cv) {
    /**
     * Return the value of +3 standard deviations for a given lms.
     * @param lms {Hash}: a dictionary containing the lms values:
     *     'power': the Box-Cox power (L),
     *     'median': the median value (M),
     *     'cv': the coefficient of variation (S).
     * @return {Number}
     */
    return standard_deviation(power, median, cv, 3);
}

function standard_deviation_3_neg(power, median, cv) {
    /**
     * Return the value of -3 standard deviations for a given lms.
     * @param lms {Hash}: a dictionary containing the lms values:
     *     'power': the Box-Cox power (L),
     *     'median': the median value (M),
     *     'cv': the coefficient of variation (S).
     * @return {Number}
     */
    return standard_deviation(power, median, cv, -3);
}

function standard_deviation_2_pos(power, median, cv) {
    /**
     * Return the value of +2 standard deviations for a given lms.
     * @param lms {Hash}: a dictionary containing the lms values:
     *     'power': the Box-Cox power (L),
     *     'median': the median value (M),
     *     'cv': the coefficient of variation (S).
     * @return {Number}
     */
    return standard_deviation(power, median, cv, 2);
}

function standard_deviation_2_neg(power, median, cv) {
    /**
     * Return the value of -2 standard deviations for a given lms.
     * @param lms {Hash}: a dictionary containing the lms values:
     *     'power': the Box-Cox power (L),
     *     'median': the median value (M),
     *     'cv': the coefficient of variation (S).
     * @return {Number}
     */
    return standard_deviation(power, median, cv, -2);
}

function zscore_individual(measure, power, median, cv) {
    /**
     * Return the individual z score for a given measure and lms parameters.
     * @param lms {Hash}: a dictionary containing the lms values:
     *     'power': the Box-Cox power (L),
     *     'median': the median value (M),
     *     'cv': the coefficient of variation (S).
     * @param measure {Number}: the measured value.
     * @return {Number}
     */
    var correct_median = Math.pow(measure / median, power) - 1;
    var deviation = cv * power;
    return correct_median / deviation;
}

function zscore_fix(zscore, measure, power, median, cv) {
    /**
     * Return the fixed z score for scores less than -3 or greate than +3.
     * @param lms {Hash}: a dictionary containing the lms values:
     *     'power': the Box-Cox power (L),
     *     'median': the median value (M),
     *     'cv': the coefficient of variation (S).
     * @param zscore {Number}: the individual z score obtained.
     * @param measure {Number}: the measured value.
     * @return {Number}
     */
    if (Math.abs(zscore) <= 3) {
        return zscore;
    }

    var constant = null, deviation = null, deltadeviation = null;
    if (zscore > 3) {
        constant = 3;
        deviation = standard_deviation_3_pos(power, median, cv);
        deltadeviation = deviation - standard_deviation_2_pos(power, median, cv);
    } else {
        constant = -3;
        deviation = standard_deviation_3_neg(power, median, cv);
        deltadeviation = standard_deviation_2_neg(power, median, cv) - deviation;
    }

    return constant + (measure - deviation) / deltadeviation;
}

function to_zscore(measure, power, median, cv) {
    /**
     * Convert a given measure with lms parameters to z score.
     * @param lms {Hash}: a dictionary containing the lms values:
     *     'power': the Box-Cox power (L),
     *     'median': the median value (M),
     *     'cv': the coefficient of variation (S).
     * @param measure {Number}: the measured value.
     * @return {Number}
     */
    return zscore_fix(
        zscore_individual(measure, power, median, cv),
        measure,
        power,
        median,
        cv
    );
}

function to_measure(zscore, power, median, cv) {
    /**
     * Convert a given z score with lms parameters to a measure. The estimative
     * is only valid for -3 <= zscore <= 3.
     * @param lms {Hash}: a dictionary containing the lms values:
     *     'power': the Box-Cox power (L),
     *     'median': the median value (M),
     *     'cv': the coefficient of variation (S).
     * @param zscore {Number}: a given z score.
     * @return {Number}
     */
    return standard_deviation(power, median, cv, zscore);
}

/**
 * Testing
 */
function precision(value, decimal) {
    decimal = !isNaN(decimal) ? decimal : 4;
    return (value).toFixed(decimal);
}

var measures = [
    [30, -1.7862, 16.9392, 0.11070, 3.35],
    [14, -1.3529, 20.4951, 0.12579, -3.80],
    [19, -1.6318, 16.0490, 0.10038, 1.47]
];

measures.forEach(function (list) {
    var score = to_zscore(list[0], list[1], list[2], list[3]);
    console.log(
        precision((to_measure(score, list[1], list[2], list[3]))),
        list[0],
        precision((score)),
        list[4]);
});<commit_msg>Update methods signature to receive hashs.<commit_after>function standard_deviation(options) {
    /**
     * Return the standard deviation for a given lms parameters and multiplier.
     * @param lms {Hash}: a dictionary containing the lms values:
     *     'power': the Box-Cox power (L),
     *     'median': the median value (M),
     *     'cv': the coefficient of variation (S).
     * @param multiplier {Number}: the standard deviation to be retrieved.
     * @return {Number}
     */
    var multiplier = options.multiplier,
        lms = options.lms;
    var variance = 1 + lms.power * lms.cv * multiplier;
    return lms.median * Math.pow(variance, 1 / lms.power);
}

function standard_deviation_3_pos(lms) {
    /**
     * Return the value of +3 standard deviations for a given lms.
     * @param lms {Hash}: a dictionary containing the lms values:
     *     'power': the Box-Cox power (L),
     *     'median': the median value (M),
     *     'cv': the coefficient of variation (S).
     * @return {Number}
     */
    return standard_deviation({multiplier: 3, lms: lms});
}

function standard_deviation_3_neg(lms) {
    /**
     * Return the value of -3 standard deviations for a given lms.
     * @param lms {Hash}: a dictionary containing the lms values:
     *     'power': the Box-Cox power (L),
     *     'median': the median value (M),
     *     'cv': the coefficient of variation (S).
     * @return {Number}
     */
    return standard_deviation({multiplier: -3, lms: lms});
}

function standard_deviation_2_pos(lms) {
    /**
     * Return the value of +2 standard deviations for a given lms.
     * @param lms {Hash}: a dictionary containing the lms values:
     *     'power': the Box-Cox power (L),
     *     'median': the median value (M),
     *     'cv': the coefficient of variation (S).
     * @return {Number}
     */
    return standard_deviation({multiplier: 2, lms: lms});
}

function standard_deviation_2_neg(lms) {
    /**
     * Return the value of -2 standard deviations for a given lms.
     * @param lms {Hash}: a dictionary containing the lms values:
     *     'power': the Box-Cox power (L),
     *     'median': the median value (M),
     *     'cv': the coefficient of variation (S).
     * @return {Number}
     */
    return standard_deviation({multiplier: -2, lms: lms});
}

function zscore_individual(options) {
    /**
     * Return the individual z score for a given measure and lms parameters.
     * @param lms {Hash}: a dictionary containing the lms values:
     *     'power': the Box-Cox power (L),
     *     'median': the median value (M),
     *     'cv': the coefficient of variation (S).
     * @param measure {Number}: the measured value.
     * @return {Number}
     */
    var measure = options.measure,
        lms = options.lms
    var correct_median = Math.pow(measure / lms.median, lms.power) - 1,
        deviation = lms.cv * lms.power;
    return correct_median / deviation;
}

function zscore_fix(options) {
    /**
     * Return the fixed z score for scores less than -3 or greate than +3.
     * @param lms {Hash}: a dictionary containing the lms values:
     *     'power': the Box-Cox power (L),
     *     'median': the median value (M),
     *     'cv': the coefficient of variation (S).
     * @param zscore {Number}: the individual z score obtained.
     * @param measure {Number}: the measured value.
     * @return {Number}
     */
    var zscore = options.zscore,
        measure = options.measure,
        lms = options.lms;

    if (Math.abs(zscore) <= 3) {
        return zscore;
    }

    var constant = null, deviation = null, deltadeviation = null;
    if (zscore > 3) {
        constant = 3;
        deviation = standard_deviation_3_pos(lms);
        deltadeviation = deviation - standard_deviation_2_pos(lms);
    } else {
        constant = -3;
        deviation = standard_deviation_3_neg(lms);
        deltadeviation = standard_deviation_2_neg(lms) - deviation;
    }

    return constant + (measure - deviation) / deltadeviation;
}

function to_zscore(options) {
    /**
     * Convert a given measure with lms parameters to z score.
     * @param lms {Hash}: a dictionary containing the lms values:
     *     'power': the Box-Cox power (L),
     *     'median': the median value (M),
     *     'cv': the coefficient of variation (S).
     * @param measure {Number}: the measured value.
     * @return {Number}
     */
    options.zscore = zscore_individual(options);
    return zscore_fix(options);
}

function to_measure(options) {
    /**
     * Convert a given z score with lms parameters to a measure. The estimative
     * is only valid for -3 <= zscore <= 3.
     * @param lms {Hash}: a dictionary containing the lms values:
     *     'power': the Box-Cox power (L),
     *     'median': the median value (M),
     *     'cv': the coefficient of variation (S).
     * @param zscore {Number}: a given z score.
     * @return {Number}
     */
    options.multiplier = options.zscore
    return standard_deviation(options);
}

/**
 * Testing
 */
function precision(value, decimal) {
    decimal = !isNaN(decimal) ? decimal : 4;
    return (value).toFixed(decimal);
}

var measures = [
    {measure: 30, lms: {power: -1.7862, median: 16.9392, cv: 0.11070}, expec: 3.35},
    {measure: 14, lms: {power: -1.3529, median: 20.4951, cv: 0.12579}, expec: -3.80},
    {measure: 19, lms: {power: -1.6318, median: 16.0490, cv: 0.10038}, expec: 1.47}
];

measures.forEach(function (options) {
    options.zscore = to_zscore(options);
    console.log(
        precision((to_measure(options))),
        options.measure,
        precision((score)),
        options.expec
    );
});
{'fraction_non_alphanumeric': 0.12710347296813462, 'fraction_numerical': 0.017633369137128537, 'mean_word_length': 2.537998733375554, 'pattern_counts': {'":': 0, '<': 9, '<?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': '5652155', 'n_tokens_mistral': 3655, 'n_tokens_neox': 3500, 'n_words': 1156}