<commit_before><commit_msg>Profile model selection <commit_after>import numpy
import logging
import sys
import scipy.sparse
from apgl.util.Sampling import Sampling 
from apgl.util.ProfileUtils import ProfileUtils
from exp.sandbox.recommendation.IterativeSoftImpute import IterativeSoftImpute
from exp.util.SparseUtils import SparseUtils

logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)

class IterativeSoftImputeProfile(object):
    def __init__(self):
        numpy.random.seed(21)        
        
        #Create a low rank matrix  
        n = 2000 
        m = 2000 
        self.r = 50 
        k = 10**3
        
        self.X = SparseUtils.generateSparseLowRank((n, m), self.r, k)
        print(self.X.nnz)
        
    def profileModelSelect(self):
        lmbdas = numpy.linspace(1.0, 0.01, 5)
        softImpute = IterativeSoftImpute(k=500)
        
        folds = 5
        cvInds = Sampling.randCrossValidation(folds, self.X.nnz)
        ProfileUtils.profile('softImpute.modelSelect(self.X, lmbdas, cvInds)', globals(), locals())

profiler = IterativeSoftImputeProfile()
profiler.profileModelSelect()
{'fraction_non_alphanumeric': 0.09139307897071872, 'fraction_numerical': 0.022182786157941437, 'mean_word_length': 3.0285714285714285, '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': '417314', 'n_tokens_mistral': 372, 'n_tokens_neox': 351, 'n_words': 74}