def sslim_train(A, B, l1_reg=0.001, l2_reg=0.0001): """ Computes W matrix of SLIM This link is useful to understand the parameters used: http://web.stanford.edu/~hastie/glmnet_matlab/intro.html Basically, we are using this: Sum( yi - B0 - xTB) + ... As: Sum( aj - 0 - ATwj) + ... Remember that we are wanting to learn wj. If you don't undestand this mathematical notation, I suggest you to read section III of: http://glaros.dtc.umn.edu/gkhome/slim/overview """ alpha = l1_reg+l2_reg l1_ratio = l1_reg/alpha model = SGDRegressor( penalty='elasticnet', fit_intercept=False, alpha=alpha, l1_ratio=l1_ratio ) # Following cSLIM proposal on creating an M' matrix = [ M, FT] # * alpha is used to control relative importance of the side information #Balpha = np.sqrt(alpha) * B Balpha = B Mline = vstack((A, Balpha), format='lil') # Fit each column of W separately. We put something in each positions of W # to allow us direct indexing of each position in parallel total_columns = Mline.shape[1] ranges = generate_slices(total_columns) separated_tasks = [] for from_j, to_j in ranges: separated_tasks.append([from_j, to_j, Mline, model]) pool = multiprocessing.Pool() pool.map(work, separated_tasks) pool.close() pool.join() return shared_array
def sslim_train(A, B, l1_reg=0.001, l2_reg=0.0001): """ Computes W matrix of SLIM This link is useful to understand the parameters used: http://web.stanford.edu/~hastie/glmnet_matlab/intro.html Basically, we are using this: Sum( yi - B0 - xTB) + ... As: Sum( aj - 0 - ATwj) + ... Remember that we are wanting to learn wj. If you don't undestand this mathematical notation, I suggest you to read section III of: http://glaros.dtc.umn.edu/gkhome/slim/overview """ alpha = l1_reg + l2_reg l1_ratio = l1_reg / alpha model = SGDRegressor(penalty='elasticnet', fit_intercept=False, alpha=alpha, l1_ratio=l1_ratio) # Following cSLIM proposal on creating an M' matrix = [ M, FT] # * alpha is used to control relative importance of the side information #Balpha = np.sqrt(alpha) * B Balpha = B Mline = vstack((A, Balpha), format='lil') # Fit each column of W separately. We put something in each positions of W # to allow us direct indexing of each position in parallel total_columns = Mline.shape[1] ranges = generate_slices(total_columns) separated_tasks = [] for from_j, to_j in ranges: separated_tasks.append([from_j, to_j, Mline, model]) pool = multiprocessing.Pool() pool.map(work, separated_tasks) pool.close() pool.join() return shared_array
def slim_train(A, l1_reg=0.001, l2_reg=0.0001): """ Computes W matrix of SLIM This link is useful to understand the parameters used: http://web.stanford.edu/~hastie/glmnet_matlab/intro.html Basically, we are using this: Sum( yi - B0 - xTB) + ... As: Sum( aj - 0 - ATwj) + ... Remember that we are wanting to learn wj. If you don't undestand this mathematical notation, I suggest you to read section III of: http://glaros.dtc.umn.edu/gkhome/slim/overview """ alpha = l1_reg+l2_reg l1_ratio = l1_reg/alpha model = SGDRegressor( penalty='elasticnet', fit_intercept=False, alpha=alpha, l1_ratio=l1_ratio, ) total_columns = A.shape[1] ranges = generate_slices(total_columns) separated_tasks = [] for from_j, to_j in ranges: separated_tasks.append([from_j, to_j, A, model]) pool = multiprocessing.Pool() pool.map(work, separated_tasks) pool.close() pool.join() return shared_array