Record Class LogTransformSpec
- Record Components:
a- The offset added before taking the log (or subtracted after exponentiating when unlogging).base- The base of the logarithm; 0 means the natural log and base e.unlog- True to apply the inverse transform, false to apply the log transform.
Logging applies f(x) = log_base(a + x); unlogging applies its inverse g(x) = base^x - a. A base of 0 means the natural log and base e, matching the convention used by the dataset-wide transform.
All three fields are per variable rather than per dataset because their correct values depend on the variable's scale. The offset in particular is scale-relative: since log(a + x) is approximately log(a) + x/a when x is much smaller than a, a single offset shared across variables of different magnitude performs a genuine logarithmic transform on the large-valued ones and an approximately affine rescaling on the small-valued ones. Keeping base and direction alongside the offset also guarantees that a transform can be inverted with the same spec.
- Author:
- josephramsey
-
Constructor Summary
ConstructorsConstructorDescriptionLogTransformSpec(double a, int base, boolean unlog) Creates an instance of aLogTransformSpecrecord class. -
Method Summary
Modifier and TypeMethodDescriptiondoublea()Returns the value of thearecord component.doubleapply(double x) Applies this spec to a single value.intbase()Returns the value of thebaserecord component.static Map<String, LogTransformSpec> Decodes a string produced byencode(java.util.Map).static Stringencode(Map<String, LogTransformSpec> specs) Encodes a map of specs as a single string, for storage in aParametersobject and hence in a saved session.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.static doublesafeOffsetFor(double[] column) Returns the smallest offset that keeps every value of the given column strictly positive under a log transform, or 0.0 if the column is already strictly positive.final StringtoString()Returns a string representation of this record class.booleanunlog()Returns the value of theunlogrecord component.
-
Constructor Details
-
LogTransformSpec
-
-
Method Details
-
apply
public double apply(double x) Applies this spec to a single value.- Parameters:
x- The value to transform.- Returns:
- The transformed value.
-
encode
Encodes a map of specs as a single string, for storage in aParametersobject and hence in a saved session.The format is one variable per line, with fields separated by tabs: name, offset, base, unlog. A string is used rather than a serialized object so that the stored form is stable across versions of this class and legible when a saved session is inspected; tab and newline are safe separators because a variable name containing either could not have been read from a delimited data file.
- Parameters:
specs- The specs to encode; may be null or empty.- Returns:
- The encoded string, empty if there is nothing to encode.
-
decode
Decodes a string produced byencode(java.util.Map). Malformed lines are skipped rather than throwing, so that a session saved by a later version with extra fields still opens.- Parameters:
encoded- The encoded string; may be null or empty.- Returns:
- The decoded specs, empty if there was nothing to decode.
-
safeOffsetFor
public static double safeOffsetFor(double[] column) Returns the smallest offset that keeps every value of the given column strictly positive under a log transform, or 0.0 if the column is already strictly positive. This is a convenience for editors that want to propose a safe default; it is not applied automatically anywhere.- Parameters:
column- The column values.- Returns:
- A safe offset for the column, or 0.0 if none is needed.
-
toString
-
hashCode
-
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with thecomparemethod from their corresponding wrapper classes. -
a
-
base
-
unlog
-