0

I have some difficults with calibraton code of basinhopping by using (L-BFGS-B) method, i tried many codes but i didn't success every time give me 8 numbers after comma like that

(5.00000001 , 1.0000001, 5.00545111)

I would like just three numbers after cumma if that possible like that :

(5.001, 1.005, 5.003)

i use this code:

def opt(x0):

bd0 = (0,100)
bd1 = (0,0.100)
bd2 = (2,8)
bnds = (bd0, bd1, bd2)
minimizer_kwargs = {"method":"L-BFGS-B", "bounds":bnds, "tol":1e0}
res = basinhopping(rmse, x0, minimizer_kwargs=minimizer_kwargs,T=1.0, stepsize=1.0, niter=10)
print(res.x)
Azeezof
  • 3
  • 1
  • 5
  • Do you want to limit the number of decimals printed ([see here](https://stackoverflow.com/a/21008904/3005167)) or do you want to restrict the optimizer solution? – MB-F Nov 02 '17 at 09:59
  • i am sorry this question is different, here i want to change some settings in method by using scipy settings – Azeezof Nov 02 '17 at 10:08
  • This is weird. I never voted to close this question as duplicate... Anyway, you need to explain your problem better ("i want numbers that way" is not good enough). Especially **where** and **why** do you want the numbers limited to three decimals? – MB-F Nov 02 '17 at 10:14
  • i want to save time , so that in this state i need more two days and i think this problem is not easy to find solution for it by normal methods – Azeezof Nov 02 '17 at 10:34
  • Scipy optimizers do not support limiting parameter precision. – MB-F Nov 02 '17 at 10:43
  • The real question here is: what for (which is totally unclear to me)? Make that clear and we can deduce if that's something possible (and in some interpretations: it's not). – sascha Nov 02 '17 at 11:40
  • The problem is in accurcy of parameter, when i write X0 is like that X0=(50, 0.50, 5) and the last value is (50.54215, 0.142545, 5.545451) , so that i ask if i can change from accurcy of parameters to be just three numbers after comma – Azeezof Nov 02 '17 at 12:11
  • That's informal and ignores the why. Make clear what you want to achieve and how it compares to rounding a solution at the end. – sascha Nov 02 '17 at 12:18
  • when the accurcy is so big , for example if the accurcy is 8 numbers after comma that means i need a lot of time to finish the optimization and i need from my work to find the value of parameters quickly and now i need about 2-3 days so for 3 numbers after comma the process will be faster – Azeezof Nov 02 '17 at 12:34
  • Then benchmark the times and not go by those output-values. These will always be unrounded and looking strange. Using tol or max_iter (more precise: ftol, gtol, maxiter; in the inner local-opt) is the way to go. – sascha Nov 02 '17 at 13:09
  • There are more speedup-ideas, but you should add an example we can run to work on it and sadly: the question is closed for now! – sascha Nov 02 '17 at 13:17
  • In my work i call java from python , and after that i apply the last code and i use Mean Squared Error as objective function so when scipy change parameters it changes in java and after that apply objective function , but i tried to do somthing by ftol, gtol but i didn't success the values always like that parameteroutfile = 'paramout.lst' f = open(parameteroutfile, "a") f.write(str(x0)) f.write("\n") f.close() [ 59.37242798 0.19526749 6.67386831] [ 60.75445816 0.18820302 6.91529492] [ 57.36454047 0.25075446 6.44873114] – Azeezof Nov 02 '17 at 14:24
  • That's too broad and we can't answer here as the question is still closed. The most important speedup is probably not using numerical-differentiation by defining jac. Even better would be to use another optimizer, not part of scipy's minimize. The overall speedup should be 10x-100x (just guessing). But well... as long as your task is defined like that and the question is closed, there will not be much help here. – sascha Nov 02 '17 at 14:27
  • Thank you so much sascha, that's really nice of you, really my question is important, i didn#t find other package for optimization and espically my work is to find global minmum not only local minmum, i will try again may be someone able to help me, because i tried to use python from 10 monthes – Azeezof Nov 02 '17 at 14:33
  • If it's so important, start investing some time when asking here. It was incomprehensible at first and now it's still very sparse without much info (or an minimal example)! And i was talking about using one of scipy's minimizers for least-squares which are much better when optimizing RMSE like you do. But these are not part of the minimize-wrapper, but can be used. (they also give you the jacobian for free) – sascha Nov 02 '17 at 14:34
  • def opt(x0): bd0 = (0,100) bd1 = (0,0.100) bd2 = (2,8) bnds = (bd0, bd1, bd2) minimizer_kwargs = {"method":"Nelder-Mead", "bounds":bnds} res = basinhopping(rmse, x0, minimizer_kwargs=minimizer_kwargs,T=1.0, stepsize=1.0, niter=10) print(res.x) return res.x # go. def main(): x0 = ([50.0, 0.50, 5.0]) # initial guess opt(x0) if __name__ == "__main__": main() – Azeezof Nov 02 '17 at 14:35
  • I won't even try to read that. Sorry. The comment-section is not for stuff like that! And despite the unreadability there is also no question or context. – sascha Nov 02 '17 at 14:36
  • sorry, have i other way to send you the code ? – Azeezof Nov 02 '17 at 14:38
  • 1
    Let's try this: formulate a new highly-detailed question. If you did that < 1 hour (preparation of theory/code/reproducible minimal example, writing...), don't post it. (no; don't send me code; ask detailed questions according to SOs rules please) – sascha Nov 02 '17 at 14:38

0 Answers0