Affine Transformation |
This topic contains the following sections:
Affine Transformation is linear transformation which maps an original vector space R m onto an image vector space R k and preserves geometrical proportions on lines in Euclidean space, that is, the collinearity relation between points (all points lying on a line still lie on a line after transformation) and ratios of distances along a line (e.g., the midpoint of a line segment remains the midpoint after transformation). But it does not necessarily preserve angles or lengths.
General form of an Affine Transformation is composition of a linear conversion and an additive translation (or "shift"); in matrix notation this composition is presented as the two-item expression:
Y[n x k] = X[n x m] W[m x k] + I[n] b[k]T,
where:
X[n x k] is the matrix presenting n observations in the original m-dimensional space;
The Y[n x k] matrix contains the result of transformation: n observations in the image k-dimensional space;
The W[m x k] matrix performs Rm -> Rk mapping (linear conversion);
The vector b[k] is the displacement vector, it contains shifts on k spatial coordinates applied to all the observations;
the member I[n] b[k]T presents the translation part of the transformation (I[n] is the unit column vector).
Matrices allow transformations to be represented in a consistent format, suitable for computation. This also allows linear conversions (rotation, isotropic, scaling, shear, etc.) to be combined into a single one easily by multiplying their matrices, so that the general formula above remains applicable.
Affine Transformation is implemented by the AffineTransformation class.
This class also provides basic interface for other Factor Analysis methods, Principal Component Analysis.
To initialize an instance of the class use one of the three constructors provided to perform either full or reduced transformation:
The first constructor specifies a transformation that performs both multiplication and addition, the second one is to apply just linear conversion (multiplication) and the last constructor is to use when only translation (addition) is needed.Tip |
---|
It is possible to use the first constructor to specify one of the reduced transformations passing null instead of one of the input parameters. |
Each of the constructors checks dimensionality of the input parameters and tries to compute matrix and/or vector of inverse transformation; if the input data are good for this then the instance of the class signals readiness via the properties:
Property | Description |
---|---|
Computation status: the returned value MethodSucceeded indicates that the class is ready to perform direct and inverse transformations. | |
Dimensionality of the original vector space. | |
Dimensionality of the target (image) vector space. |
Transforming is performed with Transform and InverseTransform methods that can operate either with single or multiple observations and provide results either via return type or write results into the supplied object:
Operation | Description |
---|---|
Direct transformations | Transform single observation: Transform multiple observations: |
Inverse transformations | Transform single observation: InverseTransform(Vector, Vector) Transform multiple observations: |
The example of AffineTransformation class usage:
1using System; 2using FinMath.LinearAlgebra; 3using FinMath.FactorAnalysis; 4 5namespace FinMath.Samples 6{ 7 class AffineTransformationSample 8 { 9 static void Main() 10 { 11 // Input parameters. 12 const Int32 seriesCount = 5; 13 const Int32 transformedSeriesCount = 3; 14 15 // Generate inputs. 16 Vector dataVector = Vector.Random(seriesCount); 17 Matrix transformMatrix = Matrix.Random(seriesCount, transformedSeriesCount); 18 Vector shiftVector1 = Vector.Random(seriesCount); 19 Vector shiftVector2 = Vector.Random(transformedSeriesCount); 20 Console.WriteLine("Input data vector: + dataVector: " + dataVector.ToString("0.000")); 21 Console.WriteLine("Transformation matrix (A):"); 22 Console.WriteLine(transformMatrix.ToString("0.000")); 23 Console.WriteLine("Shift vector (b1):" + shiftVector1.ToString("0.000")); 24 Console.WriteLine("Shift vector (b2):" + shiftVector2.ToString("0.000")); 25 26 // Perform transformation and output results. 27 Console.WriteLine("Results:"); 28 // y1 = x + b1. 29 AffineTransformation shiftTransform = new AffineTransformation(shiftVector1); 30 Console.WriteLine(" y1 = x + b1: " + shiftTransform.Transform(dataVector).ToString("0.000")); 31 32 // y2 = x * A. 33 AffineTransformation linearTransform = new AffineTransformation(transformMatrix); 34 Console.WriteLine(" y2 = x * A: " + linearTransform.Transform(dataVector).ToString("0.000")); 35 36 // y3 = x * A + b2. 37 AffineTransformation afineTransform = new AffineTransformation(transformMatrix, shiftVector2); 38 Console.WriteLine(" y2 = x * A: " + afineTransform.Transform(dataVector).ToString("0.000")); 39 40 // Combination y4 = (x + b1) * A + b2. 41 AffineTransformation combineTransform = afineTransform * shiftTransform; 42 Console.WriteLine(" y4 = (x + b1) * A + b2: " + combineTransform.Transform(dataVector).ToString("0.000")); 43 } 44 } 45}