Implicit differentiation · Nonconvex.jl (2024)

Background

Differentiating implicit functions efficiently using the implicit function theorem has many applications including:

  • Nonlinear partial differential equation constrained optimization
  • Differentiable optimization layers in deep learning (aka deep declarative networks)
  • Differentiable fixed point iteration algorithms for optimal transport (e.g. the Sinkhorn methods)
  • Gradient-based bi-level and robust optimization (aka anti-optimization)
  • Multi-parameteric programming (aka optimization sensitivity analysis)

For more on implicit differentation, refer to the last part of the Understanding automatic differentiation (in Julia) video on YouTube and the Efficient and modular implicit differentiation manuscript for an introduction to the methods implemented here.

Relationship to ImplicitDifferentiation.jl

ImplicitDifferentiation.jl is an attempt to simplify the implementation in Nonconvex making it more lightweight and better documented. For instance, the documentation of ImplicitDifferentiation presents a number of examples of implicit functions all of which can be defined using Nonconvex instead.

Explicit parameters

There are 4 components to any implicit function:

  1. The parameters p
  2. The variables x
  3. The residual f(p, x) which is used to define x(p) as the x which satisfies f(p, x) == 0 for a given value p
  4. The algorithm used to evaluate x(p) satisfying the condition f(p, x) == 0

In order to define a differentiable implicit function using Nonconvex, you have to specify the "forward" algorithm which finds x(p). For instance, consider the following example:

using SparseArrays, NLsolve, Zygote, NonconvexN = 10A = spdiagm(0 => fill(10.0, N), 1 => fill(-1.0, N-1), -1 => fill(-1.0, N-1))p0 = randn(N)f(p, x) = A * x + 0.1 * x.^2 - pfunction forward(p) # Solving nonlinear system of equations sol = nlsolve(x -> f(p, x), zeros(N), method = :anderson, m = 10) # Return the zero found (ignore the second returned value for now) return sol.zero, nothingend

forward above solves for x in the nonlinear system of equations f(p, x) == 0 given the value of p. In this case, the residual function is the same as the function f(p, x) used in the forward pass. One can then use the 2 functions forward and f to define an implicit function using:

imf = ImplicitFunction(forward, f)xstar = imf(p0)

where imf(p0) solves the nonlinear system for p = p0 and returns the zero xstar of the nonlinear system. This function can now be part of any arbitrary Julia function differentiated by Zygote, e.g. it can be part of an objective function in an optimization problem using gradient-based optimization:

obj(p) = sum(imf(p))g = Zygote.gradient(obj, p0)[1]

In the implicit function's adjoint rule definition, the partial Jacobian ∂f/∂x is used according to the implicit function theorem. Often this Jacobian or a good approximation of it might be a by-product of the forward function. For example when the forward function does an optimization using a BFGS-based approximation of the Hessian of the Lagrangian function, the final BFGS approximation can be a good approximation of ∂f/∂x where the residual f is the gradient of the Lagrangian function wrt x. In those cases, this Jacobian by-product can be returned as the second argument from forward instead of nothing.

Implicit parameters

In some cases, it may be more convenient to avoid having to specify p as an explicit argument in forward and f. The following is also valid to use and will give correct gradients with respect to p:

function obj(p) N = length(p) f(x) = A * x + 0.1 * x.^2 - p function forward() # Solving nonlinear system of equations sol = nlsolve(f, zeros(N), method = :anderson, m = 10) # Return the zero found (ignore the second returned value for now) return sol.zero, nothing end imf = ImplicitFunction(forward, f) return sum(imf())endg = Zygote.gradient(obj, p0)[1]

Notice that p was not an explicit argument to f or forward in the above example and that the implicit function is called using imf(). Using some explicit parameters and some implicit parameters is also supported.

Matrix-free linear solver in the adjoint

In the adjoint definition of implicit functions, a linear system:

(df/dy) * x = v

is solved to find the adjoint vector. To solve the system using a matrix-free iterative solver (GMRES by default) that avoids constructing the Jacobian df/dy, you can set the matrixfree keyword argument to true (default is false). When set to false, the entrie Jacobian matrix is formed and the linear system is solved using LU factorization.

Arbitrary data structures

Both p and x above can be arbitrary data structures, not just arrays of numbers.

Tolerance

The implicit function theorem assumes that some conditions f(p, x) == 0 is satisfied. In practice, this will only be approximately satisfied. When this condition is violated, the gradient reported by the implicit function theorem cannot be trusted since its assumption is violated. The maximum tolerance allowed to "accept" the solution x(p) and the gradient is given by the keyword argument tol (default value is 1e-5). When the norm of the residual function f(p, x) is greater than this tolerance, NaNs are returned for the gradient instead of the value computed via the implicit function theorem. If additionally, the keyword argument error_on_tol_violation is set to true (default value is false), an error is thrown if the norm of the residual exceeds the specified tolerance tol.

Implicit differentiation · Nonconvex.jl (2024)

FAQs

What is the method of implicit differentiation to find? ›

The process called “ implicit differentiation” is used to find the derivative of y with respect to the variable x without solving the given equations for y.

How do you know when to use implicit differentiation? ›

Implicit differentiation is super useful when you want to find the derivative dy/dx, but x and y are not related in a simple manner like y = ƒ(x). Rather, x and y might be related by some more complicated expression like sin(x + y) = x where it might be tricky to write y in terms of x.

What is the formula for the implicit differential equation? ›

Implicit Differentiation Formula

However, a formula for implicit differentiation of y terms is, in essence, the Chain Rule: d u d x = d u d y ⋅ d y d x , where u is the term containing a y.

Can a mathway do implicit differentiation? ›

The Derivative Calculator supports solving first, second...., fourth derivatives, as well as implicit differentiation and finding the zeros/roots. You can also get a better visual and understanding of the function by using our graphing tool.

How to do implicit differentiation fast? ›

How to Do Implicit Differentiation
  1. Differentiate each side of the equation by treating y as an implicit function of x. This means you need to use the Chain Rule on terms that include y by multiplying by d y d x \frac{dy}{dx} dxdy.
  2. Solve for d y d x \frac{dy}{dx} dxdy.
May 1, 2022

How to solve an implicit function? ›

First differentiate the entire expression f(x, y) = 0, with reference to one independent variable x. As a second step, find the dy/dx of the expression by algebraically moving the variables. The final answer of the differentiation of implicit function would have both variables.

Do you use the chain rule in implicit differentiation? ›

Definition. Implicit differentiation makes use of the chain rule to differentiate a function which cannot be explicitly expressed in the form y=f(x) y = f ( x ) .

What is an example of an implicit equation? ›

An example of an implicit equation is x^2 - y^2 = 0. It is implicit because it cannot be written explicitly without needing more than one explicit function. The explicit functions are y = x and y = -x.

What is implicit differentiation better explained? ›

Implicit differentiation is the procedure of differentiating an implicit equation with respect to the desired variable x while treating the other variables as unspecified functions of x.

What is implicit differentiation for dummies? ›

Implicit differentiation is the process of calculating the derivative of a function defined implicitly by a relation H(x,y)=0.

What is implicit differentiation with an example? ›

Taking the derivative of an explicit function is referred to as explicit differentiation. An explicit function defines one variable entirely in terms of the other. Typically, this means that the independent variable (x) is expressed explicitly in terms of the dependent variable (y). y=f(x) is the general form.

How to do hard implicit differentiation? ›

Solved Example
  1. Step 1: Differentiating both sides wrt x,
  2. Step 2: Using Chain Rule.
  3. Step 3: Expanding the above equation.
  4. Step 4: Taking all terms with dy/dx on LHS.
  5. Step 5: Taking dy/dx common from the LHS of equation.
  6. Step 6: Isolate dy/dx.
May 29, 2024

What is the implicit differentiation strategy? ›

Problem-Solving Strategy: Implicit Differentiation

Rewrite the equation so that all terms containing dy/dx are on the left and all terms that do not contain dy/dx are on the right. Factor out dy/dx on the left. Solve for dy/dx by dividing both sides of the equation by an appropriate algebraic expression.

How to use implicit differentiation to find derivative of inverse function? ›

Implicit differentiation uses the following steps.
  1. Start with an equation involving your two variables, say x and y. y . ...
  2. Create a new equation by differentiating each side of the equation. ...
  3. Solve the new equation for y′=dydx y ′ = d y d x as a function of x and y.

What is the process of finding a derivative? ›

Computing Derivatives

Basically, we can compute the derivative of f(x) using the limit definition of derivatives with the following steps: Find f(x + h). Plug f(x + h), f(x), and h into the limit definition of a derivative. Simplify the difference quotient.

How to use implicit differentiation to find the slope of a tangent line? ›

Take the derivative of the given function. Evaluate the derivative at the given point to find the slope of the tangent line. Plug the slope of the tangent line and the given point into the point-slope formula for the equation of a line, ( y − y 1 ) = m ( x − x 1 ) (y-y_1)=m(x-x_1) (y−y1​)=m(x−x1​), then simplify.

References

Top Articles
Vegan Shepherd's Pie Recipe
300+ Short Positive Quotes to Brighten Your Day
Spectrum Store Appointment
Grizzly Expiration Date 2023
Look Who Got Busted New Braunfels
Craigslist Free En Dallas Tx
Creative Fall Bloxburg House Ideas For A Cozy Season
Jcpenney Associate Meevo
Selinas Gold Full Movie Netflix
SAP Secure Login Service for SAP GUI Now Available
Care Guide for Platy Fish – Feeding, Breeding, and Tank Mates
El Puerto Harrisonville Mo Menu
Sundance Printing New Braunfels
Iapd Lookup
Osrs Mahogany Homes Calc
Rancho Medanos Schedule
Lighthouse Diner Taylorsville Menu
Vanessa Garske Reddit
2503 South Tacoma Way
Kentucky Lottery Scratch Offs Remaining
Kristine Leahy Spouse
Starter Blocked Freightliner Cascadia
Drys Pharmacy
Weather Arlington Radar
Check Subdomains Of A Domain
5162635626
Qmf Bcbs Prefix
Fast X Showtimes Near Evo Cinemas Creekside 14
How to Learn Brazilian Jiu‐Jitsu: 16 Tips for Beginners
When Is Meg Macnamara Due
Busted Barren County Ky
Korslien Auction
Gwcc Salvage
Rare Rides: The 1970 Chevrolet Chevelle SS454 LS6 Convertible - Street Muscle Rare Rides
Buzzy Shark Tank Net Worth 2020
20 Fantastic Things To Do In Nacogdoches, The Oldest Town In Texas
Windows 10 Defender Dateien und Ordner per Rechtsklick prüfen
Wlox Jail Docket
Accident On 215
CNA Classes & Certification | How to Become a CNA | Red Cross
Nina Volyanksa
MAXSUN Terminator Z790M D5 ICE Motherboard Review
Sdn Md 2023-2024
Promiseb Discontinued
Personapay/Glens Falls Hospital
Crustless Pizza Bowl Pizza Hut
Basis Phoenix Primary Calendar
Caldo Tlalpeño de Pollo: Sabor Mexicano - Paulina Cocina
Perolamartinezts
Mets vs. Reds: Injury Report, Updates & Probable Starters – Sept. 7 - Bleacher Nation
Texas State Final Grades
O2 Fitness West Ashley Photos
Latest Posts
Article information

Author: Tyson Zemlak

Last Updated:

Views: 6379

Rating: 4.2 / 5 (63 voted)

Reviews: 94% of readers found this page helpful

Author information

Name: Tyson Zemlak

Birthday: 1992-03-17

Address: Apt. 662 96191 Quigley Dam, Kubview, MA 42013

Phone: +441678032891

Job: Community-Services Orchestrator

Hobby: Coffee roasting, Calligraphy, Metalworking, Fashion, Vehicle restoration, Shopping, Photography

Introduction: My name is Tyson Zemlak, I am a excited, light, sparkling, super, open, fair, magnificent person who loves writing and wants to share my knowledge and understanding with you.