ukhsa-collaboration / covid-19-app-android-ag-public

COVID19 Android app
Other
142 stars 31 forks source link

Code: is infectiousness (based on days from symptom onset) "double-counted"? #36

Closed sourcejedi closed 4 years ago

sourcejedi commented 4 years ago

Thank you for the detailed explanation in issue #6 . Is there a problem in ExposureWindow.riskScore()?

riskScoreCalculator.calculate() calculates infectiousness from days from onset, using a formula. We then multiply this by infectiousnessFactor().

infectiousnessFactor() is calculated from ExposureWindow.infectiousness. But I think this is also calculated from days from onset.

I think this would cause the infectiousness curve to fall faster than it is supposed to.

  getInfectiousness() Infectiousness of the TEK that caused this exposure, computed from the days since onset of symptoms using the daysToInfectiousnessMapping.

    private fun ExposureWindow.riskScore(
        config: RiskScoreCalculatorConfiguration,
        riskCalculation: V2RiskCalculation
    ): Double {
        val scanInstances = scanInstances.map { it.toNHSScanInstance() }
        val riskScoreCalculator = riskScoreCalculatorProvider.riskScoreCalculator(config)
        return 60 * riskScoreCalculator.calculate(scanInstances) * infectiousnessFactor(
            riskCalculation
        )
    }

https://github.com/nhsx/covid-19-app-android-ag-public/blob/36ba4bd/app/src/main/java/uk/nhs/nhsx/covid19/android/app/exposure/encounter/calculation/ExposureWindowRiskCalculator.kt#L55

I believe the daysToInfectiousness values used are defined here:

      "v2RiskCalculation": {
        "daysSinceOnsetToInfectiousness":[0,0,0,0,0,0,0,0,0,1,1,1,2,2,2,2,2,2,1,1,1,1,1,1,0,0,0,0,0],
        "infectiousnessWeights": [0.0, 0.4, 1.0],

https://github.com/nhsx/covid19-app-system-public/commit/621f1c8a5f0dd17984c313ff9d4f5a61548d3d13#diff-c2b1334f0a4a1bf2207e788ffdfd602d5177f43bdd515b726a7b69fda25e88b5R64

sourcejedi commented 4 years ago

OK, I understand it now.

In "API Mode 2", the app calculates risk scores and tests them against a threshold in ExposureWindowRiskCalculator and ExposureWindowRiskManager. ExposureWindow refers to part of the new API. This mode includes the more precise distance calculation. The calculation using the distance is performed in riskscore-kt (packages uk.nhs.riskscore.*).

"API Mode 2" uses the daysSinceOnsetToInfectiousness config. It does not use a smooth curve of infectiousness. It calculates either 100% infectious ("high"), or 40% infectious ("normal"), depending on days since symptom onset. After accounting duration, distance, and infectiousness, the threshold score is 120 points.

If "API Mode 2" is not available, the app calculates risk scores and tests them against a threshold in RiskCalculator [sic] and ExposureInformationRiskManager. In this case, the distance is only known as 0-2m, 2-4m, or 4m+. 4m+ is ignored. The infectiousness is calculated using the smooth infectiousness curve / formula shown in issue #6.

This explanation applies to git version 36ba4bd, "Changes for 2020-10-29".