Example #1
0
    def fit(self, X, Y, T):  # X,Y, and T must be sorted by T beforehand
        self.t = T
        max_iter = 2000
        # print(max_iter)
        d = X.shape[1]
        self.w = np.zeros((d, 1))
        f_old = np.inf

        for i in range(max_iter):
            self.cumulative_h(X, Y)
            # h = self.h_estimator()

            def nloglf(w):
                return NpGlm.nlogl(w, None, self.H, X, Y, T)

            self.w, self.f = optimize(nloglf, self.w)

            # logging.info('%d\t%f' % (i, self.f / len(T)))
            # if self.conv is not None:
            #    self.conv.append((i, -self.f / len(T)))

            if abs(self.f - f_old) < 1e-3:
                break

            f_old = self.f
Example #2
0
    def fit(self, X, Y, T):
        X = augment(X)
        d = X.shape[1]
        max_iter = 2000
        self.w = np.zeros((d, 1))
        f_old = np.inf

        for i in range(max_iter):
            nloglw = lambda w: WblGlm.nloglw(w, self.a, X, Y, T)
            self.w, self.f = optimize(nloglw, self.w)

            nlogla = lambda a: WblGlm.nlogla(self.w, a, X, Y, T)
            self.a, self.f = optimize(nlogla, self.a)

            if abs(self.f - f_old) < 1e-4:
                break

            f_old = self.f
Example #3
0
 def fit(self, X, Y, T):
     X = augment(X)
     d = X.shape[1]
     self.w = np.zeros((d, 1))
     nloglw = lambda w: WblGlm.nloglw(w, self.a, X, Y, T)
     self.w, self.f = optimize(nloglw, self.w)