Main Content

fixed.qlessqrFixedpointTypes

Determine fixed-point types for transforming A to R in-place, where R is upper-triangular factor of QR decomposition of A, without computing Q

Since R2021b

Description

T = fixed.qlessqrFixedpointTypes(m,max_abs_A,precisionBits) computes fixed-point types for transforming A to R in-place, where R is the upper-triangular factor of the QR decomposition of A, without computing Q. T is returned as a structure with field T.A containing a fi object that specifies the fixed-point type for A, which guarantees no overflow will occur in the QR algorithm.

The QR algorithm transforms A in-place into upper-triangular R, where QR=A is the QR decomposition of A.

example

T = fixed.qlessqrFixedpointTypes(m,max_abs_A,precisionBits,regularizationParameter) computes fixed-point types for transforming [λInA] in-place to R=Q'[λInA] where λ is the regularizationParameter, QR is the economy size QR decomposition of [λInA], A is an m-by-n matrix, and In = eye(n). regularizationParameter is an optional parameter. If not supplied or empty, then the default value is used.

T = fixed.qlessqrFixedpointTypes(___,maxWordLength) specifies the maximum word length of the fixed-point types. maxWordLength is an optional parameter. If not supplied or empty, then the default value is used.

Examples

collapse all

This example shows how to use fixed.qlessqrFixedpointTypes to analytically determine a fixed-point type for the computation of the Q-less QR decomposition.

Define Matrix Dimensions

Specify the number of rows and columns in matrix A.

m = 10; % Number of rows in matrix A
n = 3;  % Number of columns in matrix A

Generate Matrix A

Use the helper function realUniformRandomArray to generate a random matrix A such that the elements of A are between -1 and +1.

rng('default')
A = fixed.example.realUniformRandomArray(-1,1,m,n);

Select Fixed-Point Type

Use the fixed.qlessqrFixedpointTypes function to select the fixed-point data type for matrix A that guarantees no overflow will occur in the transformation of A in-place to R=QA.

max_abs_A = 1;  % Upper bound on max(abs(A(:))
precisionBits = 24;  % Number of bits of precision
T = fixed.qlessqrFixedpointTypes(m,max_abs_A,precisionBits)
T = struct with fields:
    A: [0x0 embedded.fi]

T.A is the type computed for transforming A to R=QA in-place so that it does not overflow.

T.A
ans = 

[]

          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Signed
            WordLength: 29
        FractionLength: 24

Use the Specified Type to Compute the Q-less QR Decomposition

Cast the input to the type determined by fixed.qlessqrFixedpointTypes.

A = cast(A,'like',T.A);

Accelerate fixed.qlessQR by using fiaccel to generate a MATLAB® executable (MEX) function.

fiaccel fixed.qlessQR -args {A} -o qlessQR_mex

Compute the QR decomposition.

R = qlessQR_mex(A);

Verify That R Is Upper-Triangular

R is an upper-triangular matrix.

R
R = 
    2.2180    0.8559   -0.5607
         0    2.0578   -0.4017
         0         0    1.7117

          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Signed
            WordLength: 29
        FractionLength: 24
isequal(R,triu(R))
ans = logical
   1

Verify the Accuracy of the Output

To evaluate the accuracy of the fixed.qlessQR function, compute the relative error.

R=QA, and Q is orthogonal, so RR=AQQA=AA, within rounding error.

relative_error = norm(double(R'*R - A'*A))/norm(double(A'*A))
relative_error = 
1.0699e-06

Suppress mlint warnings.

%#ok<*NOPTS>

Input Arguments

collapse all

Number of rows in A, specified as a positive integer-valued scalar.

Data Types: double

Maximum of the absolute value of A, specified as a scalar.

Example: max(abs(A(:)))

Data Types: double

Required number of bits of precision, specified as a positive integer-valued scalar.

Data Types: double

Regularization parameter, specified as a nonnegative scalar. Small, positive values of the regularization parameter can improve the conditioning of the problem and reduce the variance of the estimates. While biased, the reduced variance of the estimate often results in a smaller mean squared error when compared to least-squares estimates.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fi

Maximum word length of fixed-point types, specified as a positive integer.

If the word length of the fixed-point type exceeds the specified maximum word length, the default of 65535 bits is used.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fi

Output Arguments

collapse all

Fixed-point type for A, returned as a structure. The structure T has field T.A that contains a fi object that specifies a fixed-point type for A that guarantees no overflow will occur in the QR algorithm.

Algorithms

The number of integer bits required to prevent overflow is derived from the following bound on the growth of R [1]. The required number of integer bits is added to the number of bits of precision, precisionBits, of the input, plus one for the sign bit, plus one bit for intermediate CORDIC gain of approximately 1.6468 [2].

The elements of R are bounded in magnitude by

max(|R(:)|)mmax(|A(:)|).

References

[2] Voler, Jack E. "The CORDIC Trigonometric Computing Technique." IRE Transactions on Electronic Computers EC-8 (1959): 330-334.

Version History

Introduced in R2021b

expand all