Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update _algorithm.py #240

Merged
merged 2 commits into from
Nov 13, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 6 additions & 14 deletions spotpy/algorithms/_algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

This file holds the standards for every algorithm.
'''

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
Expand All @@ -15,8 +14,6 @@
import numpy as np
import time
import threading
import inspect
import sys


try:
Expand All @@ -30,7 +27,6 @@
from Queue import Queue



class _RunStatistic(object):
"""
this class checks for each run if the objectivefunction got better and holds the
Expand Down Expand Up @@ -292,13 +288,9 @@ def __init__(self, spot_setup, dbname=None, dbformat=None, dbinit=True,
# the normal work on the chains
self.repeat = ForEach(self.simulate)


# method "save" needs to know whether objective function result is list or float, default is float
self.like_struct_typ = type(1.1)





def __str__(self):
return '{type}({mtype}())->{dbname}'.format(
type=type(self).__name__,
Expand Down Expand Up @@ -355,17 +347,17 @@ def __is_list_type(self, data):
def save(self, like, randompar, simulations, chains=1):
# Initialize the database if no run was performed so far
self._init_database(like, randompar, simulations)

if self.__is_list_type(self.like_struct_typ) and self.__is_list_type(self.save_threshold):
# Test if like and the save threshold are float/list and compare accordingly
if self.__is_list_type(like) and self.__is_list_type(self.save_threshold):
if all(i > j for i, j in zip(like, self.save_threshold)): #Compares list/list
self.datawriter.save(like, randompar, simulations, chains=chains)
if not self.__is_list_type(self.like_struct_typ) and not self.__is_list_type(self.save_threshold):
if (not self.__is_list_type(like)) and (not self.__is_list_type(self.save_threshold)):
if like>self.save_threshold: #Compares float/float
self.datawriter.save(like, randompar, simulations, chains=chains)
if self.__is_list_type(self.like_struct_typ) and not self.__is_list_type(self.save_threshold):
if self.__is_list_type(like) and (not self.__is_list_type(self.save_threshold)):
if like[0]>self.save_threshold: #Compares list/float
self.datawriter.save(like, randompar, simulations, chains=chains)
if not self.__is_list_type(self.like_struct_typ) and self.__is_list_type(self.save_threshold): #Compares float/list
if (not self.__is_list_type(like)) and self.__is_list_type(self.save_threshold): #Compares float/list
if (like > self.save_threshold).all:
self.datawriter.save(like, randompar, simulations, chains=chains)

Expand Down