Skip to content

Commit

Permalink
Merge branch 'master' into fix-(p)dds-parameter-bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
thouska authored Sep 8, 2020
2 parents 5c7f593 + 309e8d9 commit 4391506
Show file tree
Hide file tree
Showing 41 changed files with 353 additions and 263 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ __pycache__/

#other files
*.out
*.in
*.png
*.csv
site/*
mkdocs.yml
#mkdocs.yml

# Distribution / packaging
.Python
Expand Down
30 changes: 25 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
language: python
python:
#- "2.7"
#- "3.5"
- "3.6"
- "3.7"
# - "3.8" #Errors on Travis, build times out because no output was received...

# Uses cache to build faster
cache: pip

# this ubuntu distribution has sure the libopenmpi-dev packages available
dist: bionic
Expand Down Expand Up @@ -31,8 +33,26 @@ install:


script:
- py.test tests/test_* --cov spotpy --cov-report term-missing -v
- py.test tests/test_* --cov spotpy --cov-report term-missing -v
# - mpirun -c 4 python spotpy/examples/tutorial_parallel_computing_hymod.py 100
- pip uninstall spotpy -y
after_success:
- coveralls

jobs:
include:
- stage: Coveralls
name: Report Coveralls
after_success: python3 -m coveralls

# Publish spotpy on PyPi if taged
deploy:
provider: pypi
distributions: "sdist bdist_wheel"
on:
# In this case I want to deploy only when a tag is present...
tags: true
# ... and when tag is on master and respects the form "v0.0.0"
branch:
- master
- /v?(\d+\.)?(\d+\.)?(\*|\d+)$/
user: thouska
password : ${deploying}
9 changes: 9 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
include README.md
include MANIFEST.in
include setup.py
include setup.cfg
recursive-include spotpy/examples/cmf_data *
recursive-include spotpy/examples/hymod_exe *
recursive-include spotpy/examples/hymod_unix *
recursive-include spotpy/examples/hymod_python *
include LICENSE
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ A Statistical Parameter Optimization Tool for Python
[![Build Status][travis-image]][travis-link]
[![License][license-image]][license-link]
[![Coverage Status](https://coveralls.io/repos/github/thouska/spotpy/badge.svg?branch=master)](https://coveralls.io/github/thouska/spotpy?branch=master)
[![Documentation Status](https://readthedocs.org/projects/spotpy/badge/?version=latest)](https://readthedocs.org/projects/spotpy/badge/?version=latest)

[pypi-v-image]: https://img.shields.io/pypi/v/spotpy.png
[pypi-v-link]: https://pypi.python.org/pypi/spotpy
Expand Down Expand Up @@ -147,7 +148,7 @@ Or, after downloading the [source code](https://pypi.python.org/pypi/spotpy "sou
Support
=================

* Documentation: http://www.uni-giessen.de/cms/faculties/f09/institutes/ilr/hydro/download/spotpy
* Documentation: https://spotpy.readthedocs.io/en/latest/

* Feel free to contact the authors of this tool for any support questions.

Expand All @@ -160,7 +161,7 @@ Support

Getting started
=================
Have a look at https://github.com/thouska/spotpy/tree/master/spotpy/examples and http://fb09-pasig.umwelt.uni-giessen.de/spotpy/Tutorial/2-Rosenbrock/
Have a look at https://github.com/thouska/spotpy/tree/master/spotpy/examples and https://spotpy.readthedocs.io/en/latest/getting_started/


Contributing
Expand Down
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ We want to make this task as easy as possible. Some features you can use with th
Documentation
-------------

Documentation is available at `<http://fb09-pasig.umwelt.uni-giessen.de/spotpy>`__
Documentation is available at `<https://spotpy.readthedocs.io/en/latest>`__


Install
Expand Down Expand Up @@ -178,4 +178,4 @@ Patches/enhancements/new algorithms and any other contributions to this package
Getting started
---------------

Have a look at https://github.com/thouska/spotpy/tree/master/spotpy/examples and http://fb09-pasig.umwelt.uni-giessen.de/spotpy/Tutorial/2-Rosenbrock/
Have a look at https://github.com/thouska/spotpy/tree/master/spotpy/examples and https://spotpy.readthedocs.io/en/latest/getting_started/
File renamed without changes.
16 changes: 8 additions & 8 deletions docs/Tutorial/7-Advanced_hints.md → docs/Advanced_hints.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ IMPLEMENTATION OF TWO COMPLEMENTING VARIANCE-BASED ALGORITHMS, 2012] (https://ww

$$N = (1+4M^2(1+(k-2)d))k$$

with N = needed parameter iterations, M= inference factor (SPOTPY default M=4) and d= frequenzy step (SPOTPY default d=2) and k as the number of parameters of your model.
with N = needed parameter iterations, M= inference factor (SPOTPY default M=4) and d= frequency step (SPOTPY default d=2) and k as the number of parameters of your model.

You can start the simulation with

Expand Down Expand Up @@ -99,9 +99,9 @@ Just note that this works not for 'MLE', 'MCMC', 'SCE-UA', 'SA', 'DE-MCz' and 'R

## Sampling from a given parameter list

SPOTPY enables you to sample directly from a given parameter list. This can be useful if you want to check specific parameter combinations or if you want to resample
SPOTPY enables you to sample directly from a given parameter list. This can be useful if you want to check specific parameter combinations or if you want to re-sample
calibrated parameter set, in order to test different model setups or to save further model outputs. To use this functionality you just have to rewrite your paramters function
in your spotpy setup. We will show you a example how to test parameters of the rosenbrock tutorial. Just give the values you want to test as a list into the spotpy.parameter.List function:
in your spotpy setup. We will show you a example how to test parameters of the Rosenbrock tutorial. Just give the values you want to test as a list into the spotpy.parameter.List function:

def __init__(self):
self.params = [spotpy.parameter.List('x',[1,2,3,4,6,7,8,9,0]), #Give possible x values as a List
Expand All @@ -128,13 +128,13 @@ After that you will be able to sample the parameter combinations with the normal
sampler=spotpy.algorithms.mc(spot_setup(),dbname='Iterator_example', dbformat='csv') #Parameter lists can be sampled with MC
sampler.sample(10) #Choose equaly (or less) repetitions as you have parameters in your List

This will also run with MPI parallelzation.
This will also run with MPI parallelization.

## Create a own database

SPOTPY enables you to save results of the sampling in a own database. Users may request different sorts of databases like SQL, hdf5 files, tab separated txt files, xls timeseries.
SPOTPY enables you to save results of the sampling in a own database. Users may request different sorts of databases like SQL, hdf5 files, tab separated txt files, xls time-series.
SPOTPY does not provide all these databases yet, BUT any sort of database can be connected to SPOTPY. Therefore one just has to write his one interface. We provide a simple example how this can be done:
We use the above created example and add a selfmade txt database into a new save function:
We use the above created example and add a self-made txt database into a new save function:

class spot_setup(object):
slow = 1000
Expand Down Expand Up @@ -172,10 +172,10 @@ out the keywords 'dbname' and 'dbformat' when you initialize the algorithm:
spot_setup=spot_setup()
'Leave out dbformat and dbname and spotpy will return results in spot_setup.save function'
sampler=spotpy.algorithms.mc(spot_setup)
sampler.sample(10) #Choose equaly or less repetitions as you have parameters in your List
sampler.sample(10) #Choose equally or less repetitions as you have parameters in your List
spot_setup.database.close() # Close the created txt file

Apart from that, some users might be interested not to save there simulation results and only the objective functions and the paramter values,
Apart from that, some users might be interested not to save there simulation results and only the objective functions and the parameter values,
e.g. to save memory space. This is supported during the initialization of the algorithm, by setting save_sim to False (default=True):

sampler = spotpy.algorithms.mc(spotpy_setup() dbname='no_simulations', dbformat='csv', save_sim=False)
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ Keep in mind, that the \__init\__ function is only called once during the sampli
The more you can separate from you model into the \__init\__ function, the faster you sampling will be.

class spotpy_setup(object):
def __init__(self):
def __init__(self, obj_func=None):
#Just a way to keep this example flexible and applicable to various examples
self.obj_func = obj_func
datastart = datetime(1998,6,1)
dataend = datetime(2000,1,1)
analysestart = datetime(1999,1,1)
Expand Down Expand Up @@ -171,21 +173,29 @@ To define the VanGenuchten parameter boundaries we use a normal distribution.
return self.cmfmodel.observations

def objectivefunction(self,simulation,evaluation):
objectivefunction= -spotpy.objectivefunctions.rmse(evaluation,simulation)
return objectivefunction
#SPOTPY expects to get one or multiple values back,
#that define the performence of the model run
if not self.obj_func:
# This is used if not overwritten by user
# RMSE (root mean squared error) works good for the SCE-UA algorithm,
# as it minimizes the objective function.
# All other implemented algorithm maximize the objectivefunction
model_performance = spotpy.objectivefunctions.rmse(evaluation,simulation)
else:
#Way to ensure flexible spot setup class
model_performance = self.obj_func(evaluation,simulation)
return model_performance


## Sampling

spotpy_setup=spotpy_setup()

sampler = spotpy.algorithms.mc(spotpy_setup,dbname='MC_CMF',dbformat='csv')
sampler = spotpy.algorithms.mle(spotpy_setup,dbname='MLE_CMF',dbformat='csv')
sampler = spotpy.algorithms.lhs(spotpy_setup,dbname='LHS_CMF',dbformat='csv')
sampler = spotpy.algorithms.sceua(spotpy_setup,dbname='SCEUA_CMF',dbformat='csv')
sampler = spotpy.algorithms.demcz(spotpy_setup,dbname='DE-MCz_CMF',dbformat='csv')
sampler = spotpy.algorithms.sa(spotpy_setup,dbname='SA_CMF',dbformat='csv')
sampler = spotpy.algorithms.rope(spotpy_setup,dbname='ROPE_CMF',dbformat='csv')
sampler = spotpy.algorithms.mc(spotpy_setup(),dbname='MC_CMF',dbformat='csv')
sampler = spotpy.algorithms.mle(spotpy_setup(),dbname='MLE_CMF',dbformat='csv')
sampler = spotpy.algorithms.lhs(spotpy_setup(),dbname='LHS_CMF',dbformat='csv')
sampler = spotpy.algorithms.sceua(spotpy_setup(used_algorithm='sceua'),dbname='SCEUA_CMF',dbformat='csv')
sampler = spotpy.algorithms.demcz(spotpy_setup(),dbname='DE-MCz_CMF',dbformat='csv')
sampler = spotpy.algorithms.sa(spotpy_setup(),dbname='SA_CMF',dbformat='csv')
sampler = spotpy.algorithms.rope(spotpy_setup(),dbname='ROPE_CMF',dbformat='csv')

algorithms=['MC','LHS','MLE','MCMC','SCE-UA','SA','DE-MCz','ROPE']
results=[]
Expand Down
2 changes: 1 addition & 1 deletion docs/Tutorial/1-Introduction.md → docs/Introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ Before you start to use SPOTPY you should be familiar with Python. Otherwise I r

Basic knowledge about NumPy is also needed. You can get this [here](http://www.engr.ucsb.edu/~shell/che210d/numpy.pdf "NumPY tutorial").

Last but not least you will need to have knowledge about [Bayesian techniques](https://github.com/CamDavidsonPilon/Probabilistic-Programming-and-Bayesian-Methods-for-Hackers/tree/master/ "Bayesian techniques").
Last but not least you might want to have some knowledge about [Bayesian techniques](https://github.com/CamDavidsonPilon/Probabilistic-Programming-and-Bayesian-Methods-for-Hackers/tree/master/ "Bayesian techniques").

You will find all the needed code to reproduce the following examples in the `PYTHONPATH/Lib/site-packages/spotpy/examples` folder.
6 changes: 4 additions & 2 deletions docs/Tutorial/2-Rosenbrock.md → docs/Rosenbrock.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ where we defined control variables as *-10 < x < 10* and *-10 < y < 10*, with *

*Figure 1: Response surface of the two dimensional Rosenbrock function. Check out `/examples/3dplot.py`to produce such plots.*

We want to find the global minimum of this function. To do so, one could test every possible parameter setting for *x* and *y* OR one can use SPOTPYPY.
We want to find the global minimum of this function. To do so, one could test every possible parameter setting for *x* and *y* OR one can use SPOTPY.

## Creating the setup file

Expand All @@ -34,10 +34,12 @@ We start to have a look at the parameters *x* and *y*:
We assume to have no prior knowledge about the parameters *x* and *y*, which is why we select a uniform prior distribution from them using NumPy.
Numpy offers a wide range of distributions such as uniform, normal and chi-squared.
As a minimum (`low`) of the distribution we select *-10* and as maximum (`high`) *10*. The next information which is needed is the name of each parameter (`x` and `y`).

The `stepsize` is biggest possible jump, which a algorithm can make to the next sampling point (used in MCMC, MLE and SA).
It is used as the standard derivation within a normal distribution around the last sampled point.
The `optguess` value is the initial parameter setting. It will be your first sample in the results and should be selected to a good as possible setting,
because it influences how the algorithms evolove from this position.

Further settings can be made by minbound and maxbound, which set the boundaries for the algorithms to sample parameter combination inside the prior given range. If they are not given,
bound are determined by sampling 1,000 times from the prior distribution and selecting the minimum and maximum of the sampled values as bounds.

Expand All @@ -55,7 +57,7 @@ In this case, we know, that *f(x=1,y=1) = 0*. Accordingly, our evaluation functi
observations=[0]
return observations

Finally, we have to create a function to evaluate our samples. To do so, we select a objective function out of the SPOTPYPY objective function package.
Finally, we have to create a function to evaluate our samples. To do so, we select a objective function out of the SPOTPY objective function package.
In this case we select the Root Mean Squared Error, giving the simulations and the evaluations.
As we want to minimize our function, we select a negative objective function at this point.

Expand Down
File renamed without changes.
34 changes: 34 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
site_name: SPOTPY Documentation
site_url: http://fb09-pasig.umwelt.uni-giessen.de/spotpy/
site_description: The documentation of the Statistical Parameter Optimization Framework
site_author: Tobias Houska

repo_url: https://github.com/thouska/spotpy/
edit_url: ""

theme:
name: readthedocs

#markdown_extensions: [mathjax]


nav:
- Home: index.md
- Tutorial:
- Introduction: Introduction.md
- Getting Started: getting_started.md
- Rosenbrock: Rosenbrock.md
- Griewank: Griewank.md
- Ackley: Ackley.md
- Hydrological_model: Hydrological_model.md
- Working with DREAM and Hymod: Working with DREAM and Hymod.md
- Advanced_hints: Advanced_hints.md
- Algorithm_guide: Algorithm_guide.md

- License: license.md


copyright: Copyright &copy; 2015, <a href="http://www.uni-giessen.de/cms/fbz/fb09/institute/ilr/wasser/mitarbeiter/houska">Tobias Houska</a>.



15 changes: 15 additions & 0 deletions readthedocs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# .readthedocs.yml
# Read the Docs configuration file
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details

# Required
version: 2


# Build documentation with MkDocs
mkdocs:
configuration: mkdocs.yml

# Optionally build your docs in additional formats such as PDF and ePub
formats: all

8 changes: 5 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@

setup(
name = 'spotpy',
version = '1.5.8',
version = '1.5.13',
description = 'A Statistical Parameter Optimization Tool',
long_description=open(os.path.join(os.path.dirname(__file__),
"README.rst")).read(),
author = 'Tobias Houska, Philipp Kraft, Alejandro Chamorro-Chavez and Lutz Breuer',
author_email = '[email protected]',
url = 'http://www.uni-giessen.de/cms/faculties/f09/institutes/ilr/hydro/download/spotpy',
url = 'https://spotpy.readthedocs.io/en/latest/',
license = 'MIT',
install_requires=[
'scipy', 'numpy'],
packages=find_packages(exclude=["tests*", "docs*"]),
include_package_data = True,
use_2to3 = True,
keywords = 'Monte Carlo, MCMC, MLE, SCE-UA, Simulated Annealing, DE-MCz, DREAM, ROPE, Artifical Bee Colony, DDS, PA-DDS, Uncertainty, Calibration, Model, Signatures',
classifiers = [
Expand All @@ -28,5 +29,6 @@
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Topic :: Software Development :: Libraries :: Python Modules'],
)
5 changes: 3 additions & 2 deletions spotpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
- mpi4py (optional) (http://mpi4py.scipy.org/)
- pathos (optional) (https://pypi.python.org/pypi/pathos/)
- sqlite3 (optional) (https://pypi.python.org/pypi/sqlite3/)
- numba (optional) (https://pypi.python.org/pypi/numba/)
:help: For specific questions, try to use the documentation website at:
http://fb09-pasig.umwelt.uni-giessen.de/spotpy/
https://spotpy.readthedocs.io/en/latest/
For general things about parameter optimization techniques have a look at:
https://github.com/CamDavidsonPilon/Probabilistic-Programming-and-Bayesian-Methods-for-Hackers/tree/master/
Expand All @@ -39,4 +40,4 @@
from . import describe # Contains some helper functions to describe samplers and set-ups
from .hydrology import signatures # Quantifies goodness of fit between simulation and evaluation data with hydrological signatures

__version__ = '1.5.8'
__version__ = '1.5.13'
Loading

0 comments on commit 4391506

Please sign in to comment.