Skip to content

Instantly share code, notes, and snippets.

source "https://rubygems.org"
gem "rails", "~> 4.2"
gem "rails_admin"
gem "pg"
% Experiments on 5% of the data
% Parralellisation 8 workers 4 cores with hyperthreading
>> tic; trainLFM(P, 10, 1, 1); toc
Elapsed time is 150.857689 seconds.
>> tic; trainLFM(P, 100, 1, 1); toc
Elapsed time is 2153.943994 seconds.
% Just threads
function [X,Y] = trainLFM(P, f, alpha, lambda)
%trainLFM Trains Latent Factor Model for CF with implicit feedback
% Takes a playcount matrix P and its parameters alpha and lambda.
% and uses the C_{u,s} = 1 + \alpha P_{u,s} as confidence model
[num_users, num_songs] = size(P);
% Initialize decomposisiton X and Y with values from 0 to 1
X = rand(num_users, f);
Y = rand(num_songs, f);
brazilian reggae
graz
black metal from netherlands
hardcore old school
worldwide electro elite
kc
blues based rock
dance island 2008
danish hip-hop
english lyrics
import sys
from collections import namedtuple
from collections import defaultdict
import numpy as np
import logging
from progress_bar import ProgressBar
ArtistTermFreq = namedtuple('ArtistTermFreq', ['artist_id', 'term', 'freq'])
class ArtistTermFreqIterator:
from collections import namedtuple
from collections import defaultdict
ArtistTermFreq = namedtuple('ArtistTermFreq', ['artist_id', 'term', 'freq'])
class ArtistTermFreqIterator:
def __init__(self, artist_term_file, artist_collection, term_collection):
self.term_file = artist_term_file
self.artist_indexes = self._create_artist_indexes(artist_collection)
self.track_index = self._create_track_reverse_mapping()
#!/usr/bin/env python3
import os
import sys
import tables
import numpy as np
from scipy import sparse
from scipy import io
from collections import defaultdict
from multiprocessing import Queue, Process
#!/usr/bin/env python3
import os
import sys
import tables
import numpy as np
TASTE_PROFILE_FILE = os.path.abspath(sys.argv[1])
TASTE_PROFILE_STATISTICS_FILE = os.path.abspath(sys.argv[2])
import re
import scipy.io
import scipy.linalg
import scipy.sparse.linalg;
import numpy
import matplotlib.pyplot
def relative_residual(U, z):
m, n = U.shape
return numpy.linalg.norm((numpy.eye(m) - U.dot(U.T)).dot(z)) / numpy.linalg.norm(z)
# Load data
import re
import scipy.io
import scipy.linalg
import scipy.sparse.linalg;
import numpy
import matplotlib.pyplot
def relative_residual(U, z):