Enum Norm

java.lang.Object
java.lang.Enum<Norm>
it.unimi.dsi.law.util.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.

    Methods inherited from class java.lang.Object

    getClass, notify, notifyAll, wait, wait, wait
  • Enum Constant Details

    • L_1

      public static final Norm 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

      public static final Norm 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

      public static final Norm L_INFINITY
      The norm of a vector is the maximum of the absolute values of its components.
  • Method Details

    • values

      public static Norm[] 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

      public static Norm valueOf​(String name)
      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 name
      NullPointerException - 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.NaNs unless newNorm 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.NaNs unless newNorm is zero.

      Parameters:
      v - the vector to be normalized.
      newNorm - the new norm value (nonnegative).
      Returns:
      v.
    • main

      public static void main​(String[] arg) throws NumberFormatException, IOException, JSAPException
      Throws:
      NumberFormatException
      IOException
      JSAPException