HBLR.py 文件源码

python
阅读 43 收藏 0 点赞 0 评论 0

项目:PersonalizedMultitaskLearning 作者: mitmedialab 项目源码 文件源码
def computeSMatrix(self):
        for m in range(self.n_tasks):
            task_X = self.task_dict[m]['X']
            task_Y = self.task_dict[m]['Y']
            task_xi = np.array(self.xi[m])

            for k in range(self.K):
                # Note that transposes are different because we are using different notation than in the paper - specifically we use row vectors where they are using column vectors

                # This does all data points (n) at once 
                inner = np.dot(np.atleast_2d(self.theta[k,:]).T, np.atleast_2d(self.theta[k,:])) + self.gamma[k]
                diag_entries = np.einsum('ij,ij->i', np.dot(task_X, inner), task_X)
                s_sum = -rhoFunction(task_xi)*diag_entries

                s_sum += ((task_Y.T - 0.5)* np.dot(np.atleast_2d(self.theta[k,:]), task_X.T))[0,:]
                s_sum += np.log(sigmoid(task_xi))
                s_sum += (-0.5)*task_xi
                s_sum += rhoFunction(task_xi)*(task_xi**2)

                s_sum = np.sum(s_sum)

                if k < self.K-1:
                    s_sum = s_sum + scipy.special.psi(self.small_phi1[k]) \
                                    - scipy.special.psi(self.small_phi1[k] + self.small_phi2[k])
                if k > 0:
                    for i in range(k):
                        s_sum = s_sum + scipy.special.psi(self.small_phi2[i]) \
                                    - scipy.special.psi(self.small_phi1[i] + self.small_phi2[i])


                self.s[m,k] = s_sum
        if self.debug: print "s:", self.s
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号