<commit_before>package com.bylak.android.normalize;

/**
 * Created with IntelliJ IDEA.
 * User: Artur.Bylak
 * Date: 30.09.13
 * Time: 13:01
 * To change this template use File | Settings | File Templates.
 */
public final class DefaultInputProcessor implements InputProcessor {
    public double[] processInput(int expectedOutputCount, float[] dataToProcess) {

        if (expectedOutputCount < 0) {
            throw new IllegalArgumentException("Expected count should be positive");
        }

        if (dataToProcess == null || dataToProcess.length < 1) {
            throw new IllegalArgumentException("Incorrect data to process");
        }

        double[] normalizedData = normalize(dataToProcess);

        return changeSize(normalizedData, expectedOutputCount);
    }

    private double[] normalize(float[] dataToProcess) {
        int length = dataToProcess.length;

        double min = dataToProcess[0];
        double max = dataToProcess[0];
        for (int i = 0; i < length; i++) {
            double currentValue = dataToProcess[i];

            if (currentValue > max) {
                max = currentValue;
            }
            if (currentValue < min) {
                min = currentValue;
            }
        }

        return normalize(max, min, dataToProcess);
    }

    private double[] normalize(double max, double min, float[] dataToNormalzie) {
        int length = dataToNormalzie.length;
        double[] normalziedData = new double[length];
        double diff = (max - min);

        for (int i = 0; i < length; i++) {
            double currentValue = dataToNormalzie[i];

            normalziedData[i] = (currentValue - min) / diff;
        }

        return normalziedData;
    }

    private double[] changeSize(double[] dataToProcess, int expectedOutputCount) {
        return dataToProcess;
    }
}<commit_msg>Small changes<commit_after>package com.bylak.android.normalize;

/**
 * Created with IntelliJ IDEA.
 * User: Artur.Bylak
 * Date: 30.09.13
 * Time: 13:01
 * To change this template use File | Settings | File Templates.
 */
public final class DefaultInputProcessor implements InputProcessor {
    public double[] processInput(int expectedOutputCount, float[] dataToProcess) {

        if (expectedOutputCount < 0) {
            throw new IllegalArgumentException("Expected count should be positive");
        }

        if (dataToProcess == null || dataToProcess.length < 1) {
            throw new IllegalArgumentException("Incorrect data to process");
        }

        double[] normalizedData = normalize(dataToProcess);

        return changeSize(normalizedData, expectedOutputCount);
    }

    private double[] normalize(float[] dataToProcess) {
        int length = dataToProcess.length;

        double min = dataToProcess[0];
        double max = dataToProcess[0];
        for (int i = 0; i < length; i++) {
            double currentValue = dataToProcess[i];

            if (currentValue > max) {
                max = currentValue;
            }
            if (currentValue < min) {
                min = currentValue;
            }
        }

        return normalize(max, min, dataToProcess);
    }

    private double[] normalize(double max, double min, float[] dataToNormalzie) {
        int length = dataToNormalzie.length;
        double[] normalziedData = new double[length];
        double diff = (max - min);

        for (int i = 0; i < length; i++) {
            double currentValue = dataToNormalzie[i];

            normalziedData[i] = (currentValue - min) / diff;
        }

        return normalziedData;
    }

    private double[] changeSize(double[] dataToProcess, int expectedOutputCount) {
        int length = dataToProcess.length;

        if (expectedOutputCount == length) {
            return dataToProcess;
        } else if (expectedOutputCount == 2 && length > 2) {
            return new double[]{dataToProcess[0], dataToProcess[length - 1]};
        } else if (expectedOutputCount < length) {
            return reduceArray(dataToProcess, expectedOutputCount);
        } else {
            return resizeArray(dataToProcess, expectedOutputCount);
        }
    }

    private double[] reduceArray(double[] dataToProcess, int expectedOutputCount) {
        double[] reducedValues = new double[expectedOutputCount];
        int currentLength = dataToProcess.length;
        int step = currentLength / expectedOutputCount;

        for (int i = 0; i < expectedOutputCount; i++) {
            int nextIndex = i * step;
            reducedValues[i] = dataToProcess[nextIndex];
        }

        return reducedValues;
    }

    private double[] resizeArray(double[] dataToProcess, int expectedOutputCount) {
        return dataToProcess;
    }
}
{'fraction_non_alphanumeric': 0.09719586759434956, 'fraction_numerical': 0.0078009698503057135, 'mean_word_length': 2.381325730577334, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 6, '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': '2410033', 'n_tokens_mistral': 1295, 'n_tokens_neox': 1220, 'n_words': 349}