Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/AsyncLinUCB_AM.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ def getUCB(self, alpha, article_FeatureVector):
article_FeatureVector_g = article_FeatureVector[:self.d_g]
article_FeatureVector_l = article_FeatureVector[self.d_g:]
mean_g = np.dot(self.UserTheta_g, article_FeatureVector_g)
var_g = np.sqrt(np.dot(np.dot(article_FeatureVector_g, self.AInv_g), article_FeatureVector_g))
var_g = np.sqrt(np.linalg.multi_dot([article_FeatureVector_g, self.AInv_g, article_FeatureVector_g]))
mean_l = np.dot(self.UserTheta_l, article_FeatureVector_l)
var_l = np.sqrt(np.dot(np.dot(article_FeatureVector_l, self.AInv_l), article_FeatureVector_l))
var_l = np.sqrt(np.linalg.multi_dot([article_FeatureVector_l, self.AInv_l, article_FeatureVector_l]))
pta = mean_g + alpha_g * var_g + mean_l + alpha_l * var_l
return pta

Expand Down
2 changes: 1 addition & 1 deletion lib/CLUB.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def updateParametersofClusters(self,clusters,userID,Graph,users):

def getProb(self, alpha, article_FeatureVector,time):
mean = np.dot(self.CTheta, article_FeatureVector)
var = np.sqrt(np.dot(np.dot(article_FeatureVector, self.CAInv), article_FeatureVector))
var = np.sqrt(np.linalg.multi_dot([article_FeatureVector, self.CAInv, article_FeatureVector]))
pta = mean + alpha * var*np.sqrt(math.log10(time+1))
return pta

Expand Down
4 changes: 2 additions & 2 deletions lib/CoDBand.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def updateLocalUserModel(self, articlePicked_FeatureVector, click):
self.lambda_)

def getCB(self, x):
var = np.sqrt(np.dot(np.dot(x, self.AInv), x))
var = np.sqrt(np.linalg.multi_dot([x, self.AInv, x]))
if self.alpha != -1:
return self.alpha * var
else:
Expand Down Expand Up @@ -382,4 +382,4 @@ def getTheta(self, userID):
return self.globalModels[self.userID2globalModelIndex[userID]].Mean

if __name__ == '__main__':
pass
pass
2 changes: 1 addition & 1 deletion lib/DisLinUCB.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def getUCB(self, alpha, article_FeatureVector):
alpha = self.alpha_t

mean = np.dot(self.UserTheta, article_FeatureVector)
var = np.sqrt(np.dot(np.dot(article_FeatureVector, self.AInv), article_FeatureVector))
var = np.sqrt(np.linalg.multi_dot([article_FeatureVector, self.AInv, article_FeatureVector]))
pta = mean + alpha * var
return pta

Expand Down
8 changes: 4 additions & 4 deletions lib/DyClu.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def updateLocalUserModel(self, articlePicked_FeatureVector, click):
self.lambda_)

def getCB(self, x, useConstantAlpha = False):
var = np.sqrt(np.dot(np.dot(x, self.AInv), x))
var = np.sqrt(np.linalg.multi_dot([x, self.AInv, x]))
if useConstantAlpha:
return self.alpha * var
else:
Expand All @@ -109,7 +109,7 @@ def getInstantaneousBadness(self, articlePicked, click, method="ChiSquare"):
else:
mean = np.dot(self.UserThetaNoReg, x)
rewardEstimationError = (mean - click)**2
rewardEstimationErrorSTD = self.NoiseScale**2 * (1 + np.dot(np.dot(x, np.linalg.pinv(self.A-self.lambda_ * np.identity(n=self.d))), x))
rewardEstimationErrorSTD = self.NoiseScale**2 * (1 + np.linalg.multi_dot([x, np.linalg.pinv(self.A-self.lambda_ * np.identity(n=self.d)), x]))
df1 = 1

chiSquareStatistic = rewardEstimationError / rewardEstimationErrorSTD
Expand Down Expand Up @@ -164,7 +164,7 @@ def __init__(self, cluster):
self.lambda_)

def getCB(self, x, useConstantAlpha = False):
var = np.sqrt(np.dot(np.dot(x, self.AInv), x))
var = np.sqrt(np.linalg.multi_dot([x, self.AInv, x]))
if useConstantAlpha:
return self.alpha * var
else:
Expand Down Expand Up @@ -400,4 +400,4 @@ def resetUserConnectedness(self, userID):
self.user_graph[0:self.cur_userIndex, self.userID2userIndex[userID]] = 1

def getTheta(self, userID):
return self.users[userID].UserTheta
return self.users[userID].UserTheta
6 changes: 3 additions & 3 deletions lib/LinUCB.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,10 @@ def updateParameters(self, articlePicked_FeatureVector, click, userID):
def getProb(self, alpha, article_FeatureVector,userID):
x = article_FeatureVector
z = vectorize(np.outer(self.users[userID].userFeature, article_FeatureVector))
temp =np.dot(np.dot(np.dot( self.A_zInv , np.transpose( self.users[userID].B)) , self.users[userID].AInv), x )
temp =np.linalg.multi_dot([self.A_zInv , np.transpose( self.users[userID].B) , self.users[userID].AInv, x ])
mean = np.dot(self.users[userID].UserTheta, x)+ np.dot(self.beta, z)
s_t = np.dot(np.dot(z, self.A_zInv), z) + np.dot(np.dot(x, self.users[userID].AInv), x)
-2* np.dot(z, temp)+ np.dot(np.dot( np.dot(x, self.users[userID].AInv) , self.users[userID].B ) ,temp)
s_t = np.linalg.multi_dot([z, self.A_zInv, z]) + np.linalg.multi_dot([x, self.users[userID].AInv, x])
-2* np.dot(z, temp)+ np.linalg.multi_dot([x, self.users[userID].AInv , self.users[userID].B ,temp])

var = np.sqrt(s_t)
pta = mean + alpha * var
Expand Down
6 changes: 3 additions & 3 deletions lib/dLinUCB.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ def getProbInfo(self, alpha, article_FeatureVector):
if alpha == -1:
alpha = alpha = 0.1*np.sqrt(np.log(self.time+1))
mean = np.dot(self.UserTheta, article_FeatureVector)
var = np.sqrt(np.dot(np.dot(article_FeatureVector, self.AInv), article_FeatureVector))
var = np.sqrt(np.linalg.multi_dot([article_FeatureVector, self.AInv, article_FeatureVector]))
self.alpha_t = self.NoiseScale *np.sqrt(np.log(np.linalg.det(self.A)/float(self.sigma * self.lambda_) )) + np.sqrt(self.lambda_)
#pta = mean + alpha * var
return {'mean':mean, 'var':var, 'alpha':alpha, 'alpha_t':self.alpha_t}

def getProb_plot(self, alpha, article_FeatureVector):
mean = np.dot(self.UserTheta, article_FeatureVector)
var = np.sqrt(np.dot(np.dot(article_FeatureVector, self.AInv), article_FeatureVector))
var = np.sqrt(np.linalg.multi_dot([article_FeatureVector, self.AInv, article_FeatureVector]))
pta = mean + alpha * var
return pta, mean, alpha * var

Expand Down Expand Up @@ -154,7 +154,7 @@ def getSlavePredictionInfo(self, alpha, article_FeatureVector):
if alpha == -1:
alpha = alpha = 0.1*np.sqrt(np.log(self.time+1))
mean = np.dot(self.UserTheta, article_FeatureVector)
var = np.sqrt(np.dot(np.dot(article_FeatureVector, self.AInv), article_FeatureVector))
var = np.sqrt(np.linalg.multi_dot([article_FeatureVector, self.AInv, article_FeatureVector]))
# self.alpha_t = self.NoiseScale*np.sqrt(self.d* np.log( (self.lambda_ + self.update_num)/float(self.sigma * self.lambda_) )) + np.sqrt(self.lambda_)
self.alpha_t = self.NoiseScale ** 2 * np.sqrt(
self.d * np.log(1 + self.update_num / (self.d * self.lambda_)) + 2 * np.log(1 / self.delta_1)) + np.sqrt(
Expand Down
6 changes: 3 additions & 3 deletions lib/factorUCB.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def updateParameters(self, articles, clicks, userID):

self.UserTheta = matrixize(np.dot(self.AInv, self.b), len(articles[0].V))
self.CoTheta = np.dot(self.UserTheta, self.W)
self.CCA = np.dot(np.dot(self.BigW , self.AInv), np.transpose(self.BigW))
self.CCA = np.linalg.multi_dot([self.BigW , self.AInv, np.transpose(self.BigW)])

def getA(self):
return self.A
Expand All @@ -97,8 +97,8 @@ def getProb(self, alpha, alpha2, article, userID):
TempFeatureV = vectorize(TempFeatureM)

mean = np.dot(self.CoTheta.T[userID], article.V)
var = np.sqrt(np.dot(np.dot(TempFeatureV, self.CCA), TempFeatureV))
var2 = np.sqrt(np.dot(np.dot(self.CoTheta.T[userID][self.context_dimension:], article.A2Inv), self.CoTheta.T[userID][self.context_dimension:]))
var = np.sqrt(np.linalg.multi_dot([TempFeatureV, self.CCA, TempFeatureV]))
var2 = np.sqrt(np.linalg.multi_dot([self.CoTheta.T[userID][self.context_dimension:], article.A2Inv, self.CoTheta.T[userID][self.context_dimension:]]))
pta = mean + alpha * var + alpha2*var2
return pta
def getProb_plot(self, alpha, alpha2, article, userID):
Expand Down