Skip to content
DeepForgeby svx
All problems
EasyProbabilitypr-199

Survival From Hazard

Problem

Approximate survival probability from a piecewise-constant hazard over steps of width dt:

R = exp(-dt * sum(hazards)).

An empty list returns 1.0.

Hint

The cumulative hazard is the area under the hazard curve.

Test cases

case 1
in: [[0.1,0.2,0.3],1]
expected: 0.5488116360940264
case 2
in: [[1],2]
expected: 0.1353352832366127
case 3
in: [[],5]
expected: 1
case 4
in: [[0.5,0.5],0.5]
expected: 0.6065306597126334
Starter codePython
import math


def survival_from_hazard(hazards, dt):
    # Your code here
    pass

4 test cases · run your code against them in the editor