{"id":1544,"date":"2024-02-01T00:00:00","date_gmt":"2024-02-01T05:00:00","guid":{"rendered":"https:\/\/molecularsciences.org\/content\/?p=1544"},"modified":"2024-02-22T10:17:19","modified_gmt":"2024-02-22T15:17:19","slug":"how-to-find-global-optima-using-simulated-annealing-in-python","status":"publish","type":"post","link":"https:\/\/molecularsciences.org\/content\/how-to-find-global-optima-using-simulated-annealing-in-python\/","title":{"rendered":"How to find Global Optima using Simulated Annealing in Python"},"content":{"rendered":"\n<p>In Python, you can use the <code>scipy.optimize.dual_annealing<\/code> function to perform global optimization using Simulated Annealing. This optimization method is particularly useful for finding global optima in complex, non-convex, and multi-modal objective functions.<\/p>\n\n\n\n<p>Here&#8217;s an example of how to use Simulated Annealing for global optimization:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from scipy.optimize import dual_annealing\r\n\r\n# Define the objective function to minimize\r\ndef objective_function(x):\r\n    return (x&#91;0] - 2)**2 + (x&#91;1] - 3)**2\r\n\r\n# Define the bounds for the variables\r\nbounds = &#91;(-5, 5), (-5, 5)]  # Adjust bounds based on your problem\r\n\r\n# Perform global optimization using Simulated Annealing\r\nresult = dual_annealing(objective_function, bounds)\r\n\r\n# Display the result\r\nprint(\"Global optimum:\", result.x)\r\nprint(\"Optimal objective function value:\", result.fun)\r<\/code><\/pre>\n\n\n\n<p>In this example:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>objective_function<\/code> is the function you want to minimize.<\/li>\n\n\n\n<li><code>bounds<\/code> specify the bounds for each variable in the objective function.<\/li>\n<\/ul>\n\n\n\n<p><code>dual_annealing<\/code> uses Simulated Annealing to find the global minimum of the objective function within the specified bounds. You can adjust the bounds and the objective function based on your specific problem.<\/p>\n\n\n\n<p>Always refer to the <a>SciPy documentation<\/a> for detailed information on the parameters and options available for <code>dual_annealing<\/code>. Additionally, experiment with the <code>maxiter<\/code> and <code>local_search_options<\/code> parameters to fine-tune the algorithm&#8217;s behavior according to your optimization requirements.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In Python, you can use the scipy.optimize.dual_annealing function to perform global optimization using Simulated Annealing. This optimization method is particularly useful for finding global optima in complex, non-convex, and multi-modal objective functions. Here&#8217;s an example of how to use Simulated Annealing for global optimization: In this example: dual_annealing uses Simulated Annealing to find the global [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1793,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[203],"tags":[480,137,476],"class_list":["post-1544","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-optimization","tag-python","tag-scipy"],"_links":{"self":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/1544","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/comments?post=1544"}],"version-history":[{"count":1,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/1544\/revisions"}],"predecessor-version":[{"id":1545,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/1544\/revisions\/1545"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/media\/1793"}],"wp:attachment":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/media?parent=1544"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/categories?post=1544"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/tags?post=1544"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}