Alterna · learning material
01.3 How to measure length
First we find the length of the arrow on the Pythagorean Theorem, then compare the other measurement rules that answer another question about distance.
What this material covers
- "Long" must satisfy the rules
- A single ball reveals the chosen geometry.
- Distance is the norm of difference
- The magnitude of the signs changes the neighborhood.
Content and key concepts
On the previous page, from where the coordinates are calculated.
First we find the length of the arrow on the Pythagorean Theorem, then compare the other measurement rules that answer another question about distance.
Arrow: 3 to the right, 4 up.
Координаты и расчёт геометрического примера приведены в тексте. Для изменения пространственного рисунка включитеJavaScript.
"Long" must satisfy the rules
On a rectangular grid, the route can be measured by the sum of horizontal and vertical movements; free movement over a plane is naturally measured by a straight cut; the limit at the largest coordinate sets another geometry. All these options are the standard because for the vector,
x
x
x
, scalar
α
\alpha
α
and vectors
y
y
y
The following are implemented:
∥
x
∥
≥
0
,
∥
x
∥
=
0
⟺
x
=
0
,
∥
α
x
∥
=
∣
α
∣
∥
x
∥
,
∥
x
+
y
∥
≤
∥
x
∥
+
∥
y
∥
.
\|x\|\ge 0,
\qquad \|x\|=0\Longleftrightarrow x=0,
\qquad \|\alpha x\|=|\alpha|\|x\|,
\qquad \|x+y\|\le\|x\|+\|y\|.
∥
x
∥
≥
0
,
∥
x
∥
=
0
⟺
x
=
0
,
∥
αx
∥
=
∣
α
∣∥
x
∥
,
∥
x
+
y
∥
≤
∥
x
∥
+
∥
y
∥.
The last property is the inequality of the triangle.
x
+
y
x+y
x
+
y
not longer than the route first along
x
x
x
and then along
y
y
y
Without these characteristics, the arbitrary function cannot be considered to be the correct length.
Three standards used in the course:
∥
x
∥
1
=
∑
i
∣
x
i
∣
,
∥
x
∥
2
=
∑
i
x
i
2
,
∥
x
∥
∞
=
max
i
∣
x
i
∣
.
\|x\|_1=\sum_i|x_i|,
\qquad
\|x\|_2=\sqrt{\sum_i x_i^2},
\qquad
\|x\|_\infty=\max_i|x_i|.
∥
x
∥
1
=
i
∑
∣
x
i
∣
,
∥
x
∥
2
=
i
∑
x
i
2
,
∥
x
∥
∞
=
i
max
∣
x
i
∣.
For
x
=
[
3
,
4
]
T
x=[3,4]^T
x
=
[
3
,
4
]
T
:
∥
x
∥
1
=
7
,
∥
x
∥
2
=
5
,
∥
x
∥
∞
=
4.
\|x\|_1=7,
\qquad \|x\|_2=5,
\qquad \|x\|_\infty=4.
∥
x
∥
1
=
7
,
∥
x
∥
2
=
5
,
∥
x
∥
∞
=
4.
These are not three approaches to one mandatory number, but three different definitions of geometry.
A single ball reveals the chosen geometry.
The only ball of the normal is a multitude.
{
x
:
∥
x
∥
≤
1
}
\{x:\|x\|\le1\}
{
x
:
∥
x
∥
≤
1
}
On the plane of the border, the boundary has different forms:
for
L
1
L_1
L
1
: Rom
∣
x
1
∣
+
∣
x
2
∣
=
1
|x_1|+|x_2|=1
∣
x
1
∣
+
∣
x
2
∣
=
1
;
for
L
2
L_2
L
2
: circle
x
1
2
+
x
2
2
=
1
x_1^2+x_2^2=1
x
1
2
+
x
2
2
=
1
;
for
L
∞
L_\infty
L
∞
: square
max
(
∣
x
1
∣
,
∣
x
2
∣
)
=
1
\max(|x_1|,|x_2|)=1
max
(
∣
x
1
∣
,
∣
x
2
∣
)
=
1
.
The standardization of the non-zero vector divides it by the selected standard.
x
/
∥
x
∥
x/\|x\|
x
/∥
x
∥
It lies on the relevant border, but its coordinates differ:
x
∥
x
∥
1
=
[
3
/
7
,
4
/
7
]
T
,
x
∥
x
∥
2
=
[
3
/
5
,
4
/
5
]
T
,
x
∥
x
∥
∞
=
[
3
/
4
,
1
]
T
.
\frac{x}{\|x\|_1}=[3/7,4/7]^T,
\quad
\frac{x}{\|x\|_2}=[3/5,4/5]^T,
\quad
\frac{x}{\|x\|_\infty}=[3/4,1]^T.
∥
x
∥
1
x
=
[
3/7
,
4/7
]
T
,
∥
x
∥
2
x
=
[
3/5
,
4/5
]
T
,
∥
x
∥
∞
x
=
[
3/4
,
1
]
T
.
Distance is the norm of difference
The selected standard sets the metric.
d
p
(
x
,
y
)
=
∥
x
−
y
∥
p
.
d_p(x,y)=\|x-y\|_p.
d
p
(
x
,
y
)
=
∥
x
−
y
∥
p
.
For
x
=
[
3
,
4
]
T
x=[3,4]^T
x
=
[
3
,
4
]
T
,
y
=
[
1
,
0
]
T
y=[1,0]^T
y
=
[
1
,
0
]
T
The difference is equal
[
2
,
4
]
T
[2,4]^T
[
2
,
4
]
T
, so
d
1
(
x
,
y
)
=
6
,
d
2
(
x
,
y
)
=
20
,
d
∞
(
x
,
y
)
=
4.
d_1(x,y)=6,
\qquad d_2(x,y)=\sqrt{20},
\qquad d_\infty(x,y)=4.
d
1
(
x
,
y
)
=
6
,
d
2
(
x
,
y
)
=
20
,
d
∞
(
x
,
y
)
=
4.
The number "distance equals 4" is incomplete without the name of the metric.
L
1
L_1
L
1
There are many of the shortest ramps of length 6.
L
2
L_2
L
2
The shortest is the straight cut.
L
∞
L_\infty
L
∞
The value is determined by the largest coordinate deviation.
Euclidic standard quadratic is often used in loss,
q
(
x
)
=
∥
x
∥
2
2
=
∑
i
x
i
2
,
q(x)=\|x\|_2^2=\sum_i x_i^2,
q
(
x
)
=
∥
x
∥
2
2
=
i
∑
x
i
2
,
but the norm is not:
q
(
2
x
)
=
4
q
(
x
)
q(2x)=4q(x)
q
(
2
x
)
=
4
q
(
x
)
while the uniformity of the norm requires multiplier 2. "
L
0
L_0
L
0
" as the number of non-zero components is also not normal: for example, scaling the non-negative vector does not multiply this number by
∣
α
∣
|\alpha|
∣
α
∣
The sum of coordinates without modules is not even as long as y
[
1
,
−
1
]
[1,-1]
[
1
,
−
1
]
It's equal to zero.
The magnitude of the signs changes the neighborhood.
If the first coordinate is measured in metres and then recorded in centimeters, its numerical contribution to the distance will increase 100 times. The object closest to the original units may no longer be nearer after the change of scale. Therefore, standardization of the topics is part of the data model, not the cosmetics of the interface.
Regulation
x
/
∥
x
∥
2
x/\|x\|_2
x
/∥
x
∥
2
Saves the direction of the non-zero vector and removes the length. For embeddings, it is sometimes useful when comparing directions but the length can carry a trained signal. It is only possible to rule automatically when the question is asked: What information is allowed to be discarded?
from math import sqrt
x = [3, 4]
assert sum(abs(v) for v in x) == 7
assert sqrt(sum(v*v for v in x)) == 5
assert max(abs(v) for v in x) == 4
The code repeats the operations just taken care of.
Completely checked Python-example Chapter
Available with a separate file; the short piece shown does not replace its implementation.
We've got the length, not the new coordinates.
How does this question go about the result?
Python examples of Chapter 01
Academic base