HELP: matrix-l2-norm
{ $values { "m" matrix } { "n" number } }
-{ $description "Find the norm (size) of a matrix in 𝑙₂ (" { $snippet "L^2" } ") vector space, usually written ∥・∥₂ₚ."
+{ $description "Find the norm (size) of a matrix in 𝑙₂ (" { $snippet "L^2" } ") vector space, usually written ∥・∥₂."
$nl "This is the matrix norm when " { $snippet "p=2" } ", and is the square root of the sums of the squares of all the elements of the matrix." }
{ $notelist
{ "This norm is sometimes called the Hilbert-Schmidt norm." }
} ;
{ matrix-p-norm matrix-p-norm-entrywise } related-words
-{ matrix-p-norm matrix-p-q-norm } related-words
+{ matrix-l1-norm matrix-l2-norm matrix-l-infinity-norm matrix-p-norm matrix-p-q-norm } related-words
HELP: matrix-normalize
{ $values { "m" "a matrix with at least 1 non-zero number" } { "m'" matrix } }
CONSTANT: qj { 0 0 1 0 }
CONSTANT: qk { 0 0 0 1 }
-{ 1.0 } [ qi l2-norm ] unit-test
-{ 1.0 } [ qj l2-norm ] unit-test
-{ 1.0 } [ qk l2-norm ] unit-test
-{ 1.0 } [ q1 l2-norm ] unit-test
-{ 0.0 } [ q0 l2-norm ] unit-test
+{ 1.0 } [ qi norm ] unit-test
+{ 1.0 } [ qj norm ] unit-test
+{ 1.0 } [ qk norm ] unit-test
+{ 1.0 } [ q1 norm ] unit-test
+{ 0.0 } [ q0 norm ] unit-test
{ t } [ qi qj q* qk = ] unit-test
{ t } [ qj qk q* qi = ] unit-test
{ t } [ qk qi q* qj = ] unit-test
$nl
"SSE2 introduces double-precision SIMD (" { $snippet "double-2" } ") and integer SIMD (all types). Integer SIMD is missing a few features; in particular, the " { $link vmin } " and " { $link vmax } " operations only work on " { $snippet "uchar-16" } " and " { $snippet "short-8" } "."
$nl
-"SSE3 introduces horizontal adds (summing all components of a single vector register), which are useful for computing dot products. Where available, SSE3 operations are used to speed up " { $link sum } ", " { $link vdot } ", " { $link norm-sq } ", " { $link l2-norm } ", and " { $link distance } "."
+"SSE3 introduces horizontal adds (summing all components of a single vector register), which are useful for computing dot products. Where available, SSE3 operations are used to speed up " { $link sum } ", " { $link vdot } ", " { $link norm-sq } ", " { $link norm } ", and " { $link distance } "."
$nl
"SSSE3 introduces " { $link vabs } " for " { $snippet "char-16" } ", " { $snippet "short-8" } " and " { $snippet "int-4" } "."
$nl
! Test type propagation
{ V{ float } } [ [ { float-4 } declare norm-sq ] final-classes ] unit-test
-{ V{ float } } [ [ { float-4 } declare l2-norm ] final-classes ] unit-test
+{ V{ float } } [ [ { float-4 } declare norm ] final-classes ] unit-test
{ V{ float-4 } } [ [ { float-4 } declare normalize ] final-classes ] unit-test
{ n+v { +scalar+ +vector+ -> +vector+ } }
{ n-v { +scalar+ +vector+ -> +vector+ } }
{ n/v { +scalar+ +vector+ -> +vector+ } }
- { l2-norm { +vector+ -> +nonnegative+ } }
+ { norm { +vector+ -> +nonnegative+ } }
{ norm-sq { +vector+ -> +nonnegative+ } }
{ normalize { +vector+ -> +vector+ } }
{ v* { +vector+ +vector+ -> +vector+ } }
M: simd-128 v*n over simd-with v* ; inline
M: simd-128 v/n over simd-with v/ ; inline
M: simd-128 norm-sq dup vdot assert-positive ; inline
-M: simd-128 distance v- l2-norm ; inline
+M: simd-128 distance v- norm ; inline
M: simd-128 >pprint-sequence ;
M: simd-128 pprint* pprint-object ;
vdot
norm-sq
l1-norm
- l2-norm
+ norm
l-infinity-norm
p-norm
}
HELP: l1-norm
{ $values { "k" sequence } { "x" "a non-negative real number" } }
-{ $contract "Computes the norm (size) of " { $snippet "k" } " in 𝑙₁ (" { $snippet "L^1" } ") vector space." }
+{ $contract "Computes the norm (size) of " { $snippet "k" } " in 𝑙₁ (" { $snippet "L^1" } ") vector space, usually written ∥・∥₁." }
{ $notes "See " { $link matrix-l1-norm } " for matrix-specific documentation about this word." }
{ $examples
{ $example
HELP: l2-norm
{ $values { "k" sequence } { "x" "a non-negative real number" } }
-{ $contract "Computes the norm (size) of " { $snippet "k" } " in 𝑙₂ (" { $snippet "L^2" } ") vector space." }
-{ $notes "See " { $link matrix-l2-norm } " for matrix-specific documentation about this word." }
+{ $contract "Implementation for the default " { $link norm } ", in 𝑙₂ (" { $snippet "L^2" } ") vector space, usually written ∥・∥₂." }
+{ $notes "See " { $link matrix-l2-norm } " for matrix-specific documentation about this word." } ;
+
+HELP: norm
+{ $values { "k" sequence } { "x" "a non-negative real number" } }
+{ $contract "Computes the norm (size) of " { $snippet "k" } " in 𝑙₂ (" { $snippet "L^2" } ") vector space, usually written ∥・∥₂. " }
+{ $notes "This is generally the \"default norm\", and when referring to an unqualified norm, so it is an alias for the " { $link l2-norm } " implementation." }
{ $examples
{ $example
"USING: math.vectors math.functions prettyprint ;"
- "{ 1 2 3 4 } l2-norm 5.4772255 10e-8 ~ ."
+ "{ 1 2 3 4 } norm 5.4772255 10e-8 ~ ."
"t"
}
} ;
HELP: l-infinity-norm
{ $values { "k" sequence } { "x" "a non-negative real number" } }
-{ $contract "Computes the norm (size) of " { $snippet "k" } " in 𝑙∞ (" { $snippet "L^∞" } ") vector space. For a mathematical vector, this is simply its " { $link supremum } "." }
+{ $contract "Computes the norm (size) of " { $snippet "k" } " in 𝑙∞ (" { $snippet "L^∞" } ") vector space, usually written ∥・∥∞. For a mathematical vector, this is simply its " { $link supremum } "." }
{ $notes "See " { $link matrix-l-infinity-norm } " for matrix-specific documentation about this word." }
{ $examples
{ $example
HELP: p-norm
{ $values { "k" { $sequence number } } { "p" "a positive real number" } { "x" "a non-negative real number" } }
-{ $contract "Computes the norm (size) of " { $snippet "k" } " in 𝑙ₚ (" { $snippet "L^p" } ") vector space." }
+{ $contract "Computes the norm (size) of " { $snippet "k" } " in 𝑙ₚ (" { $snippet "L^p" } ") vector space, usually written ∥・∥ₚ." }
{ $notes "See " { $link matrix-p-norm } " for matrix-specific documentation about this word." } ;
+{ norm-sq l1-norm l2-norm norm l-infinity-norm p-norm } related-words
+
HELP: normalize
{ $values { "v" { $sequence "at least 1 non-zero number" } } { "w" { $sequence number } } }
{ $description "Outputs a vector with the same direction as " { $snippet "v" } ", but length 1." } ;
+{ normalize matrix-normalize } related-words
+
HELP: distance
{ $values { "u" { $sequence number } } { "v" { $sequence number } } { "x" "a non-negative real number" } }
{ $description "Outputs the Euclidean distance between two vectors." } ;
GENERIC: l2-norm ( k -- x )
M: object l2-norm norm-sq sqrt ; inline
+ALIAS: norm l2-norm
GENERIC: l-infinity-norm ( k -- x )
M: object l-infinity-norm supremum ; inline