<commit_before>import numpy as np

class Chain(object):
    def __init__(self):
        self.matrix = None
        self.states = {}
        self.states_by_label = {}

    def new_state(self, label=None):
        new_state = State(label)
        if label is not None:
            if label in self.states_by_label:
                label_str = str(label)
                raise ValueError("The state label " + label_str + " is " + 
                                 "already taken")
        
            self.states_by_label[label] = new_state

        new_index = 0

        if self.matrix is None:
            self.matrix = np.matrix(np.array([0]), np.float64)
        else:
            (x,y) = self.matrix.shape
            new_index = x
            self.matrix.resize((x+1,y+1))

        self.states[new_state] = new_index
        return new_state


    def get_state(self, label):
        if label in self.states_by_label:
            return self.states_by_label[label]
        else:
            return None

    def set_transition(self, from_state, to_state, chance):
        if from_state not in self.states:
            raise Exception("The from_state is not part of this chain")
        if to_state not in self.states:
            raise Exception("The to_state is not a part of this chain")
        if from_state == to_state:
            raise Exception("The from_state and to_state much be different")

        if chance < 0 or chance > 1:
            raise Exception("The chance of the state transition must not be " +
                            "less than 0 or greater than 1, but the value " + 
                            chance + " was provided")

        from_index = self.states[from_state]
        to_index = self.states[to_state]
        self.matrix[to_index,from_index] = chance

    def get_transition(self, from_state, to_state):
        if from_state not in self.states:
            raise Exception("The from_state is not part of this chain")
        if to_state not in self.states:
            raise Exception("The to_state is not a part of this chain")
        if from_state == to_state:
            raise Exception("The from_state and to_state much be different")
            
        from_index = self.states[from_state]
        to_index = self.states[to_state]
        return self.matrix[to_index,from_index]

    def _create_start_vector(self, start_state=None):
        (rows,cols) = self.matrix.shape

        pi = np.matrix(np.ones(rows), np.float64)<commit_msg>Fix error message creation when the argument is not a string<commit_after>import numpy as np

class Chain(object):
    def __init__(self):
        self.matrix = None
        self.states = {}
        self.states_by_label = {}

    def new_state(self, label=None):
        new_state = State(label)
        if label is not None:
            if label in self.states_by_label:
                label_str = str(label)
                raise ValueError("The state label " + label_str + " is " + 
                                 "already taken")
        
            self.states_by_label[label] = new_state

        new_index = 0

        if self.matrix is None:
            self.matrix = np.matrix(np.array([0]), np.float64)
        else:
            (x,y) = self.matrix.shape
            new_index = x
            self.matrix.resize((x+1,y+1))

        self.states[new_state] = new_index
        return new_state


    def get_state(self, label):
        if label in self.states_by_label:
            return self.states_by_label[label]
        else:
            return None

    def set_transition(self, from_state, to_state, chance):
        if from_state not in self.states:
            raise Exception("The from_state is not part of this chain")
        if to_state not in self.states:
            raise Exception("The to_state is not a part of this chain")
        if from_state == to_state:
            raise Exception("The from_state and to_state much be different")

        if chance < 0 or chance > 1:
            raise Exception("The chance of the state transition must not be " +
                            "less than 0 or greater than 1, but the value " + 
                            str(chance) + " was provided")

        from_index = self.states[from_state]
        to_index = self.states[to_state]
        self.matrix[to_index,from_index] = chance

    def get_transition(self, from_state, to_state):
        if from_state not in self.states:
            raise Exception("The from_state is not part of this chain")
        if to_state not in self.states:
            raise Exception("The to_state is not a part of this chain")
        if from_state == to_state:
            raise Exception("The from_state and to_state much be different")
            
        from_index = self.states[from_state]
        to_index = self.states[to_state]
        return self.matrix[to_index,from_index]

    def _create_start_vector(self, start_state=None):
        (rows,cols) = self.matrix.shape

        pi = np.matrix(np.ones(rows), np.float64)
{'fraction_non_alphanumeric': 0.08108108108108109, 'fraction_numerical': 0.0047694753577106515, 'mean_word_length': 1.9346938775510205, 'pattern_counts': {'":': 0, '<': 5, '<?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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2595492', 'n_tokens_mistral': 1441, 'n_tokens_neox': 1394, 'n_words': 423}