Skip to content

Commit 3083425

Browse files
author
Symbolics
committed
Document nu:norm, L-norms for vectors and matrices
1 parent 7645e92 commit 3083425

File tree

1 file changed

+70
-2
lines changed

1 file changed

+70
-2
lines changed

content/en/docs/Manuals/lla.md

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ description: >
1212
LLA works with matrices, that is arrays of rank 2, with all numerical values. Categorical variables could be integer coded if you need to.
1313

1414

15-
## Basic Usage
15+
## Setup
1616

1717
`lla` requires a BLAS and LAPACK shared library. These may be available via
1818
your operating systems package manager, or you can download [OpenBLAS](https://github.com/xianyi/OpenBLAS), which includes precompiled binaries for MS Windows.
@@ -39,7 +39,7 @@ To load `lla`:
3939
(use-package 'lla) ;access to the symbols
4040
```
4141

42-
## Examples
42+
### Getting Started
4343

4444
To make working with matrices easier, we're going to use the matrix-shorthand library. Load it like so:
4545

@@ -62,3 +62,71 @@ To make working with matrices easier, we're going to use the matrix-shorthand li
6262
6363
; #(5.0d0 11.0d0 17.0d0)
6464
```
65+
66+
## Basics
67+
68+
### norm
69+
70+
**`norm`** returns a matrix or vector norm. This function is able to return one of eight different matrix norms, or one of an infinite number of vector norms (described below), depending on the value of the `ord` parameter. `ord` may be one of: `integer`, `:frob`, `:inf` `:-inf`. `ord` must be >= 0.
71+
72+
Note that norm is not, by default, part of the LS-USER package.
73+
74+
The following norms can be calculated:
75+
76+
| ord | norm for matrices | norm for vector |
77+
|---------|--------------------------|-----------------|
78+
| None | Frobenious norm | 2-norm |
79+
| `:frob` | Frobenius norm | - |
80+
| `:nuc` | nuclear norm | - |
81+
| `:inf` | max(sum(abs(a), axis=1)) | (max (abs a)) |
82+
| `:-inf` | min(sum(abs(a), axis=1)) | (min (abs a)) |
83+
| `0` | - | (sum a) |
84+
| `1` | max(sum(abs(a), axis=0)) | as below |
85+
| `-1` | N/A | as below |
86+
| `2` | 2-nrom | as below |
87+
| `-2` | N/A | as below |
88+
89+
The Frobenius norm is given by
90+
91+
The nuclear norm is the sum of the singular values.
92+
93+
Both the Frobenius and nuclear norm orders are only defined for matrices.
94+
95+
#### Examples
96+
97+
```lisp
98+
(defparameter a #(-4 -3 -2 -1 0 1 2 3 4))
99+
(defparameter b (reshape a '(3 3)))
100+
```
101+
102+
```lisp
103+
LS-USER> (nu:norm a)
104+
7.745967
105+
LS-USER> (nu:norm b)
106+
7.745967
107+
LS-USER> (nu:norm b :frob)
108+
7.745967
109+
LS-USER> (nu:norm a :inf)
110+
4
111+
LS-USER> (nu:norm b :inf)
112+
9
113+
LS-USER> (nu:norm a :-inf)
114+
0
115+
LS-USER> (nu:norm b :-inf)
116+
2
117+
```
118+
119+
```lisp
120+
LS-USER> (nu:norm a 1)
121+
20
122+
LS-USER> (nu:norm b 1)
123+
7
124+
LS-USER> (nu:norm a 2)
125+
7.745967
126+
LS-USER> (nu:norm b 2)
127+
7.745967
128+
LS-USER> (nu:norm b 3)
129+
5.8480353
130+
```
131+
132+

0 commit comments

Comments
 (0)