Skip to content

Commit

Permalink
20200410
Browse files Browse the repository at this point in the history
  • Loading branch information
czifan committed Apr 10, 2020
0 parents commit 0ce33f4
Show file tree
Hide file tree
Showing 35 changed files with 861 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .idea/DeepSurv.pytorch.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

146 changes: 146 additions & 0 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added __pycache__/datasets.cpython-37.pyc
Binary file not shown.
Binary file added __pycache__/networks.cpython-37.pyc
Binary file not shown.
Binary file added __pycache__/utils.cpython-37.pyc
Binary file not shown.
13 changes: 13 additions & 0 deletions configs/gaussian.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[train]
h5_file = 'data/gaussian/gaussian_survival_data.h5'
epochs = 500
learning_rate = 3.194e-3
lr_decay_rate = 3.173e-4
optimizer = 'Adam'

[network]
drop = 0.401
norm = True
dims = [10, 17, 17, 17, 1]
activation = 'ReLU'
l2_reg = 0
13 changes: 13 additions & 0 deletions configs/gbsg.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[train]
h5_file = 'data/gbsg/gbsg_cancer_train_test.h5'
epochs = 500
learning_rate = 0.154
lr_decay_rate = 5.667e-3
optimizer = 'Adam'

[network]
drop = 0.661
norm = True
dims = [7, 8, 1]
activation = 'SELU'
l2_reg = 0
13 changes: 13 additions & 0 deletions configs/linear.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[train]
h5_file = 'data/linear/linear_survival_data.h5'
epochs = 500
learning_rate = 2.922e-3
lr_decay_rate = 3.579e-4
optimizer = 'Adam'

[network]
drop = 0.375
norm = True
dims = [10, 4, 1]
activation = 'SELU'
l2_reg = 0
13 changes: 13 additions & 0 deletions configs/metabric.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[train]
h5_file = 'data/metabric/metabric_IHC4_clinical_train_test.h5'
epochs = 500
learning_rate = 0.010
lr_decay_rate = 4.169e-3
optimizer = 'Adam'

[network]
drop = 0.160
norm = True
dims = [9, 41, 1]
activation = 'SELU'
l2_reg = 0
13 changes: 13 additions & 0 deletions configs/support.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[train]
h5_file = 'data/support/support_train_test.h5'
epochs = 500
learning_rate = 0.047
lr_decay_rate = 2.573e-3
optimizer = 'Adam'

[network]
drop = 0.255
norm = True
dims = [14, 44, 1]
activation = 'SELU'
l2_reg = 0
13 changes: 13 additions & 0 deletions configs/treatment.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[train]
h5_file = 'data/treatment/sim_treatment_dataset.h5'
epochs = 500
learning_rate = 0.026
lr_decay_rate = 1.636e-4
optimizer = 'Adam'

[network]
drop = 0.109
norm = True
dims = [11, 45, 1]
activation = 'SELU'
L2_reg = 0
13 changes: 13 additions & 0 deletions configs/whas.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[train]
h5_file = 'data/whas/whas_train_test.h5'
epochs = 500
learning_rate = 0.067
lr_decay_rate = 6.494e-4
optimizer = 'Adam'

[network]
drop = 0.147
norm = True
dims = [6, 48, 48, 1]
activation = 'ReLU'
l2_reg = 0
Binary file added data/gaussian/gaussian_survival_data.h5
Binary file not shown.
Binary file added data/gbsg/gbsg_cancer_train_test.h5
Binary file not shown.
Binary file added data/linear/linear_survival_data.h5
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added data/support/support_train_test.h5
Binary file not shown.
Binary file added data/treatment/sim_treatment_dataset.h5
Binary file not shown.
Binary file added data/whas/whas_train_test.h5
Binary file not shown.
69 changes: 69 additions & 0 deletions datasets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# ------------------------------------------------------------------------------
# --coding='utf-8'--
# Written by czifan (czifan@pku.edu.cn)
# ------------------------------------------------------------------------------
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import h5py
import numpy as np
import pandas as pd
import torch

from torch.utils.data import Dataset

class SurvivalDataset(Dataset):
''' The dataset class performs loading data from .h5 file. '''
def __init__(self, h5_file, is_train):
''' Loading data from .h5 file based on (h5_file, is_train).
:param h5_file: (String) the path of .h5 file
:param is_train: (bool) which kind of data to be loaded?
is_train=True: loading train data
is_train=False: loading test data
'''
# loads data
self.X, self.e, self.y = \
self._read_h5_file(h5_file, is_train)
# normalizes data
self._normalize()

print('=> load {} samples'.format(self.X.shape[0]))

def _read_h5_file(self, h5_file, is_train):
''' The function to parsing data from .h5 file.
:return X: (np.array) (n, m)
m is features dimension.
:return e: (np.array) (n, 1)
whether the event occurs? (1: occurs; 0: others)
:return y: (np.array) (n, 1)
the time of event e.
'''
split = 'train' if is_train else 'test'
with h5py.File(h5_file, 'r') as f:
X = f[split]['x'][()]
e = f[split]['e'][()].reshape(-1, 1)
y = f[split]['t'][()].reshape(-1, 1)
return X, e, y

def _normalize(self):
''' Performs normalizing X data. '''
self.X = (self.X-self.X.min(axis=0)) / \
(self.X.max(axis=0)-self.X.min(axis=0))

def __getitem__(self, item):
''' Performs constructing torch.Tensor object'''
# gets data with index of item
X_item = self.X[item] # (m)
e_item = self.e[item] # (1)
y_item = self.y[item] # (1)
# constructs torch.Tensor object
X_tensor = torch.from_numpy(X_item)
e_tensor = torch.from_numpy(e_item)
y_tensor = torch.from_numpy(y_item)
return X_tensor, y_tensor, e_tensor

def __len__(self):
return self.X.shape[0]
26 changes: 26 additions & 0 deletions logs/2020-04-10-16-21-55.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
2020-04-10 16:21:55,239 - utils - INFO - Running Simulated Linear(linear.ini)...
2020-04-10 16:23:38,320 - utils - INFO - The best valid c-index: 0.7787218145430287
2020-04-10 16:23:38,320 - utils - INFO -
2020-04-10 16:23:38,320 - utils - INFO - Running Simulated Nonlinear(gaussian.ini)...
2020-04-10 16:24:17,832 - utils - INFO - The best valid c-index: 0.5005123415610407
2020-04-10 16:24:17,833 - utils - INFO -
2020-04-10 16:24:17,833 - utils - INFO - Running WHAS(whas.ini)...
2020-04-10 16:24:53,124 - utils - INFO - The best valid c-index: 0.8449728673025717
2020-04-10 16:24:53,125 - utils - INFO -
2020-04-10 16:24:53,125 - utils - INFO - Running SUPPORT(support.ini)...
2020-04-10 16:33:32,915 - utils - INFO - The best valid c-index: 0.6173979652937414
2020-04-10 16:33:32,924 - utils - INFO -
2020-04-10 16:33:32,924 - utils - INFO - Running METABRIC(metabric.ini)...
2020-04-10 16:33:47,937 - utils - INFO - The best valid c-index: 0.6371630149173443
2020-04-10 16:33:47,938 - utils - INFO -
2020-04-10 16:33:47,938 - utils - INFO - Running Simulated Treatment(treatment.ini)...
2020-04-10 16:34:41,391 - utils - INFO - The best valid c-index: 0.5599653102068045
2020-04-10 16:34:41,391 - utils - INFO -
2020-04-10 16:34:41,391 - utils - INFO - Running Rotterdam & GBSG(gbsg.ini)...
2020-04-10 16:35:21,385 - utils - INFO - The best valid c-index: 0.670171035229049
2020-04-10 16:35:21,386 - utils - INFO -
2020-04-10 16:35:21,386 - utils - INFO - +------------------+---------------------+----------+----------+----------+---------------------+------------------+
| Simulated Linear | Simulated Nonlinear | WHAS | SUPPORT | METABRIC | Simulated Treatment | Rotterdam & GBSG |
+------------------+---------------------+----------+----------+----------+---------------------+------------------+
| 0.778722 | 0.500512 | 0.844973 | 0.617398 | 0.637163 | 0.559965 | 0.670171 |
+------------------+---------------------+----------+----------+----------+---------------------+------------------+
Loading

0 comments on commit 0ce33f4

Please sign in to comment.