thouska / spotpy

A Statistical Parameter Optimization Tool
https://spotpy.readthedocs.io/en/latest/
MIT License
254 stars 152 forks source link

minus or positive sign when RMSE objective function is used #161

Closed flydream0428 closed 3 years ago

flydream0428 commented 6 years ago

What is the right sign +/- when rmse objective funciton is used with SCE-UA? When I tried to run my model, with a negative sign before the rmse objective funciton objectivefunction= -spotpy.objectivefunctions.rmse(evaluation,simulation) , a high percentage of the model crashed. When I removed the -, the model didn't crash anymore although I didn't get a converging solution. Then I tested this sign with Rosenbrock example. I found it always works no matter what sign I use. This is not what I expected. I think a wrong sign should not work. Any idea?

thouska commented 6 years ago

Thanks for your message. Did you set the alt_objectfunc keyword to None?

sampler=spotpy.algorithms.sceua(spot_setup, dbname='SCEUA_hymod', dbformat='csv', alt_objfun=None)

This should force SCE-UA to use the def objectivefunction in your spot setup class. If it is not set, SCE-UA ist using the + RMSE by default. The idea behind this setting was to provide a well working setting. This resulted in the RMSE beeing hardcoded, because the algorithm is very sensitive to different objectivefunctions and might not perform well with other settings. However, this way has proven to be not very intuitive. If you want, I can set the default to use the def obejctivefunction.

flydream0428 commented 6 years ago

Thanks, Tobias. I checked my code. I used alt_objectfun=None. I guess this is why it's very sensitive when I change the sign of RMSE. In the Rosenbrock example, this is not set. This means SCE-UA always uses the +RMSE. Is this right? Sorry, I am still very confused. For example, in the tutorial, http://fb09-pasig.umwelt.uni-giessen.de/spotpy/Tutorial/2-Rosenbrock/, you said " 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.

def objectivefunction(self,simulation,evaluation):
    objectivefunction= -spotpy.objectivefunctions.rmse(evaluation,simulation)      
    return objectivefunction"

But, in the tutorial, the None set is not activated. sampler=spotpy.algorithms.sceua(spotpy_setup, dbname='RosenSCEUA', dbformat='csv') results.append(sampler.sample(rep,ngs=4))

thouska commented 3 years ago

As this alt_objectfun keyword resulted in quite some confusion, it was removed some time ago and all algorithms use the user defined objective function. To get some hint, which objective function should be used for which sampler, I introduced a keyword for each algorithm. It can be seen as a class parameter in every algorithm file or accessed after initializing the sampler, e.g.

sampler=spotpy.algorithms.sceua(spot_setup, dbname='sceua_output') sampler.optimization_direction Out[1]: 'minimizing'

Meaning that in this case the sce-ua sampler is minzing the user defined objective function, i.e. it work with the normal RMSE, without any minus sign. There is also an tutorial availble.