F_VN_CreateLbgModel

F_VN_CreateLbgModel 1:

Create a LBG model of the specified type. The initial reference count is set to one if a new model is created and kept, otherwise. Models of this type neither support on-line training (sample by sample) nor retraining.

Syntax

Definition:

FUNCTION F_VN_CreateLbgModel : HRESULT
VAR_INPUT
    ipMlModel         : Reference To ITcVnMlModel;
    eLbgType          : ETcVnPrototypeClusterer;
    nMaxClusters      : UDINT;
    fMaxClusterRadius : LREAL;
    bSingleSplitSteps : BOOL;
    hrPrev            : HRESULT;
END_VAR

F_VN_CreateLbgModel 2: Inputs

Name

Type

Description

ipMlModel

Reference To ITcVnMlModel

Returns the created model (Non-zero interface pointers are reused.)

eLbgType

ETcVnPrototypeClusterer

LBG model type

nMaxClusters

UDINT

Maximum number of clusters

fMaxClusterRadius

LREAL

Maximum allowed radius (L2 norm) of a single cluster, i.e. clusters with a higher radius will be split into smaller ones, until a global number of nMaxClusters is reached.

bSingleSplitSteps

BOOL

If true, the global optimization is always run after a single cluster has been split. If false, several clusters are split within the same step before applying the global optimization. Applying the global optimization less often is faster, but can lead to less optimal results, especially having 2 nearby clusters that could be represented by 1.

hrPrev

HRESULT

HRESULT indicating the result of previous operations (If SUCCEEDED(hrPrev) equals false, no operation is executed.)

F_VN_CreateLbgModel 3: Return value

HRESULT

Further information

The function F_VN_CreateLbgModel creates a Linde-Buzo-Gray (LBG) model.

Linde-Buzo-Gray models

LBG models work similarly to K-Means++ models by iteratively adjusting the clusters to the samples. The main feature of LBG is that new clusters are created in the iteration process as soon as they are larger than fMaxClusterRadius (until the maximum number nMaxClusters is reached). With K-Means++, on the other hand, the number of clusters is set initially.

Parameter

Model

The created model is returned in the interface pointer ipMlModel.

Model type

eLbgType specifies whether LBG is used for clustering (TCVN_PC_CLUSTERER) or for anomaly detection (TCVN_PC_NOVELTY_DETECTOR).

Maximum number of clusters

If nMaxClusters exist in total due to the splitting of clusters that are too large, no more new clusters are created.

Maximum cluster radius

If the radius of a cluster becomes larger than fMaxClusterRadius during training, this cluster is split into two smaller clusters.

Optimization quality

Part of the iterative training process is a global optimization step. If bSingleSplitSteps = TRUE, this optimization is executed after each individual cluster split. This leads to a higher quality of clusters, but also to a longer training time. If bSingleSplitSteps = FALSE, the optimization is only executed after several clusters have been split.

Expert parameters

The expert variant F_VN_CreateLbgModelExp contains additional parameters.

Application

For example, an LBG model for clustering with 5 clusters, a maximum cluster size of 3.6 and high optimization quality can be created in this way:

hr := F_VN_CreateLbgModel(
    ipMlModel           := ipMlModel,
    eLbgType            := TCVN_PC_CLUSTERER,
    nMaxClusters        := 5,
    fMaxClusterRadius   := 3.6,
    bSingleSplitSteps   := TRUE,
    hrPrev              := hr);

Required License

TC3 Vision Machine Learning

System Requirements

Development environment

Target platform

PLC libraries to include

TwinCAT V3.1.4024.54 or later

PC or CX (x64) with PL50, e.g. Intel 4-core Atom CPU

Tc3_Vision