NETWORK.SIR OpenBI
Spreading through the network (the SIR model), step by step.
Group: Networks. OpenBI’s own: DAX has no function of this name.
Syntax
NETWORK.SIR ( <links>, <from>, <to>, <beta>, <gamma> [, <runs> [, <seeds>, <seed>]] )
| Parameter | Type | Description |
|---|---|---|
links | Table | The rows that make the network, one link a row: a table of the model or a table expression, as the filters leave it. |
from | Expression evaluated for each row | One end of each row's link, such as a payer, a customer or a place. |
to | Expression evaluated for each row | The other end of each row's link. |
beta | Number | How fast an infected node infects each neighbour that has not had it: infections per link per unit of time, 0 or more. |
gamma | Number | How fast an infected node recovers: recoveries per unit of time, above 0. 1 / gamma is how long a node stays infectious, on average. |
runs | Whole number optional | How many simulations are averaged, from 1 to 100,000: 100 when left out. |
seeds | Table optional | The rows whose nodes are infected at the start. Left out, each run starts at one node chosen at random. |
seed | Expression optional, evaluated for each row | The node of each row of seeds; it comes with seeds. |
Returns
Table. 101 rows from time 0 to the end of the longest run. Their columns: Time; Susceptible, Infected and Recovered; Infected low and Infected high; and Reached share.
Remarks
- The SIR model: every node is susceptible, infected or recovered. An infected node passes it on along each link at the rate beta and recovers at the rate gamma, and a recovered node is not infected again. Time runs on continuously, not in rounds.
- The links are taken both ways, and no weight is used.
- The runs draw their random numbers from a fixed start, so the same query gives the same numbers every time; more runs give steadier ones.
- Susceptible, Infected and Recovered are the mean number of nodes in each state at that time, over the runs. Infected low and Infected high are the 10th and 90th percentiles of the infected: eight runs in ten fall between them.
- Reached share is the mean share of the nodes that were ever infected, the same on every row.
- For each node's chance of being reached, use
NETWORK.SIR.NODES.
Compared with DAX
An OpenBI function: DAX has none like it, so a measure or query that uses it works in OpenBI only, not in Power BI or Analysis Services.
Examples
How far word of mouth goes
Starting from one friend at random, at two rates of passing it on.
EVALUATE
VAR Links =
DATATABLE (
"From", STRING, "To", STRING,
{
{ "Ann", "Bo" }, { "Ann", "Cy" }, { "Bo", "Cy" }, { "Cy", "Di" },
{ "Di", "Ed" }, { "Ed", "Fay" }, { "Di", "Fay" }, { "Fay", "Gus" }
}
)
RETURN
ROW (
"Reached at beta 0.5", MAXX ( NETWORK.SIR ( Links, [From], [To], 0.5, 1 ), [Reached share] ),
"Reached at beta 2", MAXX ( NETWORK.SIR ( Links, [From], [To], 2, 1 ), [Reached share] )
)
| Reached at beta 0.5 | Reached at beta 2 |
|---|---|
| 0.288571428571428 | 0.571428571428572 |
The epidemic over time, from Ann
Every 20th of the 101 points.
EVALUATE
VAR Links =
DATATABLE (
"From", STRING, "To", STRING,
{
{ "Ann", "Bo" }, { "Ann", "Cy" }, { "Bo", "Cy" }, { "Cy", "Di" },
{ "Di", "Ed" }, { "Ed", "Fay" }, { "Di", "Fay" }, { "Fay", "Gus" }
}
)
VAR Start = DATATABLE ( "Person", STRING, { { "Ann" } } )
VAR Epidemic = NETWORK.SIR ( Links, [From], [To], 0.5, 1, 1000, Start, [Person] )
RETURN
SELECTCOLUMNS (
FILTER ( Epidemic, MOD ( ROUND ( 100 * [Time] / MAXX ( Epidemic, [Time] ), 0 ), 20 ) = 0 ),
"Time", [Time],
"Infected", [Infected],
"Infected low", [Infected low],
"Infected high", [Infected high],
"Recovered", [Recovered]
)
ORDER BY [Time]
| Time | Infected | Infected low | Infected high | Recovered |
|---|---|---|---|---|
| 0 | 1 | 1 | 1 | 0 |
| 2.21618394600517 | 0.376 | 0 | 1 | 1.57 |
| 4.43236789201034 | 0.065 | 0 | 0 | 1.987 |
| 6.6485518380155 | 0.007 | 0 | 0 | 2.056 |
| 8.86473578402067 | 0.001 | 0 | 0 | 2.062 |
| 11.0809197300258 | 0 | 0 | 0 | 2.063 |
Related functions
NETWORK.SIR.NODES, NETWORK.REACH, NETWORK.PROPAGATE, MONTECARLO.
NETWORK.SIR is OpenBI's own code: it calls no function of Open Graph, OpenBI's graph library. See the OAX network functions and Open Graph.