Best Python code snippet using pandera_python
shermann.py
Source:shermann.py  
1#!/usr/bin/env python2.72import numpy as np3from numpy import linalg4import time5method = 'HybridUCB'6class HybridUCB:7    def __init__(self):8        self.article_features = {}9        # upper bound coefficient10        self.alpha = 3 #1 + np.sqrt(np.log(2/delta)/2)11        r1 = 20.12        r0 = -0.513        self.r = (r0, r1)14        # dimension of user features = d15        self.d = 516        # dimension of article features = k17        self.k = self.d*self.d18        # A0 : matrix to compute hybrid part, k*k19        self.A0 = np.identity(self.k)20        self.A0I = np.identity(self.k)21        # b0 : vector to compute hybrid part, k22        self.b0 = np.zeros((self.k, 1))23        # Aa : collection of matrix to compute disjoint part for each article a, d*d24        self.Aa = {}25        # AaI : collection of matrix to compute disjoint part for each article a, d*d26        self.AaI = {}27        # Ba : collection of matrix to compute hybrid part, d*k28        self.Ba = {}29        # BaT : collection of matrix to compute hybrid part, d*k30        self.BaT = {}31        # ba : collection of vectors to compute disjoin part, d*132        self.ba = {}33        self.updateCycle = 1034        self.lastUp = 035        # other dicts to speed up computation36        self.AaIba = {}37        self.AaIBa = {}38        self.BaTAaI = {}39        self.theta = {}40        #additional stuff that is computated in the update function instead of recommend41	self.A0IBaTAaI = {}42        self.A0IBaA0IBaTAaI = {}43        self.lastart = []44        self.beta = np.zeros((self.k, 1))45        self.index = {}46        self.a_max = 047        self.z = None48        self.zT = None49        self.xaT = None50        self.xa = None51    # Evaluator will call this function and pass the article features.52    # Check evaluator.py description for details.53    def set_articles(self, art):54        # init collection of matrix/vector Aa, Ba, ba55        i = 056        art_len = len(art)57        self.art = art58        self.article_features = np.zeros((art_len, 1, self.d))59        self.Aa = np.zeros((art_len, self.d, self.d))60        self.AaI = np.zeros((art_len, self.d, self.d))61        self.Ba = np.zeros((art_len, self.d, self.k))62        self.BaT = np.zeros((art_len, self.k, self.d))63        self.ba = np.zeros((art_len, self.d, 1))64        self.AaIba = np.zeros((art_len, self.d, 1))65        self.AaIBa = np.zeros((art_len, self.d, self.k))66        self.BaTAaI = np.zeros((art_len, self.k, self.d))67        self.A0IBaTAaI = np.zeros((art_len, self.k, self.d))68        self.A0IBaA0IBaTAaI = np.zeros((art_len, self.d, self.d))69        self.theta = np.zeros((art_len, self.d, 1))70        for key in art:71            self.index[key] = i72            self.article_features[i] = art[key]73            self.Aa[i] = np.identity(self.d)74            self.AaI[i] = np.identity(self.d)75            self.Ba[i] = np.zeros((self.d, self.k))76            self.BaT[i] = np.zeros((self.k, self.d))77            self.ba[i] = np.zeros((self.d, 1))78            self.AaIba[i] = np.zeros((self.d, 1))79            self.AaIBa[i] = np.zeros((self.d, self.k))80            self.BaTAaI[i] = np.zeros((self.k, self.d))81            self.A0IBaTAaI[i] = np.zeros((self.k, self.d))82            self.A0IBaA0IBaTAaI[i] = np.zeros((self.d, self.d))83            self.theta[i] = np.zeros((self.d, 1))84            i += 185    # This function will be called by the evaluator.86    # Check task description for details.87    def update(self, reward):88        global ttime89        #print reward90        if reward == -1:91             pass92        else:93            r = self.r[reward]94            self.A0 += np.dot(self.BaTAaI[self.a_max], self.Ba[self.a_max])95            self.b0 += np.dot(self.BaTAaI[self.a_max], self.ba[self.a_max])96            self.Aa[self.a_max] += np.dot(self.xa, self.xaT)97            B = np.divide(98                np.dot(np.dot(self.AaI[self.a_max], np.dot(self.xa, self.xaT)), self.AaI[self.a_max]),99                (1 + np.dot(np.dot(self.xaT, self.AaI[self.a_max]), self.xa)))100            self.AaI[self.a_max] = self.AaI[self.a_max] - B101            self.Ba[self.a_max] += np.dot(self.xa, self.zT)102            self.BaT[self.a_max] = np.transpose(self.Ba[self.a_max])103            self.ba[self.a_max] += r * self.xa104            self.AaIba[self.a_max] = np.dot(self.AaI[self.a_max], self.ba[self.a_max])105            self.AaIBa[self.a_max] = np.dot(self.AaI[self.a_max], self.Ba[self.a_max])106            self.BaTAaI[self.a_max] = np.dot(self.BaT[self.a_max], self.AaI[self.a_max])107            self.A0 += np.dot(self.z, self.zT) - np.dot(self.BaTAaI[self.a_max], self.Ba[self.a_max])108            self.b0 += r * self.z - np.dot(self.BaT[self.a_max], np.dot(self.AaI[self.a_max], self.ba[self.a_max]))109            #change to LSG?110            self.A0I = linalg.inv(self.A0)111            self.beta = np.dot(self.A0I, self.b0)112            #self.beta = linalg.solve(self.A0, self.b0)113            # if not np.array_equal(beta1, self.beta.all):114            #     print115            self.A0IBaTAaI[self.a_max] = np.dot(self.A0I,self.BaTAaI[self.a_max])116            self.A0IBaA0IBaTAaI[self.a_max] = np.dot(self.AaIBa[self.a_max],self.A0IBaTAaI[self.a_max])117            #do this here !!!!!118            #self.lastUp = self.lastUp + 1119            #if self.lastUp > self.updateCycle:120                 #self.matrixUpdate()121                 #self.lastUp = 0122            123            self.theta = self.AaIba - np.dot(self.AaIBa, self.beta)#self.AaI[article].dot(self.ba[article] - self.Ba[article].dot(self.beta))124            self.lastart = []125    def matrixUpdate(self):126          #global ttime127          #ttime = ttime - time.time()128          for ind in range(self.BaTAaI.shape[0]):129                #print self.A0IBaTAaI130                self.A0IBaTAaI[ind] = np.dot(self.A0I,self.BaTAaI[ind])131                self.A0IBaA0IBaTAaI[ind] = np.dot(self.AaIBa[ind],self.A0IBaTAaI[ind])132          #ttime = ttime + time.time()133    # This function will be called by the evaluator.134    # Check task description for details.135	# Use vectorized code to increase speed136    def recommend(self, timestamp, user_features, articles):137        global ttime138        article_len = len(articles)139        # za : feature of current user/article combination, k*1140        self.xaT = np.array([user_features])141        self.xa = np.transpose(self.xaT)142        # recommend using hybrid ucb143        # fast vectorized for loops144        index = [self.index[article] for article in articles]145        ttime = ttime - time.time()146        if cmp(self.lastart,index)!=0:147            self.article_features_tmp = self.article_features[index]148            #preprocess matrices149            self.preA0IBaA0IBaTAaI=self.A0IBaA0IBaTAaI[index]150            self.preAaI = self.AaI[index]151            self.preA0IBaTAaI = self.A0IBaTAaI[index]152            self.preTheta = self.theta[index]153            self.lastart = index154            155        ttime = ttime + time.time()156        zaT_tmp = np.einsum('i,j', self.article_features_tmp.reshape(-1), user_features).reshape(article_len, 1, self.k)157	#print zaT_tmp.shape158        za_tmp = np.transpose(zaT_tmp, (0,2,1))#np.transpose(zaT_tmp,(0,2,1))159        A0IBaTAaIxa_tmp = np.dot(self.preA0IBaTAaI, self.xa)160        #looks good :)161        #print A0IBaTAaIxa_tmp1-A0IBaTAaIxa_tmp162        A0Iza_tmp = np.transpose(np.dot(zaT_tmp, np.transpose(self.A0I)), (0,2,1)) # (20, 36, 1)163        A0Iza_diff_2A0IBaTAaIxa_tmp = A0Iza_tmp - 2*A0IBaTAaIxa_tmp164        sa_1_tmp = np.sum(za_tmp.reshape(article_len,self.k,1,1)*A0Iza_diff_2A0IBaTAaIxa_tmp.reshape(article_len, self.k,1,1),-3)165        #ttime = ttime - time.time()166        AaIxa_add_AaIBaA0IBaTAaIxa_tmp = np.dot(self.preAaI, self.xa) + np.dot(self.preA0IBaA0IBaTAaI,self.xa)167        #ttime = ttime + time.time()168	#print AaIxa_add_AaIBaA0IBaTAaIxa_tmp - AaIxa_add_AaIBaA0IBaTAaIxa_tmp1169	sa_2_tmp = np.transpose(np.dot(np.transpose(AaIxa_add_AaIBaA0IBaTAaIxa_tmp,(0,2,1)),self.xa),(0,2,1))170        sa_tmp = sa_1_tmp + sa_2_tmp171        xaTtheta_tmp = np.transpose(np.dot(np.transpose(self.preTheta,(0,2,1)),self.xa),(0,2,1))172        max_index = np.argmax(np.dot(zaT_tmp, self.beta) + xaTtheta_tmp + self.alpha * np.sqrt(sa_tmp))173        self.z = za_tmp[max_index]174        self.zT = zaT_tmp[max_index]175        art_max = index[max_index]176        # article index with largest UCB177        # global a_max, entries178        self.a_max = art_max179       # return np.random.choice(articles)180        return articles[max_index]181algorithms = {182    'HybridUCB': HybridUCB()183}184algorithm = algorithms[method]185set_articles = algorithm.set_articles186update = algorithm.update187ttime = 0...example.py
Source:example.py  
1#!/usr/bin/env python2.72import numpy as np3from numpy import linalg4method = 'HybridUCB'5combcut = 06artcut = 07usercut = 08class HybridUCB:9    def __init__(self):10        self.article_features = {}11        # upper bound coefficient12        self.alpha = 3 #1 + np.sqrt(np.log(2/delta)/2)13        r1 = 20.14        r0 = -0.515        self.r = (r0, r1)16        # dimension of user features = d17        self.d = 618        # dimension of article features = k19        self.k = self.d*self.d-combcut20	print self.k21	#select subset of features22	ind = np.arange(self.d*self.d)23	np.random.shuffle(ind)24	self.scols = ind[:self.k]25	print self.scols26        # A0 : matrix to compute hybrid part, k*k27        self.A0 = np.identity(self.k)28        self.A0I = np.identity(self.k)29        # b0 : vector to compute hybrid part, k30        self.b0 = np.zeros((self.k, 1))31        # Aa : collection of matrix to compute disjoint part for each article a, d*d32        self.Aa = {}33        # AaI : collection of matrix to compute disjoint part for each article a, d*d34        self.AaI = {}35        # Ba : collection of matrix to compute hybrid part, d*k36        self.Ba = {}37        # BaT : collection of matrix to compute hybrid part, d*k38        self.BaT = {}39        # ba : collection of vectors to compute disjoin part, d*140        self.ba = {}41        # other dicts to speed up computation42        self.AaIba = {}43        self.AaIBa = {}44        self.BaTAaI = {}45        self.theta = {}46        self.beta = np.zeros((self.k, 1))47        self.index = {}48        self.a_max = 049        self.z = None50        self.zT = None51        self.xaT = None52        self.xa = None53    # Evaluator will call this function and pass the article features.54    # Check evaluator.py description for details.55    def set_articles(self, art):56        # init collection of matrix/vector Aa, Ba, ba57        i = 058        art_len = len(art)59        self.article_features = np.zeros((art_len, 1, self.d))60        self.Aa = np.zeros((art_len, self.d, self.d))61        self.AaI = np.zeros((art_len, self.d, self.d))62        self.Ba = np.zeros((art_len, self.d, self.k))63        self.BaT = np.zeros((art_len, self.k, self.d))64        self.ba = np.zeros((art_len, self.d, 1))65        self.AaIba = np.zeros((art_len, self.d, 1))66        self.AaIBa = np.zeros((art_len, self.d, self.k))67        self.BaTAaI = np.zeros((art_len, self.k, self.d))68        self.theta = np.zeros((art_len, self.d, 1))69        for key in art:70            self.index[key] = i71            self.article_features[i] = art[key]72            self.Aa[i] = np.identity(self.d)73            self.AaI[i] = np.identity(self.d)74            self.Ba[i] = np.zeros((self.d, self.k))75            self.BaT[i] = np.zeros((self.k, self.d))76            self.ba[i] = np.zeros((self.d, 1))77            self.AaIba[i] = np.zeros((self.d, 1))78            self.AaIBa[i] = np.zeros((self.d, self.k))79            self.BaTAaI[i] = np.zeros((self.k, self.d))80            self.theta[i] = np.zeros((self.d, 1))81            i += 182    # This function will be called by the evaluator.83    # Check task description for details.84    def update(self, reward):85        #print reward86        if reward == -1:87             pass88        else:89            r = self.r[reward]90            self.A0 += np.dot(self.BaTAaI[self.a_max], self.Ba[self.a_max])91            self.b0 += np.dot(self.BaTAaI[self.a_max], self.ba[self.a_max])92            self.Aa[self.a_max] += np.dot(self.xa, self.xaT)93            B = np.divide(94                np.dot(np.dot(self.AaI[self.a_max], np.dot(self.xa, self.xaT)), self.AaI[self.a_max]),95                (1 + np.dot(np.dot(self.xaT,self.AaI[self.a_max]),self.xa)))96            self.AaI[self.a_max] = self.AaI[self.a_max] - B97            #A = linalg.inv(self.Aa[self.a_max])98            self.Ba[self.a_max] += np.dot(self.xa, self.zT)99            self.BaT[self.a_max] = np.transpose(self.Ba[self.a_max])100            self.ba[self.a_max] += r * self.xa101            self.AaIba[self.a_max] = np.dot(self.AaI[self.a_max], self.ba[self.a_max])102            self.AaIBa[self.a_max] = np.dot(self.AaI[self.a_max], self.Ba[self.a_max])103            self.BaTAaI[self.a_max] = np.dot(self.BaT[self.a_max], self.AaI[self.a_max])104            self.A0 += np.dot(self.z, self.zT) - np.dot(self.BaTAaI[self.a_max], self.Ba[self.a_max])105            self.b0 += r * self.z - np.dot(self.BaT[self.a_max], np.dot(self.AaI[self.a_max], self.ba[self.a_max]))106            self.A0I = linalg.inv(self.A0)107            self.beta = np.dot(self.A0I, self.b0)108            self.theta = self.AaIba - np.dot(self.AaIBa, self.beta)#self.AaI[article].dot(self.ba[article] - self.Ba[article].dot(self.beta))109    # This function will be called by the evaluator.110    # Check task description for details.111	# Use vectorized code to increase speed112    def recommend(self, timestamp, user_features, articles):113        article_len = len(articles)114        # za : feature of current user/article combination, k*1115        self.xaT = np.array([user_features])116        self.xa = np.transpose(self.xaT)117        # recommend using hybrid ucb118        # fast vectorized for loops119        index = [self.index[article] for article in articles]120        article_features_tmp = self.article_features[index]121        #zaT_tmp = np.einsum('i,j', article_features_tmp.reshape(-1), user_features).reshape(article_len, 1, self.k)122	#use different features123	#print "test"124	#print article_features_tmp.shape125	#print self.scols126	zaT_tmp = np.einsum('i,j', article_features_tmp.reshape(-1), user_features).reshape(article_len, 1, self.d*self.d)[:,:,self.scols]127	#print zaT_tmp.shape128	za_tmp = np.transpose(zaT_tmp, (0,2,1))#np.transpose(zaT_tmp,(0,2,1))129        #np.dot(self.A0I, np.dot(BaTAaI_tmp, self.xa)) (20, 36, 1)130        A0IBaTAaIxa_tmp = np.transpose(np.dot(np.transpose(np.dot(self.BaTAaI[index], self.xa), (0,2,1)), np.transpose(self.A0I)), (0,2,1))131        A0Iza_tmp = np.transpose(np.dot(zaT_tmp, np.transpose(self.A0I)), (0,2,1)) # (20, 36, 1)132        A0Iza_diff_2A0IBaTAaIxa_tmp = A0Iza_tmp - 2*A0IBaTAaIxa_tmp133        # np.dot(zaT_tmp, A0Iza_diff_2A0IBaTAaIxa_tmp), (20, 1, 1)134        sa_1_tmp = np.sum(za_tmp.reshape(article_len,self.k,1,1)*A0Iza_diff_2A0IBaTAaIxa_tmp.reshape(article_len, self.k,1,1),-3)135        # np.dot(AaIBa_tmp, A0IBaTAaIxa_tmp)136        AaIxa_add_AaIBaA0IBaTAaIxa_tmp = np.dot(self.AaI[index], self.xa) + np.sum(np.transpose(self.AaIBa[index], (0,2,1)).reshape(article_len, self.k,self.d,1)*A0IBaTAaIxa_tmp.reshape(article_len,self.k,1,1),-3)137        sa_2_tmp = np.transpose(np.dot(np.transpose(AaIxa_add_AaIBaA0IBaTAaIxa_tmp,(0,2,1)),self.xa),(0,2,1))138        sa_tmp = sa_1_tmp + sa_2_tmp139        # np.dot(self.xaT, self.theta[article])140        xaTtheta_tmp = np.transpose(np.dot(np.transpose(self.theta[index],(0,2,1)),self.xa),(0,2,1))141        max_index = np.argmax(np.dot(zaT_tmp, self.beta) + xaTtheta_tmp + self.alpha * np.sqrt(sa_tmp))142        self.z = za_tmp[max_index]143        self.zT = zaT_tmp[max_index]144        art_max = index[max_index]145        # article index with largest UCB146        # global a_max, entries147        self.a_max = art_max148       # return np.random.choice(articles)149        return articles[max_index]150algorithms = {151    'HybridUCB': HybridUCB()152}153algorithm = algorithms[method]154set_articles = algorithm.set_articles155update = algorithm.update...shermannold.py
Source:shermannold.py  
1#!/usr/bin/env python2.72import numpy as np3from numpy import linalg4method = 'HybridUCB'5class HybridUCB:6    def __init__(self):7        self.article_features = {}8        # upper bound coefficient9        self.alpha = 3 #1 + np.sqrt(np.log(2/delta)/2)10        r1 = 20.11        r0 = -0.512        self.r = (r0, r1)13        # dimension of user features = d14        self.d = 615        # dimension of article features = k16        self.k = self.d*self.d17        # A0 : matrix to compute hybrid part, k*k18        self.A0 = np.identity(self.k)19        self.A0I = np.identity(self.k)20        # b0 : vector to compute hybrid part, k21        self.b0 = np.zeros((self.k, 1))22        # Aa : collection of matrix to compute disjoint part for each article a, d*d23        self.Aa = {}24        # AaI : collection of matrix to compute disjoint part for each article a, d*d25        self.AaI = {}26        # Ba : collection of matrix to compute hybrid part, d*k27        self.Ba = {}28        # BaT : collection of matrix to compute hybrid part, d*k29        self.BaT = {}30        # ba : collection of vectors to compute disjoin part, d*131        self.ba = {}32        # other dicts to speed up computation33        self.AaIba = {}34        self.AaIBa = {}35        self.BaTAaI = {}36        self.theta = {}37        self.beta = np.zeros((self.k, 1))38        self.index = {}39        self.a_max = 040        self.z = None41        self.zT = None42        self.xaT = None43        self.xa = None44    # Evaluator will call this function and pass the article features.45    # Check evaluator.py description for details.46    def set_articles(self, art):47        # init collection of matrix/vector Aa, Ba, ba48        i = 049        art_len = len(art)50        self.article_features = np.zeros((art_len, 1, self.d))51        self.Aa = np.zeros((art_len, self.d, self.d))52        self.AaI = np.zeros((art_len, self.d, self.d))53        self.Ba = np.zeros((art_len, self.d, self.k))54        self.BaT = np.zeros((art_len, self.k, self.d))55        self.ba = np.zeros((art_len, self.d, 1))56        self.AaIba = np.zeros((art_len, self.d, 1))57        self.AaIBa = np.zeros((art_len, self.d, self.k))58        self.BaTAaI = np.zeros((art_len, self.k, self.d))59        self.theta = np.zeros((art_len, self.d, 1))60        for key in art:61            self.index[key] = i62            self.article_features[i] = art[key]63            self.Aa[i] = np.identity(self.d)64            self.AaI[i] = np.identity(self.d)65            self.Ba[i] = np.zeros((self.d, self.k))66            self.BaT[i] = np.zeros((self.k, self.d))67            self.ba[i] = np.zeros((self.d, 1))68            self.AaIba[i] = np.zeros((self.d, 1))69            self.AaIBa[i] = np.zeros((self.d, self.k))70            self.BaTAaI[i] = np.zeros((self.k, self.d))71            self.theta[i] = np.zeros((self.d, 1))72            i += 173    # This function will be called by the evaluator.74    # Check task description for details.75    def update(self, reward):76        #print reward77        if reward == -1:78             pass79        else:80            r = self.r[reward]81            self.A0 += np.dot(self.BaTAaI[self.a_max], self.Ba[self.a_max])82            self.b0 += np.dot(self.BaTAaI[self.a_max], self.ba[self.a_max])83            self.Aa[self.a_max] += np.dot(self.xa, self.xaT)84            B = np.divide(85                np.dot(np.dot(self.AaI[self.a_max], np.dot(self.xa, self.xaT)), self.AaI[self.a_max]),86                (1 + np.dot(np.dot(self.xaT, self.AaI[self.a_max]), self.xa)))87            self.AaI[self.a_max] = self.AaI[self.a_max] - B88            self.Ba[self.a_max] += np.dot(self.xa, self.zT)89            self.BaT[self.a_max] = np.transpose(self.Ba[self.a_max])90            self.ba[self.a_max] += r * self.xa91            self.AaIba[self.a_max] = np.dot(self.AaI[self.a_max], self.ba[self.a_max])92            self.AaIBa[self.a_max] = np.dot(self.AaI[self.a_max], self.Ba[self.a_max])93            self.BaTAaI[self.a_max] = np.dot(self.BaT[self.a_max], self.AaI[self.a_max])94            self.A0 += np.dot(self.z, self.zT) - np.dot(self.BaTAaI[self.a_max], self.Ba[self.a_max])95            self.b0 += r * self.z - np.dot(self.BaT[self.a_max], np.dot(self.AaI[self.a_max], self.ba[self.a_max]))96            #change to LSG?97            self.A0I = linalg.inv(self.A0)98            self.beta = np.dot(self.A0I, self.b0)99            #self.beta = linalg.solve(self.A0, self.b0)100            # if not np.array_equal(beta1, self.beta.all):101            #     print102            self.theta = self.AaIba - np.dot(self.AaIBa, self.beta)#self.AaI[article].dot(self.ba[article] - self.Ba[article].dot(self.beta))103    # This function will be called by the evaluator.104    # Check task description for details.105	# Use vectorized code to increase speed106    def recommend(self, timestamp, user_features, articles):107        article_len = len(articles)108        # za : feature of current user/article combination, k*1109        self.xaT = np.array([user_features])110        self.xa = np.transpose(self.xaT)111        # recommend using hybrid ucb112        # fast vectorized for loops113        index = [self.index[article] for article in articles]114        article_features_tmp = self.article_features[index]115        zaT_tmp = np.einsum('i,j', article_features_tmp.reshape(-1), user_features).reshape(article_len, 1, self.k)116        za_tmp = np.transpose(zaT_tmp, (0,2,1))#np.transpose(zaT_tmp,(0,2,1))117        #np.dot(self.A0I, np.dot(BaTAaI_tmp, self.xa)) (20, 36, 1)118        A0IBaTAaIxa_tmp = np.transpose(np.dot(np.transpose(np.dot(self.BaTAaI[index], self.xa), (0,2,1)), np.transpose(self.A0I)), (0,2,1))119        A0Iza_tmp = np.transpose(np.dot(zaT_tmp, np.transpose(self.A0I)), (0,2,1)) # (20, 36, 1)120        A0Iza_diff_2A0IBaTAaIxa_tmp = A0Iza_tmp - 2*A0IBaTAaIxa_tmp121        # np.dot(zaT_tmp, A0Iza_diff_2A0IBaTAaIxa_tmp), (20, 1, 1)122        sa_1_tmp = np.sum(za_tmp.reshape(article_len,self.k,1,1)*A0Iza_diff_2A0IBaTAaIxa_tmp.reshape(article_len, self.k,1,1),-3)123        # np.dot(AaIBa_tmp, A0IBaTAaIxa_tmp)124        AaIxa_add_AaIBaA0IBaTAaIxa_tmp = np.dot(self.AaI[index], self.xa) + np.sum(np.transpose(self.AaIBa[index], (0,2,1)).reshape(article_len, self.k,self.d,1)*A0IBaTAaIxa_tmp.reshape(article_len,self.k,1,1),-3)125        sa_2_tmp = np.transpose(np.dot(np.transpose(AaIxa_add_AaIBaA0IBaTAaIxa_tmp,(0,2,1)),self.xa),(0,2,1))126        sa_tmp = sa_1_tmp + sa_2_tmp127        # np.dot(self.xaT, self.thea[article])128        xaTtheta_tmp = np.transpose(np.dot(np.transpose(self.theta[index],(0,2,1)),self.xa),(0,2,1))129        max_index = np.argmax(np.dot(zaT_tmp, self.beta) + xaTtheta_tmp + self.alpha * np.sqrt(sa_tmp))130        self.z = za_tmp[max_index]131        self.zT = zaT_tmp[max_index]132        art_max = index[max_index]133        # article index with largest UCB134        # global a_max, entries135        self.a_max = art_max136       # return np.random.choice(articles)137        return articles[max_index]138algorithms = {139    'HybridUCB': HybridUCB()140}141algorithm = algorithms[method]142set_articles = algorithm.set_articles143update = algorithm.update...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
