def testFactorsAreCorrectlyUpdated(self): pmf = Pmf(numTopics=3, lamb=0.5, gamma=0.25) factors1 = np.array([4, 2, 3]) factors2 = np.array([5, 2, 1]) updatedFactors = pmf._updateFactors(factors1, factors2, 3) self.assertListEqual([7.25, 3.25, 3.375], updatedFactors.tolist())
def testFactorsRemainsUnchangedIfGammaIsZero(self): pmf = Pmf(numTopics=3, lamb=0.5, gamma=0) factors1 = np.array([1, 2, 3]) factors2 = np.array([4, 5, 6]) updatedFactors = pmf._updateFactors(factors1, factors2, -5) self.assertListEqual([1, 2, 3], updatedFactors.tolist())
def testFactorsAreCorrectlyUpdatedWhenLambdaIsZero(self): pmf = Pmf(numTopics=3, lamb=0, gamma=0.5) factors1 = np.array([1, 2, 3]) factors2 = np.array([2, 1, 2]) updatedFactors = pmf._updateFactors(factors1, factors2, 2) self.assertListEqual([3, 3, 5], updatedFactors.tolist())
def MakeCdfFromList(seq, name=''): """Creates a CDF from an unsorted sequence. Args: seq: unsorted sequence of sortable values name: string name for the cdf Returns: Cdf object """ hist = Pmf.MakeHistFromList(seq) return MakeCdfFromHist(hist, name)
import numpy as np from pmf import Pmf rows = 15 cols = 15 x = np.random.random_integers(1, 5, size=(rows, cols)) y = np.random.uniform(0, 1, size=(rows, cols)) # sparsity z = y < 0.10 user_rating_mat = np.multiply(x, z) t = Pmf() t.x = user_rating_mat t.k = 10 t.pmf() print(t.P) print(t.x)
def testBiasIsCorrectlyUpdated(self): pmf = Pmf(numTopics=1, lamb=0.25, gamma=0.5) updatedBias = pmf._updateBias(8, 4) self.assertEqual(9, updatedBias)
def testBiasIsCorrectlyUpdatedWhenLambdaIsZero(self): pmf = Pmf(numTopics=1, lamb=0, gamma=0.5) updatedBias = pmf._updateBias(10, 4) self.assertEqual(12, updatedBias)
def testBiasRemainsUnchangedIfGammaIsZero(self): pmf = Pmf(numTopics=1, lamb=0.5, gamma=0) updatedBias = pmf._updateBias(12, -5) self.assertEqual(12, updatedBias)
def setUp(self): pmf = Pmf(numTopics=4, lamb=0.1, gamma=0.2) self.model = pmf.train(ratings=None, numRows=2, numCols=3, maxIterations=0)