FB_ALY_LinearRegressionInference

The Linear Regression Inference function block calculates the linear combination of the inputs (Input 01 .. Input 0n) with the coefficients (Weights 00.. Weights 0n).

FB_ALY_LinearRegressionInference 1:

The parameters Weights 00 to Weights 0n can either be set manually or automatically via a file generated by the Linear Regression Fitting function block by dragging / dropping onto the parameter field. Typically, the Linear Regression Fitting function block is first used to fit the weights for the regression of a target variable. Then, using the Linear Regression Inference function block and the fitted weights, the target variable can be predicted based on the input variables.

Syntax

Definition:

FUNCTION_BLOCK FB_ALY_LinearRegressionInference
VAR_OUTPUT
    ipResultMessage: Tc3_EventLogger.I_TcMessage;
    bError: BOOL; 
    bNewResult: BOOL;
    bConfigured: BOOL;
    bBusy: BOOL;
    eState: E_ALY_ConfigState;
    stFileHeader: ST_ALY_FileHeader;
    fResult : LREAL;
END_VAR

FB_ALY_LinearRegressionInference 2: Outputs

Name

Type

Description

ipResultMessage

I_TcMessage

Contains more detailed information on the current return value. This special interface pointer is internally secured so that it is always valid/assigned.

bError

BOOL

This output is TRUE if an error occurs.

bNewResult

BOOL

When a new result has been calculated, the output is TRUE.

bConfigured

BOOL

Displays TRUE when the function block is successfully configured.

bBusy

BOOL

TRUE if the FB is active due to a file access.

eState

E_ALY_ConfigState

Configuration status of the function block.

stFileHeader

ST_ALY_FileHeader

Header information of the file that was read.

fResult

LREAL

Specifies the value calculated from the linear combination.

FB_ALY_LinearRegressionInference 3:Methods

Name

Definition location

Description

Call()

Local

Method for calculating the outputs for a specific configuration.

Configure()

Local

General configuration of the algorithm after the individual coefficients have been set.

ConfigureChannel()

Local

Configuration of the coefficients.

ConfigureFromFile()

Local

Configuration of the algorithm via a previously created file.

FB_init

Local

Initializes the number of input channels.

GetBusyState()

Local

This method returns the Busy state of the function block.

Reset()

Local

Resets all internal states or the calculations performed so far.

SetChannelValue()

Local

Method for passing values to the algorithm.

UpdateState()

Local

Updating the state after a state change has been initiated and while the target state has not been reached.

Example – Configuration by parameters

VAR
    fbLinearRegressionInference : FB_ALY_LinearRegressionInference(nNumChannels := 1);
    fCoefficient0 : LREAL := 10.0;
    fCoefficient1 : LREAL := 1.0;
    bConfigure : BOOL := TRUE;
    fInputX : LREAL;
END_VAR
// Configure algorithm
IF bConfigure THEN
    bConfigure := FALSE;
    
    fbLinearRegressionInference.ConfigureChannel(0, fCoefficient0);
    fbLinearRegressionInference.ConfigureChannel(1, fCoefficient1);
    fbLinearRegressionInference.Configure(); 
END_IF

// Call algorithm
fbLinearRegressionInference.SetChannelValue(1, fInputX);
fbLinearRegressionInference.Call();
END_CASE

Sample – Configuration by file

VAR
    fbLinearRegressionInference : FB_ALY_LinearRegressionInference(nNumChannels := 1);
    tTimeout : TIME := T#5S;
    sFilePath : STRING := 'C:\TwinCAT\3.1\Boot\LinearRegressionFitting.tas';
    bConfigure : BOOL := TRUE;
    fInputX : LREAL;
END_VAR
// Configure algorithm
IF bConfigure THEN
    bConfigure := FALSE;
    fbLinearRegressionInference.ConfigureFromFile(tTimeout, sFilePath);
END_IF

// Update pending state
IF fbLinearRegressionInference.eState = E_ALY_ConfigState.Pending THEN
    fbLinearRegressionInference.UpdateState();    
END_IF

// Call algorithm
IF fbLinearRegressionInference.eState = E_ALY_ConfigState.Configured THEN
    fbLinearRegressionInference.SetChannelValue(1, fInputX);
    fbLinearRegressionInference.Call();
END_IF

Requirements

Development environment

Target platform

Plc libraries to include

TwinCAT v3.1.4024.0

PC or CX (x64, x86)

Tc3_Analytics