Main Content

cordicsigmoid

CORDIC-based approximation of sigmoid activation

Since R2023b

Description

Y = cordicsigmoid(X) computes the sigmoid activation of the numeric input X by applying the sigmoid transfer function. All values in Y are between 0 and 1.

To optimize the numerics for fixed-point input, the cordicsigmoid function implements the sigmoid activation using a CORDIC-based approximation of hyperbolic tangent, without computing the exponential.

Y=11+exp(X)=1tanh(X/2)2

example

Y = cordicsigmoid(X,N) additionally specifies the maximum shift value N in the CORDIC iterations. For fixed-point input X, the maximum shift value N is limited by the word length minus one.

example

Examples

collapse all

This example shows how to use the cordicsigmoid function to apply the sigmoid function to fixed-point input data.

x = fi(linspace(-10,10,100));
y = cordicsigmoid(x);
plot(x,y)

This example shows how to specify the maximum shift value in CORDIC iterations for the cordicsigmoid function.

wl = 11;
fl = 7;
nt = numerictype(1,wl,fl);

rDbl = range(nt);
nPts = min(2^18,2^wl);

xDbl = double(linspace(rDbl(1),rDbl(2),nPts));
x = fi(xDbl,nt);

for nIter = 5:5:10
    y = cordicsigmoid(x,nIter);
    plot(x,y);
    hold on;
end

yIdeal = 1 ./ ( 1 + exp(-double(x)));
plot(x,yIdeal);
hold off;

legend('N = 5','N = 10','Ideal')

Figure contains an axes object. The axes object contains 3 objects of type line. These objects represent N = 5, N = 10, Ideal.

Input Arguments

collapse all

Input data, specified as a scalar, vector, matrix, or multidimensional array.

When X is fixed point, then it must use binary-point scaling.

Data Types: single | double | fi

Maximum shift value in CORDIC iterations, specified as a real integer-valued scalar.

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

Output Arguments

collapse all

Sigmoid activations, returned as a vector. All values in Y are between 0 and 1.

When the input X is a floating-point data type, then the output Y has the same data type as the input X. When the input X is a fixed-point data type, then the output Y has a signed, fixed-point data type with the same word length as X and fraction length equal to two less than the word length.

Algorithms

collapse all

References

[1] Volder, Jack E. “The CORDIC Trigonometric Computing Technique.” IRE Transactions on Electronic Computers. EC-8, no. 3 (Sept. 1959): 330–334.

[2] Andraka, Ray. “A Survey of CORDIC Algorithm for FPGA Based Computers.” In Proceedings of the 1998 ACM/SIGDA Sixth International Symposium on Field Programmable Gate Arrays, 191–200. https://dl.acm.org/doi/10.1145/275107.275139.

[3] Walther, J.S. “A Unified Algorithm for Elementary Functions.” In Proceedings of the May 18-20, 1971 Spring Joint Computer Conference, 379–386. https://dl.acm.org/doi/10.1145/1478786.1478840.

[4] Schelin, Charles W. “Calculator Function Approximation.” The American Mathematical Monthly, no. 5 (May 1983): 317–325. https://doi.org/10.2307/2975781.

Extended Capabilities

expand all

Version History

Introduced in R2023b