Tutorial (français)

Exemples

  1. Mixture of SIRD simulation and plotting

  2. SIRD simulation and plotting

  3. SIRDc simulation and plotting

  4. Stochastic Gradient Descent applied to linear regression

Mixture of SIRD simulation and plotting

(Source code, png, hires.png, pdf)

_images/model_covidsir_mixture-1.png

(original entry : covid_sird_mixture.py:docstring of aftercovid.models.covid_sird_mixture.CovidSIRDMixture, line 16)

SIRD simulation and plotting

(Source code, png, hires.png, pdf)

_images/model_covidsir-1.png

(original entry : covid_sird.py:docstring of aftercovid.models.covid_sird.CovidSIRD, line 13)

SIRDc simulation and plotting

(Source code, png, hires.png, pdf)

_images/model_covidsir_cst-1.png

(original entry : covid_sird_cst.py:docstring of aftercovid.models.covid_sird_cst.CovidSIRDc, line 80)

Stochastic Gradient Descent applied to linear regression

The following example how to optimize a simple linear regression.

<<<

import numpy
from aftercovid.optim import SGDOptimizer


def fct_loss(c, X, y):
    return numpy.linalg.norm(X @ c - y) ** 2


def fct_grad(c, x, y, i=0):
    return x * (x @ c - y) * 0.1


coef = numpy.array([0.5, 0.6, -0.7])
X = numpy.random.randn(10, 3)
y = X @ coef

sgd = SGDOptimizer(numpy.random.randn(3))
sgd.train(X, y, fct_loss, fct_grad, max_iter=15, verbose=True)
print('optimized coefficients:', sgd.coef)

>>>

    0/15: loss: 19.08 lr=0.1
    1/15: loss: 2.369 lr=0.1
    2/15: loss: 1.464 lr=0.1
    3/15: loss: 0.2519 lr=0.1
    4/15: loss: 0.1158 lr=0.1
    5/15: loss: 0.0312 lr=0.1
    6/15: loss: 0.02224 lr=0.1
    7/15: loss: 0.003585 lr=0.1
    8/15: loss: 0.002548 lr=0.1
    9/15: loss: 0.0004227 lr=0.1
    10/15: loss: 0.0003873 lr=0.1
    11/15: loss: 0.0002125 lr=0.1
    12/15: loss: 4.391e-05 lr=0.1
    13/15: loss: 2.502e-05 lr=0.1
    14/15: loss: 5.924e-06 lr=0.1
    15/15: loss: 2.996e-06 lr=0.1
    optimized coefficients: [ 0.5  0.6 -0.7]

(original entry : sgd.py:docstring of aftercovid.optim.sgd.SGDOptimizer, line 32)

Ligne de commande

Commande check

check

Vérifie que le module fonctionne comme prévu.

<<<

python -m aftercovid check --help

>>>

--SCRIPT---m aftercovid check --help
--OUT--

--ERR--
INFO: Showing help with the command '__main__.py check -- --help'.

NAME
    __main__.py check - Runs a couple of functions to check the module is working.

SYNOPSIS
    __main__.py check <flags>

DESCRIPTION
    Runs a couple of functions to check the module is working.

FLAGS
    --verbose=VERBOSE
        Default: 1
        0 to hide the standout output
--PATH--
None