Top Description Inners Constructors Methods
com.google.common.math

public abstract Class LinearTransformation

extends Object
Class Inheritance
Known Direct Subclasses
com.google.common.math.LinearTransformation.RegularLinearTransformation, com.google.common.math.LinearTransformation.VerticalLinearTransformation, com.google.common.math.LinearTransformation.NaNLinearTransformation
Annotations
@J2ktIncompatible
@GwtIncompatible
@ElementTypesAreNonnullByDefault
Static Imports
com.google.common.base.Preconditions.checkArgument, com.google.common.math.DoubleUtils.isFinite, java.lang.Double.NaN

The representation of a linear transformation between real numbers x and y. Graphically, this is the specification of a straight line on a plane. The transformation can be expressed as y = m * x + c for finite m and c, unless it is a vertical transformation in which case x has a constant value for all y. In the non-vertical case, m is the slope of the transformation (and a horizontal transformation has zero slope).
Author
Pete Gillin
Since
20.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
LinearTransformation.LinearTransformationBuilder

This is an intermediate stage in the construction process.

private static class
private static class
private static class

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static LinearTransformation
forNaN()

Builds an instance for datasets which contains Double#NaN.

public static LinearTransformation
horizontal(double y)

Builds an instance representing a horizontal transformation with a constant value of y.

public abstract LinearTransformation
inverse()

Returns the inverse linear transformation.

public abstract boolean
isHorizontal()

Returns whether this is a horizontal transformation.

public abstract boolean
isVertical()

Returns whether this is a vertical transformation.

public static LinearTransformation.LinearTransformationBuilder
mapping(double x1, double y1)

Start building an instance which maps x = x1 to y = y1.

public abstract double
slope()

Returns the slope of the transformation, i.e. the rate of change of y with respect to x.

public abstract double
transform(double x)

Returns the y corresponding to the given x.

public static LinearTransformation
vertical(double x)

Builds an instance representing a vertical transformation with a constant value of x.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

LinearTransformationback to summary
public LinearTransformation()

Method Detail

forNaNback to summary
public static LinearTransformation forNaN()

Builds an instance for datasets which contains Double#NaN. The isHorizontal and isVertical methods return false and the slope, and transform methods all return Double#NaN. The inverse method returns the same instance.

horizontalback to summary
public static LinearTransformation horizontal(double y)

Builds an instance representing a horizontal transformation with a constant value of y. (The inverse of this will be a vertical transformation.)

inverseback to summary
public abstract LinearTransformation inverse()

Returns the inverse linear transformation. The inverse of a horizontal transformation is a vertical transformation, and vice versa. The inverse of the forNaN transformation is itself. In all other cases, the inverse is a transformation such that applying both the original transformation and its inverse to a value gives you the original value give-or-take numerical errors. Calling this method multiple times on the same instance will always return the same instance. Calling this method on the result of calling this method on an instance will always return that original instance.

isHorizontalback to summary
public abstract boolean isHorizontal()

Returns whether this is a horizontal transformation.

isVerticalback to summary
public abstract boolean isVertical()

Returns whether this is a vertical transformation.

mappingback to summary
public static LinearTransformation.LinearTransformationBuilder mapping(double x1, double y1)

Start building an instance which maps x = x1 to y = y1. Both arguments must be finite. Call either LinearTransformationBuilder#and or LinearTransformationBuilder#withSlope on the returned object to finish building the instance.

slopeback to summary
public abstract double slope()

Returns the slope of the transformation, i.e. the rate of change of y with respect to x. This must not be called on a vertical transformation (i.e. when isVertical() is true).

transformback to summary
public abstract double transform(double x)

Returns the y corresponding to the given x. This must not be called on a vertical transformation (i.e. when isVertical() is true).

verticalback to summary
public static LinearTransformation vertical(double x)

Builds an instance representing a vertical transformation with a constant value of x. (The inverse of this will be a horizontal transformation.)

com.google.common.math back to summary

public final Class LinearTransformation.LinearTransformationBuilder

extends Object
Class Inheritance
  • java.lang.Object
  • com.google.common.math.LinearTransformation.LinearTransformationBuilder

This is an intermediate stage in the construction process. It is returned by LinearTransformation#mapping. You almost certainly don't want to keep instances around, but instead use method chaining. This represents a single point mapping, i.e. a mapping between one x and y value pair.
Since
20.0

Field Summary

Modifier and TypeField and Description
private final double
private final double

Constructor Summary

AccessConstructor and Description
private
LinearTransformationBuilder(double x1, double y1)

Method Summary

Modifier and TypeMethod and Description
public LinearTransformation
and(double x2, double y2)

Finish building an instance which also maps x = x2 to y = y2.

public LinearTransformation
withSlope(double slope)

Finish building an instance with the given slope, i.e. the rate of change of y with respect to x.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

x1back to summary
private final double x1
y1back to summary
private final double y1

Constructor Detail

LinearTransformationBuilderback to summary
private LinearTransformationBuilder(double x1, double y1)

Method Detail

andback to summary
public LinearTransformation and(double x2, double y2)

Finish building an instance which also maps x = x2 to y = y2. These values must not both be identical to the values given in the first mapping. If only the x values are identical, the transformation is vertical. If only the y values are identical, the transformation is horizontal (i.e. the slope is zero).

withSlopeback to summary
public LinearTransformation withSlope(double slope)

Finish building an instance with the given slope, i.e. the rate of change of y with respect to x. The slope must not be NaN. It may be infinite, in which case the transformation is vertical. (If it is zero, the transformation is horizontal.)

com.google.common.math back to summary

private final Class LinearTransformation.NaNLinearTransformation

extends LinearTransformation
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv static final LinearTransformation.NaNLinearTransformation

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public LinearTransformation
inverse()

Implements abstract com.google.common.math.LinearTransformation.inverse.

Returns the inverse linear transformation.
public boolean
isHorizontal()

Implements abstract com.google.common.math.LinearTransformation.isHorizontal.

Returns whether this is a horizontal transformation.
public boolean
isVertical()

Implements abstract com.google.common.math.LinearTransformation.isVertical.

Returns whether this is a vertical transformation.
public double
slope()

Implements abstract com.google.common.math.LinearTransformation.slope.

Returns the slope of the transformation, i.e. the rate of change of y with respect to x.
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
public double
transform(double x)

Implements abstract com.google.common.math.LinearTransformation.transform.

Returns the y corresponding to the given x.
Inherited from com.google.common.math.LinearTransformation:
forNaNhorizontalmappingvertical

Field Detail

INSTANCEback to summary
pack-priv static final LinearTransformation.NaNLinearTransformation INSTANCE

Constructor Detail

NaNLinearTransformationback to summary
private NaNLinearTransformation()

Method Detail

inverseback to summary
public LinearTransformation inverse()

Implements abstract com.google.common.math.LinearTransformation.inverse.

Doc from com.google.common.math.LinearTransformation.inverse.

Returns the inverse linear transformation. The inverse of a horizontal transformation is a vertical transformation, and vice versa. The inverse of the forNaN transformation is itself. In all other cases, the inverse is a transformation such that applying both the original transformation and its inverse to a value gives you the original value give-or-take numerical errors. Calling this method multiple times on the same instance will always return the same instance. Calling this method on the result of calling this method on an instance will always return that original instance.

Annotations
@Override
isHorizontalback to summary
public boolean isHorizontal()

Implements abstract com.google.common.math.LinearTransformation.isHorizontal.

Doc from com.google.common.math.LinearTransformation.isHorizontal.

Returns whether this is a horizontal transformation.

Annotations
@Override
isVerticalback to summary
public boolean isVertical()

Implements abstract com.google.common.math.LinearTransformation.isVertical.

Doc from com.google.common.math.LinearTransformation.isVertical.

Returns whether this is a vertical transformation.

Annotations
@Override
slopeback to summary
public double slope()

Implements abstract com.google.common.math.LinearTransformation.slope.

Doc from com.google.common.math.LinearTransformation.slope.

Returns the slope of the transformation, i.e. the rate of change of y with respect to x. This must not be called on a vertical transformation (i.e. when isVertical() is true).

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
transformback to summary
public double transform(double x)

Implements abstract com.google.common.math.LinearTransformation.transform.

Doc from com.google.common.math.LinearTransformation.transform.

Returns the y corresponding to the given x. This must not be called on a vertical transformation (i.e. when isVertical() is true).

Annotations
@Override
com.google.common.math back to summary

private final Class LinearTransformation.RegularLinearTransformation

extends LinearTransformation
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv LinearTransformation
pack-priv final double
pack-priv final double

Constructor Summary

AccessConstructor and Description
pack-priv
RegularLinearTransformation(double slope, double yIntercept)

pack-priv
RegularLinearTransformation(double slope, double yIntercept, LinearTransformation inverse)

Method Summary

Modifier and TypeMethod and Description
private LinearTransformation
public LinearTransformation
inverse()

Implements abstract com.google.common.math.LinearTransformation.inverse.

Returns the inverse linear transformation.
public boolean
isHorizontal()

Implements abstract com.google.common.math.LinearTransformation.isHorizontal.

Returns whether this is a horizontal transformation.
public boolean
isVertical()

Implements abstract com.google.common.math.LinearTransformation.isVertical.

Returns whether this is a vertical transformation.
public double
slope()

Implements abstract com.google.common.math.LinearTransformation.slope.

Returns the slope of the transformation, i.e. the rate of change of y with respect to x.
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
public double
transform(double x)

Implements abstract com.google.common.math.LinearTransformation.transform.

Returns the y corresponding to the given x.
Inherited from com.google.common.math.LinearTransformation:
forNaNhorizontalmappingvertical

Field Detail

inverseback to summary
pack-priv LinearTransformation inverse
Annotations
@CheckForNull
@LazyInit
slopeback to summary
pack-priv final double slope
yInterceptback to summary
pack-priv final double yIntercept

Constructor Detail

RegularLinearTransformationback to summary
pack-priv RegularLinearTransformation(double slope, double yIntercept)
RegularLinearTransformationback to summary
pack-priv RegularLinearTransformation(double slope, double yIntercept, LinearTransformation inverse)

Method Detail

createInverseback to summary
private LinearTransformation createInverse()
inverseback to summary
public LinearTransformation inverse()

Implements abstract com.google.common.math.LinearTransformation.inverse.

Doc from com.google.common.math.LinearTransformation.inverse.

Returns the inverse linear transformation. The inverse of a horizontal transformation is a vertical transformation, and vice versa. The inverse of the forNaN transformation is itself. In all other cases, the inverse is a transformation such that applying both the original transformation and its inverse to a value gives you the original value give-or-take numerical errors. Calling this method multiple times on the same instance will always return the same instance. Calling this method on the result of calling this method on an instance will always return that original instance.

Annotations
@Override
isHorizontalback to summary
public boolean isHorizontal()

Implements abstract com.google.common.math.LinearTransformation.isHorizontal.

Doc from com.google.common.math.LinearTransformation.isHorizontal.

Returns whether this is a horizontal transformation.

Annotations
@Override
isVerticalback to summary
public boolean isVertical()

Implements abstract com.google.common.math.LinearTransformation.isVertical.

Doc from com.google.common.math.LinearTransformation.isVertical.

Returns whether this is a vertical transformation.

Annotations
@Override
slopeback to summary
public double slope()

Implements abstract com.google.common.math.LinearTransformation.slope.

Doc from com.google.common.math.LinearTransformation.slope.

Returns the slope of the transformation, i.e. the rate of change of y with respect to x. This must not be called on a vertical transformation (i.e. when isVertical() is true).

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
transformback to summary
public double transform(double x)

Implements abstract com.google.common.math.LinearTransformation.transform.

Doc from com.google.common.math.LinearTransformation.transform.

Returns the y corresponding to the given x. This must not be called on a vertical transformation (i.e. when isVertical() is true).

Annotations
@Override
com.google.common.math back to summary

private final Class LinearTransformation.VerticalLinearTransformation

extends LinearTransformation
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv LinearTransformation
pack-priv final double
x

Constructor Summary

AccessConstructor and Description
pack-priv
pack-priv

Method Summary

Modifier and TypeMethod and Description
private LinearTransformation
public LinearTransformation
inverse()

Implements abstract com.google.common.math.LinearTransformation.inverse.

Returns the inverse linear transformation.
public boolean
isHorizontal()

Implements abstract com.google.common.math.LinearTransformation.isHorizontal.

Returns whether this is a horizontal transformation.
public boolean
isVertical()

Implements abstract com.google.common.math.LinearTransformation.isVertical.

Returns whether this is a vertical transformation.
public double
slope()

Implements abstract com.google.common.math.LinearTransformation.slope.

Returns the slope of the transformation, i.e. the rate of change of y with respect to x.
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
public double
transform(double x)

Implements abstract com.google.common.math.LinearTransformation.transform.

Returns the y corresponding to the given x.
Inherited from com.google.common.math.LinearTransformation:
forNaNhorizontalmappingvertical

Field Detail

inverseback to summary
pack-priv LinearTransformation inverse
Annotations
@CheckForNull
@LazyInit
xback to summary
pack-priv final double x

Constructor Detail

VerticalLinearTransformationback to summary
pack-priv VerticalLinearTransformation(double x)
VerticalLinearTransformationback to summary
pack-priv VerticalLinearTransformation(double x, LinearTransformation inverse)

Method Detail

createInverseback to summary
private LinearTransformation createInverse()
inverseback to summary
public LinearTransformation inverse()

Implements abstract com.google.common.math.LinearTransformation.inverse.

Doc from com.google.common.math.LinearTransformation.inverse.

Returns the inverse linear transformation. The inverse of a horizontal transformation is a vertical transformation, and vice versa. The inverse of the forNaN transformation is itself. In all other cases, the inverse is a transformation such that applying both the original transformation and its inverse to a value gives you the original value give-or-take numerical errors. Calling this method multiple times on the same instance will always return the same instance. Calling this method on the result of calling this method on an instance will always return that original instance.

Annotations
@Override
isHorizontalback to summary
public boolean isHorizontal()

Implements abstract com.google.common.math.LinearTransformation.isHorizontal.

Doc from com.google.common.math.LinearTransformation.isHorizontal.

Returns whether this is a horizontal transformation.

Annotations
@Override
isVerticalback to summary
public boolean isVertical()

Implements abstract com.google.common.math.LinearTransformation.isVertical.

Doc from com.google.common.math.LinearTransformation.isVertical.

Returns whether this is a vertical transformation.

Annotations
@Override
slopeback to summary
public double slope()

Implements abstract com.google.common.math.LinearTransformation.slope.

Doc from com.google.common.math.LinearTransformation.slope.

Returns the slope of the transformation, i.e. the rate of change of y with respect to x. This must not be called on a vertical transformation (i.e. when isVertical() is true).

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
transformback to summary
public double transform(double x)

Implements abstract com.google.common.math.LinearTransformation.transform.

Doc from com.google.common.math.LinearTransformation.transform.

Returns the y corresponding to the given x. This must not be called on a vertical transformation (i.e. when isVertical() is true).

Annotations
@Override