Ejemplo n.º 1
0
    def test_censoring_funs_no_time_discrete(self, expected_tte_d,
                                             expected_is_censored_d, events_d):
        times_to_event = padded_events_to_tte(events_d, discrete_time=True)
        not_censored = padded_events_to_not_censored(events_d,
                                                     discrete_time=True)

        assert (
            expected_tte_d == times_to_event).all(), '  time_to_event failed'
        assert (expected_is_censored_d !=
                not_censored).all(), 'not_censored failed'
Ejemplo n.º 2
0
def test_censoring_funs_no_time():
    # TODO proper unit testing
    #    print 'TTE & CENSORING'
    #    print 'padded discrete'
    expected_tte = expected_tte_d
    expected_is_censored = expected_is_censored_d
    times_to_event = padded_events_to_tte(events_d, discrete_time=True)
    not_censored = padded_events_to_not_censored(events_d, discrete_time=True)

    assert (expected_tte == times_to_event).all(), '  time_to_event failed'
    assert (expected_is_censored != not_censored).all(), 'not_censored failed'

    #   print 'padded continuous'
    expected_tte = expected_tte_c
    expected_is_censored = expected_is_censored_c
    times_to_event = padded_events_to_tte(events_c, discrete_time=False)
    not_censored = padded_events_to_not_censored(events_c, discrete_time=False)

    assert (expected_tte == times_to_event).all(), '  time_to_event failed'
    assert (expected_is_censored != not_censored).all(), 'not_censored failed'
Ejemplo n.º 3
0
    def test_censoring_funs_no_time_continuous(self, expected_tte_c,
                                               expected_is_censored_c,
                                               events_c):
        times_to_event = padded_events_to_tte(events_c, discrete_time=False)
        not_censored = padded_events_to_not_censored(events_c,
                                                     discrete_time=False)

        assert (
            expected_tte_c == times_to_event).all(), '  time_to_event failed'
        assert (expected_is_censored_c !=
                not_censored).all(), 'not_censored failed'
Ejemplo n.º 4
0
def prep_tensors(x,events):
    # 0. calculate time to event and censoring indicators.
    y  = np.ones([events.shape[0],events.shape[1],2])
    y[:,:,0] = tr.padded_events_to_tte(np.squeeze(events),discrete_time=True)
    y[:,:,1] = tr.padded_events_to_not_censored(np.squeeze(events),discrete_time=True)

    # 1. Disalign features and targets otherwise truth is leaked.
    # 2. drop first timestep (that we now dont have features for)
    # 3. nan-mask the last timestep of features. (that we now don't have targets for)
    events = events[:,1:,]
    y  = y[:,1:]
    x  = np.roll(x, shift=1, axis=1)[:,1:,]
    x  = x + 0*np.expand_dims(events,-1)
    return x,y,events