You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/user_interface/truncations.md
+121-6Lines changed: 121 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,11 @@ CollapsedDocStrings = true
5
5
6
6
# Truncations
7
7
8
-
Currently, truncations are supported through the following different methods:
8
+
Truncation strategies allow you to control which eigenvalues or singular values to keep when computing partial or truncated decompositions. These strategies are used in functions like [`eigh_trunc`](@ref), [`eig_trunc`](@ref), and [`svd_trunc`](@ref) to reduce the size of the decomposition while retaining the most important information.
9
+
10
+
## Truncation Strategies
11
+
12
+
MatrixAlgebraKit provides several built-in truncation strategies:
9
13
10
14
```@docs; canonical=false
11
15
notrunc
@@ -15,11 +19,122 @@ truncfilter
15
19
truncerror
16
20
```
17
21
18
-
It is additionally possible to combine truncation strategies by making use of the `&` operator.
19
-
For example, truncating to a maximal dimension `10`, and discarding all values below `1e-6` would be achieved by:
22
+
## Combining Strategies
23
+
24
+
Truncation strategies can be combined using the `&` operator to create intersection-based truncation.
25
+
When strategies are combined, only the values that satisfy all conditions are kept.
26
+
27
+
For example, to keep at most 10 eigenvalues while also discarding all values below `1e-6`:
println("Kept $(size(D_combined, 1)) eigenvalues (max 15, all above 1e-8)")
106
+
107
+
# 5. Truncated SVD example
108
+
B = randn(100, 80)
109
+
U, S, Vh = svd_trunc(B; trunc = (maxrank = 20,))
110
+
@assert size(S) == (20, 20)
111
+
@assert size(U) == (100, 20)
112
+
@assert size(Vh) == (20, 80)
113
+
114
+
# Verify the truncated decomposition is accurate
115
+
@assert norm(B - U * S * Vh) ≈ norm(svd(B).S[21:end])
116
+
```
117
+
118
+
## Truncation with SVD vs Eigenvalue Decompositions
119
+
120
+
When using truncations with different decomposition types, keep in mind:
121
+
122
+
-**`svd_trunc`**: Singular values are always real and non-negative, sorted in descending order. Truncation by value typically keeps the largest singular values.
123
+
124
+
-**`eigh_trunc`**: Eigenvalues are real but can be negative for symmetric matrices. By default, `truncrank` sorts by absolute value, so `truncrank(k)` keeps the `k` eigenvalues with largest magnitude (positive or negative).
125
+
126
+
-**`eig_trunc`**: For general (non-symmetric) matrices, eigenvalues can be complex. Truncation by absolute value considers the complex magnitude.
127
+
128
+
## Advanced: Custom Truncation Filters
129
+
130
+
For specialized needs, you can use [`truncfilter`](@ref) to define custom selection criteria:
0 commit comments