The **cavity method** is a mathematical method presented by Marc Mézard, Giorgio Parisi and Miguel Angel Virasoro in 1987^{[1]} to derive and solve some mean field-type models in statistical physics, specially adapted to disordered systems. The method has been used to compute properties of ground states in many condensed matter and optimization problems.

Initially invented to deal with the Sherrington–Kirkpatrick model of spin glasses, the cavity method has shown wider applicability. It can be regarded as a generalization of the Bethe–Peierls iterative method in tree-like graphs, to the case of a graph with loops that are not too short. The cavity method can solve many problems also solvable using the replica trick but has the advantage of being more intuitive and less mathematically subtle than replica-based methods.

The cavity method proceeds by perturbing a large system with the addition of a non-thermodynamic number of additional constituents and approximating the response of the entire system perturbatively. The application of the resulting approximation, along with an assumption that certain observables are self-averaging, yields a self-consistency equation for the statistics of the added constituents. The added constituents are then considered to be the mean-field variables.

The cavity method has proved useful in solving optimization problems such as k-satisfiability and graph coloring. It has yielded not only ground states energy predictions in the average case but has also inspired algorithmic methods.