Пример #1
0
    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())
Пример #2
0
    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())
Пример #3
0
    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())
Пример #4
0
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)
Пример #5
0
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)
Пример #6
0
    def testBiasIsCorrectlyUpdated(self):
        pmf = Pmf(numTopics=1, lamb=0.25, gamma=0.5)

        updatedBias = pmf._updateBias(8, 4)

        self.assertEqual(9, updatedBias)
Пример #7
0
    def testBiasIsCorrectlyUpdatedWhenLambdaIsZero(self):
        pmf = Pmf(numTopics=1, lamb=0, gamma=0.5)

        updatedBias = pmf._updateBias(10, 4)

        self.assertEqual(12, updatedBias)
Пример #8
0
    def testBiasRemainsUnchangedIfGammaIsZero(self):
        pmf = Pmf(numTopics=1, lamb=0.5, gamma=0)

        updatedBias = pmf._updateBias(12, -5)

        self.assertEqual(12, updatedBias)
Пример #9
0
 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)