Generated reference › One Class SVM Score — Machine Learning/Anomaly Detection
kind: generated#block#machine-learning-anomaly-detection

One Class SVM Score — Machine Learning/Anomaly Detection

Machine_Learning/Anomaly_Detection/One_Class_SVM_Score · 1 input / 2 output port(s) at insert · exports to Python, MATLAB, Java, Rust, C, C++, VHDL, Verilog, SystemVerilog, PLC Structured Text

Description#

The block's own DESCRIPTION_HTML, rendered verbatim — the same text the config dialog's info panel and the library navigator show. Fix a wrong sentence in the block's .cpp (R-D9), never here.

One Class SVM Score

Machine Learning / Anomaly Detection

Scores a sample against a fitted one-class SVM – a boundary drawn around what the training data looked like – and says whether it falls outside:

score = intercept + Σi coefi·K(svi, u), and outlier = 1 when score < 0, 0 otherwise.

This is the same kernel machine as SVM Predictor, read differently: the sign is the decision and the magnitude is how far inside or outside the boundary the sample sits. It answers "does this look like the data the model was trained on?", which is the question to ask before trusting any other model's output on the same sample.

Ports

  • u – the feature vector, a column [d,1], where d must equal the number of columns of Support Vectors.
  • score – a scalar [1,1]: signed distance to the boundary in kernel units. Positive is inside (normal), negative is outside (novel), and the magnitude is the margin.
  • outlier – a scalar [1,1], 1 or 0: the decision on its own, for a monitor that wants to count, average or latch it. Emitted as a number rather than a boolean, so no backend needs a type the others lack.

Parameters

Identical to SVM Predictor's, and read the same way – the two blocks share one implementation, so a model pasted into either means the same thing.

  • Support Vectors – an [N,d] matrix, one support vector per row: scikit-learn's support_vectors_, so it pastes in without transposing.
  • Dual CoefficientsN values, scikit-learn's dual_coef_, which already carry their sign.
  • Intercept – ⚠ a scalar, and for a one-class model this is offset_, not offset_. scikit-learn reports an offset it subtracts; this block adds an intercept, so paste the negated value and the sign convention then matches decision_function exactly – positive inside, negative outside.
  • KernelRBF (Gaussian) (the default, and what almost every fitted one-class SVM uses), Linear, or Polynomial. See SVM Predictor for the three formulas.
  • Gamma, Coef0, Degree – the kernel's own parameters, as on that block.
  • Sampling Time (s) – zero or less inherits the solver's rate; a positive value runs the block at that period.

Code export

All ten targets: Python, MATLAB, Java, Rust, C, C++, VHDL, Verilog, SystemVerilog and PLC Structured Text. The whole model is baked in at export time; there is no tunable parameter.

Linear and Polynomial export to genuine Q16.16 fixed point on the three HDL targets – they are multiply-accumulate only, and the linear kernel additionally folds to a single weight vector. RBF has an exponential, so its three HDL bodies are simulation-only real arithmetic that quantizes at the port boundary. Since RBF is the default here and by far the common case for a one-class model, expect this block's HDL rows to be the simulation-only ones in practice.

Simulink bridge

None. One-class SVM prediction belongs to the Statistics and Machine Learning Toolbox, which is not installed on this machine, and its predict blocks take a fitted model object that no parameter mapping could carry. The bridge reports the block rather than dropping it silently, and it has no parity testbench, which is the documented consequence of Support::None. Code export verification still covers it across all ten languages, in every kernel.

Notes

  • Algebraic and stateless, and deliberately carries no state space: the outlier flag is a discontinuous function of the input, which no A/B/C/D describes.
  • The flag is discontinuous at the boundary, so the three HDL targets can disagree with the simulation on a sample whose score sits within one Q16.16 quantum (about 1.5e-5) of zero. Threshold the score downstream in floating point if that matters – and note that a sample sitting exactly on a novelty boundary is, by construction, one the model has no opinion about.
  • Pairs with the cheaper monitors rather than replacing them. Input Domain Monitor asks whether each feature is in the range it was fitted on, and Mahalanobis Distance asks how far the sample is from the mean under one covariance. This block draws an arbitrary, possibly non-convex boundary, which is what it is for – and it costs N kernel evaluations per sample to do it.

Code facts#

FactValue
registered typeMachine_Learning/Anomaly_Detection/One_Class_SVM_Score
familyMachine_Learning/Anomaly_Detection
solver environment classICoreBlock_0_Machine_Learning_1_Anomaly_Detection_2_One_Class_SVM_Score
sourcesrc/ICoreSDK/ICoreBlockLibrary/Blocks/Machine_Learning/Anomaly_Detection/One_Class_SVM_Score/ICoreBlock_0_Machine_Learning_1_Anomaly_Detection_2_One_Class_SVM_Score.cpp
headersrc/ICoreSDK/ICoreBlockLibrary/Blocks/Machine_Learning/Anomaly_Detection/One_Class_SVM_Score/ICoreBlock_0_Machine_Learning_1_Anomaly_Detection_2_One_Class_SVM_Score.h
default size on canvas140 × 90 px
ports at insert1 in, 2 out
code generators implementedPython, MATLAB, Java, Rust, C, C++, VHDL, Verilog, SystemVerilog, PLC Structured Text

Ports#

#DirectionSignal typeDescription label
1inICoreDoubleu
2outICoreDoublescore
3outICoreDoubleoutlier

Ports the constructor creates. A block whose port list changes with its configuration adds or removes ports at load time; the count above is the one a freshly inserted block has.

Configuration variables#

Config variableDefaultSimulink parameter
Support Vectors[0.6 0.2; -0.5 0.4; 0.1 -0.7]
Dual Coefficients[0.4; 0.35; 0.25]
Intercept-0.5
Kernelsvm::kernelComboSpec()
Gamma0.5
Coef00
Degree3

Every block also carries Sampling Time (s) from ICoreBlockSolverEnvironment: zero or less inherits the solver's rate, a positive value runs the block at that period.

supportSupport::None
Simulink path
port-count rulePortsParam::None
SampleTime parameteryes

Caveat (shown to the user): no Simulink equivalent available: one-class SVM prediction lives in the Statistics and Machine Learning Toolbox, which is not installed on this machine, and its predict blocks take a fitted model OBJECT rather than parameters -- there is no ParamRule that could carry a support-vector set and its kernel across

Catalog contract: src/ICoreSDK/ICoreCoder/ICoreCommandSystem/SimulinkBridge/ICoreSimulinkBlockCatalog.h

Description vs code#

The checker has a blind spot here — it could not resolve something (a grouped port bullet, a computed config name), which is reported and never counted as a pass. A reader has to settle it:

  • B0 every stimulus in the sample errored — cross-checks skipped

The verdict above is tools/docs/check_block_descriptions.py (P7.1), which compares LISTS. It cannot read a sentence: "stateless" on a block with a state, an initial-value semantic the recursion does not implement, a "not synthesizable" caveat the HDL banner contradicts. That is the agent audit (P7.3) on BLOCK_DESCRIPTION_AUDIT.md, and this tool's green is not a substitute for one.

File banner (developer view)#

The top comment of the block's .cpp — the maths, the realization and the export strategy, addressed to whoever changes it. It must not contradict the description above (P7.5).

One Class SVM Score — novelty against a fitted boundary score = intercept + SUM_i coef_i * K(sv_i, u) outlier = 1 when score < 0, else 0

The kernel machine is ICoreSvmKernelSupport's, shared verbatim with Classical_Models/SVM_Predictor -- this file is the block around it. The two differ in one line of arithmetic (a 0/1 flag rather than a +/-1 label) and in what the score MEANS.

The test is spelled score < 0 -> outlier in every backend, never >= 0 -> inlier in some and < 0 in others: the two disagree on a score of exactly zero, which is the sample a fixed-point backend is most likely to produce, and the flag is a whole step apart.

Sample results#

No stimulus produced a sampled output in this rig — Invalid model at: ICore Blocks/Home/One Class SVM Score. That is a fact about the single-block rig, not a verdict on the block: an offline batch fit, a block whose output only appears at onSolverFinish, or one that needs a driven environment cannot be exercised alone.

Category unsampled · sample time 0.1 · 60 steps · commit ccf005c8 · produced by docsSample --out <folder> --steps 60

Sample data: docs/generated/samples/Machine_Learning__Anomaly_Detection__One_Class_SVM_Score.json