<commit_before>from utilities import int_binsearch

import numpy as np
from scipy.integrate import quad
from numpy import linalg as LA

# Integral subdivision limit
LIMIT = 10

# Maximum number of iterations for the Lloyd-Max algorithm
MAX_ITERATIONS = 20

class Encoder:
    def __init__(self, boundaries):
        self.boundaries = boundaries

    def encode(self, *msg):
        assert len(msg) == 1 # One real number
        x = msg[0]
        return int_binsearch(lambda i: self.boundaries[i] >= x,
                0, len(self.boundaries)) - 1


class Decoder:
    def __init__(self, levels, boundaries):
        self.levels = levels
        self.boundaries = boundaries

    def decode(self, *msg):
        assert len(msg) == 1 # One integer
        i = msg[0]
        return self.levels[i]

    def get_interval(self, i):
        return self.boundaries[i], self.boundaries[i + 1]


def generate(n_levels, distr):
    # Initialize the boundaries (TODO: can be done more efficiently)
    # Start with the same total probability 1/n_levels in each interval<commit_msg>Increased the iteration limit for the Lloyd-Max algorithm<commit_after>from utilities import int_binsearch

import numpy as np
from scipy.integrate import quad
from numpy import linalg as LA

# Integral subdivision limit
LIMIT = 10

# Maximum number of iterations for the Lloyd-Max algorithm
MAX_ITERATIONS = 200

class Encoder:
    def __init__(self, boundaries):
        self.boundaries = boundaries

    def encode(self, *msg):
        assert len(msg) == 1 # One real number
        x = msg[0]
        return int_binsearch(lambda i: self.boundaries[i] >= x,
                0, len(self.boundaries)) - 1


class Decoder:
    def __init__(self, levels, boundaries):
        self.levels = levels
        self.boundaries = boundaries

    def decode(self, *msg):
        assert len(msg) == 1 # One integer
        i = msg[0]
        return self.levels[i]

    def get_interval(self, i):
        return self.boundaries[i], self.boundaries[i + 1]


def generate(n_levels, distr):
    # Initialize the boundaries (TODO: can be done more efficiently)
    # Start with the same total probability 1/n_levels in each interval
{'fraction_non_alphanumeric': 0.08359981726815897, 'fraction_numerical': 0.011420740063956145, 'mean_word_length': 2.931777378815081, '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': '4726332', 'n_tokens_mistral': 675, 'n_tokens_neox': 626, 'n_words': 226}