Software Development Kit (SDK): Difference between revisions

From Eigenvector Research Documentation Wiki
Jump to navigation Jump to search
No edit summary
 
(15 intermediate revisions by 3 users not shown)
Line 1: Line 1:
== Solo_Predictor Software Development Kit (SDK) Overview ==
== Solo_Predictor Software Development Kit (SDK) Overview ==


In order to facilitate communication with and operations in Solo_Predictor from external environments, Eigenvector Research provides a software development kit (SDK) for common application languages.  At this time the SDK is available in Python.  Matlab, Java, and C# ports are planned for later release. Contact the help desk at helpdesk@eigenvector.com to obtain the SDK package.
In order to facilitate communication with and operations in Solo_Predictor from external environments, Eigenvector Research provides a software development kit (SDK) for common application languages.  At this time the SDK is available in Python, MATLAB, and C#.  A Java port is planned at a later time. '''Contact the help desk at helpdesk@eigenvector.com to obtain the SDK package'''.


The SDK includes a number of methods which cover a signification portion of common usage for deploying an existing model with new data.  Description of the methods - inputs, outputs, options - may be found in the above table.  These methods will, for the most part, be common across all platform and exceptions will be clearly noted.
The SDK includes a number of methods that cover a signification portion of common usage for deploying an existing model with new data.  A description of the methods - inputs, outputs, options - may be found in the above table.  These methods will, for the most part, be common across all platforms and exceptions will be clearly noted.


 
== SDK Methods ==
 
=== SDK Methods ===
{| class="wikitable"
{| class="wikitable"
! method || function || arguments || returns
! method || function || arguments || Python returns || MATLAB returns || C# returns
|-
|-
| <code>getLastResponse()</code> || last response returned by Solo/Solo_Predictor, typically in XML format || none || string(plain or XML)
| <code>getLastResponse()</code> || last response returned by Solo/Solo_Predictor, typically in XML format || none || string(plain or XML) || string(plain or XML) || string(plain or XML)
|-
|-
| <code>getLastError()</code> || last error generated in operations || none || string(plain)
| <code>getLastError()</code> || last error generated in operations || none || string(plain) || string(plain) || string(plain)
|-
|-
| <code>clearVariables()</code> || clear all workspace variables || none || Boolean
| <code>clearVariables()</code> || clear all workspace variables || none || Boolean || Boolean || Boolean
|-
|-
| <code>listVariables()</code> || list of workspace variables || none || Python <code>list</code>
| <code>listVariables()</code> || list of workspace variables || none || <code>list</code> || <code>string array</code> || <code>string[]</code>
|-
|-
| <code>applyModel()</code> || apply workspace variable <code>mdl</code> to workspace variable <code>data</code> || none || Boolean
| <code>applyModel()</code> || apply workspace variable <code>mdl</code> to workspace variable <code>data</code> || none || Boolean || Boolean || Boolean
|-
|-
| <code>setDataFile(pathString)</code> || load specified file (method argument) and convert to workspace variable <code>data</code> || string - path to data file || Boolean
| <code>setDataFile(pathString)</code> || load specified file (method argument) and convert to workspace variable <code>data</code> || string - path to data file || Boolean || Boolean || Boolean
|-
|-
| <code>setModelFile(pathString)</code> || load specified file (method argument) and convert to workspace variable <code>mdl</code> || string - path to model file (.mat extension required) || Boolean
| <code>setModelFile(pathString)</code> || load specified file (method argument) and convert to workspace variable <code>mdl</code> || string - path to model file (.mat extension required) || Boolean || Boolean || Boolean
|-
|-
| <code>setOutputFormat(formatString)</code> || specify output format for prediction results - choice of Python <code>dict</code> or XML || string - choice of "dict" or "xml" (case insensitive) || Boolean
| <code>setOutputFormat(formatString)</code> || specify output format for prediction results - choice of <code>field->value</code> object or XML || string <br> <code>Python</code>: choice of "dict" or "xml" (case insensitive) <br> <code>MATLAB</code>: choice of "struct", "containers.Map", or "xml" <br> <code>C#</code>: choice of "dict" or "xml" || Boolean || Boolean || Boolean
|-
|-
| <code>setPort(portValue)</code> || specify communication port with Solo/Solo_Predictor || integer or string (which can be converted to integer) in the range of 1024:65535; default value = 2211 || Boolean
| <code>setPort(portValue)</code> || specify communication port with Solo/Solo_Predictor || integer or string (which can be converted to integer) in the range of 1024:65535; default value = 2211 || Boolean || Boolean || Boolean
|-
|-
| <code>setIPAddress(IPAddressString)</code> || specify IP address to communicate with Solo/Solo_Predictor || string with valid value for IP address; default value is 127.0.0.1 || Boolean
| <code>setIPAddress(IPAddressString)</code> || specify IP address to communicate with Solo/Solo_Predictor || string with valid value for IP address; default value is 127.0.0.1 || Boolean || Boolean || Boolean
|-
|-
| <code>getDataFile()</code> || return data file set by <code>setDataFile</code> || none || string(plain)
| <code>getDataFile()</code> || return data file set by <code>setDataFile</code> || none || string(plain) || string(plain) || string(plain)
|-
|-
| <code>getModelFile()</code> || return model file set by <code>setModelFile</code> || none || string(plain)
| <code>getModelFile()</code> || return model file set by <code>setModelFile</code> || none || string(plain) || string(plain) || string(plain)
|-
|-
| <code>getPort()</code> || return port value set by <code>setPort</code>/default value || none || integer
| <code>getPort()</code> || return port value set by <code>setPort</code>/default value || none || integer || integer || integer
|-
|-
| <code>getIPAddress()</code> || return IP address set by <code>setIPAddress</code>/default value || none || string(plain)
| <code>getIPAddress()</code> || return IP address set by <code>setIPAddress</code>/default value || none || string(plain) || string(plain) || string(plain)
|-
|-
| <code>getOutputFormat()</code> || return output format for model predictions as set by <code>setOutputFormat</code>/default value || none || string(plain)
| <code>getOutputFormat()</code> || return output format for model predictions as set by <code>setOutputFormat</code>/default value || none || string(plain) || string(plain) || string(plain)
|-
|-
| <code>getPredictionResults()</code> || return model prediction values as either Python <code>dict</code> or XML formatted dataset object || none || string(XML) or Python <code>dict</code>; empty string if error encountered
| <code>getPredictionResults()</code> || return model prediction values as either <code>field->value</code> object or XML formatted dataset object || none || string(XML) or <code>dict</code>; empty string if error encountered || string(XML), <code>struct</code>, or <code>containers.Map</code> || string(XML) or <code>Dictionary</code>
|-
|-
| <code>getModelInfo()</code> || return info from loaded model || none || string(plain)
| <code>getModelInfo()</code> || return info from loaded model || none || string(plain) || string(plain)|| string(plain)
|-
|-
| <code>getPredictionResultsVarNames()</code> || names of Python <code>dict</code> keys for prediction outputs || none || Python <code>list</code>
| <code>getPredictionResultsVarNames()</code> || fields of <code>field->value</code> object for prediction outputs || none || <code>list</code> || <code>string array</code> || <code>string[]</code>
|-
|-
| <code>getVersion(modeString)</code> || returns version information for Solo_Predictor || string with value of "terse" or "full"; default value (no input) is "terse" || string(plain) or Python <code>dict</code>
| <code>getVersion(modeString)</code> || returns version information for Solo_Predictor || string with value of "terse" or "full"; default value (no input) is "terse" || string(plain) or <code>dict</code> || string(plain) or <code>containers.Map</code> || string(plain) or <code>Dictionary</code>
|-
|-
| <code>runIncludeFile(pathString)</code> || execute content of text file pathString containing valid Solo scripting commands || string to text file containing valid Solo scripting commands || string(XML)
| <code>runIncludeFile(pathString)</code> || execute content of text file pathString containing valid Solo scripting commands || string to text file containing valid Solo scripting commands || string(XML) || string(XML) || string(XML)
|-
|-
| <code>getVersionSDK()</code> || return current version of SDK || none || string(plain)
| <code>getVersionSDK()</code> || return current version of SDK || none || string(plain) || string(plain) || string(plain)
|}
|}


A number of the methods return Boolean values indicating success or failure at completing the desired operation.  When a return value of <code>False</code> is obtained, detail surrounding the nature of the error may be found from the <code>.getLastError()</code> method.  It's important to note that communication errors with Solo_Predictor are '''not''' handled by the SDK.  As such, your code for communicating with Solo_Predictor should include the platform appropriate error trapping procedures for such instances.
A number of the methods return Boolean values indicating success or failure at completing the desired operation.  When a return value of <code>False</code> is obtained, detail surrounding the nature of the error may be found from the <code>.getLastError()</code> method.  It's important to note that communication errors with Solo_Predictor are '''not''' handled by the SDK.  As such, your code for communicating with Solo_Predictor should include the platform-appropriate error-trapping procedures for such instances.


=== Supported Models ===
== Supported Models ==


The following model types are supported by the SDK:
The following model types are supported by the SDK:
Line 80: Line 78:
:PARAFAC
:PARAFAC


=== Python Implementation ===
== Solo_Predictor Requirements ==
==== Requirements ====
The target Solo_Predictor must be running and have had its default.xml file modified so its "keywordonly" tag set = 0. See [https://www.wiki.eigenvector.com/index.php?title=Solo_Predictor_Installation_and_Configuration#Evriscript_Object_Use keywordonly]
 
== Python Requirements ==
 
The Python version of the SDK has been tested using Python versions 3.7 and 2.7.  The following table lists the versions of libraries used with the tested versions of Python:


The Python version of the SDK has been  tested on releases 2.7 and 3.7. The following libraries - appropriate to the installed version of Python - need to be installed for proper operation:
{| class="wikitable"
* <code>requests</code>
| '''library''' || Python 3.7 || Python 2.7
* <code>BeautifulSoup</code>
|-
* <code>numpy</code>
| <code>requests</code> || style="text-align:right;"|2.24 ||style="text-align:right;"|2.24
|-
| <code>bs4</code> ||style="text-align:right;"|4.9.1 ||style="text-align:right;"|4.9.1
|-
| <code>numpy</code> ||style="text-align:right;"|1.19.2 ||style="text-align:right;"|1.16.6
|-
| <code>lxml</code> ||style="text-align:right;"|4.5.2 ||style="text-align:right;"|4.5.2
|}


==== Example ====
== C# Requirements ==
{| class="wikitable"
| '''library''' || Version
|-
| <code>HtmlAgilityPack</code> ||style="text-align:right;"|1.11
|}
 
== Example ==
A working example is provided below with comments for many of the steps.
A working example is provided below with comments for many of the steps.


===== Configuration =====
=== Configuration ===
==== Python ====
<pre>from evrisdk import EvriSdk
<pre>from evrisdk import EvriSdk
curInstance = EvriSdk()
curInstance = EvriSdk()
curInstance.setIPAddress("127.0.0.1")
curInstance.setIPAddress("127.0.0.1")
curInstance.setPort(2211)</pre>
curInstance.setPort(2211)</pre>
==== MATLAB ====
<pre>curInstance = evrisdk()
curInstance.setIPAddress("127.0.0.1")
curInstance.setPort(2211)</pre>
==== C# ====
<pre>using evrisdk; // use in header
// then put the following in class instantiation
EvriSdk curInstance = new EvriSdk();
curInstance.setIPAddress("127.0.0.1");
curInstance.setPort(2211);</pre>


After creating an instance of the <code>EvriSdk</code> class, the next two lines set the IP address of the computer running Solo_Predictor (here using the <code>localhost</code> address) and the port.  The latter may be configured with the argument as either an integer or a string.  Note that these lines are somewhat redundant as the values provided are the default ones.
After creating an instance of the <code>EvriSdk</code> class, the next two lines set the IP address of the computer running Solo_Predictor (here using the <code>localhost</code> address) and the port.  The latter may be configured with the argument as either an integer or a string.  Note that these lines are somewhat redundant as the values provided are the default ones.


===== Solo_Predictor Workspace =====
=== Solo_Predictor Workspace ===


<pre>retVal = curInstance.clearVariables()
<pre>retVal = curInstance.clearVariables()
variableList = curInstance.listVariables()</pre>
variableList = curInstance.listVariables()</pre>


The <code>.clearVariables()</code> method will clear the Solo_Predictor workspace with a Boolean return indicating success or failure of the operation.  Verification of this step is accomplished from the <code>.listVariables()</code> method.
The <code>.clearVariables()</code> method will clear the Solo_Predictor workspace with a Boolean return indicating the success or failure of the operation.  Verification of this step is accomplished from the <code>.listVariables()</code> method.


===== Loading Data and Model =====
=== Loading Data and Model ===


The following code segment will a) load a data file, b) load a model file, c) get a list of the prediction outuputs from the model, and d) return information on the model (model type, date constructed, etc.):
The following code segment will a) load a data file, b) load a model file, c) get a list of the prediction outputs from the model, and d) return information on the model (model type, date constructed, etc.):


<pre>retVal        = curInstance.setDataFile(fullPathToDataFile)
<pre>retVal        = curInstance.setDataFile(fullPathToDataFile)
Line 114: Line 143:
predVarList  = curInstance.getPredictionResultsVarNames()
predVarList  = curInstance.getPredictionResultsVarNames()
modelInfo    = curInstance.getModelInfo()</pre>
modelInfo    = curInstance.getModelInfo()</pre>
==== C# ====
Make sure to have the data type of the returned variables:
<pre>bool retVal          = curInstance.setDataFile(fullPathToDataFile)
bool retVal          = curInstance.setModelFile(fullPathToModelFile)
var predVarList      = curInstance.getPredictionResultsVarNames()
string modelInfo    = curInstance.getModelInfo()</pre>


A few comments are in order:
A few comments are in order:


* data may be imported from any of the files supported by Solo_Predictor; see [[Solo_Predictor_Script_Construction\#Importing_From_a_File|this page for importing data into Solo_Predictor]]
* data may be imported from any of the files supported by Solo_Predictor; see this [[Solo_Predictor_Script_Construction#Importing_From_a_File|page for importing data into Solo_Predictor]]
* if data is imported from a Matlab file, the file may contain only one variable (at this time the SDK does not support importing specified variables from a Matlab file)
* if data is imported from a Matlab file, the file may contain only one variable (at this time the SDK does not support importing specified variables from a Matlab file)
* a Matlab file (file extension:  <code>.mat</code>) is expected for loading a model file.  Any other extension will result in an error
* a Matlab file (file extension:  <code>.mat</code>) is expected for loading a model file.  Any other extension will result in an error
** currently all EVRI model types are supported by the <code>.setModelFile</code> method except for calibration transfer and hierarchical models
** currently all EVRI model types are supported by the <code>.setModelFile</code> method except for calibration transfer and hierarchical models
* the Python <code>list</code> output will contain the variable sgenerated from from <code>model.plotscores(psops)</code>, where <code>psops</code> is a structure created from
* the Python <code>list</code> output will contain the variables generated from from <code>model.plotscores(psops)</code>, where <code>psops</code> is a structure created from
:<code>psops = plotscores('options');</code>
:<code>psops = plotscores('options');</code>
:<code>psops.reducedstats = {'q' 't2'};</code>
:<code>psops.reducedstats = {'q' 't2'};</code>


In a later section the difference between prediction output formats - Python <code>dict</code> <=> XML - is addressed.
=== Apply Model and Return Results ===
 
===== Apply Model and Return Results =====
Applying the model to the data and reviewing the outputs with some error trapping in the event the model application fails:
Applying the model to the data and reviewing the outputs with some error trapping in the event the model application fails:
 
==== Python ====
<pre>retVal  = curInstance.applyModel()
<pre>retVal  = curInstance.applyModel()
if retVal:
if retVal:
Line 137: Line 171:
         print(key, "=>", res[key])
         print(key, "=>", res[key])
else:
else:
     print curInstance.returnLastError()</pre>
     print(curInstance.returnLastError())</pre>
 
In the above, each value of <code>res[key]</code> will be a <code>numpy array</code> containing as many elements as there are samples in the data which has been loaded.
 
==== MATLAB ====
The following code assumes the output format is <code>containers.Map</code>.
<pre>retVal  = curInstance.applyModel();
if retVal
    curInstance.setOutputFormat("containers.Map");
    predResults = curInstance.getPredictionResults();
    fnames = keys(predResults);
    for i=1:length(fnames)
        disp([fnames{i} "=>", num2str(predResults(fnames{i}))]);
    end
else
    disp(curInstance.returnLastError())
end</pre>


In the above each value of <code>res[key]</code> will be a <code>numpy array</code> containing as many elements as there are samples in the data which has been loaded.
==== C# ====
The following code assumes the output format is <code>dict</code>.
<pre>bool retVal  = curInstance.applyModel();
if (retVal)
    {
    curInstance.setOutputFormat("dict");
    var pred = curInstance.getPredictionResults();
    foreach (var kvp in pred)
            {
                Console.WriteLine("Key = {0}, Value = {1}", kvp.Key, string.Join(", ",kvp.Value));
                Console.WriteLine();
            }
    }
else
    {
    Console.WriteLine(curInstance.returnLastError())
    }
</pre>


To look at the contents of the workspace:
To look at the contents of the workspace:
Line 192: Line 259:
     'Q Residuals Reduced': array([5.71331078e-05]), 'Hotelling T^2': array([1.636762e-05])}</pre>
     'Q Residuals Reduced': array([5.71331078e-05]), 'Hotelling T^2': array([1.636762e-05])}</pre>


The latter format provides only numerical results and the appropriate tags, in this case the <code>keys</code> of the Python <code>dict</code>.  The advantage of the form is that any metadata associated with mode 1 of the loaded data - labels, classes, axis scales - are copied to the prediction results output.  However, parsing of the XML output falls to the end user.
The latter format provides only numerical results and the appropriate tags, in this case, the <code>keys</code> of the Python <code>dict</code>.  The advantage of the former is that any metadata associated with mode 1 of the loaded data - labels, classes, axis scales - is copied to the prediction results output.  However, parsing of the XML output falls to the end user.
Output formats <code>containers.Map</code> or <code>struct</code> for Matlab, and <code>dict</code> for C# will generate similar results as what is shown above.


====.runIncludeFile Method ====
==.runIncludeFile Method ==


For more advanced operations, a text file containing valid SOlo scripting commands may be used with the <code>.runIncludeMethod</code>.  As an example,  
For more advanced operations, a text file containing valid [[Solo_Predictor_Script_Construction|Solo_Predictor scripting commands]] may be used with the <code>.runIncludeMethod</code>.  As an example,  


<pre>retVal = curInstance.runIncludeFile(FullPathToIncludeScript)</pre>
<pre>retVal = curInstance.runIncludeFile(FullPathToIncludeScript)</pre>
Line 208: Line 276:
</response></pre>
</response></pre>


for the following commands contained within the the script file:
for the following commands contained within the script file:


<pre>:clear
<pre>:clear
myMdl='FullPathToMOdelFile';
myMdl='FullPathToModelFile';
myData='FullPathToDataFile';
myData='FullPathToDataFile';
myPred=myMdl|myData;
myPred=myMdl|myData;

Latest revision as of 10:19, 14 May 2024

Solo_Predictor Software Development Kit (SDK) Overview

In order to facilitate communication with and operations in Solo_Predictor from external environments, Eigenvector Research provides a software development kit (SDK) for common application languages. At this time the SDK is available in Python, MATLAB, and C#. A Java port is planned at a later time. Contact the help desk at helpdesk@eigenvector.com to obtain the SDK package.

The SDK includes a number of methods that cover a signification portion of common usage for deploying an existing model with new data. A description of the methods - inputs, outputs, options - may be found in the above table. These methods will, for the most part, be common across all platforms and exceptions will be clearly noted.

SDK Methods

method function arguments Python returns MATLAB returns C# returns
getLastResponse() last response returned by Solo/Solo_Predictor, typically in XML format none string(plain or XML) string(plain or XML) string(plain or XML)
getLastError() last error generated in operations none string(plain) string(plain) string(plain)
clearVariables() clear all workspace variables none Boolean Boolean Boolean
listVariables() list of workspace variables none list string array string[]
applyModel() apply workspace variable mdl to workspace variable data none Boolean Boolean Boolean
setDataFile(pathString) load specified file (method argument) and convert to workspace variable data string - path to data file Boolean Boolean Boolean
setModelFile(pathString) load specified file (method argument) and convert to workspace variable mdl string - path to model file (.mat extension required) Boolean Boolean Boolean
setOutputFormat(formatString) specify output format for prediction results - choice of field->value object or XML string
Python: choice of "dict" or "xml" (case insensitive)
MATLAB: choice of "struct", "containers.Map", or "xml"
C#: choice of "dict" or "xml"
Boolean Boolean Boolean
setPort(portValue) specify communication port with Solo/Solo_Predictor integer or string (which can be converted to integer) in the range of 1024:65535; default value = 2211 Boolean Boolean Boolean
setIPAddress(IPAddressString) specify IP address to communicate with Solo/Solo_Predictor string with valid value for IP address; default value is 127.0.0.1 Boolean Boolean Boolean
getDataFile() return data file set by setDataFile none string(plain) string(plain) string(plain)
getModelFile() return model file set by setModelFile none string(plain) string(plain) string(plain)
getPort() return port value set by setPort/default value none integer integer integer
getIPAddress() return IP address set by setIPAddress/default value none string(plain) string(plain) string(plain)
getOutputFormat() return output format for model predictions as set by setOutputFormat/default value none string(plain) string(plain) string(plain)
getPredictionResults() return model prediction values as either field->value object or XML formatted dataset object none string(XML) or dict; empty string if error encountered string(XML), struct, or containers.Map string(XML) or Dictionary
getModelInfo() return info from loaded model none string(plain) string(plain) string(plain)
getPredictionResultsVarNames() fields of field->value object for prediction outputs none list string array string[]
getVersion(modeString) returns version information for Solo_Predictor string with value of "terse" or "full"; default value (no input) is "terse" string(plain) or dict string(plain) or containers.Map string(plain) or Dictionary
runIncludeFile(pathString) execute content of text file pathString containing valid Solo scripting commands string to text file containing valid Solo scripting commands string(XML) string(XML) string(XML)
getVersionSDK() return current version of SDK none string(plain) string(plain) string(plain)

A number of the methods return Boolean values indicating success or failure at completing the desired operation. When a return value of False is obtained, detail surrounding the nature of the error may be found from the .getLastError() method. It's important to note that communication errors with Solo_Predictor are not handled by the SDK. As such, your code for communicating with Solo_Predictor should include the platform-appropriate error-trapping procedures for such instances.

Supported Models

The following model types are supported by the SDK:

PCA
MCR
Regression models
PLS
PCR
LWR
SVM-R
MLR
CLS
ANN
XGB
Classification models
PLSDA
SIMCA
SVM-C
ANNDA
XGBDA
LREGDA
PARAFAC

Solo_Predictor Requirements

The target Solo_Predictor must be running and have had its default.xml file modified so its "keywordonly" tag set = 0. See keywordonly

Python Requirements

The Python version of the SDK has been tested using Python versions 3.7 and 2.7. The following table lists the versions of libraries used with the tested versions of Python:

library Python 3.7 Python 2.7
requests 2.24 2.24
bs4 4.9.1 4.9.1
numpy 1.19.2 1.16.6
lxml 4.5.2 4.5.2

C# Requirements

library Version
HtmlAgilityPack 1.11

Example

A working example is provided below with comments for many of the steps.

Configuration

Python

from evrisdk import EvriSdk
curInstance = EvriSdk()
curInstance.setIPAddress("127.0.0.1")
curInstance.setPort(2211)

MATLAB

curInstance = evrisdk()
curInstance.setIPAddress("127.0.0.1")
curInstance.setPort(2211)

C#

using evrisdk; // use in header
// then put the following in class instantiation
EvriSdk curInstance = new EvriSdk();
curInstance.setIPAddress("127.0.0.1");
curInstance.setPort(2211);

After creating an instance of the EvriSdk class, the next two lines set the IP address of the computer running Solo_Predictor (here using the localhost address) and the port. The latter may be configured with the argument as either an integer or a string. Note that these lines are somewhat redundant as the values provided are the default ones.

Solo_Predictor Workspace

retVal = curInstance.clearVariables()
variableList = curInstance.listVariables()

The .clearVariables() method will clear the Solo_Predictor workspace with a Boolean return indicating the success or failure of the operation. Verification of this step is accomplished from the .listVariables() method.

Loading Data and Model

The following code segment will a) load a data file, b) load a model file, c) get a list of the prediction outputs from the model, and d) return information on the model (model type, date constructed, etc.):

retVal        = curInstance.setDataFile(fullPathToDataFile)
retVal        = curInstance.setModelFile(fullPathToModelFile)
predVarList   = curInstance.getPredictionResultsVarNames()
modelInfo     = curInstance.getModelInfo()

C#

Make sure to have the data type of the returned variables:

bool retVal          = curInstance.setDataFile(fullPathToDataFile)
bool retVal          = curInstance.setModelFile(fullPathToModelFile)
var predVarList      = curInstance.getPredictionResultsVarNames()
string modelInfo     = curInstance.getModelInfo()

A few comments are in order:

  • data may be imported from any of the files supported by Solo_Predictor; see this page for importing data into Solo_Predictor
  • if data is imported from a Matlab file, the file may contain only one variable (at this time the SDK does not support importing specified variables from a Matlab file)
  • a Matlab file (file extension: .mat) is expected for loading a model file. Any other extension will result in an error
    • currently all EVRI model types are supported by the .setModelFile method except for calibration transfer and hierarchical models
  • the Python list output will contain the variables generated from from model.plotscores(psops), where psops is a structure created from
psops = plotscores('options');
psops.reducedstats = {'q' 't2'};

Apply Model and Return Results

Applying the model to the data and reviewing the outputs with some error trapping in the event the model application fails:

Python

retVal   = curInstance.applyModel()
if retVal:
    curInstance.setOutputFormat("dict")
    predResults = curInstance.getPredictionResults()
    for key in predResults:
        print(key, "=>", res[key])
else:
    print(curInstance.returnLastError())

In the above, each value of res[key] will be a numpy array containing as many elements as there are samples in the data which has been loaded.

MATLAB

The following code assumes the output format is containers.Map.

retVal   = curInstance.applyModel();
if retVal
    curInstance.setOutputFormat("containers.Map");
    predResults = curInstance.getPredictionResults();
    fnames = keys(predResults);
    for i=1:length(fnames)
        disp([fnames{i} "=>", num2str(predResults(fnames{i}))]);
    end
else
    disp(curInstance.returnLastError())
end

C#

The following code assumes the output format is dict.

bool retVal   = curInstance.applyModel();
if (retVal)
    {
    curInstance.setOutputFormat("dict");
    var pred = curInstance.getPredictionResults();
    foreach (var kvp in pred)
            {
                Console.WriteLine("Key = {0}, Value = {1}", kvp.Key, string.Join(", ",kvp.Value));
                Console.WriteLine();
            }
    }
else
    {
    Console.WriteLine(curInstance.returnLastError())
    }

To look at the contents of the workspace:

variableList = curInstance.listVariables()

IF XML output format is specified - curInstance.setOutputFormat("xml") - then the variable predResults will be an XML formatted string of the dataset object output. As an example, when applying a PCA model built in the arch demo dataset using 3 PCs and applying it to a test sample, specifying XML format results gives:

<response>
  <result class="dataset">
    <name class="string" />
    <type class="string">data</type>
    <author class="string" />
    <date class="numeric" size="[1,6]">2020,9,3,14,47,53.553401</date>
    <moddate class="numeric" size="[1,6]">2020,9,3,14,47,53.593668</moddate>
    <imagesize class="numeric" size="[0,0]" />
    <imagemode class="numeric" size="[0,0]" />
    <data class="numeric" size="[1,8]">-0.00223280606154,-0.00145155625614,-0.00357717299812,9.42744403283e-05,1.63676200186e-05,5.71331078063e-05,1.91433195948e-06,0.847852727433</data>
    <label class="cell" size="[2,1]">
      <tr>
        <td class="string" />
      </tr>
      <tr>
        <td class="string">
          <sr>Scores on PC 1       </sr>
          <sr>Scores on PC 2       </sr>
          <sr>Scores on PC 3       </sr>
          <sr>Q Residuals          </sr>
          <sr>Hotelling T^2        </sr>
          <sr>Q Residuals Reduced  </sr>
          <sr>Hotelling T^2 Reduced</sr>
          <sr>KNN Score Distance   </sr>
        </td>
      </tr>
    </label>
    <labelname class="cell" size="[2,1]">
      <tr>
        <td class="string" />
      </tr>
      <tr>
        <td class="string" />
      </tr>
    </labelname>
    <axisscale class="cell" size="[2,1]"> 
    . . .

By contrast, specifying Python dict returns the following:

    {'KNN Score Distance': array([0.84785273]), 'Hotelling T^2 Reduced': array([1.91433196e-06]), 
    'Q Residuals': array([9.42744403e-05]), 'Scores on PC 1': array([-0.00223281]), 
    'Scores on PC 3': array([-0.00357717]), 'Scores on PC 2': array([-0.00145156]), 
    'Q Residuals Reduced': array([5.71331078e-05]), 'Hotelling T^2': array([1.636762e-05])}

The latter format provides only numerical results and the appropriate tags, in this case, the keys of the Python dict. The advantage of the former is that any metadata associated with mode 1 of the loaded data - labels, classes, axis scales - is copied to the prediction results output. However, parsing of the XML output falls to the end user. Output formats containers.Map or struct for Matlab, and dict for C# will generate similar results as what is shown above.

.runIncludeFile Method

For more advanced operations, a text file containing valid Solo_Predictor scripting commands may be used with the .runIncludeMethod. As an example,

retVal = curInstance.runIncludeFile(FullPathToIncludeScript)

returns

<response>
  <result class="numeric" size="[1,3]">-0.00223280606154,-0.00145155625614,-0.00357717299812</result>
  <error class="string" />
  <date class="string">Thu 03 Sep 2020 15:25:52</date>
</response>

for the following commands contained within the script file:

:clear
myMdl='FullPathToModelFile';
myData='FullPathToDataFile';
myPred=myMdl|myData;
myPred.scores;

As previously, parsing of the XML output is the responsibility of the end user.