<commit_before>from numpy import *
from numpy.linalg import LinAlgError
from numpy.random import randint
from itertools import izip

from .logger import log_message

from .mask_starts import mask_starts
from .linear_algebra import BlockPlusDiagonalMatrix

from .cylib.compute_cluster_masks import accumulate_cluster_mask_sum
# from .cylib.m_step import compute_cluster_means, compute_covariance_matrix
from .cylib.m_step import compute_covariance_matrix
from .numbalib.m_step import compute_cluster_means
from .cylib.e_step import compute_log_p_and_assign

import time

__all__ = ['KK']

def get_diagonal(x):
    '''
    Return a writeable view of the diagonal of x
    '''
    return x.reshape(-1)[::x.shape[0]+1]

default_parameters = dict(
     prior_point=1,
     mua_point=1,
     noise_point=1,
     points_for_cluster_mask=10,
     penalty_k=0.0,
     penalty_k_log_n=1.0,
     max_iterations=10,
     num_changed_threshold=0.05,
     full_step_every=20,
     split_first=20,
     split_every=40,
     max_possible_clusters=100,
     )                          

class KK(object):
    def __init__(self, data, log_prefix='', **params):        
        self.data = data
        self.params = params
        actual_params = default_parameters.copy()
        actual_params.update(**params)
        for k, v in actual_params.iteritems():
            setattr(self, k, v)
        self.log_prefix = log_prefix
            
    def log(self, level, msg):
        # todo: would be better to use a logging hierarchy and filter out K2 and K3 in console
        log_message(level, msg, name=self.log_prefix)
            
    def copy(self, log_prefix='kk_copy'):<commit_msg>Added more log options and initial parameters<commit_after>from numpy import *
from numpy.linalg import LinAlgError
from numpy.random import randint
from itertools import izip

from .logger import log_message

from .mask_starts import mask_starts
from .linear_algebra import BlockPlusDiagonalMatrix

from .cylib.compute_cluster_masks import accumulate_cluster_mask_sum
# from .cylib.m_step import compute_cluster_means, compute_covariance_matrix
from .cylib.m_step import compute_covariance_matrix
from .numbalib.m_step import compute_cluster_means
from .cylib.e_step import compute_log_p_and_assign

import time

__all__ = ['KK']

def get_diagonal(x):
    '''
    Return a writeable view of the diagonal of x
    '''
    return x.reshape(-1)[::x.shape[0]+1]

default_parameters = dict(
     prior_point=1,
     mua_point=1,
     noise_point=1,
     points_for_cluster_mask=10,
     penalty_k=0.0,
     penalty_k_log_n=1.0,
     max_iterations=10,
     num_changed_threshold=0.05,
     full_step_every=20,
     split_first=20,
     split_every=40,
     max_possible_clusters=100,
     )                          

class KK(object):
    def __init__(self, data, log_prefix='', **params):        
        self.log_prefix = log_prefix
        self.data = data
        self.params = params
        actual_params = default_parameters.copy()
        actual_params.update(**params)
        for k, v in actual_params.iteritems():
            setattr(self, k, v)
            if log_prefix=='':
                self.log('info', '%s = %s' % (k, v), suffix='initial_parameters')
            
    def log(self, level, msg, suffix=None):
        if suffix is not None:
            if self.log_prefix=='':
                name = suffix
            else:
                name = self.log_prefix+'.'+suffix
        else:
            name = self.log_prefix
        log_message(level, msg, name=name)
            
    def copy(self, log_prefix='kk_copy'):
{'fraction_non_alphanumeric': 0.08657047724750278, 'fraction_numerical': 0.014983351831298557, 'mean_word_length': 2.843283582089552, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2100565', 'n_tokens_mistral': 1167, 'n_tokens_neox': 1135, 'n_words': 272}