Skip to content

Instantly share code, notes, and snippets.

@krishnanraman
Last active August 29, 2015 14:03
Show Gist options
  • Save krishnanraman/7f7ed98b2f9dcbe8b9cf to your computer and use it in GitHub Desktop.
Save krishnanraman/7f7ed98b2f9dcbe8b9cf to your computer and use it in GitHub Desktop.
Approximation of L2 norm of matrix using gershgorin's circles
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)))
}
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.
$ 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