Ejemplo n.º 1
0
 def can_recommend(self, i):
     '''See if node i should be allowed to recommend the sp.'''
     p = self.Ts[i] >= self.params['trust_threshold']
     dist = f.d(self.current_c, self.crecv[i])
     tscale = self.Ts[i] * f.sigmoid_s(f.d(self.c[i], self.c_cached[i]))
     q = self.params['eta']**(dist + tscale) <= self.params['tau']
     return p or q
Ejemplo n.º 2
0
 def update_C(self, i):
     '''Update the aggregated context.'''
     self.C_cached[i] = self.C[i]
     cs = self.cs[
         i, 0:min(int(self.current_c[0]) + 1, self.params['zeta'] + 1)]
     if len(cs):
         dists = self.params['theta']**f.d(self.c[i], cs)
     else:
         dists = self.params['theta']**f.d(
             self.c[i], np.zeros(self.params['number_contexts']))
     self.C[i] = np.sum((dists * cs.T).T, axis=0) / np.sum(dists)
Ejemplo n.º 3
0
 def calc_T(self):
     '''Calculate the trust of sp.'''
     if self.ever_got_recs:
         idx = self.ever_got_recs
         dists = f.sigmoid_s(-f.d(self.current_c, self.use_c[idx]))
         ind_t = np.sum(self.QC[idx] * dists * self.R[idx] *
                        self.Ts[idx]) / np.sum(dists)
     else:
         ind_t = 0
     alpha = f.sigmoid(2 * np.abs(self.Tdir) /
                       dist if (dist := f.d(self.Tdir, ind_t)) > 0 else 0)
     beta = 1 - alpha
     self.T = alpha * self.Tdir + beta * ind_t
     return self.T
Ejemplo n.º 4
0
 def update_rep(self, i):
     '''Update the reputation.'''
     forget = self.params['eta']**f.d(self.c[i], self.C_cached[i])
     cached_comb = self.R_cached[i] * forget
     idx = list(set(self.got_recs) - {i})
     self.R_cached[i] = self.R[i]
     gradient = self.params['delta_r'] * sum(self.Ts[i] * self.Ts[idx])
     self.R[i] = np.clip(cached_comb + gradient, -1, 1)
Ejemplo n.º 5
0
 def update_QC(self, i):
     '''Update the quality of context.'''
     self.QC[i] = f.sigmoid_s(f.d(self.c[i], self.C[i]))