{"id":20748896,"url":"https://github.com/amaliezzz/Eigen-Analyzer","last_synced_at":"2025-05-11T05:32:54.294Z","repository":{"id":261910218,"uuid":"885690742","full_name":"amaliezzz/Eigen-Analyzer","owner":"amaliezzz","description":"Eigen-Analyzer: A numerical tool for matrix analysis, computing eigenvalues and eigenvectors.","archived":false,"fork":false,"pushed_at":"2025-01-28T07:19:34.000Z","size":30817,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-11T13:50:35.998Z","etag":null,"topics":["analyzer","matrix","matrix-decompositions","numerical-methods","python","streamlit"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/amaliezzz.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-09T06:05:13.000Z","updated_at":"2025-02-24T07:13:54.000Z","dependencies_parsed_at":"2024-11-09T07:32:34.179Z","dependency_job_id":"d22fac72-1ddf-4fc7-a09a-4a40c6e1f318","html_url":"https://github.com/amaliezzz/Eigen-Analyzer","commit_stats":null,"previous_names":["serize02/power-method","serize02/eigen-analyzer","amaliezzz/eigen-analyzer"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amaliezzz%2FEigen-Analyzer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amaliezzz%2FEigen-Analyzer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amaliezzz%2FEigen-Analyzer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amaliezzz%2FEigen-Analyzer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/amaliezzz","download_url":"https://codeload.github.com/amaliezzz/Eigen-Analyzer/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253523696,"owners_count":21921815,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["analyzer","matrix","matrix-decompositions","numerical-methods","python","streamlit"],"created_at":"2024-11-17T08:19:19.816Z","updated_at":"2025-05-11T05:32:54.285Z","avatar_url":"https://github.com/amaliezzz.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Numerical Analysis Lab\n\nThe power method is an iterative technique used in numerical analysis to find the dominant eigenvalue and corresponding eigenvector of a matrix. It is particularly useful for large sparse matrices where other methods may be computationally expensive.  Its extension to the inverse power method is practical for finding any eigenvalue provided that a\ngood initial approximation is known.\n\nEnsure you have Python installed on your system. Then, install the necessary dependencies by running:\n\n```shell\npip install -r requirements.txt\n```\n\n## Computing the Dominant Eigenvalues\n\nLet $A$ be an $n \\times n$, non-singular real valued matrix with a basis of eigenvectors. Denote the eigenvalues by $\\lambda_j$ and eigenvectors by $v_j$. \n\nWe assume here there is a single eigenvalue of largest magnitude (the ‘dominant’ eigenvalue). Label them as follows:\n\n$$ |\\lambda_1| \u003e |\\lambda_2| \\geq |\\lambda_3| \\geq \\dots \\geq |\\lambda_n| \u003e 0$$\n\nNote that if $A$ has real-valued entries, it must be that $\\lambda_1$ is real (why?).\n\nThe simplest approach to computing $\\lambda_1$ and $v_1$ is the power method. The idea is as follows. Let $x$ be any vector. Then, since $\\left(v_j\\right)$ is a basis,\n\n$$x = c_1v_1+\\dots+c_nv_n$$\n\nNow suppose that $c_1 \\neq 0$. Then,\n\n$$Ax = c_1\\lambda_1v_1 + \\dots + c_n\\lambda_nv_n$$\n\nand, applying $A$ again,\n\n$$A^kx = {\\sum_{j=1}^n}c_j\\lambda_j^kv_j$$\n\nSince the $\\lambda_1^k$ term is largest in magnitude, in the sequence\n\n$$x, Ax, A^2x, A^3x\\dots$$\n\nwe expect the $\\lambda_1^kv_1$  term will dominate so\n\n$${A} A^kx \\approx c\\lambda_1^kv_1 + smaller terms$$ \n\n\nEach iteration grows the largest term relative to the others, so after enough iterations only the first term (what we want) will be left.\n\n## The Basic Method\n\nLet’s formalize the observation and derive a practical method. The main trouble is that $\\lambda_1^k$\nwill either grow exponentially (bad) or decay to zero (less bad, but still bad). By taking the\nright ratio, the issue can be avoided.\n\nLet $x$ and $x$ be vectors with $w^Tv_1 \\neq 0$ and such that $x$ has non-zero $v_1$ component. Then\n\n$$ \\frac{w^tA^kx}{w^tA^{k-1}x} = \\lambda_1 + O((\\lambda_2/\\lambda_1)^k)\\quad as \\quad k \\to \\infty  $$\n\n***Poof.*** Since the eigenvectors form a basis, there are scalars $c_1,\\dots,c_n$ such that\n\n$$x = \\sum_{j=1}^nv_jc_j$$\n\nBy assumption, $c_1 \\neq 0$. Since $A^kv_j = \\lambda_j^kv_j$, it follows that\n\n$$A^kx = \\sum_{j=1}^nc_j\\lambda_j^kv_j = \\lambda_1^k(c_1v_1 + \\sum_{j=2}^nc_j(\\frac{\\lambda_j}{\\lambda_1})^kv_j )$$\n\nAll the terms in the parentheses except the first go to zero in magnitude as $k \\to \\infty$. Thus\n\n$$\\begin{align}\\frac{w^tA^kx}{w^tA^{k-1}x} \u0026= \\lambda_1\\frac{d_1 + \\sum_{j=2}^nd_j(\\lambda_j/\\lambda_1)^k}{d_1 + \\sum_{j=2}^nd_j(\\lambda_j/\\lambda_1)^{k-1}}\\\\\\\\\u0026= \\lambda_1 \\frac{1+O((\\lambda_2/\\lambda_1)^k)}{1+O((\\lambda_2/\\lambda_1)^{k-1}}\\\\\\\\ \u0026= \\lambda_1 + O((\\lambda_2/\\lambda_1)^k) \\end{align}$$\n\nwhere $d_j = c_jw^Tv_j$ (note that $d_1 \\neq 0$ by assumption). Note that we have used that\n\n$$\\frac{1}{1+f} = 1 + O(f)$$\n\nThus, the power method computes the dominant eigenvalue (largest in magnitude), and the convergence is linear. The rate depends on the size of $\\lambda_1$ relative to the next largest eigenvalue $\\lambda_2$.\n\n## The Inverse Power Method\n\nThe Inverse Power method is a modification of the Power method that gives faster convergence. It is used to determine the eigenvalue of $A$ that is closest to a specified number $q$.\n\nSuppose that matrix $A$ has eigenvalues $\\lambda_1, \\lambda_2, \\dots, \\lambda_n$ with linearly independent eigenvectors $v_1^{(1)}, v_2^{(2)}, \\dots, v_n^{(n)}$. The eigenvalues of $(A-qI)^{-1}$ where $q \\neq \\lambda_i$ for $i = 1,2,3, \\dots, n$ are:\n\n$$\\frac{1}{\\lambda_1 - q}, \\frac{1}{\\lambda_2 - q}, \\dots, \\frac{1}{\\lambda_n - q}$$\n\nApplying the Power Method to $(A-qI)^{-1}$ gives\n\n$$ y^{(m)} = (A-qI)^{-1}x^{(m-1)} ,$$\n\n$$ \\mu^{(m)} = y_{p_{m-1}}^{(m)} = \\frac{y_{p_{m-1}}^{(m)}}{x_{p_{m-1}}^{(m-1)}} = \\frac{ \\sum_{j=1}^n \\beta\\frac{1}{(\\lambda_j-1)^m} v_{p_{m-1}}^{(j)} } {\\sum_{j=1}^n \\beta\\frac{1}{(\\lambda_j-1)^{m-1}} v_{p_{m-1}}^{(j)}},$$\n\n$$x^{(m)} = \\frac{y^{(m)}}{y_{p_m}^{(m)}}$$\n\nwhere at each step, $p_m$ represents the smallest integer for which $\\left| y_{p_m}^{(m)} \\right| = \\| y^{(m)} \\|_\\infty$. The sequence $\\left\\{\\mu^{(m)}\\right\\} $ converges to $\\frac{1}{\\lambda_k - q}$ , where\n\n$$ \\frac{1}{\\|\\lambda_k-q\\|} = \\max_{1 \\leq i \\leq n}\\frac{1}{|\\lambda_k-q|},$$\n\nand $\\lambda_k \\approx q + \\frac{1}{\\mu^{(m)}}$ is the eigenvalue of $A$ that is closest to $q$.\n\nThe vector $y^{(m)}$ is obtained by solving the system of linear equations $(A-qI)y^{(m)} = x^{(m-1)}$ and for that we use the `numpy.linalg.solve` function, that uses LU decomposition with partial pivoting and row interchanges.\n\n# Eigen-Analyzer\nAs a practical example, we have implemented a Streamlit app that words on these methods. So have fun with it!\n\n```shell\nstreamlit run app.py\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famaliezzz%2FEigen-Analyzer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Famaliezzz%2FEigen-Analyzer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famaliezzz%2FEigen-Analyzer/lists"}