Calmcode - diseases: sympy

Sympy

1 2 3 4 5 6 7

Let's use sympy to make the maths easier. Let's start by making an expression that describes the curve from the chart in the previous vide.

import sympy as sp

g, p = sp.symbols("g, p")
exp = g * (1-p) ** g

You can take this expression and differentiate it with regards to g.

sp.diff(exp, g)

We have a maximum value when there's a slope equal to zero. We can ask sympy to calculate this for us.

sp.solve(sp.diff(exp, g), g)

This means that we can use sympy to give us the optimal group size given a probability value.

g_opt = -1/sp.log(1 - p)
g_opt.subs(p, 0.01)

This is neat!

Extra!

In case you're interested, we have content on sympy if you're unfamiliar.