Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6771569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:26:52+00:00 2026-05-26T15:26:52+00:00

I have a fairly complex function f(x) that I want to optimize and I

  • 0

I have a fairly complex function f(x) that I want to optimize and I am using the fmin_bfgs function from the scipy.optimize module from Scipy. It forces me to give the function to minimize and the function of the gradient f'(x) separately, which is a pity because some of the computations for the gradient can be done when evaluating the function f(x).

Is there a way of combining both functions? I was considering saving the intermediate values required for both functions, but I don’t know if the fmin_bfgs function guarantees that f(x) is evaluated before than f'(x).

Thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T15:26:52+00:00Added an answer on May 26, 2026 at 3:26 pm

    You could use memoization to cache the intermediate values. Regardless of which function is called first, the second will be able to take advantage of the memoized value.


    cache={}
    def expensive_calc(x):
        # If x is a numpy array, you need to convert x into something hashable so it
        # can be used as a key in cache.
        key=tuple(x)
        try:
            return cache[key]
        except KeyError:
            # do expensive calc for result
            cache[key] = result
            return result
    
    def func(x):
        y=expensive_calc(x)
        return something_based_on_y
    
    def func_der(x):
        y=expensive_calc(x)
        return something_else_based_on_y
    
    def optimize_fmin_bfgs():
        xopt = fmin_bfgs(func, x_guess, fprime=func_der)  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a fairly complex system that I want to test using python. My
I have a fairly complex query (that includes a table valued function to allow
We have a fairly complex application that was previously using WebForms. We are in
I have a fairly complex multi threaded application (server) that from time to time
I have a fairly complex set of rewrite rules to give my site pages
I have a fat GUI that it getting fairly complex, and I would like
I have a web page that I use to update a fairly complex data
So I currently have an application that is fairly complex with large-scale animations and
I have a fairly complex query that will be referencing a single date as
I have a fairly complex web app that was built (by a contractor) to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.