def fit(self, X, y, instances):
    test_instances = instances['test']
    validation_instances = instances['validation']
    train_instances = instances['train']
    time_ = 0
    self.model_time = 0
    n_train = X.shape[0]
    if self.validation:
        validation_list = []
    if self.full_row_rank:
        rows_to_be_removed = _remove_redundant_rows(self.A)
        A_torch = torch.from_numpy(np.delete(self.A, rows_to_be_removed, axis=0)).float()
    else:
        A_torch = torch.from_numpy(self.A).float()
    logging.info('shape of A {} shape of A-torch {}'.format(self.A.shape, A_torch.shape))
    X_torch = torch.from_numpy(X).float()
    y_torch = torch.from_numpy(y).float()
    logging.info('training started')
    for e in range(self.epochs):
        for i in range(self.num_instance):
            start_time = time.time()
            self.optimizer.zero_grad()
            (source, dest) = train_instances[i]
            if self.full_row_rank:
                b = np.zeros(len(self.A))
                b[source] = 1
                b[dest] = (- 1)
                b = np.delete(b, rows_to_be_removed)
                b_torch = torch.from_numpy(b).float()
            else:
                b_torch = torch.zeros(len(self.A))
                b_torch[source] = 1
                b_torch[dest] = (- 1)
            c_pred = self.net(X_torch).squeeze()
            x = IPOfunc(A_torch, b_torch, torch.Tensor(), torch.Tensor(), bounds=[(0.0, None)], max_iter=self.max_iter, mu0=self.mu0, thr=self.thr, method=self.method, smoothing=self.smoothing)(c_pred)
            loss = (y_torch * x).mean()
            loss.backward()
            self.optimizer.step()
            end_time = time.time()
            time_ += (end_time - start_time)
            if self.validation:
                if (((i + 1) % 20) == 0):
                    validation_list.append(validation_module(self.net, self.A, X, y, train_instances, validation_instances, test_instances, time_, e, i))
        print('Epoch {} Loss:{} Time: {:%Y-%m-%d %H:%M:%S}'.format((e + 1), loss.item(), datetime.datetime.now()))
    if self.validation:
        dd = defaultdict(list)
        for d in validation_list:
            for (key, value) in d.items():
                dd[key].append(value)
        df = pd.DataFrame.from_dict(dd)
        logging.info(('Completion Time %s \n' % str(datetime.datetime.now())))
        return df
def fit(self, X, y, instances):
    test_instances = instances['test']
    validation_instances = instances['validation']
    train_instances = instances['train']
    time_ = 0
    self.model_time = 0
    n_train = X.shape[0]
    if self.validation:
        validation_list = []
    if self.full_row_rank:
        rows_to_be_removed = _remove_redundant_rows(self.A)
        A_torch = torch.from_numpy(np.delete(self.A, rows_to_be_removed, axis=0)).float()
    else:
        A_torch = torch.from_numpy(self.A).float()
    logging.info('shape of A {} shape of A-torch {}'.format(self.A.shape, A_torch.shape))
    X_torch = torch.from_numpy(X).float()
    y_torch = torch.from_numpy(y).float()
    logging.info('training started')
    for e in range(self.epochs):
        for i in range(self.num_instance):
            start_time = time.time()
            self.optimizer.zero_grad()
            (source, dest) = train_instances[i]
            if self.full_row_rank:
                b = np.zeros(len(self.A))
                b[source] = 1
                b[dest] = (- 1)
                b = np.delete(b, rows_to_be_removed)
                b_torch = torch.from_numpy(b).float()
            else:
                b_torch = torch.zeros(len(self.A))
                b_torch[source] = 1
                b_torch[dest] = (- 1)
            c_pred = self.net(X_torch).squeeze()
            x = IPOfunc(A_torch, b_torch, torch.Tensor(), torch.Tensor(), bounds=[(0.0, None)], max_iter=self.max_iter, mu0=self.mu0, thr=self.thr, method=self.method, smoothing=self.smoothing)(c_pred)
            loss = (y_torch * x).mean()
            loss.backward()
            self.optimizer.step()
            end_time = time.time()
            time_ += (end_time - start_time)
            if self.validation:
                if (((i + 1) % 20) == 0):
                    validation_list.append(validation_module(self.net, self.A, X, y, train_instances, validation_instances, test_instances, time_, e, i))
        print('Epoch {} Loss:{} Time: {:%Y-%m-%d %H:%M:%S}'.format((e + 1), loss.item(), datetime.datetime.now()))
    if self.validation:
        dd = defaultdict(list)
        for d in validation_list:
            for (key, value) in d.items():
                dd[key].append(value)
        df = pd.DataFrame.from_dict(dd)
        logging.info(('Completion Time %s \n' % str(datetime.datetime.now())))
        return df