• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

thouska / spotpy / 7709518362

30 Jan 2024 10:11AM UTC coverage: 77.332% (-0.2%) from 77.518%
7709518362

push

github

thouska
Merge branch 'master' of https://github.com/thouska/spotpy

4162 of 5382 relevant lines covered (77.33%)

3.33 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.74
/src/spotpy/algorithms/list_sampler.py
1
# -*- coding: utf-8 -*-
2
"""
6✔
3
Copyright (c) 2018 by Tobias Houska
4
This file is part of Statistical Parameter Optimization Tool for Python(SPOTPY).
5
:author: Tobias Houska
6
"""
7
from .. import analyser
6✔
8
from . import _algorithm
6✔
9

10

11
class list_sampler(_algorithm):
6✔
12
    """
13
    This class holds the List sampler, which samples from a given spotpy database
14
    """
15

16
    _excluded_parameter_classes = ()
6✔
17

18
    def __init__(self, *args, **kwargs):
6✔
19
        """
20
        Input
21
        ----------
22
        spot_setup: class
23
            model: function
24
                Should be callable with a parameter combination of the parameter-function
25
                and return an list of simulation results (as long as evaluation list)
26
            parameter: function
27
                When called, it should return a random parameter combination. Which can
28
                be e.g. uniform or Gaussian
29
            objectivefunction: function
30
                Should return the objectivefunction for a given list of a model simulation and
31
                observation.
32
            evaluation: function
33
                Should return the true values as return by the model.
34

35
        dbname: str
36
            * Name of the database where parameter, objectivefunction value and simulation results will be saved.
37

38
        dbformat: str
39
            * ram: fast suited for short sampling time. no file will be created and results are saved in an array.
40
            * csv: A csv file will be created, which you can import afterwards.
41

42
        parallel: str
43
            * seq: Sequentiel sampling (default): Normal iterations on one core of your cpu.
44
            * mpi: Message Passing Interface: Parallel computing on cluster pcs (recommended for unix os).
45

46
        save_sim: boolean
47
            * True:  Simulation results will be saved
48
            * False: Simulation results will not be saved
49
        """
50
        kwargs["algorithm_name"] = "List Sampler"
4✔
51
        super(list_sampler, self).__init__(*args, **kwargs)
4✔
52

53
    def sample(self, repetitions=None):
6✔
54
        """
55

56
        Parameters
57
        ----------
58
        Optional:
59
        repetitions: int
60
            maximum number of function evaluations allowed during sampling
61
            If not given number if iterations will be determined based on given list
62
        """
63

64
        parameters = analyser.load_csv_parameter_results(self.dbname)
4✔
65
        self.dbname = self.dbname + "list"
4✔
66
        if not repetitions:
4✔
67
            repetitions = len(parameters)
×
68
        self.set_repetiton(repetitions)
4✔
69

70
        # Initialization
71
        print("Starting the List sampler with " + str(repetitions) + " repetitions...")
4✔
72
        param_generator = (
4✔
73
            (rep, list(parameters[rep])) for rep in range(int(repetitions))
74
        )
75
        for rep, randompar, simulations in self.repeat(param_generator):
4✔
76
            # A function that calculates the fitness of the run and the manages the database
77
            self.postprocessing(rep, list(randompar), simulations)
4✔
78
        self.final_call()
4✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc