Ejemplo n.º 1
0
 def fit(self, X, Y):
     self.__initialize(X, Y)
     xi = self.xi
     t = 0
     while t < self.iterations:
         #Caculate weight matrix
         w = self._eta*np.power(-np.log(self._eta), xi+1)
         W = np.diag(w)
         #Z is used for updating beta
         tmp = GEVFunc.derivLink(xi, self._eta)
         Z = self._v + self._gamma \
                     *tmp \
                     *(Y - self._eta)
         #Update beta
         mat = np.matrix(X.T.dot(W).dot(X)) \
                 + np.eye(X.shape[1])*self.regular
         #self._beta = mat.I.dot(X.T).dot(W).dot(Z).getA1()
         self._beta = np.linalg.pinv(mat).dot(X.T).dot(W).dot(Z).getA1()
         #Calculate v
         self._v = X.dot(self._beta)
         GEVFunc.clip(xi, self._v)
         #Judge if eta is convergent
         newEta = GEVFunc.inverseLink2(xi, self._v)
         if np.abs(newEta - self._eta).sum() < self.tol:
             self._eta = newEta
             break
         self._eta = newEta
         t += 1