Wikipedia / Freivalds' algorithm
Wikipedia / Freivalds' algorithm
Freivalds' algorithm (named after Rūsiņš Mārtiņš Freivalds) is a probabilistic randomized algorithm used to verify matrix multiplication. Given three nn matrices. A naïve algorithm. However, the best known matrix multiplication algorithm time. Freivalds' algorithm utilizes randomization with high probability.
The algorithm
Input
Three nn matrices.
Output
; No, otherwise.
Procedure
Error
, then the probability that the algorithm returns "Yes" is less than or equal to one half. This is called one-sided error.
By iterating the algorithm k is achieved.
Example
Suppose one wished to determine whether:
A random two-element vector with entries equal to 0 or 1 is selected and used to compute:
is selected, the result becomes:
The result is nonzero, proving that in fact AB C.
), so the chance of randomly selecting these in two trials (and falsely concluding that AB=C) is 1/22 or 1/4. In the general case, the proportion of r yielding the zero vector may be less than 1/2, and a larger number of trials (such as 20) would be used, rendering the probability of error very small.
Error analysis
Let p equal the probability of error. We claim that if AB = C, then p = 0, and if AB ≠ C, then p ≤ 1/2.
Case A × B = C
. Hence the probability for error in this case is:
Case A × B ≠ C
such that
Where
.
. By the definition of matrix multiplication, we have:
.
. Using Bayes' theorem:
We use that:
Plugging these in the equation (), we get:
Therefore,
This completes the proof.
Ramifications
Simple algorithmic analysis shows that the running time of this algorithm (in big O notation). This beats the classical deterministic algorithm if using fast matrix multiplication). The error analysis also shows that if the algorithm times, an error bound can be achieved, an exponentially small quantity. The algorithm is also fast in practice due to wide availability of fast implementations for matrix-vector products. Therefore, utilization of randomized algorithms can speed up a very slow deterministic algorithm.
Freivalds' algorithm frequently arises in introductions to probabilistic algorithms because of its simplicity and how it illustrates the superiority of probabilistic algorithms in practice for some problems.
See also
References