Ejemplo n.º 1
0
 def test_aalenjohansen_simple_transitions(self):
     dataset_path = source_path + "datasets/"
     data = pd.read_csv(dataset_path + 'synthetic_data8.csv')
     sorted_data = data.sort_values(['Time', 'ID'], ascending=[True, True])
     definition = [('0', "G"), ('1', "B")]
     myState = tm.StateSpace(definition)
     myEstimator = aj.AalenJohansenEstimator(states=myState)
     labels = {
         'Timestamp': 'Time',
         'From_State': 'From',
         'To_State': 'To',
         'ID': 'ID'
     }
     result, times = myEstimator.fit(sorted_data, labels=labels)
     self.assertAlmostEqual(result[0, 0, -1],
                            0.5,
                            places=ACCURATE_DIGITS,
                            msg=None,
                            delta=None)
     self.assertAlmostEqual(result[0, 1, -1],
                            0.5,
                            places=ACCURATE_DIGITS,
                            msg=None,
                            delta=None)
     self.assertEqual(result[1, 0, -1], 0.0)
     self.assertEqual(result[1, 1, -1], 1.0)
Ejemplo n.º 2
0
    definition = [('0', "AAA"), ('1', "AA"), ('2', "A"), ('3', "BBB"),
                  ('4', "BB"), ('5', "B"), ('6', "CCC"), ('7', "D")]
elif example == 2:
    definition = [('0', "G"), ('1', "B")]
myState = tm.StateSpace(definition)
myState.describe()
# We validate that indeed the data set conforms to our expectations
labels = {'State': 'From'}
print(myState.validate_dataset(dataset=sorted_data, labels=labels))
labels = {'State': 'To'}
print(myState.validate_dataset(dataset=sorted_data, labels=labels))

# Step 3
# Estimate matrices using the Aalen-Johansen estimator
print("> Step 3: Estimate matrices using the Aalen-Johansen estimator")
myEstimator = aj.AalenJohansenEstimator(states=myState)
# labels = {'Timestamp': 'Time', 'From_State': 'From', 'To_State': 'To', 'ID': 'ID'}
labels = {'Time': 'Time', 'From': 'From', 'To': 'To', 'ID': 'ID'}
etm, times = myEstimator.fit(sorted_data, labels=labels)

# Step 4
# Print the cumulative computed matrix
print("> Step 4: Print the cumulative computed matrix")
print(etm[:, :, -1])

# Step 5
# Create a visualization of the transition rates
if example == 1 or example == 3:
    # Now lets plot a collection of curves for all ratings
    print("> Plot the transition curves")