├── .DS_Store ├── .github └── workflows │ ├── python-package.yml │ ├── python-publish.yml │ ├── test-darts.yml │ ├── test-divinity.yml │ ├── test-greykite.yml │ ├── test-merlion-prophet.yml │ ├── test-merlion.yml │ ├── test-neuralprophet.yml │ ├── test-nns-github.yml │ ├── test-nns.yml │ ├── test-orbit.yml │ ├── test-pmd.yml │ ├── test-prophet.yml │ ├── test-pydlm.yml │ ├── test-river.yml │ ├── test-scikit-learn.yml │ ├── test-scipy.yml │ ├── test-simdkalman.yml │ ├── test-sktime.yml │ ├── test-successor.yml │ ├── test-tbats.yml │ ├── test-tcn.yml │ ├── test-tsa.yml │ └── test_statsforecast.yml ├── .gitignore ├── .travis.yml ├── CONTRIBUTE.md ├── CONTRIBUTE_BATCH_STYLE_MODELS.md ├── CONTRIBUTE_COLAB_NOTEBOOK.md ├── CONTRIBUTE_ONLINE_STYLE_MODELS.md ├── FAQ.md ├── INSTALL.md ├── LICENSE ├── README.md ├── chatgpt_skater_arima.ipynb ├── docs ├── README.md ├── articles.md ├── assets │ └── images │ │ ├── README.md │ │ ├── microprediction_book.png │ │ ├── prophet_sensitivity.png │ │ ├── sf_autoarima.png │ │ └── wiggle.png ├── capstone.md ├── composition.md ├── eloratings.md ├── ensembling.md ├── interface.md ├── map.md ├── resources.md ├── skaters.md ├── template.md ├── uses.md └── why.md ├── examples ├── README.md ├── __init__.py ├── basic_usage │ ├── __init__.py │ ├── run_elo_skater.py │ ├── run_skater.py │ ├── run_skater_and_measure_forecast_error_manually.py │ ├── run_skater_and_return _forecast_error.py │ ├── run_skater_predict_five_ahead_and_plot.py │ ├── run_skater_predict_next_and_plot.py │ ├── run_statsforecast_skater.py │ └── run_statsforecast_skater_with_hypocratic_chasing.py ├── comparing │ ├── __init__.py │ └── comparesarima.py ├── data │ ├── __init__.py │ ├── demo_synthetic_exogenous.py │ ├── get_random_correlation_matrix.py │ ├── get_random_covariance_matrix.py │ ├── get_random_multivariate_data.py │ ├── get_random_precision_matrix.py │ └── get_random_univariate_data.py ├── hyper │ ├── __init__.py │ ├── demo_balanced_log_scale.py │ └── demo_param_ordering.py ├── notebooks │ ├── CompareToNaive.ipynb │ ├── top_rated_models.ipynb │ ├── wiggling.ipynb │ └── worldcup.ipynb ├── performance │ ├── __init__.py │ ├── sf_wiggly_performance.py │ ├── sk_sf_wiggly_performance.py │ └── wiggly_performance_two.py ├── sensitivity │ ├── __init__.py │ └── skaterdiscontinuity.py └── tuning │ ├── __init__.py │ └── optimizing_prophet_live.py ├── images ├── download_time.png ├── money.png └── talking_heads.jpeg ├── requirements.txt ├── setup.py ├── tests ├── __init__.py ├── bats │ ├── __init__.py │ ├── test_bats_inferface.py │ └── test_bats_random_skater.py ├── components │ └── __init__.py ├── darts │ ├── __init__.py │ └── test_darts_random_skater.py ├── divine │ ├── __init__.py │ └── test_divine.py ├── dlm │ ├── __init__.py │ ├── test_dlm_exogenous.py │ └── test_dlm_univariate.py ├── elo │ ├── __init__.py │ ├── http_cache.sqlite │ ├── test_elo_random_skater.py │ └── test_fib.py ├── gk │ ├── __init__.py │ └── test_greykite_random_skater.py ├── kts │ ├── README.md │ ├── __init__.py │ └── test_kats_random_skater.py ├── mrln │ ├── __init__.py │ └── test_merlion_random_skater.py ├── nproph │ ├── __init__.py │ ├── test_nprophet_interface.py │ └── test_nprophet_skaters.py ├── orbt │ ├── __init__.py │ └── test_lgt.py ├── pmd │ ├── __init__.py │ └── test_pmd.py ├── proph │ ├── __init__.py │ ├── test_proph_random_skater.py │ ├── test_prophet_interface.py │ └── test_prophet_skaters.py ├── pyrct │ ├── __init__.py │ └── test_pycrt_random_skater.py ├── rvr │ ├── __init__.py │ └── test_river_random_skater.py ├── simple │ ├── __init__.py │ └── test_simple.py ├── sk │ ├── __init__.py │ ├── test_sf_autoarima.py │ ├── test_sf_autoarima_wiggly.py │ ├── test_sf_hypocratic.py │ ├── test_sf_random_skater.py │ ├── test_sk_auto_random_skater.py │ └── test_sk_random_skater.py ├── smdk │ ├── __init__.py │ ├── test_individual_steps.py │ └── test_smdk_random_skater.py ├── smoothing │ ├── __init__.py │ └── test_sf_smooth.py ├── suc │ ├── __init__.py │ └── test_all_successor_skaters.py ├── test_augmentation.py ├── test_elo_rating_integrity.py ├── test_freq.py ├── test_long.py ├── test_optimizers.py ├── test_residual_data.py ├── test_setup.py └── tsa │ ├── __init__.py │ ├── test_tsa.py │ └── test_tsa_ensemble.py └── timemachines ├── __init__.py ├── inclusion ├── __init__.py ├── humpdayinclusion.py ├── matplotlibinclusion.py ├── micropredictioninclusion.py ├── pandasinclusion.py ├── scipyinclusion.py ├── sfinclusion.py ├── sklearninclusion.py ├── statsmodelsinclusion.py └── threezainclusion.py ├── skaters ├── .DS_Store ├── __init__.py ├── allskaters.py ├── ats │ ├── README.md │ ├── __init__.py │ └── atsinclusion.py ├── bats │ ├── __init__.py │ ├── allbatsskaters.py │ ├── batsfactory.py │ ├── batsifactory.py │ └── batsinclusion.py ├── divine │ ├── __init__.py │ ├── divineinclusion.py │ ├── divineparams.py │ ├── divineskaterfactory.py │ └── divineskaters.py ├── dlm │ ├── README.md │ ├── __init__.py │ ├── alldlmskaters.py │ ├── dlmcomposed.py │ ├── dlmexogenous.py │ ├── dlmhacks.py │ ├── dlminclusion.py │ └── dlmunivariate.py ├── drts │ ├── .DS_Store │ ├── alldartsskaters.py │ ├── dartsarimaskater.py │ ├── dartsautoarimaskater.py │ ├── dartsexpsmoothingskater.py │ ├── dartsfftskater.py │ ├── dartsfourthetaskater.py │ ├── dartsinclusion.py │ ├── dartsnbeatsskater.py │ ├── dartsprophetskater.py │ ├── dartsthetaskater.py │ └── dartswrappers.py ├── elo │ ├── README.md │ ├── __init__.py │ ├── alleloskaters.py │ ├── eloensemblefactory.py │ ├── eloensembles.py │ └── forever.py ├── flux │ ├── README.md │ ├── __init__.py │ ├── flux.py │ └── fluxinclusion.py ├── gk │ ├── README.md │ ├── allgreykiteskaters.py │ ├── greykitebasicskater.py │ ├── greykiteinclusion.py │ └── greykitewrappers.py ├── glu │ ├── README.md │ ├── __init__.py │ ├── gluinclusion.py │ ├── gluparams.py │ └── glusimple.py ├── ik │ └── .DS_Store ├── kts │ ├── README.md │ ├── __init__.py │ ├── allkatsskaters.py │ ├── ktsholtwintersskater.py │ ├── ktsinclusion.py │ ├── ktsprophetskater.py │ ├── ktsquadraticskater.py │ └── ktswrappers.py ├── localskaters.py ├── mrln │ ├── .DS_Store │ ├── allmerlionskaters.py │ ├── merlionarimaskater.py │ ├── merlioninclusion.py │ ├── merlionmsesskater.py │ ├── merlionprophetskater.py │ └── merlionwrappers.py ├── networkedskaters.py ├── nproph │ ├── __init__.py │ ├── allnprophetskaters.py │ ├── nprophetinclusion.py │ ├── nprophetiskaterfactory.py │ ├── nprophetskaterfactory.py │ ├── nprophetskaters.py │ ├── nprophparams.py │ └── nprophskaterscomposed.py ├── orbt │ ├── README.md │ ├── __init__.py │ ├── allorbitskaters.py │ ├── orbitinclusion.py │ ├── orbitlgtskaterfactory.py │ └── orbitwrappers.py ├── pmd │ ├── README.md │ ├── __init__.py │ ├── allpmdskaters.py │ ├── pmdcomposed.py │ ├── pmddefaultparams.py │ ├── pmdinclusion.py │ ├── pmdserialize_epicfail.py │ ├── pmdskaterfactory.py │ └── pmdskaters.py ├── preskaters.py ├── proph │ ├── .DS_Store │ ├── README.md │ ├── __init__.py │ ├── allprophetskaters.py │ ├── pathology.py │ ├── prophetinclusion.py │ ├── prophiskaterfactory.py │ ├── prophoptimize.py │ ├── prophparams.py │ ├── prophskaterfactory.py │ ├── prophskaterscomposed.py │ └── prophskaterssingular.py ├── pycrt │ ├── __init__.py │ ├── allpycaretskaters.py │ ├── pycaretblend.py │ ├── pycaretinclusion.py │ └── pycaretwrapper.py ├── pypi.py ├── rvr │ ├── README.md │ ├── __init__.py │ ├── allriverskaters.py │ ├── rvrconstant.py │ ├── rvrensembles.py │ ├── rvrhypocratic.py │ ├── rvrinclusion.py │ └── rvrsarimax.py ├── simple │ ├── README.md │ ├── __init__.py │ ├── hypocratic.py │ ├── hypocraticensemble.py │ ├── linear.py │ ├── movingaverage.py │ ├── thinking.py │ └── trivial.py ├── sk │ ├── README.md │ ├── __init__.py │ ├── allskskaters.py │ ├── sfautoarima.py │ ├── sfautoarimahypocratic.py │ ├── sfautoarimawiggly.py │ ├── sfinclusion.py │ ├── skautoarima.py │ ├── skautoarimawiggly.py │ ├── skautoets.py │ ├── skinclusion.py │ ├── sktheta.py │ └── skwrappers.py ├── smdk │ ├── README.md │ ├── __init__.py │ ├── allsmdkskaters.py │ ├── smdkarma.py │ ├── smdkarmafactory.py │ ├── smdkexample.py │ └── smdkinclusion.py ├── suc │ ├── README.md │ ├── __init__.py │ ├── allsuccessorskaters.py │ └── successorinclusion.py └── tsa │ ├── __init__.py │ ├── alltsaskaters.py │ ├── tsaconstant.py │ ├── tsaensembles.py │ ├── tsahypocratic.py │ ├── tsaparams.py │ └── tsatheta.py ├── skatertools ├── __init__.py ├── batch │ ├── README.md │ ├── __init__.py │ └── batchskater.py ├── combining │ ├── __init__.py │ ├── combiningforecasts.py │ └── hubermean.py ├── comparison │ ├── __init__.py │ ├── comparing.py │ ├── eloformulas.py │ ├── performancerating.py │ └── skaterelo.py ├── components │ ├── __init__.py │ ├── chronometer.py │ ├── observance.py │ ├── parade.py │ └── residuals.py ├── composition │ ├── __init__.py │ ├── conjugation.py │ ├── fractional.py │ ├── residualcomposition.py │ └── residualshypocratic.py ├── crowd │ ├── README.md │ ├── __init__.py │ ├── lotteryconventions.py │ └── lotteryensemblefactory.py ├── data │ ├── __init__.py │ ├── augmentation.py │ ├── hospital.csv │ ├── live.py │ ├── long.py │ ├── ornstein.py │ ├── real.py │ ├── skaterresiduals.py │ ├── stitching.py │ ├── surrogate.py │ └── synthetic.py ├── ensembling │ ├── README.md │ ├── __init__.py │ ├── ensemblefactory.py │ ├── portskater.py │ └── precisionweightedskater.py ├── evaluation │ ├── __init__.py │ └── evaluators.py ├── offlinetesting │ ├── __init__.py │ ├── allslowtests.py │ └── optimizerandomskater.py ├── recommendations │ ├── __init__.py │ ├── hardwiredsuggestions.py │ └── suggestions.py ├── sampling │ └── README.md ├── sensitivity │ ├── __init__.py │ └── skatersensitivity.py ├── smoothing │ ├── README.md │ ├── __init__.py │ └── wiggling.py ├── tuning │ ├── README.md │ ├── __init__.py │ ├── hyper.py │ ├── hyperempirical.py │ └── hyperplot.py ├── utilities │ ├── __init__.py │ ├── arrivals.py │ ├── conventions.py │ ├── epochtime.py │ ├── instantiation.py │ ├── internet.py │ ├── locations.py │ ├── nonemath.py │ ├── suppression.py │ └── wrangling.py └── visualization │ ├── __init__.py │ ├── priorplot.py │ ├── realplot.py │ └── skaterbumpplot.py └── skating.py /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/.DS_Store -------------------------------------------------------------------------------- /.github/workflows/python-package.yml: -------------------------------------------------------------------------------- 1 | # This workflow will install Python dependencies, run tests and lint with a variety of Python versions 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions 3 | 4 | name: tests 5 | 6 | on: 7 | push: 8 | branches: [ main ] 9 | pull_request: 10 | branches: [ main ] 11 | 12 | jobs: 13 | build: 14 | 15 | runs-on: ubuntu-latest 16 | strategy: 17 | matrix: 18 | python-version: ["3.10","3.11","3.12"] 19 | 20 | steps: 21 | - uses: actions/checkout@v2 22 | - name: Set up Python ${{ matrix.python-version }} 23 | uses: actions/setup-python@v2 24 | with: 25 | python-version: ${{ matrix.python-version }} 26 | - name: Install dependencies 27 | run: | 28 | python -m pip install --upgrade pip 29 | python -m pip install wheel 30 | python -m pip install flake8 pytest 31 | python -m pip install pathlib 32 | python -m pip install humpday 33 | if [ -f requirements.txt ]; then pip install -r requirements.txt; fi 34 | - name: Lint with flake8 35 | run: | 36 | # stop the build if there are Python syntax errors or undefined names 37 | flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics 38 | # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide 39 | flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics 40 | - name: Test with pytest 41 | run: | 42 | python -m pip install --upgrade scikit-learn 43 | pytest 44 | -------------------------------------------------------------------------------- /.github/workflows/python-publish.yml: -------------------------------------------------------------------------------- 1 | # This workflows will upload a Python Package using Twine when a release is created 2 | # For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries 3 | 4 | name: Upload Python Package 5 | 6 | on: 7 | release: 8 | types: [created] 9 | 10 | jobs: 11 | deploy: 12 | 13 | runs-on: ubuntu-latest 14 | 15 | steps: 16 | - uses: actions/checkout@v2 17 | - name: Set up Python 18 | uses: actions/setup-python@v2 19 | with: 20 | python-version: '3.x' 21 | - name: Install dependencies 22 | run: | 23 | python -m pip install --upgrade pip 24 | pip install setuptools wheel twine 25 | python -m pip install flake8 pytest 26 | if [ -f requirements.txt ]; then pip install -r requirements.txt; fi 27 | - name: Build and publish 28 | env: 29 | TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} 30 | TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} 31 | run: | 32 | python setup.py sdist bdist_wheel 33 | twine upload dist/* 34 | -------------------------------------------------------------------------------- /.github/workflows/test-darts.yml: -------------------------------------------------------------------------------- 1 | # This workflow will install Python dependencies, run tests and lint with a variety of Python versions 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions 3 | 4 | name: test-darts 5 | 6 | on: 7 | push: 8 | branches: [ main ] 9 | pull_request: 10 | branches: [ main ] 11 | 12 | jobs: 13 | build: 14 | 15 | runs-on: ubuntu-latest 16 | strategy: 17 | matrix: 18 | python-version: ["3.10","3.11","3.12"] 19 | 20 | steps: 21 | - uses: actions/checkout@v2 22 | - name: Set up Python ${{ matrix.python-version }} 23 | uses: actions/setup-python@v2 24 | with: 25 | python-version: ${{ matrix.python-version }} 26 | - name: Install dependencies 27 | run: | 28 | python -m pip install --upgrade pip 29 | python -m pip install wheel 30 | python -m pip install flake8 pytest 31 | python -m pip install pathlib 32 | python -m pip install darts 33 | if [ -f requirements.txt ]; then pip install -r requirements.txt; fi 34 | - name: Lint with flake8 35 | run: | 36 | # stop the build if there are Python syntax errors or undefined names 37 | flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics 38 | # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide 39 | flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics 40 | - name: Test with pytest 41 | run: | 42 | pip install -e .[test] 43 | pytest 44 | -------------------------------------------------------------------------------- /.github/workflows/test-divinity.yml: -------------------------------------------------------------------------------- 1 | name: test-divinity 2 | 3 | on: 4 | push: 5 | branches: [ main ] 6 | pull_request: 7 | branches: [ main ] 8 | 9 | jobs: 10 | build: 11 | 12 | runs-on: ubuntu-latest 13 | strategy: 14 | matrix: 15 | python-version: ["3.10","3.11","3.12"] 16 | 17 | steps: 18 | - uses: actions/checkout@v2 19 | - name: Set up Python ${{ matrix.python-version }} 20 | uses: actions/setup-python@v2 21 | with: 22 | python-version: ${{ matrix.python-version }} 23 | - name: Install dependencies 24 | run: | 25 | python -m pip install --upgrade pip 26 | python -m pip install wheel 27 | python -m pip install flake8 pytest 28 | python -m pip install pathlib 29 | python -m pip install divinity 30 | if [ -f requirements.txt ]; then pip install -r requirements.txt; fi 31 | - name: Lint with flake8 32 | run: | 33 | # stop the build if there are Python syntax errors or undefined names 34 | flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics 35 | # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide 36 | flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics 37 | - name: Test with pytest 38 | run: | 39 | pip install -e .[test] 40 | pip install scikit-learn 41 | pytest 42 | -------------------------------------------------------------------------------- /.github/workflows/test-greykite.yml: -------------------------------------------------------------------------------- 1 | # This workflow will install Python dependencies, run tests and lint with a variety of Python versions 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions 3 | 4 | name: test-greykite 5 | 6 | on: 7 | push: 8 | branches: [ main ] 9 | pull_request: 10 | branches: [ main ] 11 | 12 | jobs: 13 | build: 14 | 15 | runs-on: ubuntu-latest 16 | strategy: 17 | matrix: 18 | python-version: ["3.10","3.11","3.12"] 19 | 20 | steps: 21 | - uses: actions/checkout@v2 22 | - name: Set up Python ${{ matrix.python-version }} 23 | uses: actions/setup-python@v2 24 | with: 25 | python-version: ${{ matrix.python-version }} 26 | - name: Install dependencies 27 | run: | 28 | python -m pip install --upgrade pip 29 | python -m pip install wheel 30 | python -m pip install flake8 pytest 31 | python -m pip install pathlib 32 | python -m pip install --upgrade numpy 33 | python -m pip install osqp==0.6.1 34 | python -m pip install greykite 35 | if [ -f requirements.txt ]; then pip install -r requirements.txt; fi 36 | - name: Lint with flake8 37 | run: | 38 | # stop the build if there are Python syntax errors or undefined names 39 | flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics 40 | # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide 41 | flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics 42 | - name: Test with pytest 43 | run: | 44 | pip install -e .[test] 45 | pip install scikit-learn 46 | pytest 47 | -------------------------------------------------------------------------------- /.github/workflows/test-merlion-prophet.yml: -------------------------------------------------------------------------------- 1 | # This workflow will install Python dependencies, run tests and lint with a variety of Python versions 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions 3 | 4 | name: test-merlion-prophet 5 | 6 | on: 7 | push: 8 | branches: [ main ] 9 | pull_request: 10 | branches: [ main ] 11 | 12 | jobs: 13 | build: 14 | 15 | runs-on: ubuntu-latest 16 | strategy: 17 | matrix: 18 | python-version: ["3.10","3.11","3.12"] 19 | 20 | steps: 21 | - uses: actions/checkout@v2 22 | - name: Set up Python ${{ matrix.python-version }} 23 | uses: actions/setup-python@v2 24 | with: 25 | python-version: ${{ matrix.python-version }} 26 | - name: Install dependencies 27 | run: | 28 | python -m pip install --upgrade pip 29 | python -m pip install wheel 30 | python -m pip install flake8 pytest 31 | python -m pip install pathlib 32 | python -m pip install prophet 33 | python -m pip install salesforce-merlion 34 | if [ -f requirements.txt ]; then pip install -r requirements.txt; fi 35 | - name: Lint with flake8 36 | run: | 37 | # stop the build if there are Python syntax errors or undefined names 38 | flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics 39 | # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide 40 | flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics 41 | - name: Test with pytest 42 | run: | 43 | pip install -e .[test] 44 | pytest 45 | -------------------------------------------------------------------------------- /.github/workflows/test-merlion.yml: -------------------------------------------------------------------------------- 1 | # This workflow will install Python dependencies, run tests and lint with a variety of Python versions 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions 3 | 4 | name: test-merlion 5 | 6 | on: 7 | push: 8 | branches: [ main ] 9 | pull_request: 10 | branches: [ main ] 11 | 12 | jobs: 13 | build: 14 | 15 | runs-on: ubuntu-latest 16 | strategy: 17 | matrix: 18 | python-version: ["3.10","3.11","3.12"] 19 | 20 | steps: 21 | - uses: actions/checkout@v2 22 | - name: Set up Python ${{ matrix.python-version }} 23 | uses: actions/setup-python@v2 24 | with: 25 | python-version: ${{ matrix.python-version }} 26 | - name: Install dependencies 27 | run: | 28 | python -m pip install --upgrade pip 29 | python -m pip install wheel 30 | python -m pip install flake8 pytest 31 | python -m pip install pathlib 32 | python -m pip install salesforce-merlion[all] 33 | if [ -f requirements.txt ]; then pip install -r requirements.txt; fi 34 | - name: Lint with flake8 35 | run: | 36 | # stop the build if there are Python syntax errors or undefined names 37 | flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics 38 | # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide 39 | flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics 40 | - name: Test with pytest 41 | run: | 42 | pip install -e .[test] 43 | pytest 44 | -------------------------------------------------------------------------------- /.github/workflows/test-neuralprophet.yml: -------------------------------------------------------------------------------- 1 | # This workflow will install Python dependencies, run tests and lint with a variety of Python versions 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions 3 | 4 | name: test-neuralprophet 5 | 6 | on: 7 | push: 8 | branches: [ main ] 9 | pull_request: 10 | branches: [ main ] 11 | 12 | jobs: 13 | build: 14 | 15 | runs-on: ubuntu-latest 16 | strategy: 17 | matrix: 18 | python-version: ["3.10","3.11","3.12"] 19 | 20 | steps: 21 | - uses: actions/checkout@v2 22 | - name: Set up Python ${{ matrix.python-version }} 23 | uses: actions/setup-python@v2 24 | with: 25 | python-version: ${{ matrix.python-version }} 26 | - name: Install dependencies 27 | run: | 28 | python -m pip install --upgrade pip 29 | python -m pip install wheel 30 | python -m pip install flake8 pytest 31 | python -m pip install pathlib 32 | python -m pip install neuralprophet 33 | if [ -f requirements.txt ]; then pip install -r requirements.txt; fi 34 | - name: Lint with flake8 35 | run: | 36 | # stop the build if there are Python syntax errors or undefined names 37 | flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics 38 | # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide 39 | flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics 40 | - name: Test with pytest 41 | run: | 42 | pip install -e .[test] 43 | pip install scikit-learn 44 | pytest 45 | -------------------------------------------------------------------------------- /.github/workflows/test-nns-github.yml: -------------------------------------------------------------------------------- 1 | name: test-nns-github 2 | 3 | on: 4 | push: 5 | branches: [ main ] 6 | pull_request: 7 | branches: [ main ] 8 | 9 | jobs: 10 | build: 11 | 12 | runs-on: ubuntu-latest 13 | strategy: 14 | matrix: 15 | python-version: ["3.10","3.11","3.12"] 16 | 17 | steps: 18 | - uses: actions/checkout@v2 19 | - name: Set up Python ${{ matrix.python-version }} 20 | uses: actions/setup-python@v2 21 | with: 22 | python-version: ${{ matrix.python-version }} 23 | - name: Install dependencies 24 | run: | 25 | python -m pip install --upgrade pip 26 | python -m pip install wheel 27 | python -m pip install flake8 pytest 28 | python -m pip install pathlib 29 | python -m pip install git+https://github.com/OVVO-Financial/NNS-Python.git 30 | if [ -f requirements.txt ]; then pip install -r requirements.txt; fi 31 | - name: Lint with flake8 32 | run: | 33 | # stop the build if there are Python syntax errors or undefined names 34 | flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics 35 | # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide 36 | flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics 37 | - name: Test with pytest 38 | run: | 39 | pip install -e .[test] 40 | pip install scikit-learn 41 | pytest 42 | -------------------------------------------------------------------------------- /.github/workflows/test-nns.yml: -------------------------------------------------------------------------------- 1 | name: test-nns 2 | 3 | on: 4 | push: 5 | branches: [ main ] 6 | pull_request: 7 | branches: [ main ] 8 | 9 | jobs: 10 | build: 11 | 12 | runs-on: ubuntu-latest 13 | strategy: 14 | matrix: 15 | python-version: ["3.10","3.11","3.12"] 16 | 17 | steps: 18 | - uses: actions/checkout@v2 19 | - name: Set up Python ${{ matrix.python-version }} 20 | uses: actions/setup-python@v2 21 | with: 22 | python-version: ${{ matrix.python-version }} 23 | - name: Install dependencies 24 | run: | 25 | python -m pip install --upgrade pip 26 | python -m pip install wheel 27 | python -m pip install flake8 pytest 28 | python -m pip install pathlib 29 | python -m pip install nns 30 | if [ -f requirements.txt ]; then pip install -r requirements.txt; fi 31 | - name: Lint with flake8 32 | run: | 33 | # stop the build if there are Python syntax errors or undefined names 34 | flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics 35 | # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide 36 | flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics 37 | - name: Test with pytest 38 | run: | 39 | pip install -e .[test] 40 | pip install scikit-learn 41 | pytest 42 | -------------------------------------------------------------------------------- /.github/workflows/test-orbit.yml: -------------------------------------------------------------------------------- 1 | # This workflow will install Python dependencies, run tests and lint with a variety of Python versions 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions 3 | 4 | name: test-orbit 5 | 6 | on: 7 | push: 8 | branches: [ main ] 9 | pull_request: 10 | branches: [ main ] 11 | 12 | jobs: 13 | build: 14 | 15 | runs-on: ubuntu-latest 16 | strategy: 17 | matrix: 18 | python-version: ["3.10","3.11","3.12"] 19 | 20 | steps: 21 | - uses: actions/checkout@v2 22 | - name: Set up Python ${{ matrix.python-version }} 23 | uses: actions/setup-python@v2 24 | with: 25 | python-version: ${{ matrix.python-version }} 26 | - name: Install dependencies 27 | run: | 28 | python -m pip install --upgrade pip 29 | python -m pip install wheel 30 | python -m pip install flake8 pytest 31 | python -m pip install pathlib 32 | python -m pip install orbit-ml 33 | if [ -f requirements.txt ]; then pip install -r requirements.txt; fi 34 | - name: Lint with flake8 35 | run: | 36 | # stop the build if there are Python syntax errors or undefined names 37 | flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics 38 | # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide 39 | flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics 40 | - name: Test with pytest 41 | run: | 42 | pip install -e .[test] 43 | pip install scikit-learn 44 | pytest 45 | -------------------------------------------------------------------------------- /.github/workflows/test-pmd.yml: -------------------------------------------------------------------------------- 1 | # This workflow will install Python dependencies, run tests and lint with a variety of Python versions 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions 3 | 4 | name: test-pmd 5 | 6 | on: 7 | push: 8 | branches: [ main ] 9 | pull_request: 10 | branches: [ main ] 11 | 12 | jobs: 13 | build: 14 | 15 | runs-on: ubuntu-latest 16 | strategy: 17 | matrix: 18 | python-version: ["3.10","3.11","3.12"] 19 | 20 | steps: 21 | - uses: actions/checkout@v2 22 | - name: Set up Python ${{ matrix.python-version }} 23 | uses: actions/setup-python@v2 24 | with: 25 | python-version: ${{ matrix.python-version }} 26 | - name: Install dependencies 27 | run: | 28 | python -m pip install --upgrade pip 29 | python -m pip install wheel 30 | python -m pip install flake8 pytest 31 | python -m pip install pathlib 32 | python -m pip install pmdarima 33 | if [ -f requirements.txt ]; then pip install -r requirements.txt; fi 34 | - name: Lint with flake8 35 | run: | 36 | # stop the build if there are Python syntax errors or undefined names 37 | flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics 38 | # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide 39 | flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics 40 | - name: Test with pytest 41 | run: | 42 | pip install -e .[test] 43 | pip install scikit-learn 44 | pytest 45 | -------------------------------------------------------------------------------- /.github/workflows/test-prophet.yml: -------------------------------------------------------------------------------- 1 | # This workflow will install Python dependencies, run tests and lint with a variety of Python versions 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions 3 | 4 | name: test-prophet 5 | 6 | on: 7 | push: 8 | branches: [ main ] 9 | pull_request: 10 | branches: [ main ] 11 | 12 | jobs: 13 | build: 14 | 15 | runs-on: ubuntu-latest 16 | strategy: 17 | matrix: 18 | python-version: ["3.10","3.11","3.12"] 19 | 20 | steps: 21 | - uses: actions/checkout@v2 22 | - name: Set up Python ${{ matrix.python-version }} 23 | uses: actions/setup-python@v2 24 | with: 25 | python-version: ${{ matrix.python-version }} 26 | - name: Install dependencies 27 | run: | 28 | python -m pip install --upgrade pip 29 | python -m pip install wheel 30 | python -m pip install flake8 pytest 31 | python -m pip install pathlib 32 | python -m pip install prophet 33 | if [ -f requirements.txt ]; then pip install -r requirements.txt; fi 34 | - name: Lint with flake8 35 | run: | 36 | # stop the build if there are Python syntax errors or undefined names 37 | flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics 38 | # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide 39 | flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics 40 | - name: Test with pytest 41 | run: | 42 | pip install -e .[test] 43 | pip install scikit-learn 44 | pytest 45 | -------------------------------------------------------------------------------- /.github/workflows/test-pydlm.yml: -------------------------------------------------------------------------------- 1 | # This workflow will install Python dependencies, run tests and lint with a variety of Python versions 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions 3 | 4 | name: test-pydlm 5 | 6 | on: 7 | push: 8 | branches: [ main ] 9 | pull_request: 10 | branches: [ main ] 11 | 12 | jobs: 13 | build: 14 | 15 | runs-on: ubuntu-latest 16 | strategy: 17 | matrix: 18 | python-version: ["3.10","3.11","3.12"] 19 | 20 | steps: 21 | - uses: actions/checkout@v2 22 | - name: Set up Python ${{ matrix.python-version }} 23 | uses: actions/setup-python@v2 24 | with: 25 | python-version: ${{ matrix.python-version }} 26 | - name: Install dependencies 27 | run: | 28 | python -m pip install --upgrade pip 29 | python -m pip install wheel 30 | python -m pip install flake8 pytest 31 | python -m pip install pathlib 32 | python -m pip install pydlm 33 | if [ -f requirements.txt ]; then pip install -r requirements.txt; fi 34 | - name: Lint with flake8 35 | run: | 36 | # stop the build if there are Python syntax errors or undefined names 37 | flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics 38 | # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide 39 | flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics 40 | - name: Test with pytest 41 | run: | 42 | pip install -e .[test] 43 | pip install scikit-learn 44 | pytest 45 | -------------------------------------------------------------------------------- /.github/workflows/test-river.yml: -------------------------------------------------------------------------------- 1 | 2 | name: test-river 3 | 4 | on: 5 | push: 6 | branches: [ main ] 7 | pull_request: 8 | branches: [ main ] 9 | 10 | jobs: 11 | build: 12 | 13 | runs-on: ubuntu-latest 14 | strategy: 15 | matrix: 16 | python-version: ["3.10","3.11","3.12"] 17 | 18 | steps: 19 | - uses: actions/checkout@v2 20 | - name: Set up Python ${{ matrix.python-version }} 21 | uses: actions/setup-python@v2 22 | with: 23 | python-version: ${{ matrix.python-version }} 24 | - name: Install dependencies 25 | run: | 26 | python -m pip install --upgrade pip 27 | python -m pip install wheel 28 | python -m pip install flake8 pytest 29 | python -m pip install pathlib 30 | python -m pip install --upgrade river 31 | if [ -f requirements.txt ]; then pip install -r requirements.txt; fi 32 | - name: Lint with flake8 33 | run: | 34 | # stop the build if there are Python syntax errors or undefined names 35 | flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics 36 | # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide 37 | flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics 38 | - name: Test with pytest 39 | run: | 40 | pip install -e .[test] 41 | pip install scikit-learn 42 | pytest 43 | -------------------------------------------------------------------------------- /.github/workflows/test-scikit-learn.yml: -------------------------------------------------------------------------------- 1 | # This workflow will install Python dependencies, run tests and lint with a variety of Python versions 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions 3 | 4 | name: test-scikit-learn 5 | 6 | on: 7 | push: 8 | branches: [ main ] 9 | pull_request: 10 | branches: [ main ] 11 | 12 | jobs: 13 | build: 14 | 15 | runs-on: ubuntu-latest 16 | strategy: 17 | matrix: 18 | python-version: ["3.10","3.11","3.12"] 19 | 20 | steps: 21 | - uses: actions/checkout@v2 22 | - name: Set up Python ${{ matrix.python-version }} 23 | uses: actions/setup-python@v2 24 | with: 25 | python-version: ${{ matrix.python-version }} 26 | - name: Install dependencies 27 | run: | 28 | python -m pip install --upgrade pip 29 | python -m pip install wheel 30 | python -m pip install flake8 pytest 31 | python -m pip install pathlib 32 | if [ -f requirements.txt ]; then pip install -r requirements.txt; fi 33 | - name: Lint with flake8 34 | run: | 35 | # stop the build if there are Python syntax errors or undefined names 36 | flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics 37 | # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide 38 | flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics 39 | - name: Test with pytest 40 | run: | 41 | python -m pip install --upgrade scikit-learn 42 | pytest 43 | -------------------------------------------------------------------------------- /.github/workflows/test-scipy.yml: -------------------------------------------------------------------------------- 1 | # Minimal test, even without scikit-learn 2 | 3 | name: test-scipy 4 | 5 | on: 6 | push: 7 | branches: [ main ] 8 | pull_request: 9 | branches: [ main ] 10 | 11 | jobs: 12 | build: 13 | 14 | runs-on: ubuntu-latest 15 | strategy: 16 | matrix: 17 | python-version: ["3.10","3.11","3.12"] 18 | 19 | steps: 20 | - uses: actions/checkout@v2 21 | - name: Set up Python ${{ matrix.python-version }} 22 | uses: actions/setup-python@v2 23 | with: 24 | python-version: ${{ matrix.python-version }} 25 | - name: Install dependencies 26 | run: | 27 | python -m pip install --upgrade pip 28 | python -m pip install wheel 29 | python -m pip install flake8 pytest 30 | python -m pip install pathlib 31 | if [ -f requirements.txt ]; then pip install -r requirements.txt; fi 32 | - name: Lint with flake8 33 | run: | 34 | # stop the build if there are Python syntax errors or undefined names 35 | flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics 36 | # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide 37 | flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics 38 | - name: Test with pytest 39 | run: | 40 | python -m pip install --upgrade scipy 41 | pytest 42 | -------------------------------------------------------------------------------- /.github/workflows/test-simdkalman.yml: -------------------------------------------------------------------------------- 1 | # This workflow will install Python dependencies, run tests and lint with a variety of Python versions 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions 3 | 4 | name: test-simdkalman 5 | 6 | on: 7 | push: 8 | branches: [ main ] 9 | pull_request: 10 | branches: [ main ] 11 | 12 | jobs: 13 | build: 14 | 15 | runs-on: ubuntu-latest 16 | strategy: 17 | matrix: 18 | python-version: ["3.10","3.11","3.12"] 19 | 20 | steps: 21 | - uses: actions/checkout@v2 22 | - name: Set up Python ${{ matrix.python-version }} 23 | uses: actions/setup-python@v2 24 | with: 25 | python-version: ${{ matrix.python-version }} 26 | - name: Install dependencies 27 | run: | 28 | python -m pip install --upgrade pip 29 | python -m pip install wheel 30 | python -m pip install flake8 pytest 31 | python -m pip install pathlib 32 | python -m pip install --upgrade git+https://github.com/oseiskar/simdkalman 33 | if [ -f requirements.txt ]; then pip install -r requirements.txt; fi 34 | - name: Lint with flake8 35 | run: | 36 | # stop the build if there are Python syntax errors or undefined names 37 | flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics 38 | # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide 39 | flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics 40 | - name: Test with pytest 41 | run: | 42 | pip install -e .[test] 43 | pip install scikit-learn 44 | pytest 45 | -------------------------------------------------------------------------------- /.github/workflows/test-sktime.yml: -------------------------------------------------------------------------------- 1 | # This workflow will install Python dependencies, run tests and lint with a variety of Python versions 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions 3 | 4 | name: test-sktime 5 | 6 | on: 7 | push: 8 | branches: [ main ] 9 | pull_request: 10 | branches: [ main ] 11 | 12 | jobs: 13 | build: 14 | 15 | runs-on: ubuntu-latest 16 | strategy: 17 | matrix: 18 | python-version: ["3.10","3.11","3.12"] 19 | 20 | steps: 21 | - uses: actions/checkout@v2 22 | - name: Set up Python ${{ matrix.python-version }} 23 | uses: actions/setup-python@v2 24 | with: 25 | python-version: ${{ matrix.python-version }} 26 | - name: Install dependencies 27 | run: | 28 | python -m pip install --upgrade pip 29 | python -m pip install wheel 30 | python -m pip install flake8 pytest 31 | python -m pip install pathlib 32 | python -m pip install sktime 33 | python -m pip install pmdarima 34 | if [ -f requirements.txt ]; then pip install -r requirements.txt; fi 35 | - name: Lint with flake8 36 | run: | 37 | # stop the build if there are Python syntax errors or undefined names 38 | flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics 39 | # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide 40 | flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics 41 | - name: Test with pytest 42 | run: | 43 | pip install -e .[test] 44 | pip install scikit-learn 45 | pytest 46 | -------------------------------------------------------------------------------- /.github/workflows/test-successor.yml: -------------------------------------------------------------------------------- 1 | # This workflow will install Python dependencies, run tests and lint with a variety of Python versions 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions 3 | 4 | name: test-successor 5 | 6 | on: 7 | push: 8 | branches: [ main ] 9 | pull_request: 10 | branches: [ main ] 11 | 12 | jobs: 13 | build: 14 | 15 | runs-on: ubuntu-latest 16 | strategy: 17 | matrix: 18 | python-version: ["3.10","3.11","3.12"] 19 | 20 | steps: 21 | - uses: actions/checkout@v2 22 | - name: Set up Python ${{ matrix.python-version }} 23 | uses: actions/setup-python@v2 24 | with: 25 | python-version: ${{ matrix.python-version }} 26 | - name: Install dependencies 27 | run: | 28 | python -m pip install --upgrade pip 29 | python -m pip install wheel 30 | python -m pip install flake8 pytest 31 | python -m pip install pathlib 32 | python -m pip install successor 33 | if [ -f requirements.txt ]; then pip install -r requirements.txt; fi 34 | - name: Lint with flake8 35 | run: | 36 | # stop the build if there are Python syntax errors or undefined names 37 | flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics 38 | # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide 39 | flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics 40 | - name: Test with pytest 41 | run: | 42 | pip install -e .[test] 43 | pytest 44 | -------------------------------------------------------------------------------- /.github/workflows/test-tbats.yml: -------------------------------------------------------------------------------- 1 | # This workflow will install Python dependencies, run tests and lint with a variety of Python versions 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions 3 | 4 | name: test-tbats 5 | 6 | on: 7 | push: 8 | branches: [ main ] 9 | pull_request: 10 | branches: [ main ] 11 | 12 | jobs: 13 | build: 14 | 15 | runs-on: ubuntu-latest 16 | strategy: 17 | matrix: 18 | python-version: ["3.10","3.11","3.12"] 19 | 20 | steps: 21 | - uses: actions/checkout@v2 22 | - name: Set up Python ${{ matrix.python-version }} 23 | uses: actions/setup-python@v2 24 | with: 25 | python-version: ${{ matrix.python-version }} 26 | - name: Install dependencies 27 | run: | 28 | python -m pip install --upgrade pip 29 | python -m pip install wheel 30 | python -m pip install flake8 pytest 31 | python -m pip install pathlib 32 | python -m pip install tbats 33 | if [ -f requirements.txt ]; then pip install -r requirements.txt; fi 34 | - name: Lint with flake8 35 | run: | 36 | # stop the build if there are Python syntax errors or undefined names 37 | flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics 38 | # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide 39 | flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics 40 | - name: Test with pytest 41 | run: | 42 | pip install -e .[test] 43 | pip install scikit-learn 44 | pytest 45 | -------------------------------------------------------------------------------- /.github/workflows/test-tcn.yml: -------------------------------------------------------------------------------- 1 | # This workflow will install Python dependencies, run tests and lint with a variety of Python versions 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions 3 | 4 | name: test-tcn 5 | 6 | on: 7 | push: 8 | branches: [ main ] 9 | pull_request: 10 | branches: [ main ] 11 | 12 | jobs: 13 | build: 14 | 15 | runs-on: ubuntu-latest 16 | strategy: 17 | matrix: 18 | python-version: ["3.10","3.11","3.12"] 19 | 20 | steps: 21 | - uses: actions/checkout@v2 22 | - name: Set up Python ${{ matrix.python-version }} 23 | uses: actions/setup-python@v2 24 | with: 25 | python-version: ${{ matrix.python-version }} 26 | - name: Install dependencies 27 | run: | 28 | python -m pip install --upgrade pip 29 | python -m pip install wheel 30 | python -m pip install flake8 pytest 31 | python -m pip install keras-tcn 32 | python -m pip install tf2onnx 33 | python -m pip install onnxruntime 34 | if [ -f requirements.txt ]; then pip install -r requirements.txt; fi 35 | - name: Lint with flake8 36 | run: | 37 | # stop the build if there are Python syntax errors or undefined names 38 | flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics 39 | # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide 40 | flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics 41 | - name: Test with pytest 42 | run: | 43 | pip install -e .[test] 44 | pip install scikit-learn 45 | pytest 46 | -------------------------------------------------------------------------------- /.github/workflows/test-tsa.yml: -------------------------------------------------------------------------------- 1 | # This workflow will install Python dependencies, run tests and lint with a variety of Python versions 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions 3 | 4 | name: test-tsa 5 | 6 | on: 7 | push: 8 | branches: [ main ] 9 | pull_request: 10 | branches: [ main ] 11 | 12 | jobs: 13 | build: 14 | 15 | runs-on: ubuntu-latest 16 | strategy: 17 | matrix: 18 | python-version: ["3.10","3.11","3.12"] 19 | 20 | steps: 21 | - uses: actions/checkout@v2 22 | - name: Set up Python ${{ matrix.python-version }} 23 | uses: actions/setup-python@v2 24 | with: 25 | python-version: ${{ matrix.python-version }} 26 | - name: Install dependencies 27 | run: | 28 | python -m pip install --upgrade pip 29 | python -m pip install wheel 30 | python -m pip install flake8 pytest 31 | python -m pip install pathlib 32 | python -m pip install --upgrade statsmodels 33 | if [ -f requirements.txt ]; then pip install -r requirements.txt; fi 34 | - name: Lint with flake8 35 | run: | 36 | # stop the build if there are Python syntax errors or undefined names 37 | flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics 38 | # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide 39 | flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics 40 | - name: Test with pytest 41 | run: | 42 | pip install scikit-learn 43 | pytest 44 | -------------------------------------------------------------------------------- /.github/workflows/test_statsforecast.yml: -------------------------------------------------------------------------------- 1 | # This workflow will install Python dependencies, run tests and lint with a variety of Python versions 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions 3 | 4 | name: test-statsforecast 5 | 6 | on: 7 | push: 8 | branches: [ main ] 9 | pull_request: 10 | branches: [ main ] 11 | 12 | jobs: 13 | build: 14 | 15 | runs-on: ubuntu-latest 16 | strategy: 17 | matrix: 18 | python-version: ["3.10","3.11","3.12"] 19 | 20 | steps: 21 | - uses: actions/checkout@v2 22 | - name: Set up Python ${{ matrix.python-version }} 23 | uses: actions/setup-python@v2 24 | with: 25 | python-version: ${{ matrix.python-version }} 26 | - name: Install dependencies 27 | run: | 28 | python -m pip install --upgrade pip 29 | python -m pip install wheel 30 | python -m pip install flake8 pytest 31 | python -m pip install pathlib 32 | python -m pip install sktime 33 | python -m pip install statsforecast 34 | if [ -f requirements.txt ]; then pip install -r requirements.txt; fi 35 | - name: Lint with flake8 36 | run: | 37 | # stop the build if there are Python syntax errors or undefined names 38 | flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics 39 | # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide 40 | flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics 41 | - name: Test with pytest 42 | run: | 43 | pip install -e .[test] 44 | pip install scikit-learn 45 | pytest 46 | 47 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | python: 3 | - "3.7" 4 | - "3.8" 5 | # command to install dependencies 6 | install: 7 | - python setup.py install 8 | - pip install . 9 | # command to run tests 10 | script: pytest 11 | -------------------------------------------------------------------------------- /CONTRIBUTE_COLAB_NOTEBOOK.md: -------------------------------------------------------------------------------- 1 | ## Contribution pattern: new colab notebook illustrating conventions of a package 2 | 3 | Do you have a favourite Python package for time-series analysis that you would like to see included in the funnel? There's some discussion 4 | on this [LI post](https://www.linkedin.com/posts/petercotton_timeseries-timeseriesanalysis-forecasting-activity-6844102671906037760-bGtu) 5 | 6 | ### When to use this pattern. 7 | 8 | - You maintain a time-series package, or just really like one. 9 | - Or you are intrigued by something on this [listing](https://github.com/microprediction/timemachines/issues?q=is%3Aissue+is%3Aopen+label%3A%22create+colab+example%22) 10 | 11 | ### How to contribute 12 | 13 | Notebook examples of timeseries packages are maintained in a separate repository [timeseries-notebooks](https://github.com/microprediction/timeseries-notebooks). However 14 | suggestions for which ones to include next are maintained in the [timemachines issues](https://github.com/microprediction/timemachines/issues?q=is%3Aissue+is%3Aopen+label%3A%22create+colab+example%22). 15 | 16 | Hopefully the issues are self-explanatory. See [this one](https://github.com/microprediction/timemachines/issues/83) for example. 17 | 18 | ### Why this helps 19 | 20 | Well, the primary maintainer of timemachines (and other contributors possible) suffer from convention fatigue as a result of looking at too many packages. By creating a simple notebook example you might 21 | be helping more than you think. Given a colab notebook example, it is usually short work to create a new skater and then include it in the Elo ratings. 22 | 23 | 24 | 25 | 26 | ![](https://i.imgur.com/l14hKmr.jpg) 27 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Peter Cotton 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /docs/README.md: -------------------------------------------------------------------------------- 1 | # Timemachines documentation ([install](https://github.com/microprediction/timemachines/blob/main/INSTALL.md)) 2 | 3 | View as [web page](https://microprediction.github.io/timemachines/) or [source](https://github.com/microprediction/timemachines/blob/main/docs/README.md) 4 | 5 | ### Start here 6 | 7 | - [Skaters](https://microprediction.github.io/timemachines/skaters.html) includes a listing of timeseries packages 8 | - [Uses](https://microprediction.github.io/timemachines/uses) of this package. 9 | 10 | See also [basic usage](https://github.com/microprediction/timemachines/tree/main/examples/basic_usage) examples in the repo. 11 | 12 | ### Contents 13 | See documentation [map](https://microprediction.github.io/timemachines/map.html) that includes [articles](https://microprediction.github.io/timemachines/articles.html) written about this package. 14 | 15 | 16 | 17 | 18 | ![skating](https://i.imgur.com/elu5muO.png) 19 | -------------------------------------------------------------------------------- /docs/assets/images/README.md: -------------------------------------------------------------------------------- 1 | Stuff 2 | -------------------------------------------------------------------------------- /docs/assets/images/microprediction_book.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/docs/assets/images/microprediction_book.png -------------------------------------------------------------------------------- /docs/assets/images/prophet_sensitivity.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/docs/assets/images/prophet_sensitivity.png -------------------------------------------------------------------------------- /docs/assets/images/sf_autoarima.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/docs/assets/images/sf_autoarima.png -------------------------------------------------------------------------------- /docs/assets/images/wiggle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/docs/assets/images/wiggle.png -------------------------------------------------------------------------------- /docs/ensembling.md: -------------------------------------------------------------------------------- 1 | # Ensembling skaters 2 | View as [web page](https://microprediction.github.io/timemachines/ensembling) or [source](https://github.com/microprediction/timemachines/blob/main/docs/ensembling.md). 3 | 4 | 5 | ### Precision weighted ensembles 6 | Create a new skater *f* that is a precision weighted ensemble of moving averages as follows: 7 | 8 | from timemachines.skaters.simple.movingaverage import EMA_BASIC_SKATERS 9 | def f(y :Y_TYPE, s:dict, k:int =1, a:A_TYPE =None, t:T_TYPE =None, e:E_TYPE =None)->([float] , Any , Any): 10 | return precision_weighted_ensemble_factory(fs=EMA_BASIC_SKATERS,y=y,s=s,k=k,a=a,t=t,e=e,r=0.5) 11 | 12 | Modify the *r* parameter to make the ensemble more evenly weighted, or less. 13 | 14 | 15 | ### Implementation 16 | 17 | - See the [ensembling](https://github.com/microprediction/timemachines/tree/main/timemachines/skatertools/ensembling) utilities. 18 | 19 | 20 | ### Articles about ensembling skaters 21 | 22 | - [The Only Prediction Function You'll Ever Need?](https://microprediction.medium.com/the-only-prediction-function-youll-ever-need-fe2ae42eaff0) 23 | 24 | 25 | 26 | -+- 27 | 28 | Documentation [map](https://microprediction.github.io/timemachines/map.html) 29 | 30 | 31 | 32 | 33 | ![skating](https://i.imgur.com/elu5muO.png) 34 | -------------------------------------------------------------------------------- /docs/resources.md: -------------------------------------------------------------------------------- 1 | # Some General Python Timeseries Resources 2 | (Placeholder) 3 | 4 | 5 | - [Articles](https://microprediction.github.io/timemachines/articles.html) about the timemachines package. 6 | - List of [interesting papers or code](https://github.com/microprediction/timemachines/issues?q=is%3Aissue+is%3Aopen+label%3A%22papers+or+code+to+read%22) I keep meaning to get to and implement. 7 | 8 | 9 | -+- 10 | 11 | Documentation [map](https://microprediction.github.io/timemachines/map.html) 12 | 13 | 14 | 15 | 16 | ![skating](https://i.imgur.com/elu5muO.png) 17 | -------------------------------------------------------------------------------- /docs/template.md: -------------------------------------------------------------------------------- 1 | ## Timemachines: Predict with One Line of Code 2 | View as [web page](https://microprediction.github.io/timemachines/) or [source](https://github.com/microprediction/timemachines/blob/main/docs/template.md). 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | ### Python 11 | 12 | 13 | 14 | ### API 15 | 16 | -+- 17 | 18 | Documentation [map](https://microprediction.github.io/timemachines/map.html) 19 | 20 | 21 | 22 | 23 | ![skating](https://i.imgur.com/elu5muO.png) 24 | -------------------------------------------------------------------------------- /examples/README.md: -------------------------------------------------------------------------------- 1 | 2 | ## Demos 3 | 4 | 5 | The script [demo_balanced_log_scale.py](https://github.com/microprediction/timemachines/blob/master/examples/demo_balanced_log_scale.py) illustrates the 6 | quasi-logarithmic parameter mapping from r in (0,1) to R. 7 | 8 | ![](https://i.imgur.com/NCFCTeK.png) 9 | 10 | 11 | The script [demo_param_ordering.py](https://github.com/microprediction/timemachines/blob/master/examples/demo_param_ordering.py) illustrates 12 | the mapping from r in (0,1) to R^n. Observe why the most important parameter should be listed first. It will vary 13 | more smoothly as we vary r. 14 | 15 | [![IMAGE ALT TEXT](https://i.imgur.com/4F1oHXR.png)](https://vimeo.com/497113737 "Parameter importance") 16 | Click to see video 17 | 18 | 19 | ## Model demos 20 | 21 | Most of the model modules are runnable. 22 | 23 | -------------------------------------------------------------------------------- /examples/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/examples/__init__.py -------------------------------------------------------------------------------- /examples/basic_usage/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/examples/basic_usage/__init__.py -------------------------------------------------------------------------------- /examples/basic_usage/run_elo_skater.py: -------------------------------------------------------------------------------- 1 | from timemachines.skaters.elo.eloensembles import elo_faster_residual_balanced_ensemble 2 | import numpy as np 3 | 4 | 5 | if __name__=='__main__': 6 | y = np.cumsum(np.random.randn(1000)) 7 | s = {} 8 | x = list() 9 | for yi in y: 10 | xi, x_std, s = elo_faster_residual_balanced_ensemble(y=yi, s=s, k=3) 11 | x.append(xi) 12 | -------------------------------------------------------------------------------- /examples/basic_usage/run_skater.py: -------------------------------------------------------------------------------- 1 | from timemachines.skaters.simple.thinking import thinking_slow_and_fast 2 | import numpy as np 3 | 4 | 5 | if __name__=='__main__': 6 | y = np.cumsum(np.random.randn(1000)) 7 | s = {} 8 | x = list() 9 | for yi in y: 10 | xi, x_std, s = thinking_slow_and_fast(y=yi, s=s, k=3) 11 | x.append(xi) -------------------------------------------------------------------------------- /examples/basic_usage/run_skater_and_measure_forecast_error_manually.py: -------------------------------------------------------------------------------- 1 | from timemachines.skaters.simple.thinking import thinking_slow_and_slow 2 | from timemachines.skating import prior 3 | from timemachines.skatertools.data.real import hospital 4 | import math 5 | import numpy as np 6 | 7 | if __name__=='__main__': 8 | y = hospital(n=200) 9 | x_prior, x_std_prior = prior(f=thinking_slow_and_slow,y=y,k=3) 10 | x_ahead_k = [ xt[-1] for xt in x_prior ] # prior returns k-offset vectors 11 | n_burn = 50 12 | sq_errors = [ (x1-x2)**2 for x1,x2 in zip(y[n_burn:],x_ahead_k[n_burn:])] 13 | print(math.sqrt(np.mean(sq_errors))) -------------------------------------------------------------------------------- /examples/basic_usage/run_skater_and_return _forecast_error.py: -------------------------------------------------------------------------------- 1 | from timemachines.skaters.simple.thinking import thinking_slow_and_slow 2 | from timemachines.skatertools.evaluation.evaluators import hospital_mean_square_error_with_sporadic_fit 3 | 4 | 5 | if __name__=='__main__': 6 | print(hospital_mean_square_error_with_sporadic_fit(f=thinking_slow_and_slow,n=120,fit_frequency=10)) -------------------------------------------------------------------------------- /examples/basic_usage/run_skater_predict_five_ahead_and_plot.py: -------------------------------------------------------------------------------- 1 | from timemachines.skaters.simple.thinking import thinking_slow_and_slow 2 | from timemachines.skatertools.visualization.priorplot import prior_plot 3 | from timemachines.skatertools.data.real import hospital 4 | import matplotlib.pyplot as plt 5 | 6 | if __name__=='__main__': 7 | y = hospital(n=200) 8 | prior_plot(f=thinking_slow_and_slow,y=y,k=5) 9 | plt.show() -------------------------------------------------------------------------------- /examples/basic_usage/run_skater_predict_next_and_plot.py: -------------------------------------------------------------------------------- 1 | from timemachines.skaters.simple.thinking import thinking_slow_and_slow 2 | from timemachines.skatertools.visualization.priorplot import prior_plot 3 | from timemachines.skatertools.data.real import hospital 4 | import matplotlib.pyplot as plt 5 | 6 | if __name__=='__main__': 7 | y = hospital(n=200) 8 | prior_plot(f=thinking_slow_and_slow,y=y) 9 | plt.show() -------------------------------------------------------------------------------- /examples/basic_usage/run_statsforecast_skater.py: -------------------------------------------------------------------------------- 1 | try: 2 | from timemachines.skaters.sk.sfautoarima import sf_autoarima as f 3 | except ImportError: 4 | print('pip install timemachines') 5 | print('pip install sktime') 6 | print('pip install statsmodels') 7 | 8 | import numpy as np 9 | 10 | # Example of running Nixtla statsforecast AutoARIMA sequentially over 100 data points 11 | 12 | if __name__=='__main__': 13 | y = np.cumsum(np.random.randn(100)) 14 | s = {} 15 | x = list() 16 | for yi in y: 17 | xi, x_std, s = f(y=yi, s=s, k=3, e=1000) 18 | x.append(xi) 19 | -------------------------------------------------------------------------------- /examples/basic_usage/run_statsforecast_skater_with_hypocratic_chasing.py: -------------------------------------------------------------------------------- 1 | try: 2 | from timemachines.skaters.sk.sfautoarimahypocratic import sf_autoarima_hypocratic as f 3 | except ImportError: 4 | print('pip install timemachines') 5 | print('pip install sktime') 6 | print('pip install statsforecast') 7 | 8 | import numpy as np 9 | 10 | # Example of running Nixtla statsforecast AutoARIMA sequentially over 100 data points, and chasing residuals. 11 | 12 | if __name__=='__main__': 13 | y = np.cumsum(np.random.randn(100)) 14 | s = {} 15 | x = list() 16 | for yi in y: 17 | xi, x_std, s = f(y=yi, s=s, k=3, e=1000) 18 | x.append(xi) 19 | -------------------------------------------------------------------------------- /examples/comparing/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/examples/comparing/__init__.py -------------------------------------------------------------------------------- /examples/comparing/comparesarima.py: -------------------------------------------------------------------------------- 1 | from timemachines.inclusion.sklearninclusion import using_sklearn 2 | from timemachines.skaters.sk.sfinclusion import using_statsforecast 3 | from timemachines.skaters.sk.skinclusion import using_sktime 4 | from timemachines.skaters.pmd.pmdinclusion import using_pmd 5 | from timemachines.skatertools.comparison.comparing import compare 6 | from timemachines.skatertools.data.ornstein import simulate_arima_like_path 7 | 8 | # An example of comparing some skaters' performance 9 | # Modify the list of skaters and the data as you see fit 10 | 11 | 12 | if __name__=='__main__': 13 | if using_statsforecast and using_sklearn and using_sktime and using_pmd: 14 | from timemachines.skaters.elo.forever import forever as f1 15 | from timemachines.skaters.simple.trivial import trivial_last_value as f2 16 | from timemachines.skaters.sk.sfautoarima import sf_autoarima as f3 17 | from timemachines.skaters.tsa.tsaconstant import tsa_aggressive_ensemble as f4 18 | fs = [f1, f2, f3, f4] # <--- Add as you see fit 19 | 20 | # Make data with different ARIMA-like processes 21 | ys = [] 22 | for k in range(25): 23 | ys = ys + list(simulate_arima_like_path(seq_len=500)[100:]) 24 | 25 | compare(fs=fs, ys=ys, n_test=10, n_train=200) 26 | else: 27 | print('pip install statsforecast') 28 | print('pip install sktime') 29 | print('pip install pmdarima') -------------------------------------------------------------------------------- /examples/data/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/examples/data/__init__.py -------------------------------------------------------------------------------- /examples/data/demo_synthetic_exogenous.py: -------------------------------------------------------------------------------- 1 | from timemachines.skatertools.data.synthetic import brownian_with_exogenous 2 | 3 | 4 | if __name__=='__main__': 5 | import matplotlib.pyplot as plt 6 | y = brownian_with_exogenous(n=50) 7 | plt.plot(y) 8 | plt.legend(['target','exogenous']) 9 | plt.grid() 10 | plt.show() -------------------------------------------------------------------------------- /examples/data/get_random_correlation_matrix.py: -------------------------------------------------------------------------------- 1 | from timemachines.skatertools.data.skaterresiduals import random_multivariate_residual 2 | 3 | 4 | if __name__=='__main__': 5 | df = random_multivariate_residual(n_obs=1000) 6 | the_corrcoef = df.corr() 7 | print(the_corrcoef[:3].transpose()) 8 | -------------------------------------------------------------------------------- /examples/data/get_random_covariance_matrix.py: -------------------------------------------------------------------------------- 1 | from timemachines.skatertools.data.skaterresiduals import random_multivariate_residual 2 | from pprint import pprint 3 | 4 | if __name__=='__main__': 5 | df = random_multivariate_residual(n_obs=1000) 6 | the_cov = df.cov() 7 | pprint(the_cov[:3].transpose()) 8 | -------------------------------------------------------------------------------- /examples/data/get_random_multivariate_data.py: -------------------------------------------------------------------------------- 1 | from timemachines.skatertools.data.skaterresiduals import random_multivariate_residual 2 | import numpy as np 3 | 4 | 5 | if __name__=='__main__': 6 | X = random_multivariate_residual(n_obs=1000) 7 | print(np.shape(X)) 8 | -------------------------------------------------------------------------------- /examples/data/get_random_precision_matrix.py: -------------------------------------------------------------------------------- 1 | from timemachines.skatertools.data.skaterresiduals import random_multivariate_residual 2 | import numpy as np 3 | import pandas as pd 4 | 5 | if __name__=='__main__': 6 | df = random_multivariate_residual(n_obs=1000) 7 | the_cov = df.cov() 8 | df_inv = pd.DataFrame(data=np.linalg.pinv(the_cov.values), columns=the_cov.columns, index=the_cov.index) 9 | print(df_inv[:3].transpose()) 10 | -------------------------------------------------------------------------------- /examples/data/get_random_univariate_data.py: -------------------------------------------------------------------------------- 1 | from timemachines.skatertools.data.long import random_long_data 2 | 3 | # Pulls 'fathom' data which has reasonable signal but plenty of noise too 4 | 5 | if __name__=='__main__': 6 | import matplotlib.pyplot as plt 7 | y,t = random_long_data(n_obs=10000) 8 | plt.plot(t,y) 9 | plt.grid() 10 | plt.show() -------------------------------------------------------------------------------- /examples/hyper/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/examples/hyper/__init__.py -------------------------------------------------------------------------------- /examples/hyper/demo_balanced_log_scale.py: -------------------------------------------------------------------------------- 1 | 2 | import matplotlib.pyplot as plt 3 | import numpy as np 4 | from timemachines.skatertools.utilities.conventions import to_log_space_1d 5 | 6 | if __name__=='__main__': 7 | us = np.linspace(start=0,stop=1,num=150) 8 | ys = [to_log_space_1d(u, low=-300, high=700) for u in us] 9 | plt.plot(us, ys) 10 | plt.title('Parameter convention (1-dim)') 11 | plt.grid() 12 | plt.show() -------------------------------------------------------------------------------- /examples/hyper/demo_param_ordering.py: -------------------------------------------------------------------------------- 1 | 2 | import matplotlib.pyplot as plt 3 | import numpy as np 4 | from timemachines.skatertools.utilities.conventions import to_log_space 5 | 6 | 7 | # Illustrates mapping from (0,1) to parameters in R^3 8 | 9 | 10 | 11 | 12 | if __name__=='__main__': 13 | 14 | bounds = [(-300,300), (-1,1), (-3,3) ] 15 | fig = plt.figure() 16 | ax = fig.add_subplot(111, projection='3d') 17 | step = 0.0005 18 | 19 | vs = list() 20 | ts = list() 21 | tail_len = 1000 22 | 23 | rs = np.linspace(start=0, stop=1, num=1000) 24 | for step_no, r in enumerate(rs): 25 | ts.append(r) 26 | v = to_log_space(p=r, bounds=bounds) 27 | vs.append(v) 28 | trailing = vs[-tail_len:] 29 | tail = max(ts[:-tail_len] + [0.0001]) 30 | x, y, z = zip(*trailing) 31 | ax.clear() 32 | ax.plot(x, y, z) 33 | ax.scatter([x[-1]], [y[-1]], [z[-1]], s=100) 34 | ax.set_xlim(bounds[0]) 35 | ax.set_ylim(bounds[1]) 36 | ax.set_zlim(bounds[2]) 37 | ax.set_xlabel('Most important parameter') 38 | ax.set_ylabel('Second most important') 39 | ax.set_zlabel('Third most important') 40 | ax.set_title('t -> (' + str(np.round(tail, 4)).zfill(4) + ',' + str(np.round(r, 4)).zfill(4) + ')') 41 | plt.show(block=False) 42 | plt.pause(0.05) 43 | if step_no == 0: 44 | plt.pause(2) 45 | 46 | x, y, z = zip(*vs) 47 | ax.plot(x, y, z) 48 | plt.show() 49 | 50 | plt.title('Parameter convention (1-dim)') 51 | plt.grid() 52 | plt.show() -------------------------------------------------------------------------------- /examples/performance/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/examples/performance/__init__.py -------------------------------------------------------------------------------- /examples/performance/sf_wiggly_performance.py: -------------------------------------------------------------------------------- 1 | from timemachines.skatertools.comparison.performancerating import performance_rating 2 | 3 | 4 | if __name__=='__main__': 5 | from timemachines.skaters.sk.sfautoarimawiggly import SF_AUTOARIMA_WIGGLY_SKATERS 6 | from timemachines.skaters.sk.sfautoarima import sf_autoarima 7 | skater_names = [f.__name__ for f in SF_AUTOARIMA_WIGGLY_SKATERS + [sf_autoarima] ] 8 | performance_rating(skater_names=skater_names, update_frequency=1) -------------------------------------------------------------------------------- /examples/performance/sk_sf_wiggly_performance.py: -------------------------------------------------------------------------------- 1 | from timemachines.skatertools.comparison.performancerating import performance_rating 2 | 3 | 4 | if __name__=='__main__': 5 | from timemachines.skaters.sk.skautoarimawiggly import sk_autoarima_wiggly_mean_d05_m3, \ 6 | sk_autoarima_wiggly_huber_d05_m3 7 | from timemachines.skaters.sk.sfautoarimawiggly import sf_autoarima_wiggly_mean_d05_m3, \ 8 | sf_autoarima_wiggly_huber_d05_m3 9 | from timemachines.skaters.sk.skautoarima import sk_autoarima 10 | from timemachines.skaters.sk.sfautoarima import sf_autoarima 11 | 12 | skater_names = [f.__name__ for f in [sk_autoarima, 13 | sf_autoarima, 14 | sk_autoarima_wiggly_huber_d05_m3, 15 | sk_autoarima_wiggly_mean_d05_m3, 16 | sf_autoarima_wiggly_mean_d05_m3, 17 | sf_autoarima_wiggly_huber_d05_m3] ] 18 | performance_rating(skater_names=skater_names, update_frequency=1) -------------------------------------------------------------------------------- /examples/performance/wiggly_performance_two.py: -------------------------------------------------------------------------------- 1 | from timemachines.skatertools.comparison.performancerating import performance_rating 2 | 3 | 4 | if __name__=='__main__': 5 | from timemachines.skaters.sk.sfautoarimawiggly import sf_autoarima_wiggly_d050_m1, \ 6 | sf_autoarima_wiggly_d050_m2, sf_autoarima_wiggly_d010_m2 7 | from timemachines.skaters.sk.sfautoarima import sf_autoarima 8 | skaters = [ sf_autoarima, 9 | sf_autoarima_wiggly_d050_m1, 10 | sf_autoarima_wiggly_d050_m2, 11 | sf_autoarima_wiggly_d010_m2 ] 12 | skater_names = [f.__name__ for f in skaters ] 13 | performance_rating(skater_names=skater_names, update_frequency=1) -------------------------------------------------------------------------------- /examples/sensitivity/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/examples/sensitivity/__init__.py -------------------------------------------------------------------------------- /examples/sensitivity/skaterdiscontinuity.py: -------------------------------------------------------------------------------- 1 | from timemachines.skatertools.visualization.skaterbumpplot import skater_bump_plot 2 | 3 | 4 | if __name__=='__main__': 5 | #from timemachines.skaters.sk.skautoarima import sk_autoarima as f 6 | #from timemachines.skaters.simple.thinking import thinking_fast_and_slow as f 7 | #from timemachines.skaters.simple.movingaverage import precision_ema_ensemble as f 8 | #from timemachines.skaters.tsa.tsatheta import tsa_theta_additive as f 9 | from timemachines.skaters.sk.sfautoarima import sf_autoarima as f 10 | #from timemachines.skaters.proph.prophskaterssingular import fbprophet_univariate as f 11 | 12 | skater_bump_plot(f=f, ndx=-3, k=1) 13 | 14 | -------------------------------------------------------------------------------- /examples/tuning/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/examples/tuning/__init__.py -------------------------------------------------------------------------------- /images/download_time.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/images/download_time.png -------------------------------------------------------------------------------- /images/money.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/images/money.png -------------------------------------------------------------------------------- /images/talking_heads.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/images/talking_heads.jpeg -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | convertdate>=2.4.0 2 | microconventions>=0.5.5 3 | importlib-metadata>=1.7.0 4 | momentum>=0.2.5 5 | numpy>=1.19.5 6 | pytz>=2021.3 7 | scikit-learn 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /tests/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/tests/__init__.py -------------------------------------------------------------------------------- /tests/bats/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/tests/bats/__init__.py -------------------------------------------------------------------------------- /tests/bats/test_bats_inferface.py: -------------------------------------------------------------------------------- 1 | from timemachines.skatertools.data.real import hospital 2 | import random 3 | from timemachines.skaters.bats.batsinclusion import using_bats 4 | 5 | if using_bats: 6 | from timemachines.skaters.bats.batsifactory import bats_iskater_factory 7 | from timemachines.skaters.bats.allbatsskaters import BATS_SKATERS 8 | 9 | def test_univariate_without_time(show=False): 10 | k = 3 11 | n = 100 12 | f = random.choice(BATS_SKATERS) 13 | y = hospital(n=n) 14 | x, x_std = bats_iskater_factory(y=y, k=k) 15 | 16 | 17 | if __name__ == '__main__': 18 | import time 19 | st = time.time() 20 | test_univariate_without_time() 21 | print(time.time()-st) 22 | -------------------------------------------------------------------------------- /tests/bats/test_bats_random_skater.py: -------------------------------------------------------------------------------- 1 | from timemachines.skatertools.data.real import hospital 2 | import random 3 | from timemachines.skaters.bats.batsinclusion import using_bats 4 | from timemachines.skating import prior 5 | 6 | if using_bats: 7 | from timemachines.skaters.bats.allbatsskaters import BATS_SKATERS 8 | 9 | def test_random_skater(show=False): 10 | k = 3 11 | n = 100 12 | f = random.choice(BATS_SKATERS) 13 | y = hospital(n=n) 14 | e = [-1]*90+[100]+[-1]*90 15 | x, x_std = prior(f=f, y=y, k=k, e=e ) 16 | 17 | 18 | if __name__ == '__main__': 19 | import time 20 | st = time.time() 21 | test_random_skater() 22 | print(time.time()-st) 23 | -------------------------------------------------------------------------------- /tests/components/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/tests/components/__init__.py -------------------------------------------------------------------------------- /tests/darts/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/tests/darts/__init__.py -------------------------------------------------------------------------------- /tests/darts/test_darts_random_skater.py: -------------------------------------------------------------------------------- 1 | from timemachines.skatertools.data.real import hospital 2 | import random 3 | from timemachines.skaters.drts.dartsinclusion import using_darts 4 | from timemachines.skating import prior 5 | 6 | if using_darts: 7 | from timemachines.skaters.drts.alldartsskaters import DARTS_SKATERS 8 | 9 | def test_random_skater(show=False): 10 | k = 3 11 | n = 100 12 | f = random.choice(DARTS_SKATERS) 13 | print( f.__name__ ) 14 | y = hospital(n=n) 15 | neg_y = [-yt for yt in y] 16 | e = [-1]*90+[100]+[-1]*90 17 | x, x_std = prior(f=f, y=neg_y, k=k, e=e ) 18 | 19 | 20 | if __name__ == '__main__': 21 | assert using_darts, 'pip install darts and also other requirements for darts packages' 22 | import time 23 | for _ in range(100): 24 | st = time.time() 25 | test_random_skater() 26 | print(time.time()-st) 27 | -------------------------------------------------------------------------------- /tests/divine/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/tests/divine/__init__.py -------------------------------------------------------------------------------- /tests/divine/test_divine.py: -------------------------------------------------------------------------------- 1 | from timemachines.skaters.divine.divineinclusion import using_divinity, dv 2 | if using_divinity: 3 | from timemachines.skaters.divine.divineskaters import divine_univariate 4 | from timemachines.skatertools.evaluation.evaluators import hospital_mean_square_error_with_sporadic_fit 5 | 6 | 7 | def dont_test_divine(): # too noisy 8 | err = hospital_mean_square_error_with_sporadic_fit(f=divine_univariate, n=105) # Won't get past warmup so not a real test 9 | 10 | 11 | if __name__=='__main__': 12 | assert using_divinity,'pip install divinity' 13 | dont_test_divine() -------------------------------------------------------------------------------- /tests/dlm/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/tests/dlm/__init__.py -------------------------------------------------------------------------------- /tests/dlm/test_dlm_exogenous.py: -------------------------------------------------------------------------------- 1 | from timemachines.skaters.dlm.dlmunivariate import using_dlm 2 | if using_dlm: 3 | from timemachines.skaters.dlm.dlmexogenous import dlm_exogenous_r3, dlm_exogenous_b 4 | from timemachines.skatertools.evaluation.evaluators import hospital_mean_square_error_with_sporadic_fit, hospital_exog_mean_square_error_with_sporadic_fit 5 | import numpy as np 6 | 7 | 8 | def test_dlm_exogenous(): 9 | print(hospital_exog_mean_square_error_with_sporadic_fit(f=dlm_exogenous_r3, k=1, n=150, fit_frequency=100, n_test=1, r=np.random.rand())) 10 | print(hospital_exog_mean_square_error_with_sporadic_fit(f=dlm_exogenous_b, k=1, n=150, fit_frequency=100, n_test=1)) 11 | 12 | 13 | def test_dlm_exogenous_on_univariate(): 14 | print(hospital_mean_square_error_with_sporadic_fit(f=dlm_exogenous_b, k=1, n=150, fit_frequency=100, n_test=1)) 15 | 16 | 17 | if __name__=='__main__': 18 | test_dlm_exogenous_on_univariate() -------------------------------------------------------------------------------- /tests/dlm/test_dlm_univariate.py: -------------------------------------------------------------------------------- 1 | from timemachines.skaters.dlm.dlmunivariate import using_dlm 2 | if using_dlm: 3 | 4 | from timemachines.skaters.dlm.dlmunivariate import dlm_univariate_a, dlm_univariate_r3 5 | from timemachines.skatertools.evaluation.evaluators import hospital_mean_square_error_with_sporadic_fit 6 | 7 | 8 | def test_dlm_auto_univariate(): 9 | print(hospital_mean_square_error_with_sporadic_fit(f=dlm_univariate_a, k=3, n=150, fit_frequency=100, n_test=1)) 10 | print(hospital_mean_square_error_with_sporadic_fit(f=dlm_univariate_r3, k=3, n=150, fit_frequency=100, n_test=1, r=0.53)) 11 | 12 | 13 | if __name__=='__main__': 14 | test_dlm_auto_univariate() -------------------------------------------------------------------------------- /tests/elo/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/tests/elo/__init__.py -------------------------------------------------------------------------------- /tests/elo/http_cache.sqlite: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/tests/elo/http_cache.sqlite -------------------------------------------------------------------------------- /tests/elo/test_elo_random_skater.py: -------------------------------------------------------------------------------- 1 | import random 2 | from timemachines.skaters.elo.alleloskaters import ELO_SKATERS 3 | from timemachines.skating import prior 4 | from timemachines.skatertools.data.real import hospital 5 | from timemachines.skatertools.utilities.internet import connected_to_internet 6 | 7 | if connected_to_internet(): 8 | 9 | def test_random_elo_skater(): 10 | for _ in range(15): 11 | k = random.choice([1,3,5,11]) 12 | n = 100 13 | f = random.choice(ELO_SKATERS) 14 | y = hospital(n=n) 15 | e = [-1]*90+[100]+[-1]*90 16 | x, x_std = prior(f=f, y=y, k=k, e=e ) 17 | 18 | 19 | if __name__ == '__main__': 20 | import time 21 | st = time.time() 22 | test_random_elo_skater() 23 | print(time.time()-st) 24 | -------------------------------------------------------------------------------- /tests/elo/test_fib.py: -------------------------------------------------------------------------------- 1 | from timemachines.skatertools.recommendations.suggestions import closest_fib 2 | 3 | 4 | def test_closest(): 5 | assert closest_fib(1.4)==1 6 | assert closest_fib(14) ==13 7 | assert closest_fib(-3) ==1 8 | assert closest_fib(1000) ==34 9 | 10 | 11 | -------------------------------------------------------------------------------- /tests/gk/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/tests/gk/__init__.py -------------------------------------------------------------------------------- /tests/gk/test_greykite_random_skater.py: -------------------------------------------------------------------------------- 1 | from timemachines.skatertools.data.real import hospital 2 | import random 3 | from timemachines.skaters.gk.greykiteinclusion import using_greykite 4 | from timemachines.skating import prior 5 | 6 | if using_greykite: 7 | from timemachines.skaters.gk.allgreykiteskaters import GREYKITE_SKATERS 8 | 9 | def test_random_skater(show=False): 10 | k = 3 11 | n = 100 12 | f = random.choice(GREYKITE_SKATERS) 13 | y = hospital(n=n) 14 | neg_y = [-yt for yt in y] 15 | e = [-1]*90+[100]+[-1]*90 16 | x, x_std = prior(f=f, y=neg_y, k=k, e=e ) 17 | 18 | 19 | if __name__ == '__main__': 20 | import time 21 | for _ in range(100): 22 | st = time.time() 23 | test_random_skater() 24 | print(time.time()-st) 25 | -------------------------------------------------------------------------------- /tests/kts/README.md: -------------------------------------------------------------------------------- 1 | Placeholder for Facebook KATS -------------------------------------------------------------------------------- /tests/kts/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/tests/kts/__init__.py -------------------------------------------------------------------------------- /tests/kts/test_kats_random_skater.py: -------------------------------------------------------------------------------- 1 | from timemachines.skatertools.data.real import hospital 2 | import random 3 | from timemachines.skaters.kts.ktsinclusion import using_kats 4 | from timemachines.skating import prior 5 | 6 | if using_kats: 7 | from timemachines.skaters.kts.allkatsskaters import KATS_SKATERS 8 | 9 | def test_random_skater(show=False): 10 | k = 3 11 | n = 100 12 | f = random.choice(KATS_SKATERS) 13 | print( f.__name__ ) 14 | y = hospital(n=n) 15 | neg_y = [-yt for yt in y] 16 | e = [-1]*90+[100]+[-1]*90 17 | x, x_std = prior(f=f, y=neg_y, k=k, e=e ) 18 | 19 | 20 | if __name__ == '__main__': 21 | assert using_kats, 'pip install kats' 22 | import time 23 | for _ in range(100): 24 | st = time.time() 25 | test_random_skater() 26 | print(time.time()-st) 27 | -------------------------------------------------------------------------------- /tests/mrln/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/tests/mrln/__init__.py -------------------------------------------------------------------------------- /tests/mrln/test_merlion_random_skater.py: -------------------------------------------------------------------------------- 1 | from timemachines.skatertools.data.real import hospital 2 | import random 3 | from timemachines.skaters.mrln.merlioninclusion import using_merlion 4 | from timemachines.skating import prior 5 | 6 | 7 | if using_merlion: 8 | from timemachines.skaters.mrln.allmerlionskaters import MERLION_SKATERS 9 | 10 | def test_random_skater(show=False): 11 | k = 3 12 | n = 100 13 | f = random.choice(MERLION_SKATERS) 14 | print( f.__name__ ) 15 | y = hospital(n=n) 16 | neg_y = [-yt for yt in y] 17 | e = [-1]*90+[100]+[-1]*90 18 | x, x_std = prior(f=f, y=neg_y, k=k, e=e ) 19 | 20 | 21 | if __name__ == '__main__': 22 | assert using_merlion, 'pip install salesforce-merlion' 23 | import time 24 | for _ in range(100): 25 | st = time.time() 26 | test_random_skater() 27 | print(time.time()-st) 28 | -------------------------------------------------------------------------------- /tests/nproph/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/tests/nproph/__init__.py -------------------------------------------------------------------------------- /tests/nproph/test_nprophet_interface.py: -------------------------------------------------------------------------------- 1 | from timemachines.skatertools.data.real import hospital 2 | from timemachines.skaters.nproph.nprophetinclusion import using_neuralprophet 3 | if using_neuralprophet: 4 | from timemachines.skaters.nproph.nprophetiskaterfactory import nprophet_fit_and_predict_simple, nprophet_iskater_factory 5 | 6 | def test_univariate_without_time(show=False): 7 | k = 3 8 | n = 100 9 | y = hospital(n=n) 10 | x, x_std, forecast, m = nprophet_iskater_factory(y=y, k=k) 11 | assert len(x) == k 12 | x1, x_std1, forecast1, m1 = nprophet_fit_and_predict_simple(y=y, k=k) 13 | if show: 14 | m.plot(forecast) 15 | m1.plot(forecast1) 16 | import matplotlib.pyplot as plt 17 | plt.show() 18 | 19 | 20 | if __name__=='__main__': 21 | test_univariate_without_time(show=True) -------------------------------------------------------------------------------- /tests/nproph/test_nprophet_skaters.py: -------------------------------------------------------------------------------- 1 | from timemachines.skaters.nproph.nprophetiskaterfactory import using_neuralprophet 2 | if using_neuralprophet: 3 | 4 | from timemachines.skaters.nproph.nprophetskaters import nprophet_p1, nprophet_p8 5 | from timemachines.skatertools.evaluation.evaluators import hospital_mean_square_error_with_sporadic_fit 6 | 7 | NPROPHET_TO_TEST = [ nprophet_p1, nprophet_p8 ] 8 | 9 | 10 | def test_ensemble(): 11 | for f in NPROPHET_TO_TEST: 12 | err = hospital_mean_square_error_with_sporadic_fit(f=f, k=5, n=100, fit_frequency=70) 13 | 14 | 15 | 16 | if __name__=='__main__': 17 | import time 18 | st = time.time() 19 | test_ensemble() 20 | print(time.time()-st) -------------------------------------------------------------------------------- /tests/orbt/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/tests/orbt/__init__.py -------------------------------------------------------------------------------- /tests/orbt/test_lgt.py: -------------------------------------------------------------------------------- 1 | from timemachines.skaters.orbt.allorbitskaters import ORBIT_LGT_SKATERS 2 | from timemachines.inclusion.sklearninclusion import using_sklearn 3 | 4 | if using_sklearn: 5 | def test_ensemble(): 6 | from timemachines.skatertools.evaluation.evaluators import hospital_mean_square_error_with_sporadic_fit 7 | for f in ORBIT_LGT_SKATERS: 8 | err = hospital_mean_square_error_with_sporadic_fit(f=f, k=5, n=150, fit_frequency=100000, n_test=1) 9 | 10 | 11 | 12 | if __name__=='__main__': 13 | test_ensemble() -------------------------------------------------------------------------------- /tests/pmd/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/tests/pmd/__init__.py -------------------------------------------------------------------------------- /tests/pmd/test_pmd.py: -------------------------------------------------------------------------------- 1 | from timemachines.skaters.pmd.pmdinclusion import using_pmd, pm 2 | if using_pmd: 3 | from timemachines.skaters.pmd.allpmdskaters import PMD_SKATERS 4 | from timemachines.skaters.pmd.pmdskaters import pmd_exogenous 5 | from timemachines.skatertools.evaluation.evaluators import hospital_mean_square_error_with_sporadic_fit, hospital_exog_mean_square_error_with_sporadic_fit 6 | 7 | def test_pmd_auto_univariate(): 8 | for f in PMD_SKATERS: 9 | err = hospital_mean_square_error_with_sporadic_fit(f=f, k=5, n=150) 10 | 11 | 12 | def test_pmd_auto_exogenous(): 13 | err = hospital_exog_mean_square_error_with_sporadic_fit(f=pmd_exogenous, k=3, n=150) 14 | 15 | 16 | if __name__=='__main__': 17 | assert using_pmd,'pip install pmdarima' 18 | test_pmd_auto_univariate() 19 | test_pmd_auto_exogenous() -------------------------------------------------------------------------------- /tests/proph/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/tests/proph/__init__.py -------------------------------------------------------------------------------- /tests/proph/test_proph_random_skater.py: -------------------------------------------------------------------------------- 1 | from timemachines.skatertools.data.real import hospital 2 | import random 3 | from timemachines.skaters.proph.prophiskaterfactory import using_prophet 4 | from timemachines.skating import prior 5 | 6 | if using_prophet: 7 | from timemachines.skaters.proph.allprophetskaters import PROPHET_SKATERS 8 | 9 | def test_random_prophet_skater(show=False): 10 | k = 3 11 | n = 100 12 | f = random.choice(PROPHET_SKATERS) 13 | print(f.__name__) 14 | y = hospital(n=n) 15 | e = [-1]*90+[100]+[-1]*90 16 | x, x_std = prior(f=f, y=y, k=k, e=e ) 17 | 18 | 19 | if __name__ == '__main__': 20 | import time 21 | st = time.time() 22 | test_random_prophet_skater() 23 | print(time.time()-st) 24 | -------------------------------------------------------------------------------- /tests/proph/test_prophet_skaters.py: -------------------------------------------------------------------------------- 1 | from timemachines.skaters.proph.prophskaterfactory import using_prophet 2 | -------------------------------------------------------------------------------- /tests/pyrct/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/tests/pyrct/__init__.py -------------------------------------------------------------------------------- /tests/pyrct/test_pycrt_random_skater.py: -------------------------------------------------------------------------------- 1 | from timemachines.skatertools.data.real import hospital 2 | import random 3 | from timemachines.skaters.sk.skinclusion import using_sktime 4 | from timemachines.skaters.pycrt.pycaretinclusion import using_pycaret 5 | from timemachines.skating import prior 6 | 7 | if using_sktime and using_pycaret: 8 | from timemachines.skaters.pycrt.allpycaretskaters import PYCRT_SKATERS 9 | 10 | def test_random_skater(show=False): 11 | k = 3 12 | n = 100 13 | f = random.choice(PYCRT_SKATERS) 14 | y = hospital(n=n) 15 | neg_y = [-yt for yt in y] 16 | e = [-1]*90+[100]+[-5]*5+[100]*5 17 | x, x_std = prior(f=f, y=neg_y, k=k, e=e ) 18 | 19 | 20 | if __name__ == '__main__': 21 | import time 22 | st = time.time() 23 | test_random_skater() 24 | print(time.time()-st) 25 | -------------------------------------------------------------------------------- /tests/rvr/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/tests/rvr/__init__.py -------------------------------------------------------------------------------- /tests/rvr/test_river_random_skater.py: -------------------------------------------------------------------------------- 1 | import random 2 | from timemachines.skaters.rvr.rvrinclusion import using_river 3 | from timemachines.skating import prior 4 | 5 | if using_river: 6 | from timemachines.skaters.rvr.allriverskaters import RIVER_SKATERS 7 | from timemachines.skatertools.data.real import hospital 8 | 9 | def test_random_river_skaters(): 10 | # River is fast :) 11 | for _ in range(20): 12 | k = random.choice([1,3,5,11]) 13 | n = 100 14 | f = random.choice(RIVER_SKATERS) 15 | y = hospital(n=n) 16 | e = [-1]*90+[100]+[-1]*90 17 | x, x_std = prior(f=f, y=y, k=k, e=e ) 18 | 19 | 20 | if __name__ == '__main__': 21 | import time 22 | st = time.time() 23 | test_random_river_skaters() 24 | print(time.time()-st) 25 | -------------------------------------------------------------------------------- /tests/simple/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/tests/simple/__init__.py -------------------------------------------------------------------------------- /tests/simple/test_simple.py: -------------------------------------------------------------------------------- 1 | from timemachines.skaters.simple.movingaverage import precision_ema_ensemble, aggressive_ema_ensemble 2 | 3 | SIMPLE_TO_TEST = [ precision_ema_ensemble, aggressive_ema_ensemble ] 4 | 5 | 6 | from timemachines.inclusion.sklearninclusion import using_sklearn 7 | if using_sklearn: 8 | from timemachines.skatertools.evaluation.evaluators import hospital_mean_square_error_with_sporadic_fit, \ 9 | hospital_exog_mean_square_error_with_sporadic_fit 10 | 11 | def test_ensemble_errors(): 12 | for f in SIMPLE_TO_TEST: 13 | err = hospital_mean_square_error_with_sporadic_fit(f=f, k=5, n=150, fit_frequency=1) 14 | 15 | 16 | 17 | 18 | 19 | if __name__=='__main__': 20 | assert using_sklearn 21 | test_ensemble_errors() -------------------------------------------------------------------------------- /tests/sk/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/tests/sk/__init__.py -------------------------------------------------------------------------------- /tests/sk/test_sf_autoarima.py: -------------------------------------------------------------------------------- 1 | from timemachines.skatertools.data.real import hospital 2 | import random 3 | from timemachines.skaters.sk.skinclusion import using_sktime 4 | from timemachines.skaters.sk.sfinclusion import using_statsforecast 5 | from timemachines.skating import prior 6 | 7 | if using_sktime and using_statsforecast: 8 | from timemachines.skaters.sk.sfautoarima import sf_autoarima 9 | 10 | def test_sf_autoarima(show=False): 11 | k = 3 12 | n = 100 13 | f = sf_autoarima 14 | y = hospital(n=n) 15 | neg_y = [-yt for yt in y[:20]] 16 | e = [-1]*15+[100]+[-1]*90 17 | x, x_std = prior(f=f, y=neg_y, k=k, e=e ) 18 | 19 | 20 | if __name__ == '__main__': 21 | import time 22 | for _ in range(2): 23 | st = time.time() 24 | test_sf_autoarima(show=True) 25 | print(time.time()-st) 26 | -------------------------------------------------------------------------------- /tests/sk/test_sf_autoarima_wiggly.py: -------------------------------------------------------------------------------- 1 | from timemachines.skatertools.data.real import hospital 2 | import random 3 | from timemachines.skaters.sk.skinclusion import using_sktime 4 | from timemachines.skaters.sk.sfinclusion import using_statsforecast 5 | from timemachines.skating import prior 6 | 7 | if using_sktime and using_statsforecast: 8 | from timemachines.skaters.sk.sfautoarimawiggly import SF_AUTOARIMA_WIGGLY_SKATERS 9 | 10 | def test_random_skater(show=False): 11 | k = 3 12 | n = 100 13 | f = random.choice(SF_AUTOARIMA_WIGGLY_SKATERS) 14 | y = hospital(n=n) 15 | neg_y = [-yt for yt in y[:20]] 16 | e = [-1]*90+[100]+[-1]*90 17 | x, x_std = prior(f=f, y=neg_y, k=k, e=e ) 18 | 19 | 20 | if __name__ == '__main__': 21 | import time 22 | for _ in range(2): 23 | st = time.time() 24 | test_random_skater() 25 | print(time.time()-st) 26 | -------------------------------------------------------------------------------- /tests/sk/test_sf_hypocratic.py: -------------------------------------------------------------------------------- 1 | from timemachines.skatertools.data.real import hospital 2 | import random 3 | from timemachines.skaters.sk.skinclusion import using_sktime 4 | from timemachines.skaters.sk.sfinclusion import using_statsforecast 5 | from timemachines.skating import prior 6 | 7 | if using_sktime and using_statsforecast: 8 | from timemachines.skaters.sk.sfautoarimahypocratic import SF_HYPOCRATIC_SKATERS 9 | 10 | def test_random_skater(show=False): 11 | k = 3 12 | n = 100 13 | f = random.choice(SF_HYPOCRATIC_SKATERS) 14 | y = hospital(n=n) 15 | neg_y = [-yt for yt in y] 16 | e = [-1]*90+[100]+[-1]*90 17 | x, x_std = prior(f=f, y=neg_y, k=k, e=e ) 18 | 19 | 20 | if __name__ == '__main__': 21 | import time 22 | for _ in range(100): 23 | st = time.time() 24 | test_random_skater() 25 | print(time.time()-st) 26 | -------------------------------------------------------------------------------- /tests/sk/test_sf_random_skater.py: -------------------------------------------------------------------------------- 1 | from timemachines.skatertools.data.real import hospital 2 | import random 3 | from timemachines.skaters.sk.skinclusion import using_sktime 4 | from timemachines.skaters.sk.sfinclusion import using_statsforecast 5 | from timemachines.skating import prior 6 | 7 | if using_sktime and using_statsforecast: 8 | from timemachines.skaters.sk.sfautoarima import SF_AA_SKATERS 9 | 10 | def test_random_skater(show=False): 11 | k = 3 12 | n = 100 13 | f = random.choice(SF_AA_SKATERS) 14 | y = hospital(n=n) 15 | neg_y = [-yt for yt in y] 16 | e = [-1]*90+[100]+[-1]*90 17 | x, x_std = prior(f=f, y=neg_y, k=k, e=e ) 18 | 19 | 20 | if __name__ == '__main__': 21 | import time 22 | for _ in range(100): 23 | st = time.time() 24 | test_random_skater() 25 | print(time.time()-st) 26 | -------------------------------------------------------------------------------- /tests/sk/test_sk_auto_random_skater.py: -------------------------------------------------------------------------------- 1 | from timemachines.skatertools.data.real import hospital 2 | import random 3 | from timemachines.skaters.sk.skinclusion import using_sktime 4 | from timemachines.skaters.pmd.pmdinclusion import using_pmd 5 | from timemachines.skating import prior 6 | 7 | if using_sktime and using_pmd: 8 | from timemachines.skaters.sk.skautoarima import SK_AA_SKATERS 9 | 10 | def test_random_skater(show=False): 11 | k = 3 12 | n = 100 13 | f = random.choice(SK_AA_SKATERS) 14 | y = hospital(n=n) 15 | neg_y = [-yt for yt in y] 16 | e = [-1]*90+[100]+[-1]*90 17 | x, x_std = prior(f=f, y=neg_y, k=k, e=e ) 18 | 19 | 20 | if __name__ == '__main__': 21 | import time 22 | for _ in range(100): 23 | st = time.time() 24 | test_random_skater() 25 | print(time.time()-st) 26 | -------------------------------------------------------------------------------- /tests/sk/test_sk_random_skater.py: -------------------------------------------------------------------------------- 1 | from timemachines.skatertools.data.real import hospital 2 | import random 3 | from timemachines.skaters.sk.skinclusion import using_sktime 4 | from timemachines.skaters.pmd.pmdinclusion import using_pmd 5 | from timemachines.skating import prior 6 | 7 | if using_sktime: 8 | from timemachines.skaters.sk.allskskaters import SK_SKATERS 9 | 10 | def test_random_skater(show=False): 11 | k = 3 12 | n = 100 13 | f = random.choice(SK_SKATERS) 14 | y = hospital(n=n) 15 | neg_y = [-yt for yt in y] 16 | e = [-1]*90+[100]+[-1]*90 17 | x, x_std = prior(f=f, y=neg_y, k=k, e=e ) 18 | 19 | 20 | if __name__ == '__main__': 21 | import time 22 | for _ in range(100): 23 | st = time.time() 24 | test_random_skater() 25 | print(time.time()-st) 26 | -------------------------------------------------------------------------------- /tests/smdk/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/tests/smdk/__init__.py -------------------------------------------------------------------------------- /tests/smdk/test_smdk_random_skater.py: -------------------------------------------------------------------------------- 1 | import random 2 | from timemachines.skaters.smdk.smdkinclusion import using_simdkalman 3 | from timemachines.skating import prior 4 | 5 | if using_simdkalman: 6 | from timemachines.skaters.smdk.allsmdkskaters import SMDK_SKATERS 7 | from timemachines.skatertools.data.real import hospital 8 | 9 | def test_random_smdk_skaters(): 10 | for _ in range(4): 11 | k = random.choice([1,3,5,11]) 12 | n = 100 13 | f = random.choice(SMDK_SKATERS) 14 | y = hospital(n=n) 15 | e = [-1]*90+[100]+[-1]*90 16 | x, x_std = prior(f=f, y=y, k=k, e=e ) 17 | 18 | 19 | if __name__ == '__main__': 20 | import time 21 | st = time.time() 22 | test_random_smdk_skaters() 23 | print(time.time()-st) 24 | -------------------------------------------------------------------------------- /tests/smoothing/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/tests/smoothing/__init__.py -------------------------------------------------------------------------------- /tests/smoothing/test_sf_smooth.py: -------------------------------------------------------------------------------- 1 | from timemachines.skatertools.data.real import hospital 2 | import random 3 | from timemachines.skaters.sk.skinclusion import using_sktime 4 | from timemachines.skaters.sk.sfinclusion import using_statsforecast 5 | from timemachines.skating import prior 6 | 7 | if using_sktime and using_statsforecast: 8 | from timemachines.skaters.sk.sfautoarima import SF_AA_SKATERS 9 | from timemachines.skatertools.smoothing.wiggling import wiggler 10 | 11 | def test_random_skater_smooth(show=False): 12 | k = 3 13 | n = 15 14 | f = random.choice(SF_AA_SKATERS) 15 | 16 | def g(y,s,k): 17 | return wiggler(f=f, y=y, s=s, k=k, m=2) 18 | 19 | y = hospital(n=n) 20 | 21 | s = {} 22 | for yi in y: 23 | x, x_std, s = g(y=yi, s=s, k=k) 24 | 25 | if __name__ == '__main__': 26 | import time 27 | for _ in range(2): 28 | st = time.time() 29 | test_random_skater_smooth() 30 | print(time.time()-st) 31 | -------------------------------------------------------------------------------- /tests/suc/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/tests/suc/__init__.py -------------------------------------------------------------------------------- /tests/suc/test_all_successor_skaters.py: -------------------------------------------------------------------------------- 1 | from timemachines.skaters.suc.successorinclusion import using_successor 2 | from timemachines.skating import prior 3 | 4 | if using_successor: 5 | from successor.skaters.allsuccessorskaters import SUCCESSOR_SKATERS 6 | from timemachines.skatertools.data.real import hospital 7 | 8 | def test_all_successor_skaters(): 9 | for k in [3,1,11]: 10 | n = 100 11 | for f in SUCCESSOR_SKATERS: 12 | y = hospital(n=n) 13 | e = [-1]*90+[100]+[-1]*90 14 | x, x_std = prior(f=f, y=y, k=k, e=e ) 15 | 16 | 17 | if __name__ == '__main__': 18 | import time 19 | st = time.time() 20 | test_all_successor_skaters() 21 | print(time.time()-st) 22 | -------------------------------------------------------------------------------- /tests/test_augmentation.py: -------------------------------------------------------------------------------- 1 | from timemachines.skatertools.evaluation.evaluators import chunk_to_end 2 | 3 | 4 | def test_chunk_from_end(): 5 | ys = [1,2,3,4,5,6,7,8] 6 | chunks = chunk_to_end(ys,5) 7 | assert len(chunks[0])==5 8 | assert len(chunks)==1 9 | assert chunks[0][0]==4 -------------------------------------------------------------------------------- /tests/test_elo_rating_integrity.py: -------------------------------------------------------------------------------- 1 | from timemachines.skatertools.utilities.internet import connected_to_internet 2 | if connected_to_internet(): 3 | 4 | 5 | from timemachines.skatertools.recommendations.suggestions import top_rated_models_in_one_category, get_ratings 6 | from pprint import pprint 7 | 8 | 9 | def test_top_rated_models(): 10 | for k in [1,5, 8, 13,21,34]: 11 | print('k='+str(k)) 12 | suggestions = top_rated_models_in_one_category(k=k, max_seconds=500, require_passing=True) 13 | pprint(suggestions) 14 | print('') 15 | 16 | def dont_test_integrity_of_elo_ratings(): 17 | PROPERTIES = ['name', 'count', 'rating', 'traceback', 'seconds', 'pypi'] 18 | for category in ['univariate','residual']: 19 | for k in [1,2, 5, 8, 13,21,34]: 20 | print('k='+str(k)) 21 | rd = get_ratings(k=k,category=category) 22 | for property in PROPERTIES: 23 | if rd.get(property) is None: 24 | raise ValueError('property '+property+' missing for category '+category+' k='+str(k)) 25 | 26 | 27 | if __name__=='__main__': 28 | assert connected_to_internet() 29 | dont_test_integrity_of_elo_ratings() -------------------------------------------------------------------------------- /tests/test_freq.py: -------------------------------------------------------------------------------- 1 | from timemachines.inclusion.pandasinclusion import using_pandas 2 | 3 | if using_pandas: 4 | from timemachines.skatertools.utilities.epochtime import infer_freq_from_epoch, RECENT_SECONDS,naive_datetime_to_epoch, epoch_to_naive_datetime 5 | 6 | def test_date_stuff(): 7 | seconds = [1,5,7,10] 8 | dts = epoch_to_naive_datetime(seconds) 9 | sec_back = naive_datetime_to_epoch(dts) 10 | dts_back = epoch_to_naive_datetime(sec_back) 11 | assert all([t1==t2 for t1,t2 in zip(dts,dts_back)]) 12 | assert all([int(s1)==int(s2) for s1,s2 in zip(seconds, sec_back)]) 13 | 14 | 15 | def test_inference(): 16 | # https://github.com/pandas-dev/pandas/blob/master/pandas/tseries/frequencies.py 17 | expected = {'s':[RECENT_SECONDS + j for j in range(200)], 18 | '5s':[RECENT_SECONDS + 5 * j for j in range(200)], 19 | 'min':[RECENT_SECONDS + 60 * j for j in range(200)], 20 | '5min':[RECENT_SECONDS + 5 * 60 * j for j in range(200)]} # 5 minutes 21 | for expected_freq, t in expected.items(): 22 | freq = infer_freq_from_epoch(t) 23 | assert freq==expected_freq 24 | 25 | 26 | if __name__=='__main__': 27 | test_date_stuff() 28 | test_inference() -------------------------------------------------------------------------------- /tests/test_long.py: -------------------------------------------------------------------------------- 1 | 2 | from timemachines.inclusion.pandasinclusion import using_pandas 3 | 4 | if using_pandas: 5 | 6 | def test_long(): 7 | from timemachines.skatertools.data.long import random_long_data 8 | t,y = random_long_data(n_obs=30000) 9 | assert len(y)==30000 10 | 11 | 12 | if __name__=='__main__': 13 | test_long() -------------------------------------------------------------------------------- /tests/test_optimizers.py: -------------------------------------------------------------------------------- 1 | from timemachines.inclusion.humpdayinclusion import using_humpday 2 | 3 | if using_humpday: 4 | from humpday.optimizers.alloptimizers import OPTIMIZERS 5 | from humpday.objectives.classic import CLASSIC_OBJECTIVES 6 | import random 7 | 8 | # Just to check if someone (ahem) breaks humpday 9 | 10 | def test_optimizers(): 11 | n_trials = 10 12 | n_dim = random.choice([2,3]) 13 | optimizer = random.choice(OPTIMIZERS) 14 | objective = random.choice(CLASSIC_OBJECTIVES) 15 | best_val, best_x, feval_count = optimizer(objective, n_trials=n_trials,n_dim=n_dim,with_count=True) 16 | else: 17 | def test_optimizers(): 18 | print('pip install humpday') 19 | 20 | 21 | if __name__=='__main__': 22 | assert using_humpday,'pip install humpday' 23 | test_optimizers() -------------------------------------------------------------------------------- /tests/test_residual_data.py: -------------------------------------------------------------------------------- 1 | 2 | from timemachines.inclusion.pandasinclusion import using_pandas 3 | import numpy as np 4 | 5 | if using_pandas: 6 | 7 | def test_residual_data(): 8 | from timemachines.skatertools.data.skaterresiduals import random_multivariate_residual 9 | X = random_multivariate_residual(n_obs=100, random_start=False) 10 | print(np.shape(X)) 11 | 12 | def test_residual_data_random(): 13 | from timemachines.skatertools.data.skaterresiduals import random_multivariate_residual 14 | X = random_multivariate_residual(n_obs=100, random_start=True) 15 | print(np.shape(X)) 16 | 17 | 18 | if __name__=='__main__': 19 | test_residual_data() 20 | test_residual_data_random() -------------------------------------------------------------------------------- /tests/test_setup.py: -------------------------------------------------------------------------------- 1 | 2 | def test_nothin(): 3 | assert True -------------------------------------------------------------------------------- /tests/tsa/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/tests/tsa/__init__.py -------------------------------------------------------------------------------- /tests/tsa/test_tsa.py: -------------------------------------------------------------------------------- 1 | from timemachines.inclusion.statsmodelsinclusion import using_statsmodels 2 | 3 | if using_statsmodels: 4 | from timemachines.skaters.tsa.tsaconstant import tsa_p1_d0_q0, tsa_aggressive_ensemble 5 | from timemachines.skaters.tsa.tsahypocratic import tsa_quickly_hypocratic_d0_ensemble 6 | from timemachines.skatertools.evaluation.evaluators import hospital_mean_square_error_with_sporadic_fit 7 | 8 | TSA_TO_TEST = [ tsa_p1_d0_q0, tsa_aggressive_ensemble, tsa_quickly_hypocratic_d0_ensemble ] 9 | 10 | from timemachines.inclusion.sklearninclusion import using_sklearn 11 | if using_sklearn: 12 | def test_tsa_error(): 13 | for f in TSA_TO_TEST: 14 | err = hospital_mean_square_error_with_sporadic_fit(f=f, k=5, n=50, fit_frequency=1, n_test=10) 15 | 16 | 17 | 18 | if __name__=='__main__': 19 | assert using_sklearn 20 | test_tsa_error() -------------------------------------------------------------------------------- /tests/tsa/test_tsa_ensemble.py: -------------------------------------------------------------------------------- 1 | 2 | from timemachines.inclusion.statsmodelsinclusion import using_statsmodels 3 | from timemachines.inclusion.sklearninclusion import using_sklearn 4 | import numpy as np 5 | 6 | if using_statsmodels and using_sklearn: 7 | 8 | from timemachines.skaters.tsa.tsaconstant import tsa_p1_d0_q0, tsa_p1_d0_q1 9 | 10 | fs = [ tsa_p1_d0_q0, tsa_p1_d0_q1 ] 11 | 12 | from timemachines.skatertools.ensembling.ensemblefactory import precision_weighted_ensemble_factory 13 | 14 | def my_skater(y,s,k,**ignore): 15 | return precision_weighted_ensemble_factory(y=y,s=s,k=k,fs=fs) 16 | 17 | s = {} 18 | for y in np.random.randn(25): 19 | x, x_std, s = my_skater(y=y,s=s,k=1) 20 | 21 | 22 | -------------------------------------------------------------------------------- /timemachines/__init__.py: -------------------------------------------------------------------------------- 1 | from timemachines.skating import prior, posterior, residuals 2 | from timemachines.skatertools.visualization.priorplot import prior_plot, prior_plot_exogenous -------------------------------------------------------------------------------- /timemachines/inclusion/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/timemachines/inclusion/__init__.py -------------------------------------------------------------------------------- /timemachines/inclusion/humpdayinclusion.py: -------------------------------------------------------------------------------- 1 | try: 2 | import humpday 3 | using_humpday = True 4 | except ImportError: 5 | using_humpday = False 6 | -------------------------------------------------------------------------------- /timemachines/inclusion/matplotlibinclusion.py: -------------------------------------------------------------------------------- 1 | try: 2 | import matplotlib.pyplot as plt 3 | using_matplotlib = True 4 | except Exception as e: # Could be different kinds of error 5 | using_matplotlib = False 6 | plt = None -------------------------------------------------------------------------------- /timemachines/inclusion/micropredictioninclusion.py: -------------------------------------------------------------------------------- 1 | try: 2 | import microprediction 3 | using_microprediction = True 4 | except ImportError: 5 | using_microprediction = False 6 | -------------------------------------------------------------------------------- /timemachines/inclusion/pandasinclusion.py: -------------------------------------------------------------------------------- 1 | try: 2 | import pandas as pd 3 | using_pandas = True 4 | except ImportError: 5 | pd = 'pip install pandas' 6 | using_pandas = False 7 | -------------------------------------------------------------------------------- /timemachines/inclusion/scipyinclusion.py: -------------------------------------------------------------------------------- 1 | try: 2 | from scipy.stats import energy_distance 3 | using_scipy = True 4 | except ImportError: 5 | using_scipy = False 6 | -------------------------------------------------------------------------------- /timemachines/inclusion/sfinclusion.py: -------------------------------------------------------------------------------- 1 | try: 2 | import statsforecast 3 | using_statsforecast = True 4 | except ImportError: 5 | using_statsforecast = False 6 | -------------------------------------------------------------------------------- /timemachines/inclusion/sklearninclusion.py: -------------------------------------------------------------------------------- 1 | try: 2 | from sklearn.metrics import mean_squared_error, mean_absolute_error 3 | using_sklearn = True 4 | except ImportError: 5 | using_sklearn = False 6 | -------------------------------------------------------------------------------- /timemachines/inclusion/statsmodelsinclusion.py: -------------------------------------------------------------------------------- 1 | try: 2 | from statsmodels.tsa.arima.model import ARIMA 3 | using_statsmodels = True 4 | except ImportError: 5 | try: 6 | from statsmodels.tsa.arima_model import ARIMA 7 | using_statsmodels = True 8 | except: 9 | using_statsmodels = False 10 | -------------------------------------------------------------------------------- /timemachines/inclusion/threezainclusion.py: -------------------------------------------------------------------------------- 1 | try: 2 | import threeza 3 | using_threeza = True 4 | except ImportError: 5 | using_threeza = False 6 | -------------------------------------------------------------------------------- /timemachines/skaters/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/timemachines/skaters/.DS_Store -------------------------------------------------------------------------------- /timemachines/skaters/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/timemachines/skaters/__init__.py -------------------------------------------------------------------------------- /timemachines/skaters/allskaters.py: -------------------------------------------------------------------------------- 1 | from timemachines.skaters.localskaters import LOCAL_SKATERS, FAST_LOCAL_SKATERS 2 | from timemachines.skaters.networkedskaters import NETWORKED_SKATERS, FAST_NETWORKED_SKATERS 3 | 4 | SKATERS = NETWORKED_SKATERS + LOCAL_SKATERS 5 | FAST_SKATERS = FAST_LOCAL_SKATERS + FAST_NETWORKED_SKATERS 6 | 7 | 8 | def skater_from_name(name): 9 | valid = [f for f in SKATERS if f.__name__ == name] 10 | return valid[0] if len(valid)==1 else None 11 | 12 | -------------------------------------------------------------------------------- /timemachines/skaters/ats/README.md: -------------------------------------------------------------------------------- 1 | Placeholder for AutoTS 2 | https://github.com/microprediction/timemachines/issues/41 3 | -------------------------------------------------------------------------------- /timemachines/skaters/ats/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/timemachines/skaters/ats/__init__.py -------------------------------------------------------------------------------- /timemachines/skaters/ats/atsinclusion.py: -------------------------------------------------------------------------------- 1 | 2 | try: 3 | import auto_ts 4 | using_ats = True 5 | except ImportError: 6 | using_ats = False 7 | -------------------------------------------------------------------------------- /timemachines/skaters/bats/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/timemachines/skaters/bats/__init__.py -------------------------------------------------------------------------------- /timemachines/skaters/bats/batsifactory.py: -------------------------------------------------------------------------------- 1 | from typing import List, Tuple, Any 2 | from timemachines.skatertools.utilities.conventions import wrap 3 | from timemachines.skatertools.utilities.suppression import no_stdout_stderr 4 | from timemachines.skaters.bats.batsinclusion import using_bats 5 | 6 | if using_bats: 7 | from tbats import TBATS 8 | 9 | def bats_iskater_factory(y: [[float]], k: int, a: List = None, t: List = None, e=None, freq: str = None, n_max=1000, 10 | use_box_cox=None, box_cox_bounds=(0, 1), 11 | use_trend=None, use_damped_trend=None, 12 | seasonal_periods=None, use_arma_errors=True): 13 | if a: 14 | assert len(a) == len(y) + k 15 | 16 | if isinstance(y[0], float): 17 | y = [wrap(yj) for yj in y] 18 | 19 | estimator = TBATS(use_box_cox=use_box_cox, box_cox_bounds=box_cox_bounds, 20 | use_trend=use_trend, use_damped_trend=use_damped_trend, 21 | seasonal_periods=seasonal_periods, use_arma_errors=use_arma_errors) 22 | with no_stdout_stderr(): 23 | fitted_model = estimator.fit(y) 24 | x = list(fitted_model.forecast(steps=k)) 25 | x_std = [1.0 for _ in x] 26 | return x, x_std 27 | 28 | 29 | if __name__=='__main__': 30 | assert using_bats, 'pip install tbats' 31 | import numpy as np 32 | import time 33 | st = time.time() 34 | y = list(np.cumsum(np.random.randn(400))) 35 | x, x_std = bats_iskater_factory(y=y,k=5) 36 | print(x) 37 | print(time.time()-st) 38 | -------------------------------------------------------------------------------- /timemachines/skaters/bats/batsinclusion.py: -------------------------------------------------------------------------------- 1 | 2 | try: 3 | import tbats 4 | using_bats = True 5 | except ImportError: 6 | using_bats = False 7 | # pending issue possibily similar to sklearn similar to https://github.com/alkaline-ml/pmdarima/pull/455 8 | 9 | -------------------------------------------------------------------------------- /timemachines/skaters/divine/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/timemachines/skaters/divine/__init__.py -------------------------------------------------------------------------------- /timemachines/skaters/divine/divineinclusion.py: -------------------------------------------------------------------------------- 1 | try: 2 | import divinity as dv 3 | using_divinity = True 4 | except ImportError: 5 | class God: 6 | maybe = True 7 | dv = God() 8 | using_divinity = False -------------------------------------------------------------------------------- /timemachines/skaters/divine/divineparams.py: -------------------------------------------------------------------------------- 1 | 2 | MIN_N_WARM = 101 # Library will fail if history is too small 3 | 4 | DIVINE_MODEL = dict(confidence_interval = 34.134*2, # So it is +/- one standard deviation 5 | seasonal_periods = [7, 14., 28., 30., 90., 120., 182., 365.], 6 | optimise_trend_season_features=True, 7 | trend_order=[0, 1] 8 | ) 9 | -------------------------------------------------------------------------------- /timemachines/skaters/divine/divineskaters.py: -------------------------------------------------------------------------------- 1 | from timemachines.skaters.divine.divineinclusion import using_divinity 2 | if using_divinity: 3 | from timemachines.skaters.divine.divineskaterfactory import divinity_univariate_factory 4 | from timemachines.skatertools.composition.residualshypocratic import quickly_moving_hypocratic_residual_factory, slowly_moving_hypocratic_residual_factory 5 | 6 | def divine_univariate(y,s,k,a=None,t=None,e=None): 7 | return divinity_univariate_factory(y=y, s=s, k=k, a=a, t=t, e=e) 8 | 9 | 10 | def divine_univariate_hypocratic_slow(y,s,k,a=None,t=None,e=None): 11 | return slowly_moving_hypocratic_residual_factory(f=divine_univariate, y=y,s=s,k=k,a=a,t=t,e=e) 12 | 13 | 14 | def divine_univariate_hypocratic_fast(y,s,k,a=None,t=None,e=None): 15 | return quickly_moving_hypocratic_residual_factory(f=divine_univariate, y=y,s=s,k=k,a=a,t=t,e=e) 16 | 17 | 18 | DIVINE_SKATERS = [ divine_univariate, divine_univariate_hypocratic_slow, divine_univariate_hypocratic_fast ] 19 | else: 20 | DIVINE_SKATERS = [] -------------------------------------------------------------------------------- /timemachines/skaters/dlm/README.md: -------------------------------------------------------------------------------- 1 | ## PyDLM skaters 2 | 3 | 4 | ### PyDLM Advantages 5 | 6 | - Fast, incremental using HW discounts 7 | - Nice design makes adding factors easy 8 | 9 | 10 | ### Disadvantages 11 | 12 | - State serialization to JSON is not obvious 13 | 14 | 15 | 16 | ### Why two? 17 | 18 | - dlm_exogenous currently works for k=1 only, 19 | - dlm_univariate works for k>=1 20 | 21 | TODO: Refactor former so we don't need latter. -------------------------------------------------------------------------------- /timemachines/skaters/dlm/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/timemachines/skaters/dlm/__init__.py -------------------------------------------------------------------------------- /timemachines/skaters/dlm/alldlmskaters.py: -------------------------------------------------------------------------------- 1 | from timemachines.skaters.dlm.dlmunivariate import using_dlm 2 | if using_dlm: 3 | from timemachines.skaters.dlm.dlmunivariate import dlm_univariate_r3, dlm_univariate_a, dlm_univariate_b 4 | from timemachines.skaters.dlm.dlmexogenous import dlm_exogenous_a, dlm_exogenous_b, dlm_exogenous_r3 5 | from timemachines.skaters.dlm.dlmcomposed import DLM_SKATERS_COMPOSED 6 | 7 | DLM_SKATERS = [ dlm_univariate_a, dlm_univariate_b ] + DLM_SKATERS_COMPOSED 8 | DLM_R3_SKATERS = [ dlm_univariate_r3, dlm_exogenous_r3 ] 9 | else: 10 | DLM_SKATERS = [] 11 | DLM_R3_SKATERS = [] -------------------------------------------------------------------------------- /timemachines/skaters/dlm/dlmcomposed.py: -------------------------------------------------------------------------------- 1 | from timemachines.skaters.dlm.dlmunivariate import using_dlm 2 | if using_dlm: 3 | from timemachines.skaters.dlm.dlmunivariate import dlm_univariate_a, dlm_univariate_b 4 | from timemachines.skatertools.composition.residualshypocratic import quickly_moving_hypocratic_residual_factory 5 | from timemachines.skatertools.utilities.conventions import Y_TYPE, A_TYPE, E_TYPE, T_TYPE 6 | 7 | 8 | def dlm_univariate_hypocratic_a(y: Y_TYPE, s: dict, k: int, a: A_TYPE = None, t: T_TYPE = None, e: E_TYPE = None): 9 | return quickly_moving_hypocratic_residual_factory(f=dlm_univariate_a, y=y,s=s,k=k,a=a,t=t,e=e) 10 | 11 | 12 | def dlm_univariate_hypocratic_b(y: Y_TYPE, s: dict, k: int, a: A_TYPE = None, t: T_TYPE = None, e: E_TYPE = None): 13 | return quickly_moving_hypocratic_residual_factory(f=dlm_univariate_b, y=y,s=s,k=k,a=a,t=t,e=e) 14 | 15 | 16 | DLM_SKATERS_COMPOSED = [ dlm_univariate_a, dlm_univariate_b ] 17 | else: 18 | DLM_SKATERS_COMPOSED = [] 19 | 20 | 21 | -------------------------------------------------------------------------------- /timemachines/skaters/dlm/dlminclusion.py: -------------------------------------------------------------------------------- 1 | 2 | try: 3 | from pydlm import dlm, trend, seasonality, dynamic, autoReg 4 | using_dlm = True 5 | except ImportError: 6 | class Nothing: 7 | yup = False 8 | using_dlm = False 9 | dlm=Nothing() 10 | trend=Nothing() 11 | seasonality=Nothing() 12 | dynamic =Nothing() 13 | autoReg=Nothing() -------------------------------------------------------------------------------- /timemachines/skaters/drts/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/timemachines/skaters/drts/.DS_Store -------------------------------------------------------------------------------- /timemachines/skaters/drts/alldartsskaters.py: -------------------------------------------------------------------------------- 1 | 2 | from timemachines.skaters.drts.dartsarimaskater import DARTS_ARIMA_SKATERS 3 | from timemachines.skaters.drts.dartsautoarimaskater import DARTS_AUTOARIMA_SKATERS 4 | from timemachines.skaters.drts.dartsexpsmoothingskater import DARTS_EXPONENTIALSMOOTHING_SKATERS 5 | from timemachines.skaters.drts.dartsfftskater import DARTS_FFT_SKATERS 6 | from timemachines.skaters.drts.dartsfourthetaskater import DARTS_FOURTHETA_SKATERS 7 | from timemachines.skaters.drts.dartsprophetskater import DARTS_PROPHET_SKATERS 8 | from timemachines.skaters.drts.dartsthetaskater import DARTS_THETA_SKATERS 9 | from timemachines.skaters.drts.dartsnbeatsskater import DARTS_NBEATS_SKATERS 10 | 11 | DARTS_SKATERS = DARTS_ARIMA_SKATERS + DARTS_AUTOARIMA_SKATERS + DARTS_EXPONENTIALSMOOTHING_SKATERS + DARTS_FFT_SKATERS + DARTS_FOURTHETA_SKATERS + DARTS_PROPHET_SKATERS + DARTS_THETA_SKATERS + DARTS_NBEATS_SKATERS 12 | 13 | # Took out nbeats for now because it takes up a huge amount of disk space without asking nicely 14 | DARTS_SKATERS = DARTS_ARIMA_SKATERS + DARTS_AUTOARIMA_SKATERS + DARTS_EXPONENTIALSMOOTHING_SKATERS + DARTS_FFT_SKATERS + DARTS_FOURTHETA_SKATERS + DARTS_PROPHET_SKATERS + DARTS_THETA_SKATERS 15 | -------------------------------------------------------------------------------- /timemachines/skaters/drts/dartsarimaskater.py: -------------------------------------------------------------------------------- 1 | 2 | from timemachines.skaters.drts.dartsinclusion import using_darts 3 | 4 | if using_darts: 5 | from timemachines.skaters.drts.dartswrappers import darts_ARIMA_iskater 6 | from timemachines.skatertools.utilities.conventions import Y_TYPE, A_TYPE, R_TYPE, E_TYPE, T_TYPE 7 | from timemachines.skatertools.batch.batchskater import batch_skater_factory 8 | 9 | def darts_arima(y: Y_TYPE, s, k: int, a: A_TYPE = None, t: T_TYPE = None, e: E_TYPE = None, r: R_TYPE = None, emp_mass=0.0): 10 | return batch_skater_factory(y=y, s=s, k=k, a=a, t=t, e=e, r=r, emp_mass=emp_mass, 11 | iskater=darts_ARIMA_iskater, 12 | iskater_kwargs={}, 13 | min_e=0) 14 | 15 | DARTS_ARIMA_SKATERS = [darts_arima] 16 | 17 | else: 18 | DARTS_ARIMA_SKATERS = [] 19 | 20 | if __name__=='__main__': 21 | from timemachines.skatertools.evaluation.evaluators import hospital_mean_square_error_with_sporadic_fit 22 | err1 = hospital_mean_square_error_with_sporadic_fit(f=darts_ARIMA_iskater, k=3, n=110) -------------------------------------------------------------------------------- /timemachines/skaters/drts/dartsautoarimaskater.py: -------------------------------------------------------------------------------- 1 | 2 | from timemachines.skaters.drts.dartsinclusion import using_darts 3 | 4 | if using_darts: 5 | from timemachines.skaters.drts.dartswrappers import darts_AutoARIMA_iskater 6 | from timemachines.skatertools.utilities.conventions import Y_TYPE, A_TYPE, R_TYPE, E_TYPE, T_TYPE 7 | from timemachines.skatertools.batch.batchskater import batch_skater_factory 8 | 9 | def darts_autoarima(y: Y_TYPE, s, k: int, a: A_TYPE = None, t: T_TYPE = None, e: E_TYPE = None, r: R_TYPE = None, emp_mass=0.0): 10 | return batch_skater_factory(y=y, s=s, k=k, a=a, t=t, e=e, r=r, emp_mass=emp_mass, 11 | iskater=darts_AutoARIMA_iskater, 12 | iskater_kwargs={}, 13 | min_e=0) 14 | 15 | DARTS_AUTOARIMA_SKATERS = [darts_autoarima] 16 | 17 | else: 18 | DARTS_AUTOARIMA_SKATERS = [] 19 | 20 | if __name__=='__main__': 21 | from timemachines.skatertools.evaluation.evaluators import hospital_mean_square_error_with_sporadic_fit 22 | err1 = hospital_mean_square_error_with_sporadic_fit(f=darts_AutoARIMA_iskater, k=3, n=110) -------------------------------------------------------------------------------- /timemachines/skaters/drts/dartsexpsmoothingskater.py: -------------------------------------------------------------------------------- 1 | 2 | from timemachines.skaters.drts.dartsinclusion import using_darts 3 | 4 | if using_darts: 5 | from timemachines.skaters.drts.dartswrappers import darts_ExponentialSmoothing_iskater 6 | from timemachines.skatertools.utilities.conventions import Y_TYPE, A_TYPE, R_TYPE, E_TYPE, T_TYPE 7 | from timemachines.skatertools.batch.batchskater import batch_skater_factory 8 | 9 | def darts_exp_smoothing(y: Y_TYPE, s, k: int, a: A_TYPE = None, t: T_TYPE = None, e: E_TYPE = None, r: R_TYPE = None, emp_mass=0.0): 10 | return batch_skater_factory(y=y, s=s, k=k, a=a, t=t, e=e, r=r, emp_mass=emp_mass, 11 | iskater=darts_ExponentialSmoothing_iskater, 12 | iskater_kwargs={}, 13 | min_e=0) 14 | 15 | DARTS_EXPONENTIALSMOOTHING_SKATERS = [darts_exp_smoothing] 16 | 17 | else: 18 | DARTS_EXPONENTIALSMOOTHING_SKATERS = [] 19 | 20 | if __name__=='__main__': 21 | from timemachines.skatertools.evaluation.evaluators import hospital_mean_square_error_with_sporadic_fit 22 | err1 = hospital_mean_square_error_with_sporadic_fit(f=darts_ExponentialSmoothing_iskater, k=3, n=110) -------------------------------------------------------------------------------- /timemachines/skaters/drts/dartsfftskater.py: -------------------------------------------------------------------------------- 1 | 2 | from timemachines.skaters.drts.dartsinclusion import using_darts 3 | 4 | if using_darts: 5 | from timemachines.skaters.drts.dartswrappers import darts_FFT_iskater 6 | from timemachines.skatertools.utilities.conventions import Y_TYPE, A_TYPE, R_TYPE, E_TYPE, T_TYPE 7 | from timemachines.skatertools.batch.batchskater import batch_skater_factory 8 | 9 | def darts_fft(y: Y_TYPE, s, k: int, a: A_TYPE = None, t: T_TYPE = None, e: E_TYPE = None, r: R_TYPE = None, emp_mass=0.0): 10 | return batch_skater_factory(y=y, s=s, k=k, a=a, t=t, e=e, r=r, emp_mass=emp_mass, 11 | iskater=darts_FFT_iskater, 12 | iskater_kwargs={}, 13 | min_e=0) 14 | 15 | DARTS_FFT_SKATERS = [darts_fft] 16 | 17 | else: 18 | DARTS_FFT_SKATERS = [] 19 | 20 | if __name__=='__main__': 21 | from timemachines.skatertools.evaluation.evaluators import hospital_mean_square_error_with_sporadic_fit 22 | err1 = hospital_mean_square_error_with_sporadic_fit(f=darts_FFT_iskater, k=3, n=110) -------------------------------------------------------------------------------- /timemachines/skaters/drts/dartsfourthetaskater.py: -------------------------------------------------------------------------------- 1 | 2 | from timemachines.skaters.drts.dartsinclusion import using_darts 3 | 4 | if using_darts: 5 | from timemachines.skaters.drts.dartswrappers import darts_FourTheta_iskater 6 | from timemachines.skatertools.utilities.conventions import Y_TYPE, A_TYPE, R_TYPE, E_TYPE, T_TYPE 7 | from timemachines.skatertools.batch.batchskater import batch_skater_factory 8 | 9 | def darts_four_theta(y: Y_TYPE, s, k: int, a: A_TYPE = None, t: T_TYPE = None, e: E_TYPE = None, r: R_TYPE = None, emp_mass=0.0): 10 | return batch_skater_factory(y=y, s=s, k=k, a=a, t=t, e=e, r=r, emp_mass=emp_mass, 11 | iskater=darts_FourTheta_iskater, 12 | iskater_kwargs={}, 13 | min_e=0) 14 | 15 | DARTS_FOURTHETA_SKATERS = [darts_four_theta] 16 | 17 | else: 18 | DARTS_FOURTHETA_SKATERS = [] 19 | 20 | if __name__=='__main__': 21 | from timemachines.skatertools.evaluation.evaluators import hospital_mean_square_error_with_sporadic_fit 22 | err1 = hospital_mean_square_error_with_sporadic_fit(f=darts_FourTheta_iskater, k=3, n=110) -------------------------------------------------------------------------------- /timemachines/skaters/drts/dartsinclusion.py: -------------------------------------------------------------------------------- 1 | 2 | try: 3 | import darts 4 | from darts.models import FFT, Prophet, ARIMA, AutoARIMA, ExponentialSmoothing, Theta, FourTheta, TransformerModel, \ 5 | NBEATSModel 6 | using_darts = True 7 | except (ImportError, OSError): 8 | using_darts = False 9 | 10 | -------------------------------------------------------------------------------- /timemachines/skaters/drts/dartsnbeatsskater.py: -------------------------------------------------------------------------------- 1 | 2 | from timemachines.skaters.drts.dartsinclusion import using_darts 3 | 4 | if using_darts: 5 | from timemachines.skaters.drts.dartswrappers import darts_NBEATS_iskater 6 | from timemachines.skatertools.utilities.conventions import Y_TYPE, A_TYPE, R_TYPE, E_TYPE, T_TYPE 7 | from timemachines.skatertools.batch.batchskater import batch_skater_factory 8 | 9 | def darts_nbeats(y: Y_TYPE, s, k: int, a: A_TYPE = None, t: T_TYPE = None, e: E_TYPE = None, r: R_TYPE = None, emp_mass=0.0): 10 | return batch_skater_factory(y=y, s=s, k=k, a=a, t=t, e=e, r=r, emp_mass=emp_mass, 11 | iskater=darts_NBEATS_iskater, 12 | iskater_kwargs={}, 13 | min_e=0) 14 | 15 | DARTS_NBEATS_SKATERS = [darts_nbeats] 16 | 17 | else: 18 | DARTS_NBEATS_SKATERS = [] 19 | 20 | if __name__=='__main__': 21 | from timemachines.skatertools.evaluation.evaluators import hospital_mean_square_error_with_sporadic_fit 22 | err1 = hospital_mean_square_error_with_sporadic_fit(f=darts_NBEATS_iskater, k=3, n=110) -------------------------------------------------------------------------------- /timemachines/skaters/drts/dartsprophetskater.py: -------------------------------------------------------------------------------- 1 | 2 | from timemachines.skaters.drts.dartsinclusion import using_darts 3 | 4 | if using_darts: 5 | from timemachines.skaters.drts.dartswrappers import darts_Prophet_iskater 6 | from timemachines.skatertools.utilities.conventions import Y_TYPE, A_TYPE, R_TYPE, E_TYPE, T_TYPE 7 | from timemachines.skatertools.batch.batchskater import batch_skater_factory 8 | 9 | def darts_prophet(y: Y_TYPE, s, k: int, a: A_TYPE = None, t: T_TYPE = None, e: E_TYPE = None, r: R_TYPE = None, emp_mass=0.0): 10 | return batch_skater_factory(y=y, s=s, k=k, a=a, t=t, e=e, r=r, emp_mass=emp_mass, 11 | iskater=darts_Prophet_iskater, 12 | iskater_kwargs={}, 13 | min_e=0) 14 | 15 | DARTS_PROPHET_SKATERS = [darts_prophet] 16 | 17 | else: 18 | DARTS_PROPHET_SKATERS = [] 19 | 20 | if __name__=='__main__': 21 | from timemachines.skatertools.evaluation.evaluators import hospital_mean_square_error_with_sporadic_fit 22 | err1 = hospital_mean_square_error_with_sporadic_fit(f=darts_Prophet_iskater, k=3, n=110) -------------------------------------------------------------------------------- /timemachines/skaters/drts/dartsthetaskater.py: -------------------------------------------------------------------------------- 1 | 2 | from timemachines.skaters.drts.dartsinclusion import using_darts 3 | 4 | if using_darts: 5 | from timemachines.skaters.drts.dartswrappers import darts_Theta_iskater 6 | from timemachines.skatertools.utilities.conventions import Y_TYPE, A_TYPE, R_TYPE, E_TYPE, T_TYPE 7 | from timemachines.skatertools.batch.batchskater import batch_skater_factory 8 | 9 | def darts_theta(y: Y_TYPE, s, k: int, a: A_TYPE = None, t: T_TYPE = None, e: E_TYPE = None, r: R_TYPE = None, emp_mass=0.0): 10 | return batch_skater_factory(y=y, s=s, k=k, a=a, t=t, e=e, r=r, emp_mass=emp_mass, 11 | iskater=darts_Theta_iskater, 12 | iskater_kwargs={}, 13 | min_e=0) 14 | 15 | DARTS_THETA_SKATERS = [darts_theta] 16 | 17 | else: 18 | DARTS_THETA_SKATERS = [] 19 | 20 | if __name__=='__main__': 21 | from timemachines.skatertools.evaluation.evaluators import hospital_mean_square_error_with_sporadic_fit 22 | err1 = hospital_mean_square_error_with_sporadic_fit(f=darts_Theta_iskater, k=3, n=110) -------------------------------------------------------------------------------- /timemachines/skaters/elo/README.md: -------------------------------------------------------------------------------- 1 | ## Ensembles informed by Elo ratings 2 | 3 | 4 | def elo_ensemble_factory() -------------------------------------------------------------------------------- /timemachines/skaters/elo/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/timemachines/skaters/elo/__init__.py -------------------------------------------------------------------------------- /timemachines/skaters/elo/alleloskaters.py: -------------------------------------------------------------------------------- 1 | from timemachines.skaters.elo.eloensembles import ELO_ENSEMBLE_SKATERS 2 | from timemachines.skaters.elo.forever import FOREVER_SKATERS 3 | 4 | ELO_SKATERS = ELO_ENSEMBLE_SKATERS + FOREVER_SKATERS -------------------------------------------------------------------------------- /timemachines/skaters/elo/forever.py: -------------------------------------------------------------------------------- 1 | from timemachines.skatertools.utilities.internet import connected_to_internet 2 | from timemachines.skatertools.utilities.conventions import Y_TYPE, A_TYPE, T_TYPE, E_TYPE 3 | 4 | FASTEST = 1.0 5 | FASTER = 10.0 6 | 7 | if connected_to_internet(): 8 | 9 | from timemachines.skaters.elo.eloensembles import elo_fastest_mixed_aggressive_ensemble 10 | forever = elo_fastest_mixed_aggressive_ensemble 11 | 12 | FOREVER_SKATERS = [ forever ] 13 | 14 | else: 15 | 16 | FOREVER_SKATERS = [] 17 | 18 | -------------------------------------------------------------------------------- /timemachines/skaters/flux/README.md: -------------------------------------------------------------------------------- 1 | 2 | Flux implementation is a bit old school. I don't recommend this as a template for other skaters. 3 | -------------------------------------------------------------------------------- /timemachines/skaters/flux/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/timemachines/skaters/flux/__init__.py -------------------------------------------------------------------------------- /timemachines/skaters/flux/fluxinclusion.py: -------------------------------------------------------------------------------- 1 | try: 2 | import pyflux as pf 3 | using_pyflux = True 4 | except ImportError: 5 | class Mock: 6 | ARIMA = None 7 | pf = Mock() 8 | print('pyflux is off the list while the package on PyPI is broken. You can install from git') 9 | print('pip install git+https://github.com/RJT1990/pyflux.git') 10 | using_pyflux = False -------------------------------------------------------------------------------- /timemachines/skaters/gk/README.md: -------------------------------------------------------------------------------- 1 | Linked-In Greykite 2 | 3 | Needs unit tests ! -------------------------------------------------------------------------------- /timemachines/skaters/gk/allgreykiteskaters.py: -------------------------------------------------------------------------------- 1 | 2 | from timemachines.skaters.gk.greykitebasicskater import GREYKITE_BASIC_SKATERS 3 | GREYKITE_SKATERS = GREYKITE_BASIC_SKATERS -------------------------------------------------------------------------------- /timemachines/skaters/gk/greykitebasicskater.py: -------------------------------------------------------------------------------- 1 | from timemachines.skaters.gk.greykiteinclusion import using_greykite 2 | 3 | if using_greykite: 4 | from timemachines.skaters.gk.greykitewrappers import linkedin_greykite_iskater 5 | from timemachines.skatertools.utilities.conventions import Y_TYPE, A_TYPE, R_TYPE, E_TYPE, T_TYPE 6 | from timemachines.skatertools.batch.batchskater import batch_skater_factory 7 | 8 | def gk_basic_skater(y: Y_TYPE, s, k: int, a: A_TYPE = None, t: T_TYPE = None, e: E_TYPE = None, r: R_TYPE = None, emp_mass=0.0): 9 | return batch_skater_factory(y=y, s=s, k=k, a=a, t=t, e=e, r=r, emp_mass=emp_mass, 10 | iskater=linkedin_greykite_iskater, 11 | iskater_kwargs={}, 12 | min_e=0) 13 | 14 | GREYKITE_BASIC_SKATERS = [gk_basic_skater] 15 | 16 | else: 17 | GREYKITE_BASIC_SKATERS = [] 18 | 19 | if __name__=='__main__': 20 | from timemachines.skatertools.evaluation.evaluators import hospital_mean_square_error_with_sporadic_fit 21 | err1 = hospital_mean_square_error_with_sporadic_fit(f=gk_basic_skater, k=3, n=110) -------------------------------------------------------------------------------- /timemachines/skaters/gk/greykiteinclusion.py: -------------------------------------------------------------------------------- 1 | 2 | try: 3 | import greykite 4 | using_greykite = True 5 | except ImportError: 6 | using_greykite = False -------------------------------------------------------------------------------- /timemachines/skaters/glu/README.md: -------------------------------------------------------------------------------- 1 | 2 | A work in progress... -------------------------------------------------------------------------------- /timemachines/skaters/glu/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/timemachines/skaters/glu/__init__.py -------------------------------------------------------------------------------- /timemachines/skaters/glu/gluinclusion.py: -------------------------------------------------------------------------------- 1 | 2 | try: 3 | import gluonts 4 | using_glu = True 5 | except ImportError: 6 | using_glu = False 7 | -------------------------------------------------------------------------------- /timemachines/skaters/glu/gluparams.py: -------------------------------------------------------------------------------- 1 | GLU_META={'n_warm':20, # Default minimum number of data points before fitting 2 | 'freq':'H', # Sampling frequency used if none is supplied, or t not supplied 3 | 'n_max':1000} # Maximum length of training data 4 | 5 | GLU_DEEP_MODEL = {} -------------------------------------------------------------------------------- /timemachines/skaters/glu/glusimple.py: -------------------------------------------------------------------------------- 1 | from timemachines.skatertools.utilities.conventions import Y_TYPE, A_TYPE, R_TYPE, E_TYPE, T_TYPE, wrap 2 | from typing import Any 3 | from timemachines.skatertools.components.parade import parade 4 | from timemachines.skatertools.utilities.nonemath import nonecast 5 | from timemachines.skatertools.ensembling.ensemblefactory import precision_weighted_ensemble_factory 6 | 7 | 8 | def glu_simple(y :Y_TYPE, s, k:int, a:A_TYPE =None, t:T_TYPE =None, e:E_TYPE =None, r:R_TYPE=None): 9 | """ Rolling gluon 10 | """ 11 | assert r is not None 12 | y0 = wrap(y)[0] 13 | if not s.get('p'): 14 | s = {'p':{}, 15 | 'x':y0, 16 | 'rho':r} 17 | assert 0 <= s['rho'] <= 1, 'Expecting rho=r to be between 0 and 1' 18 | else: 19 | assert abs(r-s['rho'])<1e-6,'rho=r is immutable' 20 | 21 | if y0 is None: 22 | return None, s, None 23 | else: 24 | s['x'] = s['rho']*s['x'] + (1-s['rho'])*y0 # Make me better ! 25 | x = [s['x']]*k 26 | _we_ignore_bias, x_std, s['p'] = parade(p=s['p'], x=x, y=y0) 27 | x_std_fallback = nonecast(x_std,fill_value=1.0) 28 | return [s['x']] * k, x_std_fallback, s 29 | -------------------------------------------------------------------------------- /timemachines/skaters/ik/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/timemachines/skaters/ik/.DS_Store -------------------------------------------------------------------------------- /timemachines/skaters/kts/README.md: -------------------------------------------------------------------------------- 1 | Placeholder for Facebook KATS 2 | https://github.com/microprediction/timemachines/issues/40 3 | -------------------------------------------------------------------------------- /timemachines/skaters/kts/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/timemachines/skaters/kts/__init__.py -------------------------------------------------------------------------------- /timemachines/skaters/kts/allkatsskaters.py: -------------------------------------------------------------------------------- 1 | 2 | from timemachines.skaters.kts.ktsprophetskater import KATS_PROPHET_SKATERS 3 | from timemachines.skaters.kts.ktsholtwintersskater import KATS_HOLT_WINTERS_SKATERS 4 | from timemachines.skaters.kts.ktsquadraticskater import KATS_QUADRATIC_SKATERS 5 | 6 | KATS_SKATERS = KATS_PROPHET_SKATERS + KATS_HOLT_WINTERS_SKATERS + KATS_QUADRATIC_SKATERS 7 | -------------------------------------------------------------------------------- /timemachines/skaters/kts/ktsholtwintersskater.py: -------------------------------------------------------------------------------- 1 | 2 | from timemachines.skaters.kts.ktsinclusion import using_kats 3 | 4 | if using_kats: 5 | from timemachines.skaters.kts.ktswrappers import kats_HoltWinters_iskater 6 | from timemachines.skatertools.utilities.conventions import Y_TYPE, A_TYPE, R_TYPE, E_TYPE, T_TYPE 7 | from timemachines.skatertools.batch.batchskater import batch_skater_factory 8 | 9 | def kats_holt_winters(y: Y_TYPE, s, k: int, a: A_TYPE = None, t: T_TYPE = None, e: E_TYPE = None, r: R_TYPE = None, emp_mass=0.0): 10 | return batch_skater_factory(y=y, s=s, k=k, a=a, t=t, e=e, r=r, emp_mass=emp_mass, 11 | iskater=kats_HoltWinters_iskater, 12 | iskater_kwargs={}, 13 | min_e=0) 14 | 15 | KATS_HOLT_WINTERS_SKATERS = [kats_holt_winters] 16 | 17 | else: 18 | KATS_HOLT_WINTERS_SKATERS = [] 19 | 20 | if __name__=='__main__': 21 | from timemachines.skatertools.evaluation.evaluators import hospital_mean_square_error_with_sporadic_fit 22 | err1 = hospital_mean_square_error_with_sporadic_fit(f=kats_HoltWinters_iskater, k=3, n=110) -------------------------------------------------------------------------------- /timemachines/skaters/kts/ktsinclusion.py: -------------------------------------------------------------------------------- 1 | 2 | try: 3 | import kats 4 | using_kats = True 5 | except ImportError: 6 | using_kats = False 7 | -------------------------------------------------------------------------------- /timemachines/skaters/kts/ktsprophetskater.py: -------------------------------------------------------------------------------- 1 | 2 | from timemachines.skaters.kts.ktsinclusion import using_kats 3 | from timemachines.skaters.proph.prophetinclusion import using_prophet 4 | 5 | if using_kats and using_prophet: 6 | from timemachines.skaters.kts.ktswrappers import kats_Prophet_iskater 7 | from timemachines.skatertools.utilities.conventions import Y_TYPE, A_TYPE, R_TYPE, E_TYPE, T_TYPE 8 | from timemachines.skatertools.batch.batchskater import batch_skater_factory 9 | 10 | def kats_prophet(y: Y_TYPE, s, k: int, a: A_TYPE = None, t: T_TYPE = None, e: E_TYPE = None, r: R_TYPE = None, emp_mass=0.0): 11 | return batch_skater_factory(y=y, s=s, k=k, a=a, t=t, e=e, r=r, emp_mass=emp_mass, 12 | iskater=kats_Prophet_iskater, 13 | iskater_kwargs={}, 14 | min_e=0) 15 | 16 | KATS_PROPHET_SKATERS = [kats_prophet] 17 | 18 | else: 19 | KATS_PROPHET_SKATERS = [] 20 | 21 | if __name__=='__main__': 22 | from timemachines.skatertools.evaluation.evaluators import hospital_mean_square_error_with_sporadic_fit 23 | err1 = hospital_mean_square_error_with_sporadic_fit(f=kats_Prophet_iskater, k=3, n=110) -------------------------------------------------------------------------------- /timemachines/skaters/kts/ktsquadraticskater.py: -------------------------------------------------------------------------------- 1 | 2 | from timemachines.skaters.kts.ktsinclusion import using_kats 3 | 4 | if using_kats: 5 | from timemachines.skaters.kts.ktswrappers import kats_quadratic_iskater 6 | from timemachines.skatertools.utilities.conventions import Y_TYPE, A_TYPE, R_TYPE, E_TYPE, T_TYPE 7 | from timemachines.skatertools.batch.batchskater import batch_skater_factory 8 | 9 | def kats_quadratic(y: Y_TYPE, s, k: int, a: A_TYPE = None, t: T_TYPE = None, e: E_TYPE = None, r: R_TYPE = None, emp_mass=0.0): 10 | return batch_skater_factory(y=y, s=s, k=k, a=a, t=t, e=e, r=r, emp_mass=emp_mass, 11 | iskater=kats_quadratic_iskater, 12 | iskater_kwargs={}, 13 | min_e=0) 14 | 15 | KATS_QUADRATIC_SKATERS = [kats_quadratic] 16 | 17 | else: 18 | KATS_QUADRATIC_SKATERS = [] 19 | 20 | if __name__=='__main__': 21 | from timemachines.skatertools.evaluation.evaluators import hospital_mean_square_error_with_sporadic_fit 22 | err1 = hospital_mean_square_error_with_sporadic_fit(f=kats_quadratic_iskater, k=3, n=110) -------------------------------------------------------------------------------- /timemachines/skaters/mrln/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/timemachines/skaters/mrln/.DS_Store -------------------------------------------------------------------------------- /timemachines/skaters/mrln/allmerlionskaters.py: -------------------------------------------------------------------------------- 1 | 2 | from timemachines.skaters.mrln.merlionarimaskater import MERLION_ARIMA_SKATERS 3 | from timemachines.skaters.mrln.merlionmsesskater import MERLION_MSES_SKATERS 4 | from timemachines.skaters.mrln.merlionprophetskater import MERLION_PROPHET_SKATERS 5 | 6 | MERLION_SKATERS = MERLION_ARIMA_SKATERS + MERLION_MSES_SKATERS + MERLION_PROPHET_SKATERS 7 | -------------------------------------------------------------------------------- /timemachines/skaters/mrln/merlionarimaskater.py: -------------------------------------------------------------------------------- 1 | 2 | from timemachines.skaters.mrln.merlioninclusion import using_merlion 3 | 4 | if using_merlion: 5 | from timemachines.skaters.mrln.merlionwrappers import merlion_ARIMA_iskater 6 | from timemachines.skatertools.utilities.conventions import Y_TYPE, A_TYPE, R_TYPE, E_TYPE, T_TYPE 7 | from timemachines.skatertools.batch.batchskater import batch_skater_factory 8 | 9 | def merlion_arima(y: Y_TYPE, s, k: int, a: A_TYPE = None, t: T_TYPE = None, e: E_TYPE = None, r: R_TYPE = None, emp_mass=0.0): 10 | return batch_skater_factory(y=y, s=s, k=k, a=a, t=t, e=e, r=r, emp_mass=emp_mass, 11 | iskater=merlion_ARIMA_iskater, 12 | iskater_kwargs={}, 13 | min_e=0) 14 | 15 | MERLION_ARIMA_SKATERS = [merlion_arima] 16 | 17 | else: 18 | MERLION_ARIMA_SKATERS = [] 19 | 20 | if __name__=='__main__': 21 | from timemachines.skatertools.evaluation.evaluators import hospital_mean_square_error_with_sporadic_fit 22 | err1 = hospital_mean_square_error_with_sporadic_fit(f=merlion_ARIMA_iskater, k=3, n=110) -------------------------------------------------------------------------------- /timemachines/skaters/mrln/merlioninclusion.py: -------------------------------------------------------------------------------- 1 | 2 | try: 3 | import merlion 4 | try: 5 | import matplotlib 6 | except ImportError: 7 | print('Warning: the only reason merlion isn''t working is that matplotlib is missing') 8 | import matplotlib 9 | using_merlion = True 10 | except ImportError: 11 | using_merlion = False 12 | 13 | try: 14 | # Urgh... this doesn't succeed in determining that Merlion prophet will actually work. 15 | # Should perhaps instantiate a little prophet model to check 16 | import prophet 17 | from merlion.models.forecast.prophet import Prophet, ProphetConfig 18 | using_merlion_prophet = True 19 | except ImportError: 20 | using_merlion_prophet = False 21 | 22 | if __name__=='__main__': 23 | print(using_merlion) 24 | print(using_merlion_prophet) 25 | -------------------------------------------------------------------------------- /timemachines/skaters/mrln/merlionmsesskater.py: -------------------------------------------------------------------------------- 1 | 2 | from timemachines.skaters.mrln.merlioninclusion import using_merlion 3 | 4 | if using_merlion: 5 | from timemachines.skaters.mrln.merlionwrappers import merlion_MSES_iskater 6 | from timemachines.skatertools.utilities.conventions import Y_TYPE, A_TYPE, R_TYPE, E_TYPE, T_TYPE 7 | from timemachines.skatertools.batch.batchskater import batch_skater_factory 8 | 9 | def merlion_mses(y: Y_TYPE, s, k: int, a: A_TYPE = None, t: T_TYPE = None, e: E_TYPE = None, r: R_TYPE = None, emp_mass=0.0): 10 | return batch_skater_factory(y=y, s=s, k=k, a=a, t=t, e=e, r=r, emp_mass=emp_mass, 11 | iskater=merlion_MSES_iskater, 12 | iskater_kwargs={}, 13 | min_e=0) 14 | 15 | MERLION_MSES_SKATERS = [merlion_mses] 16 | 17 | else: 18 | MERLION_MSES_SKATERS = [] 19 | 20 | if __name__=='__main__': 21 | from timemachines.skatertools.evaluation.evaluators import hospital_mean_square_error_with_sporadic_fit 22 | err1 = hospital_mean_square_error_with_sporadic_fit(f=merlion_MSES_iskater, k=3, n=110) -------------------------------------------------------------------------------- /timemachines/skaters/mrln/merlionprophetskater.py: -------------------------------------------------------------------------------- 1 | 2 | from timemachines.skaters.mrln.merlioninclusion import using_merlion_prophet 3 | 4 | # Turned this off until using_merlion_prophet is fixed 5 | 6 | if using_merlion_prophet and False: 7 | from timemachines.skaters.mrln.merlionwrappers import merlion_Prophet_iskater 8 | from timemachines.skatertools.utilities.conventions import Y_TYPE, A_TYPE, R_TYPE, E_TYPE, T_TYPE 9 | from timemachines.skatertools.batch.batchskater import batch_skater_factory 10 | 11 | def merlion_prophet(y: Y_TYPE, s, k: int, a: A_TYPE = None, t: T_TYPE = None, e: E_TYPE = None, r: R_TYPE = None, emp_mass=0.0): 12 | return batch_skater_factory(y=y, s=s, k=k, a=a, t=t, e=e, r=r, emp_mass=emp_mass, 13 | iskater=merlion_Prophet_iskater, 14 | iskater_kwargs={}, 15 | min_e=0) 16 | 17 | MERLION_PROPHET_SKATERS = [merlion_prophet] 18 | 19 | else: 20 | MERLION_PROPHET_SKATERS = [] 21 | 22 | if __name__=='__main__': 23 | print(using_merlion_prophet) 24 | from timemachines.skatertools.evaluation.evaluators import hospital_mean_square_error_with_sporadic_fit 25 | err1 = hospital_mean_square_error_with_sporadic_fit(f=merlion_prophet, k=3, n=110) 26 | -------------------------------------------------------------------------------- /timemachines/skaters/networkedskaters.py: -------------------------------------------------------------------------------- 1 | from timemachines.skaters.elo.alleloskaters import ELO_SKATERS 2 | from timemachines.skaters.suc.allsuccessorskaters import SUCCESSOR_SKATERS 3 | 4 | NETWORKED_SKATERS = ELO_SKATERS + SUCCESSOR_SKATERS 5 | FAST_NETWORKED_SKATERS = ELO_SKATERS + SUCCESSOR_SKATERS 6 | 7 | # Networked skaters access Elo ratings 8 | 9 | 10 | def networked_skater_from_name(name): 11 | valid = [f for f in NETWORKED_SKATERS if f.__name__ == name] 12 | return valid[0] if len(valid)==1 else None 13 | -------------------------------------------------------------------------------- /timemachines/skaters/nproph/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/timemachines/skaters/nproph/__init__.py -------------------------------------------------------------------------------- /timemachines/skaters/nproph/allnprophetskaters.py: -------------------------------------------------------------------------------- 1 | from timemachines.skaters.nproph.nprophetskaters import NPROPHET_UNIVARIATE_SKATERS 2 | from timemachines.skaters.nproph.nprophskaterscomposed import NPROPHET_SKATERS_COMPOSED 3 | 4 | NPROPHET_SKATERS = NPROPHET_UNIVARIATE_SKATERS + NPROPHET_SKATERS_COMPOSED -------------------------------------------------------------------------------- /timemachines/skaters/nproph/nprophetinclusion.py: -------------------------------------------------------------------------------- 1 | try: 2 | from neuralprophet import NeuralProphet 3 | using_neuralprophet = True 4 | except ImportError: 5 | class NeuralMock: 6 | whatever=False 7 | using_neuralprophet = False 8 | NeuralProphet = NeuralMock() -------------------------------------------------------------------------------- /timemachines/skaters/nproph/nprophparams.py: -------------------------------------------------------------------------------- 1 | 2 | NPROPHET_META={'n_warm':20, # Default minimum number of data points before fitting 3 | 'freq':'H', # Sampling frequency used if none is supplied, or t not supplied 4 | 'n_max':1000} # Maximum length of training data 5 | 6 | 7 | NPROPHET_MODEL = dict(n_lags=2, 8 | changepoints_range=0.95, 9 | n_changepoints=30, 10 | weekly_seasonality=False, 11 | batch_size=64, 12 | epochs=10, 13 | learning_rate=1.0) -------------------------------------------------------------------------------- /timemachines/skaters/orbt/README.md: -------------------------------------------------------------------------------- 1 | 2 | Should include a few more 3 | 4 | https://github.com/uber/orbit/tree/master/orbit/models 5 | 6 | -------------------------------------------------------------------------------- /timemachines/skaters/orbt/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/timemachines/skaters/orbt/__init__.py -------------------------------------------------------------------------------- /timemachines/skaters/orbt/allorbitskaters.py: -------------------------------------------------------------------------------- 1 | from timemachines.skaters.orbt.orbitinclusion import using_orbit 2 | 3 | if using_orbit: 4 | from timemachines.skaters.orbt.orbitlgtskaterfactory import orbit_lgt_12, orbit_lgt_24 5 | ORBIT_LGT_SKATERS = [orbit_lgt_12, orbit_lgt_24] 6 | else: 7 | ORBIT_LGT_SKATERS = [] 8 | 9 | 10 | ORBIT_SKATERS = ORBIT_LGT_SKATERS -------------------------------------------------------------------------------- /timemachines/skaters/orbt/orbitinclusion.py: -------------------------------------------------------------------------------- 1 | try: 2 | import orbit 3 | using_orbit = True 4 | except ImportError: 5 | using_orbit = False 6 | -------------------------------------------------------------------------------- /timemachines/skaters/orbt/orbitlgtskaterfactory.py: -------------------------------------------------------------------------------- 1 | 2 | from timemachines.skaters.orbt.orbitinclusion import using_orbit 3 | 4 | if using_orbit: 5 | from timemachines.skaters.orbt.orbitwrappers import orbit_lgt_iskater 6 | from timemachines.skatertools.utilities.conventions import Y_TYPE, A_TYPE, R_TYPE, E_TYPE, T_TYPE 7 | from timemachines.skatertools.batch.batchskater import batch_skater_factory 8 | 9 | def orbit_lgt_skater_factory(y: Y_TYPE, s, k: int, a: A_TYPE = None, t: T_TYPE = None, e: E_TYPE = None, r: R_TYPE = None, 10 | emp_mass=0.0, 11 | seasonality=None): 12 | return batch_skater_factory(y=y, s=s, k=k, a=a, t=t, e=e, r=r, emp_mass=emp_mass, 13 | iskater=orbit_lgt_iskater, 14 | iskater_kwargs={'seasonality': seasonality}, 15 | min_e=0, n_warm=20) 16 | 17 | def orbit_lgt_12(y,s,k,a=None, t=None,e=None): 18 | return orbit_lgt_skater_factory(y=y, s=s, k=k, a=a,t=t,e=e, seasonality=12) 19 | 20 | 21 | def orbit_lgt_24(y,s,k,a=None, t=None,e=None): 22 | return orbit_lgt_skater_factory(y, s, k, a=a,t=t,e=e, seasonality=24) 23 | 24 | -------------------------------------------------------------------------------- /timemachines/skaters/orbt/orbitwrappers.py: -------------------------------------------------------------------------------- 1 | import pandas as pd 2 | 3 | from timemachines.skaters.orbt.orbitinclusion import using_orbit 4 | 5 | if using_orbit: 6 | from orbit.models.lgt import LGT 7 | 8 | def orbit_lgt_iskater(y, k, a, t, seasonality): 9 | """ 10 | Run orbit over a fixed history and extract predictions 11 | """ 12 | # It seems that orbit needs a two column dataframe of an index column and 13 | # measurement column in order to work. It also seems to need enough 14 | # space in the dataframe to insert the values it predicts. 15 | df = pd.DataFrame(y).reset_index().rename(columns={0: "response_col", 'index': "date_col"}) 16 | for i in range(k): 17 | df2 = pd.DataFrame([[len(df), 0]], columns=["date_col", "response_col"]) 18 | df = df.append(df2, ignore_index=True) 19 | 20 | # "test/train" split 21 | test_size = k 22 | train_df = df[:-test_size] 23 | test_df = df[-test_size:] 24 | 25 | # run the model 26 | if isinstance(seasonality, int) or seasonality == None: 27 | lgt = LGT( 28 | response_col="response_col", 29 | date_col="date_col", 30 | seasonality=seasonality 31 | ) 32 | else: 33 | print("The seasonality given was not an int or None type. Try again...") 34 | return 35 | lgt.fit(df=train_df) 36 | 37 | # get the prediction(s) 38 | predicted_df = lgt.predict(df=test_df) 39 | 40 | # list containing predictions 1 through k steps out 41 | x = list(predicted_df.prediction) 42 | # standard deviaiton list (this is technically 2 std) 43 | x_std = [a / 2 for a in list(predicted_df.prediction_95 - predicted_df.prediction_5)] 44 | 45 | return x, x_std -------------------------------------------------------------------------------- /timemachines/skaters/pmd/README.md: -------------------------------------------------------------------------------- 1 | 2 | # PMDArima skaters 3 | 4 | You'll first need to insall pmdarima 5 | 6 | pip install pmdarima 7 | 8 | pmdarima is the second most downloaded time series package. 9 | Here we create a simple skater function encompassing some of the functionality of this library. 10 | 11 | As with all skaters, the intent is that you can cycle through observations as follows: 12 | 13 | for yi, ai in zip(y, a): 14 | x, x_std, s = pmd_exog(y=yi, s=s, k=7, a=ai) 15 | 16 | where each x and s_std are length 7, in this example. -------------------------------------------------------------------------------- /timemachines/skaters/pmd/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/timemachines/skaters/pmd/__init__.py -------------------------------------------------------------------------------- /timemachines/skaters/pmd/allpmdskaters.py: -------------------------------------------------------------------------------- 1 | from timemachines.skaters.pmd.pmdinclusion import using_pmd 2 | if using_pmd: 3 | from timemachines.skaters.pmd.pmdskaters import pmd_known, pmd_exogenous, pmd_univariate 4 | from timemachines.skaters.pmd.pmdcomposed import pmd_exogenous_hypocratic, pmd_univariate_hypocratic 5 | 6 | PMD_SKATERS = [pmd_univariate, pmd_exogenous_hypocratic] # for now 7 | else: 8 | PMD_SKATERS = [] -------------------------------------------------------------------------------- /timemachines/skaters/pmd/pmdcomposed.py: -------------------------------------------------------------------------------- 1 | from timemachines.skaters.pmd.pmdinclusion import using_pmd 2 | if using_pmd: 3 | 4 | from timemachines.skaters.pmd.pmdskaters import pmd_univariate 5 | from timemachines.skatertools.composition.residualshypocratic import quickly_moving_hypocratic_residual_factory 6 | from timemachines.skatertools.utilities.conventions import Y_TYPE, A_TYPE, E_TYPE, T_TYPE 7 | 8 | 9 | def pmd_univariate_hypocratic(y: Y_TYPE, s: dict, k: int, a: A_TYPE = None, t: T_TYPE = None, e: E_TYPE = None): 10 | return quickly_moving_hypocratic_residual_factory(f=pmd_univariate, y=y,s=s,k=k,a=a,t=t,e=e) 11 | 12 | 13 | def pmd_exogenous_hypocratic(y: Y_TYPE, s: dict, k: int, a: A_TYPE = None, t: T_TYPE = None, e: E_TYPE = None): 14 | return quickly_moving_hypocratic_residual_factory(f=pmd_univariate, y=y,s=s,k=k,a=a,t=t,e=e) 15 | 16 | 17 | PMD_SKATERS_COMPOSED = [ pmd_univariate_hypocratic, pmd_exogenous_hypocratic ] 18 | else: 19 | PMD_SKATERS_COMPOSED = [] 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /timemachines/skaters/pmd/pmddefaultparams.py: -------------------------------------------------------------------------------- 1 | 2 | PMD_CRITERIA = ['aic', 'aicc', 'bic', 'hqic'] 3 | 4 | 5 | def pmd_params(method=None): 6 | """ Default hyper-params """ 7 | # https://alkaline-ml.com/pmdarima/modules/generated/pmdarima.arima.auto_arima.html 8 | s = dict(start_p=1, start_q=1, start_P=1, start_Q=1, 9 | max_p=10, max_q=10, max_P=24, max_Q=24, seasonal=False, 10 | stepwise=True, suppress_warnings=True, 11 | D=None, max_D=3, 12 | error_action='ignore', 13 | information_criterion=PMD_CRITERIA[0]) 14 | if method == '0': 15 | # Add more cases here 16 | pass 17 | return s -------------------------------------------------------------------------------- /timemachines/skaters/pmd/pmdinclusion.py: -------------------------------------------------------------------------------- 1 | try: 2 | import pmdarima as pm 3 | using_pmd = True 4 | except ImportError: 5 | using_pmd = False 6 | class Silly: 7 | nothing = True 8 | pm = Silly() 9 | 10 | -------------------------------------------------------------------------------- /timemachines/skaters/pmd/pmdserialize_epicfail.py: -------------------------------------------------------------------------------- 1 | from timemachines.skaters.pmd.pmdinclusion import using_pmd 2 | if using_pmd: 3 | from timemachines.skaters.pmd.pmdskaters import pmd_exogenous 4 | from timemachines.skatertools.data import hospital_with_exog 5 | from pmdarima.arima import ARIMA 6 | 7 | 8 | # So the task here is to serialize and re-inflate the arima model, and thus all the skater state, to JSON 9 | # It may be a lost cause, but by all means prove me wrong. 10 | 11 | 12 | def example_pmd(): 13 | s = {} 14 | y, a = hospital_with_exog(k=3) 15 | x = [ pmd_exogenous(y=yj,s=s,k=3,a=aj) for yj,aj in zip(y[:500],a) ] 16 | return s 17 | 18 | 19 | def arima_res_to_dict(arima_res): 20 | state = arima_res.__dict__ 21 | return state 22 | 23 | 24 | def pmd_to_dict(pmd): 25 | pmd['model'] = pmd['model'].__getstate__() 26 | pmd['model']['arima_res_'] = arima_res_to_dict(pmd['model']['arima_res_']) 27 | return pmd 28 | 29 | 30 | def pmd_from_dict(pmd): 31 | pmd['model']['arima_res_'] = '' 32 | 33 | 34 | if __name__=='__main__': 35 | assert using_pmd,'pip install pmdarima' 36 | pmd = example_pmd() 37 | model = pmd['model'] 38 | model1 = ARIMA(**model.get_params()) 39 | prms = model.__dict__['arima_res_'].__dict__['_results'].params 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /timemachines/skaters/preskaters.py: -------------------------------------------------------------------------------- 1 | 2 | # Not yet skaters, since they haven't had r set 3 | # Work in progress to expose and tune en masse 4 | 5 | from timemachines.skaters.proph.allprophetskaters import PROPHET_R2_SKATERS 6 | from timemachines.skaters.simple.movingaverage import EMA_R1_SKATERS 7 | 8 | SKATERS_R3 = [] 9 | SKATERS_R2 = PROPHET_R2_SKATERS 10 | SKATERS_R1 = EMA_R1_SKATERS -------------------------------------------------------------------------------- /timemachines/skaters/proph/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/timemachines/skaters/proph/.DS_Store -------------------------------------------------------------------------------- /timemachines/skaters/proph/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/timemachines/skaters/proph/__init__.py -------------------------------------------------------------------------------- /timemachines/skaters/proph/allprophetskaters.py: -------------------------------------------------------------------------------- 1 | from timemachines.skaters.proph.prophskaterssingular import PROPHET_SKATERS_SINGULAR, PROPHET_R2_SKATERS 2 | from timemachines.skaters.proph.prophskaterscomposed import PROPHET_SKATERS_COMPOSED 3 | 4 | 5 | PROPHET_SKATERS = PROPHET_SKATERS_SINGULAR + PROPHET_SKATERS_COMPOSED 6 | 7 | 8 | -------------------------------------------------------------------------------- /timemachines/skaters/proph/prophetinclusion.py: -------------------------------------------------------------------------------- 1 | try: 2 | import pandas as pd 3 | from prophet import Prophet 4 | using_prophet=True 5 | except ImportError: 6 | using_prophet=False -------------------------------------------------------------------------------- /timemachines/skaters/proph/prophoptimize.py: -------------------------------------------------------------------------------- 1 | from timemachines.skatertools.tuning import optimal_r_for_stream 2 | from timemachines.skaters.proph.prophskaterssingular import fbprophet_univariate_r2 3 | from humpday.optimizers.dlibcube import dlib_default_cube 4 | from microprediction import MicroReader 5 | from timemachines.skaters.proph.prophparams import PROPHET_META, prophet_params 6 | import random 7 | from pprint import pprint 8 | 9 | 10 | # Optimal meta-parameters for prophet skaters 11 | 12 | 13 | def fbprophet_univariate_best_r()->float: 14 | """ 15 | :return: Provides best r for a randomly chosen data stream 16 | Takes about 12 hrs to run 17 | """ 18 | mr = MicroReader() 19 | names = mr.get_stream_names() 20 | okay = False 21 | while not okay: 22 | name = random.choice(names) 23 | n_obs = len(mr.get_lagged_values(name=name)) 24 | okay = n_obs > PROPHET_META['n_warm']+50 and '~' not in name 25 | url = 'https://www.microprediction.org/stream_dashboard.html?stream='+name.replace('.json','') 26 | print('We will find the best fbprophet hyper-parameters for '+url) 27 | print('There are ' + str(n_obs) + ' observations in the series.') 28 | print("Prophet will be fit for most of them, after a burn_in, and for many different hyper-params. Don't hold your breathe.") 29 | 30 | best_r, best_value, info = optimal_r_for_stream(f=fbprophet_univariate_r2,name=name,k=10,optimizer=dlib_default_cube, 31 | n_burn=PROPHET_META['n_warm']+20,n_trials=50,n_dim=2) 32 | pprint(info) 33 | params = prophet_params(r=best_r,dim=2) 34 | pprint(params) -------------------------------------------------------------------------------- /timemachines/skaters/pycrt/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/timemachines/skaters/pycrt/__init__.py -------------------------------------------------------------------------------- /timemachines/skaters/pycrt/allpycaretskaters.py: -------------------------------------------------------------------------------- 1 | from timemachines.skaters.pycrt.pycaretblend import PYCRT_MEDIAN_SKATERS 2 | 3 | PYCRT_SKATERS = PYCRT_MEDIAN_SKATERS -------------------------------------------------------------------------------- /timemachines/skaters/pycrt/pycaretinclusion.py: -------------------------------------------------------------------------------- 1 | try: 2 | from pycaret.internal.pycaret_experiment import TimeSeriesExperiment 3 | using_pycaret=True 4 | except ImportError: 5 | using_pycaret=False 6 | -------------------------------------------------------------------------------- /timemachines/skaters/pypi.py: -------------------------------------------------------------------------------- 1 | PYPI = {'tsa':'statsmodels', 2 | 'fbprophet':'prophet', 3 | 'pmd':'pmdarima', 4 | 'rvr':'river', 5 | 'nprophet':'neuralprophet', 6 | 'dlm':'pydlm', 7 | 'divine':'divinity', 8 | 'orbit':'orbit-ml', 9 | 'bats':'tbats', 10 | 'glu':'gluonts', 11 | 'flux':'pyflux', 12 | 'sk':'sktime', 13 | 'smdk':'simdkalman', 14 | 'gk':'greykite', 15 | 'tcn':'keras-tcn', 16 | 'darts':'darts', 17 | 'kts':'kats', 18 | 'ats':'auto_ts', 19 | 'suc':'successor', 20 | 'mrln':'salesforce-merlion', 21 | 'pycrt':'pycaret', 22 | 'ik':'scikit-learn'} 23 | 24 | 25 | def pypi_from_name(name): 26 | stem = name.split('_')[0] 27 | short_name = PYPI.get(stem) 28 | stub = 'https://pypi.org/project/' 29 | return stub+short_name if short_name else stub+'timemachines' 30 | 31 | 32 | 33 | if __name__=='__main__': 34 | from timemachines.skaters.localskaters import LOCAL_SKATERS 35 | from pprint import pprint 36 | pprint([(sk.__name__,pypi_from_name(sk.__name__)) for sk in LOCAL_SKATERS]) 37 | print(len(LOCAL_SKATERS)) 38 | -------------------------------------------------------------------------------- /timemachines/skaters/rvr/README.md: -------------------------------------------------------------------------------- 1 | 2 | Just trying to get the ball rolling with river. There's a lot that can be done. -------------------------------------------------------------------------------- /timemachines/skaters/rvr/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/timemachines/skaters/rvr/__init__.py -------------------------------------------------------------------------------- /timemachines/skaters/rvr/allriverskaters.py: -------------------------------------------------------------------------------- 1 | from timemachines.skaters.rvr.rvrconstant import RIVER_CONSTANT_SKATERS 2 | from timemachines.skaters.rvr.rvrensembles import RIVER_ENSEMBLE_SKATERS 3 | from timemachines.skaters.rvr.rvrhypocratic import RIVER_HYPOCRATIC_SKATERS 4 | 5 | RIVER_SKATERS = RIVER_CONSTANT_SKATERS + RIVER_HYPOCRATIC_SKATERS + RIVER_ENSEMBLE_SKATERS -------------------------------------------------------------------------------- /timemachines/skaters/rvr/rvrconstant.py: -------------------------------------------------------------------------------- 1 | from timemachines.skaters.rvr.rvrinclusion import using_river 2 | from timemachines.skatertools.utilities.conventions import Y_TYPE, A_TYPE, R_TYPE, E_TYPE, T_TYPE, wrap 3 | from typing import Any 4 | from timemachines.skatertools.visualization.priorplot import prior_plot_exogenous 5 | 6 | if using_river: 7 | from timemachines.skaters.rvr.rvrsarimax import rvr_sarimax_factory 8 | 9 | def rvr_p1_d0_q0(y: Y_TYPE, s: dict, k: int, a: A_TYPE = None, 10 | t: T_TYPE = None, e: E_TYPE = None) -> ([float], Any, Any): 11 | return rvr_sarimax_factory(y=y,s=s,k=k,a=a,t=t,e=e,p=1,d=0,q=0) 12 | 13 | 14 | def rvr_p2_d0_q0(y: Y_TYPE, s: dict, k: int, a: A_TYPE = None, 15 | t: T_TYPE = None, e: E_TYPE = None) -> ([float], Any, Any): 16 | return rvr_sarimax_factory(y=y, s=s, k=k, a=a, t=t, e=e, p=2, d=0, q=0) 17 | 18 | 19 | def rvr_p3_d0_q0(y: Y_TYPE, s: dict, k: int, a: A_TYPE = None, 20 | t: T_TYPE = None, e: E_TYPE = None) -> ([float], Any, Any): 21 | return rvr_sarimax_factory(y=y, s=s, k=k, a=a, t=t, e=e, p=3, d=0, q=0) 22 | 23 | 24 | def rvr_p5_d0_q0(y: Y_TYPE, s: dict, k: int, a: A_TYPE = None, 25 | t: T_TYPE = None, e: E_TYPE = None) -> ([float], Any, Any): 26 | return rvr_sarimax_factory(y=y, s=s, k=k, a=a, t=t, e=e, p=5, d=0, q=0) 27 | 28 | def rvr_p8_d0_q0(y: Y_TYPE, s: dict, k: int, a: A_TYPE = None, 29 | t: T_TYPE = None, e: E_TYPE = None) -> ([float], Any, Any): 30 | return rvr_sarimax_factory(y=y, s=s, k=k, a=a, t=t, e=e, p=5, d=0, q=0) 31 | 32 | 33 | RIVER_CONSTANT_SKATERS = [rvr_p1_d0_q0, rvr_p2_d0_q0, rvr_p3_d0_q0, rvr_p3_d0_q0, rvr_p5_d0_q0, rvr_p8_d0_q0] 34 | else: 35 | RIVER_CONSTANT_SKATERS = [] 36 | 37 | if __name__=='__main__': 38 | prior_plot_exogenous(f=rvr_p1_d0_q0,k=5,n=50,n_plot=50) -------------------------------------------------------------------------------- /timemachines/skaters/rvr/rvrensembles.py: -------------------------------------------------------------------------------- 1 | from timemachines.skaters.rvr.rvrinclusion import using_river 2 | 3 | if using_river: 4 | from timemachines.skatertools.ensembling.ensemblefactory import precision_weighted_ensemble_factory, R_BALANCED, R_AGGRESSIVE, R_PRECISION 5 | from timemachines.skaters.rvr.rvrconstant import RIVER_CONSTANT_SKATERS 6 | from timemachines.skatertools.utilities.conventions import Y_TYPE,A_TYPE,T_TYPE,E_TYPE 7 | from typing import Any 8 | 9 | 10 | def rvr_precision_ensemble(y :Y_TYPE, s:dict, k:int =1, a:A_TYPE =None, t:T_TYPE =None, e:E_TYPE =None)->([float] , Any , Any): 11 | return precision_weighted_ensemble_factory(fs=RIVER_CONSTANT_SKATERS,y=y,s=s,k=k,a=a,t=t,e=e,r=R_PRECISION) 12 | 13 | 14 | def rvr_balanced_ensemble(y :Y_TYPE, s:dict, k:int =1, a:A_TYPE =None, t:T_TYPE =None, e:E_TYPE =None)->([float] , Any , Any): 15 | return precision_weighted_ensemble_factory(fs=RIVER_CONSTANT_SKATERS,y=y,s=s,k=k,a=a,t=t,e=e,r=R_BALANCED) 16 | 17 | 18 | def rvr_aggressive_ensemble(y :Y_TYPE, s:dict, k:int =1, a:A_TYPE =None, t:T_TYPE =None, e:E_TYPE =None)->([float] , Any , Any): 19 | return precision_weighted_ensemble_factory(fs=RIVER_CONSTANT_SKATERS,y=y,s=s,k=k,a=a,t=t,e=e,r=R_AGGRESSIVE) 20 | 21 | RIVER_ENSEMBLE_SKATERS = [ rvr_aggressive_ensemble, rvr_balanced_ensemble, rvr_aggressive_ensemble ] 22 | else: 23 | RIVER_ENSEMBLE_SKATERS = [] 24 | 25 | -------------------------------------------------------------------------------- /timemachines/skaters/rvr/rvrinclusion.py: -------------------------------------------------------------------------------- 1 | try: 2 | import river 3 | using_river = True 4 | except ImportError: 5 | using_river = False -------------------------------------------------------------------------------- /timemachines/skaters/simple/README.md: -------------------------------------------------------------------------------- 1 | 2 | # Simple skaters 3 | 4 | Last value caches, regressions, moving averages, filters and the like. -------------------------------------------------------------------------------- /timemachines/skaters/simple/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/timemachines/skaters/simple/__init__.py -------------------------------------------------------------------------------- /timemachines/skaters/simple/hypocratic.py: -------------------------------------------------------------------------------- 1 | from timemachines.skatertools.utilities.conventions import Y_TYPE, A_TYPE, R_TYPE, E_TYPE, T_TYPE 2 | from timemachines.skaters.simple.movingaverage import empirical_ema_r1 3 | from timemachines.skatertools.utilities.conventions import wrap 4 | 5 | # Skaters that shrink towards zero 6 | 7 | 8 | def hypocratic_ema_r1(y :Y_TYPE, s, k:int, a:A_TYPE =None, t:T_TYPE =None, e:E_TYPE =None, r:R_TYPE=None): 9 | """ 10 | r : moving average parameter (e.g. 0.75 is fast, 0.95 is slow) 11 | """ 12 | y0 = wrap(y)[0] 13 | assert r is not None 14 | x, x_std, s = empirical_ema_r1(y=y0,s=s,k=k,a=a,t=t,e=e,r=r) 15 | 16 | def hypocratic(x:float, x_std:float, confidence=0.5): 17 | """ Shrink residual prediction towards zero """ 18 | import math 19 | if abs(x_std)<1e-6 or abs(x)<1e-3*x_std: 20 | return 0.0 21 | else: 22 | return x*math.tanh(confidence*abs(x)/(3*x_std)) 23 | 24 | x_resid = [ hypocratic(xi,x_std) for xi,x_std in zip(x,x_std) ] 25 | return x_resid, x_std, s 26 | 27 | 28 | def slowly_hypocratic(y :Y_TYPE, s, k:int, a:A_TYPE =None, t:T_TYPE =None, e:E_TYPE =None): 29 | return hypocratic_ema_r1(y=y,s=s,k=k,a=a,t=t,e=e,r=0.95) 30 | 31 | 32 | def quickly_hypocratic(y :Y_TYPE, s, k:int, a:A_TYPE =None, t:T_TYPE =None, e:E_TYPE =None): 33 | return hypocratic_ema_r1(y=y,s=s,k=k,a=a,t=t,e=e,r=0.75) 34 | 35 | 36 | if __name__=='__main__': 37 | from timemachines.skatertools.data.real import hospital_with_exog 38 | from timemachines.skatertools.evaluation.evaluators import evaluate_mean_absolute_error 39 | 40 | k = 3 41 | y, a = hospital_with_exog(k=k,n=500) 42 | f = slowly_hypocratic 43 | err1 = evaluate_mean_absolute_error(f=f, k=k, y=y, a=a, n_burn=50) 44 | -------------------------------------------------------------------------------- /timemachines/skaters/sk/README.md: -------------------------------------------------------------------------------- 1 | Skaters powered by sktime 2 | 3 | This is also a reasonable template for creation of skaters from batch-style forecasting routines. 4 | You might want to C&P this one if incorporating other libraries. 5 | 6 | 1. Locate a python package that you think should be exposed to timemachines 7 | 2. Grok the package and maybe contribute to https://github.com/microprediction/timeseries-notebooks while at it. 8 | 3. Choose a short PREFIX that isn't exactly the same as the library (here PREFIX='sk', obviously) 9 | 4. Write PREFIXinclusion.py (pretty trivial) 10 | 5. Write PREFIXwrappers.py (expose the batch functionality in a simple way) 11 | 6. Write PREFIX.py (skaters using timemachines.skatertools.batch.empiricalbatchskater) 12 | 7. Write PREFIX.py (skaters using timemachines.skatertools.batch.empiricalbatchskater) 13 | 8. Collate all skaters in allPREFIXskaters.py 14 | 9. Modify timemachines.skaters.allskaters 15 | 10. Modify setup.py to include the path 16 | 11. Write tests.PREFIX... 17 | 12. Run pytest 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /timemachines/skaters/sk/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/timemachines/skaters/sk/__init__.py -------------------------------------------------------------------------------- /timemachines/skaters/sk/allskskaters.py: -------------------------------------------------------------------------------- 1 | from timemachines.skaters.sk.sktheta import SK_THETA_SKATERS 2 | from timemachines.skaters.sk.skautoarima import SK_AA_SKATERS 3 | from timemachines.skaters.sk.skautoets import SK_AE_SKATERS 4 | from timemachines.skaters.sk.sfautoarima import SF_AA_SKATERS 5 | from timemachines.skaters.sk.sfautoarimawiggly import SF_AUTOARIMA_WIGGLY_SKATERS 6 | from timemachines.skaters.sk.skautoarimawiggly import SK_AUTOARIMA_WIGGLY_SKATERS 7 | SK_SKATERS = SK_THETA_SKATERS + SK_AA_SKATERS + SK_AE_SKATERS +\ 8 | SF_AA_SKATERS + SF_AUTOARIMA_WIGGLY_SKATERS + SK_AUTOARIMA_WIGGLY_SKATERS 9 | -------------------------------------------------------------------------------- /timemachines/skaters/sk/sfautoarima.py: -------------------------------------------------------------------------------- 1 | from timemachines.skaters.sk.skinclusion import using_sktime 2 | from timemachines.skaters.sk.sfinclusion import using_statsforecast 3 | 4 | # See https://github.com/sktime/sktime/blob/main/sktime/forecasting/statsforecast.py 5 | 6 | 7 | if using_sktime and using_statsforecast: 8 | from timemachines.skaters.sk.skwrappers import sf_autoarima_iskater 9 | from timemachines.skatertools.utilities.conventions import Y_TYPE, A_TYPE, R_TYPE, E_TYPE, T_TYPE 10 | from timemachines.skatertools.batch.batchskater import batch_skater_factory 11 | 12 | def sf_autoarima(y: Y_TYPE, s, k: int, a: A_TYPE = None, t: T_TYPE = None, e: E_TYPE = None, r: R_TYPE = None, emp_mass=0.0): 13 | return batch_skater_factory(y=y, s=s, k=k, a=a, t=t, e=e, r=r, emp_mass=emp_mass, 14 | iskater=sf_autoarima_iskater, 15 | iskater_kwargs={}, 16 | min_e=0) 17 | 18 | SF_AA_SKATERS = [sf_autoarima] 19 | 20 | else: 21 | SF_AA_SKATERS = [] 22 | 23 | 24 | 25 | 26 | if __name__=='__main__': 27 | from timemachines.skatertools.evaluation.evaluators import hospital_mean_square_error_with_sporadic_fit 28 | err1 = hospital_mean_square_error_with_sporadic_fit(f=sf_autoarima, k=3, n=110) 29 | -------------------------------------------------------------------------------- /timemachines/skaters/sk/sfautoarimahypocratic.py: -------------------------------------------------------------------------------- 1 | from timemachines.skaters.sk.sfinclusion import using_statsforecast 2 | 3 | if using_statsforecast: 4 | from timemachines.skatertools.utilities.conventions import Y_TYPE, A_TYPE, E_TYPE, T_TYPE 5 | from timemachines.skatertools.composition.residualshypocratic import quickly_moving_hypocratic_residual_factory 6 | from timemachines.skaters.sk.sfautoarima import sf_autoarima 7 | 8 | 9 | def sf_autoarima_hypocratic(y: Y_TYPE, s: dict, k: int, a: A_TYPE = None, t: T_TYPE = None, e: E_TYPE = None): 10 | """ Chase residuals, somewhat cautiously using, quickly moving average """ 11 | return quickly_moving_hypocratic_residual_factory(y=y, s=s, k=k, a=a, t=t, e=e, r=None, f=sf_autoarima) 12 | 13 | 14 | 15 | SF_HYPOCRATIC_SKATERS = [ sf_autoarima_hypocratic ] 16 | -------------------------------------------------------------------------------- /timemachines/skaters/sk/sfinclusion.py: -------------------------------------------------------------------------------- 1 | 2 | try: 3 | from statsforecast.core import StatsForecast 4 | from sktime.forecasting.statsforecast import StatsForecastAutoARIMA 5 | using_statsforecast = True 6 | except ImportError: 7 | using_statsforecast = False 8 | 9 | if __name__=='__main__': 10 | print({'using_statsforecast':using_statsforecast}) 11 | from sktime.forecasting.statsforecast import StatsForecastAutoARIMA -------------------------------------------------------------------------------- /timemachines/skaters/sk/skautoarima.py: -------------------------------------------------------------------------------- 1 | from timemachines.skaters.sk.skinclusion import using_sktime 2 | from timemachines.skaters.pmd.pmdinclusion import using_pmd 3 | 4 | if using_sktime and using_pmd: 5 | from timemachines.skaters.sk.skwrappers import sk_autoarima_iskater 6 | from timemachines.skatertools.utilities.conventions import Y_TYPE, A_TYPE, R_TYPE, E_TYPE, T_TYPE 7 | from timemachines.skatertools.batch.batchskater import batch_skater_factory 8 | 9 | def sk_autoarima(y: Y_TYPE, s, k: int, a: A_TYPE = None, t: T_TYPE = None, e: E_TYPE = None, r: R_TYPE = None, emp_mass=0.0): 10 | return batch_skater_factory(y=y, s=s, k=k, a=a, t=t, e=e, r=r, emp_mass=emp_mass, 11 | iskater=sk_autoarima_iskater, 12 | iskater_kwargs={}, 13 | min_e=0) 14 | 15 | SK_AA_SKATERS = [sk_autoarima] 16 | 17 | else: 18 | SK_AA_SKATERS = [] 19 | 20 | 21 | 22 | 23 | if __name__=='__main__': 24 | from timemachines.skatertools.evaluation.evaluators import hospital_mean_square_error_with_sporadic_fit 25 | err1 = hospital_mean_square_error_with_sporadic_fit(f=sk_autoarima, k=3, n=110) 26 | -------------------------------------------------------------------------------- /timemachines/skaters/sk/skinclusion.py: -------------------------------------------------------------------------------- 1 | 2 | try: 3 | import sktime 4 | using_sktime = True 5 | except ImportError: 6 | using_sktime = False 7 | 8 | if __name__=='__main__': 9 | print({'using_sktime':using_sktime}) -------------------------------------------------------------------------------- /timemachines/skaters/sk/sktheta.py: -------------------------------------------------------------------------------- 1 | from timemachines.skaters.sk.skinclusion import using_sktime 2 | 3 | 4 | if using_sktime: 5 | from timemachines.skaters.sk.skwrappers import sk_theta_hourly_iskater 6 | from timemachines.skatertools.utilities.conventions import Y_TYPE, A_TYPE, R_TYPE, E_TYPE, T_TYPE 7 | from timemachines.skatertools.batch.batchskater import batch_skater_factory 8 | 9 | def sk_theta(y: Y_TYPE, s, k: int, a: A_TYPE = None, t: T_TYPE = None, e: E_TYPE = None, r: R_TYPE = None, emp_mass=0.0, 10 | deseasonalize=False): 11 | return batch_skater_factory(y=y, s=s, k=k, a=a, t=t, e=e, r=r, emp_mass=emp_mass, 12 | iskater=sk_theta_hourly_iskater, 13 | iskater_kwargs={'deseasonalize':deseasonalize}, 14 | min_e=0, n_warm=20) 15 | 16 | SK_THETA_SKATERS = [sk_theta] 17 | 18 | else: 19 | SK_THETA_SKATERS = [] 20 | 21 | if __name__=='__main__': 22 | from timemachines.skatertools.evaluation.evaluators import hospital_mean_square_error 23 | err1 = hospital_mean_square_error(f=sk_theta, k=3) 24 | -------------------------------------------------------------------------------- /timemachines/skaters/smdk/README.md: -------------------------------------------------------------------------------- 1 | ## Simdkalman 2 | 3 | A collection of state space model techniques where calculation is vectorized. 4 | 5 | The smdkarma factory could use the following research 6 | 7 | - Does it work for ARMA friendly time-series? 8 | - What meta-params need to be improved? 9 | - How does it compare against auto-arima on those? 10 | - Can it be made better by including differencing or fraction diff? 11 | - How does stacking smdkarma with different diff's perform in Elo? 12 | - Could organizing the space help (e.g. self-org map) ? 13 | -------------------------------------------------------------------------------- /timemachines/skaters/smdk/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/timemachines/skaters/smdk/__init__.py -------------------------------------------------------------------------------- /timemachines/skaters/smdk/allsmdkskaters.py: -------------------------------------------------------------------------------- 1 | from timemachines.skaters.smdk.smdkarma import SMDK_ARMA_SKATERS 2 | 3 | SMDK_SKATERS = SMDK_ARMA_SKATERS -------------------------------------------------------------------------------- /timemachines/skaters/smdk/smdkinclusion.py: -------------------------------------------------------------------------------- 1 | try: 2 | import simdkalman 3 | using_simdkalman = True 4 | except ImportError: 5 | using_simdkalman = False 6 | using_latest_simdkalman = False 7 | 8 | 9 | if using_simdkalman: 10 | # Also checks whether we can use the version supporting multiple systems 11 | # pip install --upgrade git+https://github.com/oseiskar/simdkalman should fix 12 | from timemachines.skaters.smdk.smdkexample import smdk_example 13 | A, H, m0, P0, Q, R, y0 = smdk_example(different_transitions=False) 14 | from simdkalman import KalmanFilter 15 | kf = KalmanFilter(state_transition=A, process_noise=Q, observation_model=H,observation_noise=R) 16 | try: 17 | A, H, m0, P0, Q, R, y0 = smdk_example(different_transitions=True) 18 | kf = KalmanFilter(state_transition=A, process_noise=Q, observation_model=H, observation_noise=R) 19 | using_latest_simdkalman = True 20 | except AssertionError: 21 | using_latest_simdkalman = False 22 | -------------------------------------------------------------------------------- /timemachines/skaters/suc/README.md: -------------------------------------------------------------------------------- 1 | ## Successor skaters 2 | 3 | Use pre-trained keras models -------------------------------------------------------------------------------- /timemachines/skaters/suc/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/timemachines/skaters/suc/__init__.py -------------------------------------------------------------------------------- /timemachines/skaters/suc/allsuccessorskaters.py: -------------------------------------------------------------------------------- 1 | from timemachines.skaters.suc.successorinclusion import using_successor 2 | 3 | if using_successor: 4 | from successor.skaters.scalarskaters.allscalarskaters import SCALAR_SKATERS 5 | SUCCESSOR_SKATERS = SCALAR_SKATERS 6 | else: 7 | SUCCESSOR_SKATERS = [] -------------------------------------------------------------------------------- /timemachines/skaters/suc/successorinclusion.py: -------------------------------------------------------------------------------- 1 | try: 2 | import successor 3 | using_successor = True 4 | except ImportError: 5 | using_successor = False -------------------------------------------------------------------------------- /timemachines/skaters/tsa/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/timemachines/skaters/tsa/__init__.py -------------------------------------------------------------------------------- /timemachines/skaters/tsa/alltsaskaters.py: -------------------------------------------------------------------------------- 1 | from timemachines.skaters.tsa.tsaconstant import TSA_CONSTANT_SKATERS 2 | from timemachines.skaters.tsa.tsaensembles import TSA_ENSEMBLE_SKATERS 3 | from timemachines.skaters.tsa.tsahypocratic import TSA_DO_HYPOCRATIC_SKATERS 4 | 5 | TSA_SKATERS = TSA_CONSTANT_SKATERS + TSA_ENSEMBLE_SKATERS + TSA_DO_HYPOCRATIC_SKATERS -------------------------------------------------------------------------------- /timemachines/skaters/tsa/tsahypocratic.py: -------------------------------------------------------------------------------- 1 | from timemachines.skatertools.utilities.conventions import Y_TYPE, A_TYPE, R_TYPE, E_TYPE, T_TYPE 2 | from timemachines.skaters.tsa.tsaconstant import TSA_D0_SKATERS 3 | from timemachines.skatertools.ensembling.ensemblefactory import precision_weighted_ensemble_factory 4 | from timemachines.skatertools.utilities.conventions import wrap 5 | 6 | 7 | def hypocratic_tsa_d0_factory(y :Y_TYPE, s, k:int, a:A_TYPE =None, t:T_TYPE =None, e:E_TYPE =None, r:R_TYPE=None): 8 | """ 9 | r : moving average parameter (e.g. 0.75 is fast, 0.95 is slow) 10 | """ 11 | y0 = wrap(y)[0] 12 | assert r is not None 13 | x, x_std, s = precision_weighted_ensemble_factory(fs=TSA_D0_SKATERS, y=y0, s=s, k=k, a=a, t=t, e=e, r=r) 14 | 15 | def hypocratic(x:float, x_std:float, confidence=0.5): 16 | """ Shrink residual prediction towards zero """ 17 | # Remains to be seen if this is sensible for TSA residuals 18 | import math 19 | if abs(x_std)<1e-6 or abs(x)<1e-3*x_std: 20 | return 0.0 21 | else: 22 | return x*math.tanh(confidence*abs(x)/(3*x_std)) 23 | 24 | x_resid = [ hypocratic(xi,x_std) for xi,x_std in zip(x,x_std) ] 25 | return x_resid, x_std, s 26 | 27 | 28 | def tsa_slowly_hypocratic_d0_ensemble(y :Y_TYPE, s, k:int, a:A_TYPE =None, t:T_TYPE =None, e:E_TYPE =None): 29 | return hypocratic_tsa_d0_factory(y=y,s=s,k=k,a=a,t=t,e=e,r=0.95) 30 | 31 | 32 | def tsa_quickly_hypocratic_d0_ensemble(y :Y_TYPE, s, k:int, a:A_TYPE =None, t:T_TYPE =None, e:E_TYPE =None): 33 | return hypocratic_tsa_d0_factory(y=y,s=s,k=k,a=a,t=t,e=e,r=0.75) 34 | 35 | 36 | TSA_DO_HYPOCRATIC_SKATERS = [tsa_slowly_hypocratic_d0_ensemble, tsa_quickly_hypocratic_d0_ensemble] -------------------------------------------------------------------------------- /timemachines/skaters/tsa/tsaparams.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | TSA_META = dict(n_warm=20) 4 | -------------------------------------------------------------------------------- /timemachines/skatertools/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/timemachines/skatertools/__init__.py -------------------------------------------------------------------------------- /timemachines/skatertools/batch/README.md: -------------------------------------------------------------------------------- 1 | 2 | Utilities for creating skaters 3 | 4 | - batchskater: 5 | - Useful when exposing as skaters a package that was not written with online use in mind. 6 | - See bats or sk for usage examples 7 | -------------------------------------------------------------------------------- /timemachines/skatertools/batch/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/timemachines/skatertools/batch/__init__.py -------------------------------------------------------------------------------- /timemachines/skatertools/combining/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/timemachines/skatertools/combining/__init__.py -------------------------------------------------------------------------------- /timemachines/skatertools/comparison/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/timemachines/skatertools/comparison/__init__.py -------------------------------------------------------------------------------- /timemachines/skatertools/comparison/comparing.py: -------------------------------------------------------------------------------- 1 | 2 | from timemachines.skatertools.evaluation.evaluators import evaluate_sklearn_metric_with_sporadic_fit 3 | from momentum.functions import var_init, var_update 4 | import random 5 | from pprint import pprint 6 | from timemachines.inclusion.sklearninclusion import using_sklearn 7 | from typing import List 8 | 9 | if using_sklearn: 10 | from sklearn.metrics import mean_squared_error, mean_absolute_error 11 | 12 | # Example of comparing two or more skaters from the timemachines package 13 | 14 | 15 | def compare(fs, ys:[float], metric=None, n_test=10, n_train=200): 16 | """ Keep running tally of relative errors 17 | :param fs: A list of skaters 18 | :param ys: A very long timeseries 19 | :return: 20 | """ 21 | if metric is None: 22 | metric = mean_squared_error 23 | 24 | n = len(ys) 25 | running_moments = [ var_init() for _ in fs ] 26 | 27 | while True: 28 | seq_len = n_train+n_test 29 | start_ndx = random.choice(list(range(n-seq_len-1))) 30 | y = ys[start_ndx:start_ndx + seq_len] 31 | es = [ evaluate_sklearn_metric_with_sporadic_fit(f=f, y=y, k=1, n_test=n_test, e_fit=60, e_nofit=-1, fit_frequency=30, metric=metric) for f in fs] 32 | for j,(mse,v) in enumerate(zip(es,running_moments)): 33 | v = var_update(v,(mse/n_test)**2) 34 | running_moments[j] = v 35 | 36 | if True: 37 | report = dict( sorted([ (v['mean'],f.__name__) for v,f in zip(running_moments,fs) ]) ) 38 | print(' ') 39 | pprint(report) 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /timemachines/skatertools/comparison/eloformulas.py: -------------------------------------------------------------------------------- 1 | 2 | # TODO: Move into ratings package to remove this dependency 3 | 4 | def elo_expected(d :float ,f :float =400 )->float: 5 | """ Expected points scored in a match by White player 6 | :param d: Difference in rating (Black minus White) 7 | :param f: "F"-Factor 8 | :return: 9 | """ 10 | if d/ f > 8: 11 | return 0.0 12 | elif d / f < -8: 13 | return 1.0 14 | else: 15 | return 1. / (1 + 10 ** (d / f)) 16 | 17 | 18 | def elo_update(white_elo, black_elo, points, k=25, f=400): 19 | """ 20 | :param white_elo: 21 | :param black_elo: 22 | :param points: 1 if White wins, 0 if Black wins 23 | :param k: K-Factor, how much to update 24 | :param f: F-Factor 25 | :return: 26 | """ 27 | d = black_elo - white_elo 28 | expected_points = elo_expected(d=d, f=f) 29 | w = points - expected_points 30 | white_new_elo = white_elo + k * w 31 | black_new_elo = black_elo - k * w 32 | return white_new_elo, black_new_elo 33 | -------------------------------------------------------------------------------- /timemachines/skatertools/components/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/timemachines/skatertools/components/__init__.py -------------------------------------------------------------------------------- /timemachines/skatertools/components/chronometer.py: -------------------------------------------------------------------------------- 1 | 2 | # Implements the old Matlab tic/toc which is still my favourite interface 3 | # That style makes is somewhat invasive - though the odds of s['chronometer'] being used for 4 | # another purpose seem slim 5 | 6 | import time 7 | from pprint import pprint 8 | 9 | 10 | def tick(s): 11 | if not s.get('chronometer'): 12 | s['chronometer'] = {'tick':time.time()} 13 | else: 14 | s['chronometer'].update({'tick':time.time()}) 15 | 16 | 17 | def tocks(s): 18 | """ Returns a copy of reported timings """ 19 | return dict([(k,v) for k,v in s['chronometer'].items() if k not in ['tick']]) 20 | 21 | 22 | def tock(s,label:str='invocation',reset=True, accumulate=True): 23 | assert label not in ['tick','tock'] 24 | assert s.get('chronometer') and s.get('chronometer').get('tick'),'Must call tick before tock' 25 | elapsed = time.time()-s['chronometer']['tick'] 26 | if accumulate and s['chronometer'].get(label): 27 | elapsed += s['chronometer'][label] 28 | s['chronometer'][label] = elapsed 29 | if reset: 30 | s['chronometer']['tick']=time.time() 31 | return s 32 | 33 | 34 | def lap(s,label:str): 35 | return tock(s=s,label=label,reset=False) 36 | 37 | 38 | if __name__=='__main__': 39 | s = dict() 40 | tick(s) 41 | time.sleep(1) 42 | tock(s) 43 | pprint(s) 44 | time.sleep(1) 45 | tock(s,'fit') 46 | pprint(s) -------------------------------------------------------------------------------- /timemachines/skatertools/components/residuals.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | def residual(s:dict, y, x): 4 | """ Return residuals 5 | :param s: state - supply empty dict on first call 6 | :param y: incoming observation 7 | :param x: term structure of predictions out k steps ahead, made after y received 8 | :returns k-vector of residuals 9 | """ 10 | k = len(x) 11 | if not s: 12 | s = {'predictions': [[] for _ in range(k)]} # Holds the cavalcade 13 | else: 14 | assert len(x) == len(s['predictions']) # 'k' is immutable 15 | 16 | assessable = s['predictions'].pop(0) 17 | z = [0 for _ in range(k)] 18 | if assessable: 19 | for j, xi in assessable: 20 | z[j] = y - xi 21 | 22 | s['predictions'].append(list()) 23 | for j, xj in enumerate(x): 24 | s['predictions'][j].append((j, xj)) 25 | 26 | return z, s -------------------------------------------------------------------------------- /timemachines/skatertools/composition/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/timemachines/skatertools/composition/__init__.py -------------------------------------------------------------------------------- /timemachines/skatertools/composition/fractional.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | 4 | def frac_weights(d: float, m: int = 20) -> list: 5 | """ 6 | :param d: Fractional order 7 | :param m: Weights are length m+1 8 | :return: 9 | """ 10 | w = [1.0] 11 | for k in range(1, m + 1): 12 | w.append(-w[-1] * ((d - k + 1.0) / k)) 13 | return w 14 | 15 | 16 | def frac_matrix(d: float, m:int = 20, n:int=50, l:int=15): 17 | """ 18 | :param d: 19 | :param m: Length of weights 20 | :param n: Total length of the time-series 21 | :param l: The number of differences that will be taken (n-l will be left alone) 22 | :return: 23 | """ 24 | assert m + 1 + l <= n 25 | 26 | w = frac_weights(d=d,m=m) 27 | A = np.eye(n) 28 | for j in range(0,l): 29 | A[j,j:j+m+1] = w 30 | return A 31 | 32 | 33 | if __name__=='__main__': 34 | d = 0.5 35 | m = 10 36 | l = 15 37 | n = 50 38 | A = frac_matrix(d=d,m=m, n=n, l=l) 39 | print(A) 40 | B = np.linalg.inv(A) 41 | C = np.matmul(A,B) 42 | print(C) 43 | -------------------------------------------------------------------------------- /timemachines/skatertools/composition/residualshypocratic.py: -------------------------------------------------------------------------------- 1 | from timemachines.skatertools.utilities.conventions import Y_TYPE, A_TYPE, E_TYPE, T_TYPE 2 | from typing import Any 3 | from timemachines.skatertools.composition.residualcomposition import residual_chaser_factory 4 | from timemachines.skaters.simple.hypocratic import quickly_hypocratic, slowly_hypocratic 5 | 6 | 7 | def quickly_moving_hypocratic_residual_factory(y :Y_TYPE, s:dict, k:int, a:A_TYPE =None, t:T_TYPE =None, e:E_TYPE =None, 8 | f=None, r=None)->([float] , Any , Any): 9 | """ A simple way to convert a skater into one whose residuals are cautiously chased with a quickly moving average 10 | 11 | f : skater 12 | r : skater's hyper-params, if any 13 | 14 | """ 15 | return residual_chaser_factory(y=y,s=s,k=k,a=a,t=t,e=e,f1=f,r1=r,f2=quickly_hypocratic,r2=r) 16 | 17 | 18 | def slowly_moving_hypocratic_residual_factory(y: Y_TYPE, s: dict, k: int, a: A_TYPE = None, t: T_TYPE = None, 19 | e: E_TYPE = None, 20 | f=None, r=None) -> ([float], Any, Any): 21 | """ A simple way to convert a skater into one whose residuals are cautiously chased with a slowly moving average 22 | 23 | f : skater 24 | r : skater's hyper-params, if any 25 | 26 | """ 27 | return residual_chaser_factory(y=y, s=s, k=k, a=a, t=t, e=e, f1=f, r1=r, f2=slowly_hypocratic, r2=r) -------------------------------------------------------------------------------- /timemachines/skatertools/crowd/README.md: -------------------------------------------------------------------------------- 1 | ### Micro-managing patterns 2 | 3 | Some utilities for creating stacks benefit from exogenous input (e.g. other algorithms recommending 4 | which skaters to use next and being rewarded for doing so). 5 | 6 | For the really long explanation see the book 7 | "Microprediction: Building an Open AI Network" (2022, but who knows when you are reading this) 8 | 9 | A word of caution, the state will be serializable with json.dumps() in general, but to reinflate 10 | you need to use the state utility provided (the lottery-type mechanisms are objects derived 11 | from dict). 12 | 13 | -------------------------------------------------------------------------------- /timemachines/skatertools/crowd/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/timemachines/skatertools/crowd/__init__.py -------------------------------------------------------------------------------- /timemachines/skatertools/crowd/lotteryconventions.py: -------------------------------------------------------------------------------- 1 | from typing import Union 2 | 3 | # Used by managing.lotteryensemblefactory 4 | 5 | E_SUGGESTION = 'suggestion' 6 | E_REWARD_STR = 'reward' 7 | EXTENDED_E_TYPE = Union[float, int, dict, str] -------------------------------------------------------------------------------- /timemachines/skatertools/data/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/timemachines/skatertools/data/__init__.py -------------------------------------------------------------------------------- /timemachines/skatertools/data/augmentation.py: -------------------------------------------------------------------------------- 1 | from typing import List, Iterator 2 | 3 | 4 | def reflect(ys:[float], n:int)->[float]: 5 | """ Lengthen time series by reflection back in time 6 | :param ys: time series shorter than n 7 | :param n: desired length of time series 8 | :return: time series length n 9 | """ 10 | assert len(ys)>=3 11 | xs = list(reversed(ys))[:-1] + list(ys) 12 | while len(xs) n_obs+10 28 | except: 29 | got = False 30 | col = random.choice(list(df.columns)) 31 | vals = list(df[col].values) 32 | k = random.choice(list(range(0,len(df.index)-n_obs-5))) 33 | y = vals[k:k+n_obs] 34 | return y,t 35 | 36 | 37 | if __name__=='__main__': 38 | y,t = random_long_data(n_obs=1000) 39 | print(y[:10]) -------------------------------------------------------------------------------- /timemachines/skatertools/data/surrogate.py: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /timemachines/skatertools/data/synthetic.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | 4 | def brownian_with_noise(n:int)->[float]: 5 | ys_ = np.cumsum(np.random.randn(n)) 6 | ys = [y + np.random.randn() for y in ys_] 7 | return list(ys) 8 | 9 | 10 | def brownian_with_exogenous(n:int)->[(float,)]: 11 | dys1__ = np.random.randn(n+2) 12 | dys1_ = np.array([ 0.1*a+0.3*b+0.2*c for a,b,c in zip( dys1__[2:], dys1__[1:],dys1__) ]) 13 | dys2_ = list(0.5*np.array(dys1_[2:]))+list(np.random.randn(2)) 14 | ys1 = np.cumsum(dys1_) + 0.025*np.random.randn(n) 15 | ys2 = np.cumsum(dys2_+0.1*dys1_)+0.15*ys1 + 0.015*np.random.randn(n) 16 | return list(zip(ys1,ys2)) 17 | 18 | 19 | -------------------------------------------------------------------------------- /timemachines/skatertools/ensembling/README.md: -------------------------------------------------------------------------------- 1 | # Ensembles, stacking, experts, portfolios, et cetera 2 | 3 | 4 | The ensemblefactory takes a list of skaters *fs* and also a meta-model *g*. It prepares a vector of the constituent model's 5 | predictions and passes them to the meta-model. 6 | 7 | - If 'empirical_std' is set to True, the constituent model's predictions will be interleaved 8 | with their std error estimates. See precisionweightedskater for an example of this style of use 9 | 10 | ### Trust constituent's errors? 11 | 12 | Note the *trust* argument in the ensemble factory. 13 | 14 | 1. If set to true, the ensemble will use the constituent models' own estimates of their errors. 15 | 2. If set to false, the ensemble factory will create a separate parade object for each model, to untrustingly 16 | construct independent estimates of the errors. 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /timemachines/skatertools/ensembling/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/timemachines/skatertools/ensembling/__init__.py -------------------------------------------------------------------------------- /timemachines/skatertools/ensembling/portskater.py: -------------------------------------------------------------------------------- 1 | from timemachines.skatertools.ensembling.precisionweightedskater import normalize, weighted_average 2 | import math 3 | import numpy as np 4 | 5 | # Not written ... jus scrap for now 6 | 7 | 8 | def port_skater(y, s, k, a, t, e, r=0.5): 9 | """ Special purpose skater since 'y' here takes a rather particular form, 10 | and it is intended to be used as with the ensemblefactory 11 | 12 | Treats y[1],y[3],y[5]... as unbiased estimates of y[0] 13 | Treats y[2],y[4],... as std 14 | 15 | r - determines the exponent: 16 | 17 | r=0.0 corresponds to equal weighting independent of x_std supplied by the models 18 | r=0.5 corresponds to simple weighting and is the default 19 | r->1 will use only the most accurate skater in the ensemble 20 | 21 | """ 22 | if s.get('cov') is None: 23 | s = {'cov':1} 24 | 25 | tol = 1e-6 # minimum allowed x_std 26 | expon = 2*math.atanh(r)/math.atanh(0.5) if r<1-1e-6 else 10.0 27 | J = int((len(y)-1)/2) 28 | y_stds = [ tol + y[2*j+2] for j in range(J) ] 29 | # Avoid overflow 30 | while np.mean(np.abs(y_stds))>1e2: 31 | y_stds = [ y_std_i/1e2 for y_std_i in y_stds ] 32 | 33 | w = normalize( [ 1./math.pow(y_std,expon) for y_std in y_stds ] ) 34 | y_hats = [ y[2*j+1] for j in range(J) ] 35 | x = weighted_average(y=y_hats, w=w) 36 | x_std = min(y_stds) # Conservative - they probably are not independent 37 | x_interp = [y[0]+(j+1)/k*(x-y[0]) for j in range(k)] 38 | x_std_interp = [math.sqrt(j+1)*x_std for j in range(k)] 39 | return x_interp, x_std_interp, {} 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /timemachines/skatertools/ensembling/precisionweightedskater.py: -------------------------------------------------------------------------------- 1 | import math 2 | import numpy as np 3 | 4 | 5 | def weighted_average(y,w): 6 | return sum(wj * yj for yj, wj in zip(y, w)) / sum(w) 7 | 8 | 9 | def normalize(w): 10 | return [ wj/sum(w) for wj in w] 11 | 12 | 13 | def precision_weighted_skater(y,s,k,a,t,e,r=0.5): 14 | """ Special purpose skater since 'y' here takes a rather particular form, 15 | and it is intended to be used as with the ensemblefactory 16 | 17 | Treats y[1],y[3],y[5]... as unbiased estimates of y[0] 18 | Treats y[2],y[4],... as std 19 | 20 | r - determines the exponent: 21 | 22 | r=0.0 corresponds to equal weighting independent of x_std supplied by the models 23 | r=0.5 corresponds to simple weighting and is the default 24 | r->1 will use only the most accurate skater in the ensemble 25 | 26 | """ 27 | tol = 1e-6 # minimum allowed x_std 28 | expon = 2*math.atanh(r)/math.atanh(0.5) if r<1-1e-6 else 10.0 29 | J = int((len(y)-1)/2) 30 | y_stds = [ tol + y[2*j+2] for j in range(J) ] 31 | # Avoid overflow 32 | while np.mean(np.abs(y_stds))>1e2: 33 | y_stds = [ y_std_i/1e2 for y_std_i in y_stds ] 34 | 35 | w = normalize( [ 1./math.pow(y_std,expon) for y_std in y_stds ] ) 36 | y_hats = [ y[2*j+1] for j in range(J) ] 37 | x = weighted_average(y=y_hats, w=w) 38 | x_std = min(y_stds) # Conservative - they probably are not independent 39 | x_interp = [y[0]+(j+1)/k*(x-y[0]) for j in range(k)] 40 | x_std_interp = [math.sqrt(j+1)*x_std for j in range(k)] 41 | return x_interp, x_std_interp, {} 42 | -------------------------------------------------------------------------------- /timemachines/skatertools/evaluation/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/timemachines/skatertools/evaluation/__init__.py -------------------------------------------------------------------------------- /timemachines/skatertools/offlinetesting/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/timemachines/skatertools/offlinetesting/__init__.py -------------------------------------------------------------------------------- /timemachines/skatertools/offlinetesting/allslowtests.py: -------------------------------------------------------------------------------- 1 | from timemachines.skatertools.offlinetesting.optimizerandomskater import optimize_random_skater 2 | import random 3 | 4 | REGRESSION_TESTS = [optimize_random_skater] 5 | 6 | 7 | 8 | 9 | 10 | if __name__=='__main__': 11 | task = random.choice(REGRESSION_TESTS) 12 | print(task.__name__) 13 | task() -------------------------------------------------------------------------------- /timemachines/skatertools/offlinetesting/optimizerandomskater.py: -------------------------------------------------------------------------------- 1 | from timemachines.skatertools.tuning.hyper import optimal_r 2 | from timemachines.skatertools.data.synthetic import brownian_with_exogenous 3 | from timemachines.skaters.localskaters import SKATERS_R1, SKATERS_R2, SKATERS_R3 4 | import time 5 | import random 6 | from pprint import pprint 7 | from timemachines.skaters.proph.prophparams import PROPHET_META 8 | 9 | try: 10 | from humpday.optimizers.alloptimizers import OPTIMIZERS 11 | except ImportError: 12 | raise ImportError('You need to pip install humpday') 13 | 14 | 15 | def optimize_random_skater(): 16 | print('Available optimizers...') 17 | print([o.__name__ for o in OPTIMIZERS]) 18 | start_time = time.time() 19 | optimizer = random.choice(OPTIMIZERS) 20 | f = random.choice(SKATERS_R1+SKATERS_R2+SKATERS_R3) 21 | k = random.choice([1,2,3,5,8,13,21]) 22 | n_trials = random.choice([15,50]) 23 | n_burn = PROPHET_META['n_warm'] 24 | n = n_burn+100 # Length of synthetic data 25 | print('Skater is '+str(f.__name__)) 26 | print('Using '+str(optimizer.__name__)) 27 | r_star, best_val, info = optimal_r(f=f, y=brownian_with_exogenous(n=n),k=k,a=None, 28 | n_trials=n_trials, optimizer=optimizer, n_burn=n_burn) 29 | print("Best hyper-param is " + str(r_star)) 30 | print('Took ' + str( (time.time()-start_time)/60 ) + ' minutes.' ) 31 | pprint(info) 32 | 33 | 34 | 35 | if __name__=='__main__': 36 | optimize_random_skater() -------------------------------------------------------------------------------- /timemachines/skatertools/recommendations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/timemachines/skatertools/recommendations/__init__.py -------------------------------------------------------------------------------- /timemachines/skatertools/sampling/README.md: -------------------------------------------------------------------------------- 1 | ### Generating 225 samples 2 | -------------------------------------------------------------------------------- /timemachines/skatertools/sensitivity/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/timemachines/skatertools/sensitivity/__init__.py -------------------------------------------------------------------------------- /timemachines/skatertools/smoothing/README.md: -------------------------------------------------------------------------------- 1 | ### Smoothing models 2 | 3 | -------------------------------------------------------------------------------- /timemachines/skatertools/smoothing/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/timemachines/skatertools/smoothing/__init__.py -------------------------------------------------------------------------------- /timemachines/skatertools/tuning/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/timemachines/skatertools/tuning/__init__.py -------------------------------------------------------------------------------- /timemachines/skatertools/tuning/hyperempirical.py: -------------------------------------------------------------------------------- 1 | import warnings 2 | 3 | from timemachines.skatertools.tuning.hyper import using_humpday 4 | 5 | try: 6 | from microprediction import MicroReader 7 | using_microprediction = True 8 | except ImportError: 9 | warnings.warn('microprediction is not installed so empirical fit cannot occur. pip install microprediction') 10 | using_microprediction = False 11 | 12 | 13 | if using_microprediction and using_humpday: 14 | 15 | from timemachines.skatertools.tuning.hyper import optimal_r 16 | 17 | def optimal_r_for_stream(f, name:str, k: int, evaluator = None, optimizer = None, 18 | n_trials = None, n_dim = None, n_burn:int = None, test_objective_first = True)->( 19 | float, float, dict): # best_r, best_val, info 20 | """ Find the best hyper-parameters for a univariate skater using live from www.microprediction.org 21 | :param f: 22 | :param name: Choose from https://www.microprediction.org/browse_streams.html but add '.json' to the end 23 | :param k: 24 | :param evaluator: 25 | :param optimizer: 26 | :param n_trials: 27 | :param n_dim: 28 | :param n_burn: 29 | :param test_objective_first: 30 | :return: best_r, best_value, info 31 | """ 32 | mr = MicroReader() 33 | lagged_values, lagged_times = mr.get_lagged_values_and_times(name=name) 34 | t = list(reversed(lagged_times)) 35 | y = list(reversed(lagged_values)) 36 | return optimal_r(f=f,y=y,k=k, a=None,t=t,e=None,evaluator=evaluator,optimizer=optimizer,n_trials=n_trials, 37 | n_dim=n_dim, n_burn=n_burn, test_objective_first=test_objective_first) 38 | 39 | -------------------------------------------------------------------------------- /timemachines/skatertools/tuning/hyperplot.py: -------------------------------------------------------------------------------- 1 | 2 | import numpy as np 3 | import matplotlib.pyplot as plt 4 | 5 | # TODO 6 | 7 | def mesh2d_(f,*args): 8 | """ Plot function taking len 2 vector as single argument 9 | f(xs) 10 | """ 11 | def g(x,y,*args): 12 | return f(np.array([x,y]),*args) 13 | mesh2d(g,*args) 14 | 15 | 16 | def mesh2d(f,*args): 17 | """ Plot function taking two arguments 18 | f(x,y) 19 | """ 20 | fig = plt.figure() 21 | ax = fig.add_subplot(111, projection='3d') 22 | x = y = np.arange(-0.5, 0.5, 0.005) 23 | X, Y = np.meshgrid(x, y) 24 | zs = np.array([ f(x_,y_,*args) for x_,y_ in zip( np.ravel(X), np.ravel(Y)) ]) 25 | Z = zs.reshape(X.shape) 26 | 27 | ax.plot_surface(X, Y, Z) 28 | 29 | ax.set_xlabel('X Label') 30 | ax.set_ylabel('Y Label') 31 | ax.set_zlabel('Z Label') 32 | 33 | plt.show() -------------------------------------------------------------------------------- /timemachines/skatertools/utilities/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/timemachines/skatertools/utilities/__init__.py -------------------------------------------------------------------------------- /timemachines/skatertools/utilities/arrivals.py: -------------------------------------------------------------------------------- 1 | from statistics import mode, StatisticsError 2 | import numpy as np 3 | 4 | 5 | def approx_dt(t:[float], default_dt=60 ): 6 | """ Crude estimate of the typical time between arrivals 7 | t: list of epoch times 8 | """ 9 | if len(t) > 5: 10 | return approx_mode([abs(dt) for dt in np.diff(list(t))]) or default_dt 11 | else: 12 | return default_dt 13 | 14 | 15 | def approx_mode(xs, ndigits=0): 16 | """ Mode of rounded numbers, or None """ 17 | xr = [round(x, ndigits) for x in xs] 18 | try: 19 | return mode(xr) 20 | except StatisticsError: 21 | return None -------------------------------------------------------------------------------- /timemachines/skatertools/utilities/instantiation.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/timemachines/skatertools/utilities/instantiation.py -------------------------------------------------------------------------------- /timemachines/skatertools/utilities/internet.py: -------------------------------------------------------------------------------- 1 | import requests 2 | 3 | CHECKED_INTERNET=False 4 | CONNECTED_TO_INTERNET=None 5 | 6 | 7 | def connected_to_internet(): 8 | global CHECKED_INTERNET 9 | global CONNECTED_TO_INTERNET 10 | if not CHECKED_INTERNET: 11 | CONNECTED_TO_INTERNET = check_if_connected_to_internet() 12 | return CONNECTED_TO_INTERNET 13 | 14 | 15 | def check_if_connected_to_internet(url='http://www.google.com/', timeout=2): 16 | try: 17 | _ = requests.head(url, timeout=timeout) 18 | return True 19 | except requests.ConnectionError: 20 | print("No internet connection available.") 21 | return False 22 | -------------------------------------------------------------------------------- /timemachines/skatertools/utilities/locations.py: -------------------------------------------------------------------------------- 1 | #moved 2 | from timemachines.skaters.pypi import PYPI, pypi_from_name -------------------------------------------------------------------------------- /timemachines/skatertools/utilities/wrangling.py: -------------------------------------------------------------------------------- 1 | 2 | def transpose(a): 3 | return list(map(list,zip(*a))) -------------------------------------------------------------------------------- /timemachines/skatertools/visualization/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprediction/timemachines/5ba624c7613644b6177877c385bf121d6e30b0a5/timemachines/skatertools/visualization/__init__.py -------------------------------------------------------------------------------- /timemachines/skatertools/visualization/realplot.py: -------------------------------------------------------------------------------- 1 | 2 | from timemachines.skatertools.data.real import hospital_with_exog 3 | from timemachines.skatertools.visualization.priorplot import prior_plot_exogenous 4 | import numpy as np 5 | 6 | 7 | def hospital_prior_plot_exogenous(f, k=None, x0=np.nan, n=150, n_plot=25): 8 | # Won't plot if matplotlib is not installed 9 | y, a = hospital_with_exog(k=k, n=450, offset=True) 10 | err = prior_plot_exogenous(f=f,k=k,y=y,a=a, n=450, n_plot=50) 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /timemachines/skatertools/visualization/skaterbumpplot.py: -------------------------------------------------------------------------------- 1 | from timemachines.skatertools.data.ornstein import simulate_arima_like_path 2 | from timemachines.skatertools.sensitivity.skatersensitivity import skater_bump 3 | from timemachines.inclusion.matplotlibinclusion import using_matplotlib 4 | 5 | if using_matplotlib: 6 | 7 | def skater_bump_plot(f, ndx, k): 8 | for _ in range(200): 9 | import numpy as np 10 | ys = simulate_arima_like_path(seq_len=100) 11 | y_final, x_final = skater_bump(ys=ys, f=f, ndx=ndx, k=k) 12 | discont_max = np.max(np.diff(np.array(x_final))) 13 | discont_median = np.median(np.abs(np.diff(np.array(x_final)))) 14 | if discont_max>10*discont_median: 15 | import matplotlib.pyplot as plt 16 | plt.plot(y_final,x_final,'bx') 17 | plt.ylabel('Prediction '+str(k)+' steps ahead') 18 | plt.xlabel('Value taken by y['+str(ndx)+']') 19 | plt.grid() 20 | plt.title(f.__name__) 21 | plt.show() 22 | import time 23 | time.sleep(2) 24 | plt.close() 25 | else: 26 | def skater_bump_plot(f, ndx, k): 27 | print('pip install matplotlib') 28 | 29 | 30 | if __name__=='__main__': 31 | #from timemachines.skaters.sk.skautoarima import sk_autoarima as f 32 | #from timemachines.skaters.simple.thinking import thinking_fast_and_slow as f 33 | #from timemachines.skaters.simple.movingaverage import precision_ema_ensemble as f 34 | #from timemachines.skaters.tsa.tsatheta import tsa_theta_additive as f 35 | from timemachines.skaters.sk.sfautoarima import sf_autoarima as f 36 | #from timemachines.skaters.proph.prophskaterssingular import fbprophet_univariate as f 37 | 38 | skater_bump_plot(f=f, ndx=-3, k=1) 39 | 40 | --------------------------------------------------------------------------------