derivatives¶
This example demonstrates the log likelihood derivatives request. In particular, the request is for the derivatives of the log likelihood with respect to the log of the edge specific rate scaling factors.
2-state pure-death model with rate 5¶
In this example with a single branch, the log likelihood is equal to the derivative of the log likelihood with respect to the log scaling factor.
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 | {
"scene" : {
"node_count" : 2,
"process_count" : 1,
"state_space_shape" : [2],
"tree" : {
"row_nodes" : [0],
"column_nodes" : [1],
"edge_rate_scaling_factors" : [5],
"edge_processes" : [0]
},
"root_prior" : {
"states" : [[1]],
"probabilities" : [1]
},
"process_definitions" : [{
"row_states" : [[1]],
"column_states" : [[0]],
"transition_rates" : [1]
}],
"observed_data" : {
"nodes" : [1],
"variables" : [0],
"iid_observations" : [[1]]
}
},
"requests" : [
{"property" : "SNNLOGL"},
{"property" : "SDNDERI"}
]
}
|
1 | {"status": "feasible", "responses": [-4.999999999999999, [-5.0]]}
|
pure death with rate 5 + 1e-8¶
Here we can see the same equality if we add a small delta to the rate scaling factor.
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 | {
"scene" : {
"node_count" : 2,
"process_count" : 1,
"state_space_shape" : [2],
"tree" : {
"row_nodes" : [0],
"column_nodes" : [1],
"edge_rate_scaling_factors" : [5.00000001],
"edge_processes" : [0]
},
"root_prior" : {
"states" : [[1]],
"probabilities" : [1]
},
"process_definitions" : [{
"row_states" : [[1]],
"column_states" : [[0]],
"transition_rates" : [1]
}],
"observed_data" : {
"nodes" : [1],
"variables" : [0],
"iid_observations" : [[1]]
}
},
"requests" : [
{"property" : "SNNLOGL"},
{"property" : "SDNDERI"}
]
}
|
1 | {"status": "feasible", "responses": [-5.00000001, [-5.00000001]]}
|
poisson with rate 3¶
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 | {
"scene" : {
"node_count" : 2,
"process_count" : 1,
"state_space_shape" : [2],
"tree" : {
"row_nodes" : [0],
"column_nodes" : [1],
"edge_rate_scaling_factors" : [3],
"edge_processes" : [0]
},
"root_prior" : {
"states" : [[1]],
"probabilities" : [1]
},
"process_definitions" : [{
"row_states" : [[1], [0]],
"column_states" : [[0], [1]],
"transition_rates" : [1, 1]
}],
"observed_data" : {
"nodes" : [1],
"variables" : [0],
"iid_observations" : [[1]]
}
},
"requests" : [
{"property" : "SNNLOGL"},
{"property" : "SDNDERI"}
]
}
|
1 | {"status": "feasible", "responses": [-0.690671495422215, [-0.014835738939808092]]}
|
poisson with rate 3 + 1e-8¶
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 | {
"scene" : {
"node_count" : 2,
"process_count" : 1,
"state_space_shape" : [2],
"tree" : {
"row_nodes" : [0],
"column_nodes" : [1],
"edge_rate_scaling_factors" : [3.00000001],
"edge_processes" : [0]
},
"root_prior" : {
"states" : [[1]],
"probabilities" : [1]
},
"process_definitions" : [{
"row_states" : [[1], [0]],
"column_states" : [[0], [1]],
"transition_rates" : [1, 1]
}],
"observed_data" : {
"nodes" : [1],
"variables" : [0],
"iid_observations" : [[1]]
}
},
"requests" : [
{"property" : "SNNLOGL"},
{"property" : "SDNDERI"}
]
}
|
1 | {"status": "feasible", "responses": [-0.6906714954716674, [-0.014835738693279968]]}
|
Using finite differences you can compute the derivative of the log liklihood with respect to the scaling factor. Three times this estimated derivative is approximately equal to the computed derivative with respect to the log of the scaling factor.
This follows from the chain rule of derivatives. So if you want to use the interface to compute derivatives of log likelihood with respect to edge rate scaling factors instead of with respect to logs of edge rate scaling factors, just divide the returned derivatives by the edge rate scaling factors.