Spectroscopic data evaluation using chemometric prediction interface of the LabCognition software suite
$ dotnet add package LC.PredictorLC.Predictor is a .NET Standard 2.0 (C#) interface used in communication between a predictor software backend and a client software frontend. The chemometrics prediction API adds predictor capabilities to the client software using LabCognition or other third party backend software offering prediction capabilities.
The SamplePredictor implementation is demonstrating how to use this API within a third party client frontend software and Labcognition software as predictor backend software.
LC.Predictor superseeds parts of LabCognition.Interface (1.2.0). Interfaces and methods used in LabCognition.Interface have been revised and renamed. Here is a matrix depicting the changes:
| LabCognition.Interface (1.2.0) | LC.Predictor (0.1.0) | Action |
|---|---|---|
| IPredicitonEngine | IPredictor | renamed and methods changed |
| IPredictionEngineReport | no implemention! | deprecated; use IPredictor methods |
| object[,] Predict(double[] dataX, double[] dataY, string[] constituents, string[] properties); | IPredictionResult[]? Predict(double[] dataX, double[] dataY); | use type specific prediction results and changed the result output using IPredicitonResult |
| string[] GetProperties(); and string[] GetConstituents(); | IPredictionResult[]? GetResultPreview(); | changed concept by returning an empty preview containing flat PredictionResult<T> objects of the expected results rather than lists of properties and constituents |
Prediction means the calculation of a physical property like a concentration value from spectroscopic data using a multivariate calibration model.
The input of such prediction method is a spectrum in the form of x,y data and a calibration model created with LabCognition software.
The output of the prediction method are one or more quantitative and/or qualitative prediction results. Each result may be a numeric or a string value generated by the calibration model algorithm when performing a prediction.
At first you must create a calibration model with LabCognition or the modelling software implementing the LC.Predictor. Once created, the calibration model is typically a single file containing the recipe to convert spectroscopic data into the desired prediction result. A detailed description on how to do this is given elsewhere.
Performing prediction requires suitable spectra taken from physical samples as files in scientific file format or as x,y values in memory.
In case additional metadata shall be calibrated in combination with spectral data, it must be appended to the x,y data of the spectrum in order to transport it through the interface.
The calibration modelling software or the predictor software used in the backend providing the prediction capabilities must implement the Interfaces IPredictorFactory and IPredictor. This may be the LabCognition or another third party software. In the client frontend software you may implement the counterparts using these two interfaces as follows:
Create an instance of the application using one of the IPredictorFactory.ReadModelFromXXXX interface method. It will create an instance or the predictor software granting communication through IPredictor interface.
Additionally, it loads the desired calibration model into that instance:
You might need information upfront on all possible outputs a calibration model will return when running a prediction. The GetResultPreview() method returns a list of all the results you will get when performing a prediction.
Each result comes with some properties describing the result:
Value The main output you are interested in. In principle two value types are supported:
Unit This is an optional text describing the value's unit, if any
Property The result type such as predicted, residual, spectral residual, Mahalanobis disctance, etc. Some results refer to a particular constituent and others refer to general spectral properties.
Constituent The name of the predicted feature e.g. fat, protein, etc. in wheat. For spectral properties this is empty.
Since the value type is not unique for all results they are returned as IPredictionResult. Use the GetValueType() method in the IPredictionResult interface to identify the value type.
Call the Predict(double[] dataX, double[] dataY) method with your spectrum's x,y data to obtain the prediction results.