Esempio n. 1
0
def test_calc():
    M = DotMap()
    M.PC = 40
    M.PEEP0 = 5
    M.RR = 18
    M.IT = 1
    M.Pbar = 760

    P1 = DotMap()
    P1.H = 140
    P1.W = 55
    P1.Cr = 15
    P1.PF = 100
    P1.HCO3 = 24
    P1.FGFO = 8
    P1.FGFA = 2
    P1.PEEP = 5

    P2 = DotMap()
    P2.H = 180
    P2.W = 70
    P2.Cr = 50
    P2.PF = 300
    P2.HCO3 = 24
    P2.FGFO = 1
    P2.FGFA = 8
    P2.PEEP = 5

    solver(M, P1, P2)
Esempio n. 2
0
    def convert_data(self, data):
        """
        Convert input data for torch
        :param data: input data
        :return: torch data
        """
        converted_data = DotMap()
        converted_data.num_nodes = data.num_nodes
        converted_data.neg_ratio = data.neg_ratio
        converted_data.H = torch.FloatTensor(data.H).to(self.device)

        # train data
        converted_data.train.edges = torch.from_numpy(data.train.X[:, 0:3]).to(
            self.device)
        nApT, nAmT = self.get_normalized_matrices(data.train.X, data.num_nodes)
        nApT = self.convert_torch_sparse(nApT, nApT.shape)
        nApT = (1 - self.c) * nApT
        converted_data.train.nApT = nApT.to(self.device)

        nAmT = self.convert_torch_sparse(nAmT, nAmT.shape)
        nAmT = (1 - self.c) * nAmT
        converted_data.train.nAmT = nAmT.to(self.device)

        y = np.asarray([1 if y_val > 0 else 0 for y_val in data.train.y])
        converted_data.train.y = torch.from_numpy(y).to(self.device)
        converted_data.class_weights = torch.from_numpy(
            data.class_weights).type(torch.float32).to(self.device)

        # test data
        converted_data.test.edges = torch.from_numpy(data.test.X[:, 0:2]).to(
            self.device)
        y = np.asarray([1 if y_val > 0 else 0 for y_val in data.test.y])
        converted_data.test.y = torch.from_numpy(y).to(self.device)

        return converted_data
Esempio n. 3
0
    def load(self, data_path, heldout_ratio=0.2):
        """
        Load data and split the data into training and test.

        :param data_path: path for dataset
        :param heldout_ratio: heldout ratio between training and test
        :return: loaded data
        """
        logger.info('Start loading the signed network...')

        X = np.loadtxt(data_path, dtype='int', delimiter='\t')
        y = X[:, 2]

        num_nodes = np.amax(X[:, 0:2]) + 1
        num_edges = X.shape[0]

        train_X, test_X, train_y, test_y = train_test_split(X, y,
                                                            test_size=heldout_ratio,
                                                            random_state=self.random_seed)


        logger.info('Start creating input features with random_seed: {}...'.format(self.random_seed))
        self.timer.tic()
        H = self.generate_input_features(train_X, num_nodes)

        gen_time = self.timer.tocvalue()
        logger.info('Generation input features completed in {:.4} sec'.format(gen_time))

        data = DotMap()
        data.train.X = train_X
        data.train.y = train_y
        data.test.X = test_X
        data.test.y = test_y
        data.H = H                   # input feature matrix
        data.num_nodes = num_nodes

        neg_idx = train_X[:, 2] < 0
        neg_ratio = train_X[neg_idx, :].shape[0] / float(train_X.shape[0])
        data.neg_ratio = neg_ratio
        data.class_weights = np.asarray([1.0, 1.0])

        return data