def main(train_file, user_sideinformation_file, test_file, normalize): A = tsv_to_matrix(train_file) B = tsv_to_matrix(user_sideinformation_file) if normalize: B = normalize_values(B) A, B = make_compatible(A, B) W = sslim_train(A, B) recommendations = slim_recommender(A, W) return compute_precision(recommendations, test_file)
def main(train_file, user_sideinformation_file, test_file, normalize): A = tsv_to_matrix(train_file) B = tsv_to_matrix(user_sideinformation_file) if normalize: B = normalize_values(B) A, B = make_compatible(A, B) W = sslim_train(A, B) save_matrix(W, 'sslim_oracle_wmatrix.tsv') recommendations = slim_recommender(A, W) precisions = compute_precision_as_an_oracle(recommendations, test_file) return precisions
def main(train_file, user_sideinformation_file, test_file): A = tsv_to_matrix(train_file) B = tsv_to_matrix(user_sideinformation_file) A, B = make_compatible(A, B) """ from util import mm2csr mm2csr(A, '/tmp/train.mat') mm2csr(useritem_featureitem, '/tmp/train_feature.mat') C = tsv_to_matrix(test_file) mm2csr(C, '/tmp/test.mat') """ W = sslim_train(A, B) recommendations = slim_recommender(A, W) compute_precision(recommendations, test_file)
train_file = args.train user_sideinformation_file = args.side_information output = args.output test_file = args.test beta = args.beta or 0.011 normalize = args.normalize fold = args.fold or 0 # Loading matrices A = tsv_to_matrix(train_file) B = tsv_to_matrix(user_sideinformation_file) if normalize: B = normalize_values(B) A, B = make_compatible(A, B) # Loading shared array to be used in results shared_array_base = multiprocessing.Array(ctypes.c_double, A.shape[1]**2) shared_array = np.ctypeslib.as_array(shared_array_base.get_obj()) shared_array = shared_array.reshape(A.shape[1], A.shape[1]) # We create a work function to fit each one of the columns of our W matrix, # because in SLIM each column is independent we can use make this work in # parallel def work(params, W=shared_array): from_j = params[0] to_j = params[1] M = params[2] model = params[3] counter = 0
import datetime from util import parse_args import simplejson as json print '>>> Start: %s' % datetime.datetime.now() args = parse_args(side_information=True, beta=True) # Loading matrices A = tsv_to_matrix(args.train) B = tsv_to_matrix(args.side_information) if args.normalize: B = normalize_values(B) A, B = make_compatible(A, B) # Loading shared array to be used in results shared_array_base = multiprocessing.Array(ctypes.c_double, A.shape[1]**2) shared_array = np.ctypeslib.as_array(shared_array_base.get_obj()) shared_array = shared_array.reshape(A.shape[1], A.shape[1]) # We create a work function to fit each one of the columns of our W matrix, # because in SLIM each column is independent we can use make this work in # parallel def work(params, W=shared_array): from_j = params[0] to_j = params[1] M = params[2] model = params[3]