Skip to content

boasbakker/MatrixEulerDiagramGen

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Matrix Euler Diagram Generator

An interactive R Shiny application that generates Euler diagrams visualizing the relationships and intersections between various matrix properties (such as invertible, diagonalizable, symmetric/self-adjoint, positive definite, nilpotent, etc.) over real ($\mathbb{R}$) and complex ($\mathbb{C}$) fields.

The automated process dynamically renders accurate diagrams to help users explore linear algebra concepts and provides explicit matrix examples for every valid region (combination of properties) in the generated diagram. I've created this for the Linear Algebra 2 course of the 1st year Applied Mathematics study of the TU Delft, but it should be applicable to most Linear Algebra 2 subjects. It is highly recommended as a fun way of studying for your exam!

🔗 Try it out using this link!

Features

  • Dynamic Euler Diagrams: The app currently supports 18 properties. You can pick 3-7 properties to make a diagram (adding more than 7 usually causes the automatic ellipse diagram creation process to fail).
  • Generation Status: The app explicitly says whether the diagram creation succeeded or not.
  • Mathematical Pruning: Never renders impossible regions based on mathematical theorems (e.g., if a matrix is positive definite, it must also be invertible and self-adjoint; a matrix cannot be both positive definite and nilpotent).
  • Field Selection: Toggle between diagrams over real ($\mathbb{R}$) and complex ($\mathbb{C}$) fields, adjusting rules and labels (e.g., orthogonal vs. unitary, symmetric vs. self-adjoint).
  • Extensive Examples: Provides simple matrix examples for every combination of the selected properties.

Exercises & Tips for Studying

This is a great tool for exam preparation. You can pick a few properties and look at the results. Sometimes a set is a subset of another set, or they are fully distinct. The goal is to prove why this is the case. All of these proofs should be at the right difficulty level for a university level Linear Algebra 2 exam!

Here are some example exercises to try:

  • Which labeled category in the complex poster diagram (see below) contains exactly three complex 2x2 matrices?
  • Try drawing one of the missing properties in the poster diagram. For some you will succeed (like positive semidefinite), for others it may be more difficult so you may have to make multiple detached blobs.
  • Try proving why only the identity matrix fits inside positive definite + unitary.
  • Try proving why only the zero matrix fits inside normal + nilpotent.

The Complex Poster Diagram

The project includes poster_complex.png, which is the most comprehensive Euler diagram over $\mathbb{C}$ I could achieve on a single plot. It visually maps the intersections of the following 7 matrix properties:

  • Diagonal
  • Invertible
  • Normal
  • Self-adjoint
  • Unitary
  • Positive Definite
  • Nilpotent

This diagram contains exactly 19 valid regions, and a corresponding $2 \times 2$ complex matrix example for each region can be found on the right side of the poster. The LaTeX code for the examples is in poster_examples.tex (and compiled in poster_examples.pdf).

Repository Structure

├── poster_complex.png            # Comprehensive Euler diagram for Complex matrices
├── poster_examples.tex           # LaTeX file for matrix examples on the poster
├── poster_examples.pdf           # Compiled PDF of the poster matrix examples
└── shinyapp/                     # Main R Shiny application directory
    ├── app.R                     # The core Shiny app code (UI & Server)
    ├── generate_examples.py      # Python script generating matrix examples for various combinations 
    ├── generate_combination_cache.R # R script that pre-computes valid property combinations
    ├── mathematically_possible_combinations_cache.json # Speed-up cache for valid sets
    ├── matrix_examples_R.json    # Cached real matrix examples for diagram regions
    └── matrix_examples_C.json    # Cached complex matrix examples for diagram regions

How It Works

  1. Property Combinations: The app tracks 18 fundamental matrix properties. The set of all combinations ($2^{18}$) is pared down to mathematically valid configurations using a rigorous set of boolean rules (in generate_combination_cache.R and generate_examples.py).
  2. Caching for Performance: Because generating subsets and intersections on the fly can be computationally intensive, valid combinations and valid matrix examples are pre-calculated offline and cached in JSON. The cache currently holds 70 unique matrix examples for the real field and 85 examples for the complex field.
  3. Diagram Layout: The eulerr R package is used to fit areas corresponding to the enabled matrices. Sizes are customized algorithmically to ensure the combinations remain visible.
  4. Rendering: Diagram shapes defaults to ellipses or circles.

Further Work

Here are several planned improvements and features to explore in the future:

  • Formal Proofs: Adding explicit mathematical proofs for every theorem and implication used to prune impossible intersections.
  • Code Consolidation: Uniting the separate Python and R scripts responsible for calculating the mathematical combinations.
  • New Properties & Non-Square Matrices: Extending the diagram rules to classify non-square matrices and introducing properties such as:
    • Scalar matrices (in the form $cI$).
    • Antidiagonal matrices.
    • Symmetric matrices for the complex case as well.
    • Jordan Canonical Form
    • Strictly upper/lower triangular
    • Square, zero matrix, and identity matrix as explicit categories.
    • Injective and surjective (which helps visualize the Rank-Nullity Theorem).
    • Full column rank and full row rank.
    • Left-unitary ($U^\ast U = I$) and right-unitary ($UU^\ast = I$).
    • Non-square analogs of:
      • (Anti)diagonal, identity, zero, scalar, (strictly) upper/lower triangular
  • Advanced Diagram Rendering: The problem of creating a correct Euler diagram with connected regions is a well-studied problem in mathematics. It is equivalent to finding a planar embedding of a dual graph, which is an NP-hard problem. However, several implementations exist that attempt to solve this problem efficiently. I plan to migrate to a package that is not strictly restricted to ellipses. Some promising options include:
    • EulerMerge / smoothEuler (Java + Python/Flask)
    • eule (Python)
    • DrawEuler and Kent University Tools (Java)
    • Implementations of the highly cited paper "A Simple Approach for Boundary Improvement of Euler Diagrams" (by Simonetto, Archambault, and Scheidegger).
  • Hopefully, after such a migration, the feature that displays a popup when a property is redundant (e.g., lower triangular, upper triangular, and diagonal) will no longer be needed; perhaps a manual approach for drawing those extra regions would be required. If the popup is retained, it would be ideal to change the default option to preserve the maximum number of distinct regions on the diagram.

Local Development

If you'd like to run the app locally:

  1. Ensure R is installed along with the required packages: shiny, eulerr, shinycssloaders, jsonlite, and svglite.
  2. Clone this repository.
  3. Depending on your editor (like RStudio), open shinyapp/app.R and click "Run App", or run it via the console:
    shiny::runApp("shinyapp")

Author

Created by Boas. If you have any questions about the app, don't hesitate to contact me!

About

An interactive application that generates Euler diagrams to visualize the relationships between various matrix properties

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors