The BFGS algorithm, implemented through SciPy's optimize.minimize function, provides an efficient method for training neural networks by computing gradients and finding optimal parameters with fewer than 100 function evaluations, significantly outperforming brute-force approaches that would require 10^27 evaluations.
Deep Dive
Prerequisite Knowledge
- No data available.
Where to go next
- No data available.
Deep Dive
The SciPy Neural Network HackAdded:
We'll use the BFGS implementation built into the SciPy optimize package, specifically within the minimize function.
To use BFGS, [music] the minimize function requires us to pass in an objective function that accepts a vector of parameters, >> [music] >> input and output data, and returns both the cost and gradients.
Our neural network implementation doesn't quite follow these semantics, [music] so we'll use a wrapper function to give it this behavior.
We'll also pass in initial parameters, [music] set the Jacobian parameter to true since we're computing the gradient within our neural network class, set the method to BFGS, pass in our input and output data, and some [music] options.
Finally, we'll implement a callback function that allows us to track the cost function value as we train [music] the network.
Once the network is trained, we'll replace the original random parameters with [music] the trained parameters.
If we plot the cost against the number of iteration through training, we see a nice monotonically decreasing function.
Further, we see that the number of function evaluations required to find a solution is less than 100, and far less than the 10 to the 27th function evaluations >> [music] >> that would have been required to find a solution by brute force as shown in part three.
Finally, we can evaluate our gradient at our solution [music] and see very small values. This makes sense as our minimum should be quite flat.
Related Videos
Agentforce NOW AMA: Build with React and Salesforce Multi-Framework
SalesforceDevs
490 viewsβ’2026-05-28
How agent o11y differs from traditional o11y β Phil Hetzel, Braintrust
aiDotEngineer
450 viewsβ’2026-05-28
WEB TECHNOLOGIES UNIT-2 | Degree 4th sem BCOM Computers web technologies unit-2 full explanationπ―β
LearnwithSahera
1K viewsβ’2026-05-29
More tests are always better? How to use AI to identify tests that bring little value
Alliance4Qualification
335 viewsβ’2026-05-29
Search Algorithms Explained in 60 Seconds! π€π¨
samarthtuliofficial
218 viewsβ’2026-06-01
People of Game of Thrones using JavaScript DOM
AltCampus
296 viewsβ’2026-05-30
Introduction to Problem Solving Part - 1 | Lecture 1 | Intermediate DSA
ascensionix
107 viewsβ’2026-05-29
So What's Odin Lang Even Good For
TechOverTea
131 viewsβ’2026-06-01











