Last active
August 29, 2015 14:03
-
-
Save krishnanraman/7f7ed98b2f9dcbe8b9cf to your computer and use it in GitHub Desktop.
Approximation of L2 norm of matrix using gershgorin's circles
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object gershgorin extends App { | |
type Matrix = Seq[Seq[Double]] | |
def gershgorin(square: Matrix) = { | |
val rows = (0 until square.size) | |
rows.map(i => square(i)(i)) zip | |
rows.map(i => (0 until i).map(j=> math.abs(square(i)(j))) ++ (i+1 until square.size).map(j=> math.abs(square(i)(j)))).map(_.sum) | |
} | |
def eigenValues(square: Matrix) = gershgorin(square).map{ cr => val (center,radius) = cr; (center - radius, center + radius)} | |
def spectralRadius(square: Matrix) = eigenValues(square).map(_._2).max | |
def mkString(m:Matrix) = m.map{r => r.mkString(",")}.mkString("\n") | |
val symmetric = Seq(Seq(7,1,2.0), Seq(1,8,3.0), Seq(2,3,9.0)) | |
print("Matrix: \n%s\n Spectral Radius: %.2f \n eigenValues: %s".format( mkString(symmetric), spectralRadius(symmetric), eigenValues(symmetric))) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Given a nxn square matrix : | |
there exist n Gershgorin Circles = 1 circle per row | |
For each row, | |
center of circle = the diagonal cell. | |
radius of circle = sum the off-diagonal cell norms | |
Theorem: Eigen Values of a matrix must lie within its Gershgorin. | |
Each real eigen value is bounded by (center - radius, center + radius) | |
The Spectral Radius is the maximum eigen value. | |
For Symmetric Matrices: | |
The L2 norm of a symmetric marix is simply the spectral radius. | |
If the matrix ain't symmeric, all bets are off. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ scala gershgorin | |
Matrix: | |
7.0,1.0,2.0 | |
1.0,8.0,3.0 | |
2.0,3.0,9.0 | |
Spectral Radius: 14.00 | |
eigenValues: Vector((4.0,10.0), (4.0,12.0), (4.0,14.0)) | |
From WolframAlpha: | |
{12.4188, 6.38677, 5.1944} | |
Notice that | |
12.4 lies between [4,14] | |
6.4 lies between [4,12] | |
5.2 lies between [4,10] | |
and true spectral radius = 12.4 is well approximated by 14 | |
For a symmetric matrix, L2 norm = spectral radius. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment