-
Notifications
You must be signed in to change notification settings - Fork 2
/
sbgresults.py
33 lines (25 loc) · 951 Bytes
/
sbgresults.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from sbg import maximize, predicted_survival, derl
import numpy as np
class SbgResults(object):
def __init__(self, cohort_name, actual_survival, t, discount, value):
"""
:param actual_survival: {t0: survive%, t1: survive%, ..., tn: survive%}
"""
self.name = cohort_name
self.discount = discount
self.value = value
self.t = t
self._actual = actual_survival
self.actual = [a for a in actual_survival.values() if not np.isnan(a)]
res = maximize(self.actual[1:])
alpha, beta = res.x
self.alpha = alpha
self.beta = beta
@property
def predicted(self):
return ([1] + predicted_survival(self.alpha, self.beta, len(self._actual) + self.t - 1))
@property
def dltv(self):
return ((derl(self.alpha, self.beta, self.discount, 0)/(1 + self.discount)) + 1) * self.value
def __repr__(self):
return self.name