Package it.unimi.dsi.law.util
Enum Norm
- All Implemented Interfaces:
Serializable
,Comparable<Norm>
,java.lang.constant.Constable
public enum Norm extends Enum<Norm>
An
Enum
providing different ℓ norms.-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>>
-
Enum Constant Summary
Enum Constants Enum Constant Description L_1
The ℓ1norm of a vector is the sum of the absolute values of its components.L_2
The ℓ2norm of a vector is the square root of the sum of the squares of its components.L_INFINITY
The ℓ∞norm of a vector is the maximum of the absolute values of its components. -
Method Summary
Modifier and Type Method Description abstract double
compute(double[] v)
Computes the norm of a vector.abstract double
compute(double[][] v)
Computes the norm of a big vector.abstract double
compute(double[][] v, double[][] w)
Computes the norm of the difference of two big vectors.abstract double
compute(double[] v, double[] w)
Computes the norm of the difference of two vectors.static void
main(String[] arg)
double[][]
normalize(double[][] v, double newNorm)
Normalizes a big vector to a given norm value.double[]
normalize(double[] v, double newNorm)
Normalizes a vector to a given norm value.static Norm
valueOf(String name)
Returns the enum constant of this type with the specified name.static Norm[]
values()
Returns an array containing the constants of this enum type, in the order they are declared.
-
Enum Constant Details
-
L_1
The ℓ1norm of a vector is the sum of the absolute values of its components. We use Kahan's summation algorithm to contain numerical errors. -
L_2
The ℓ2norm of a vector is the square root of the sum of the squares of its components. We use Kahan's summation algorithm to contain numerical errors. -
L_INFINITY
The ℓ∞norm of a vector is the maximum of the absolute values of its components.
-
-
Method Details
-
values
Returns an array containing the constants of this enum type, in the order they are declared.- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)- Parameters:
name
- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException
- if this enum type has no constant with the specified nameNullPointerException
- if the argument is null
-
compute
public abstract double compute(double[] v)Computes the norm of a vector.- Parameters:
v
- a vector.- Returns:
- the norm of
v
.
-
compute
public abstract double compute(double[] v, double[] w)Computes the norm of the difference of two vectors.- Parameters:
v
- the first vector.w
- the second vector.- Returns:
- the norm of
v
−w
.
-
compute
public abstract double compute(double[][] v)Computes the norm of a big vector.- Parameters:
v
- a big vector.- Returns:
- the norm of
v
.
-
compute
public abstract double compute(double[][] v, double[][] w)Computes the norm of the difference of two big vectors.- Parameters:
v
- the first big vector.w
- the second big vector.- Returns:
- the norm of
v
−w
.
-
normalize
public double[] normalize(double[] v, double newNorm)Normalizes a vector to a given norm value.Note that passing a zero vector will result in a vector of
Double.NaN
s unlessnewNorm
is zero.- Parameters:
v
- the vector to be normalized.newNorm
- the new norm value (nonnegative).- Returns:
v
.
-
normalize
public double[][] normalize(double[][] v, double newNorm)Normalizes a big vector to a given norm value.Note that passing a zero vector will result in a vector of
Double.NaN
s unlessnewNorm
is zero.- Parameters:
v
- the vector to be normalized.newNorm
- the new norm value (nonnegative).- Returns:
v
.
-
main
-