Version: 8.3.0
PMMLlib C++ examples

Create a neural network in a new PMML file :

    PMMLlib::PMMLlib p;

    // Set Header node
    p.SetHeader("copyright", "description", "name", "version", "annotation");  

    // Set DataDictionnary node and its DataField nodes
    int nInput = 8;
    vector<string>vfieldNameI(nInput);
    vfieldNameI[0] = "rw";
    vfieldNameI[1] = "r";
    vfieldNameI[2] = "tu";
    vfieldNameI[3] = "tl";
    vfieldNameI[4] = "hu";
    vfieldNameI[5] = "hl";
    vfieldNameI[6] = "l";
    VfieldNameI[7] = "kw";
    string fieldNameO("yhat"); 
    string opType = "continuous";
    string dataType =  "float";
    for(int j=0 ; j<nInput; j++)
    {
        p.AddDataField(vfieldNameI[j], vfieldNameI[j], opType, dataType, "ClosedClosed", 0., 0.);
    }      
    p.AddDataField(fieldNameO, fieldNameO, opType, dataType, "ClosedClosed", 0., 0.);      

    // Add a model of type NeuralNetwork   
    string modelName("sANNName");
    p.AddNeuralNetwork(modelName, PMMLlib::kREGRESSION);

    // Set MiningSchema  
    for(int j=0 ; j<nInput ; j++)
    {
        p.AddMiningSchema(vfieldNameI[j], "active");
    }
    p.AddMiningSchema(fieldNameO, "predicted"); 

    // Set NeuralInput
    double orig1=0; 
    vector<double>vnorm1(nInput);
    vnorm1[0] = -2.889932e-01;
    vnorm1[1] = -5.756638e-01;
    vnorm1[2] = -1.699313e-01;
    vnorm1[3] = -1.707007e-01;
    vnorm1[4] = -3.302777e-02;
    vnorm1[5] = -4.562070e-02;
    vnorm1[6] = -1.155882e-01;
    vnorm1[7] = -5.780019e-02;
    vector<double>vorig2(nInput);
    vorig2[0] = 9.999901e-02;
    vorig2[1] = 2.504894e+04;
    vorig2[2] = 8.933486e+04;
    vorig2[3] = 8.955232e+01;
    vorig2[4] = 1.050003e+03;
    vorig2[5] = 7.600007e+02;
    vorig2[6] = 1.400018e+03;
    vorig2[7] = 1.095001e+04;
    double norm2=0;
    for(int j=0 ; j<nInput ; j++)
    {
        p.AddNeuralInput(j, fieldName[j], opType, dataType, 
                                      vorig1, vnorm1[j], vorig2[j], vnorm2);
    }

    // Add first NeuralLayer and its neuron
    p.AddNeuralLayer(PMMLlib::kTANH);    
    int idN1 = 8;
    double bias1 = -1.263572;
    int conNb1 =  nWeights1;
    int from1 = 0;
    int nWeights1 = 8;
    vector<double>weights1(nWeights1);
    weights1[0] = 7.536629e-01;
    weights1[1] = 1.653660e-03;
    weights1[2] = 4.725001e-03;
    weights1[3] = 9.969786e-03;
    weights1[4] = 1.787976e-01;
    weights1[5] = -1.809809e-01;
    weights1[6] = -1.735688e-01;
    weights1[7] = 8.559675e-02; 
    p.AddNeuron(idN1, bias1, conNb1, from1, weights1);

    // Add second NeuralLayer and its neuron
    p.AddNeuralLayer(PMMLlib::kIDENTITY);
    int idN2 = 9;
    double bias2 = -1.745483;
    int conNb2 =  nWeights2;
    int from2 = 8;
    int nWeights2 = 1;
    vector<double>weights2(nWeights2);
    weights2[0] = 6.965512e+00;     
    p.AddNeuron(idN2, bias2, conNb2, from2, weights2);
 

    // Set NeuralOutput
    int idO = 9;
    double dorig1 = 0; 
    double dnorm1 = -5.873935e-01;
    double dorig2 = 7.781171e+01 ; 
    double dnorm2 = 0;
    p.AddNeuralOutput(idO, fieldNameO, opType, dataType,
                                     dorig1, dnorm1, dorig2, dnorm2);

    // Generate the PMML file
    string pmmlFilename = "myPmmlFile.pmml";
    p.Write( pmmlFilename );

The matching PMML file is:

<?xml version="1.0"?>
<PMML xmlns="http://www.dmg.org/PMML-4_1" version="version">
  <Header copyright="copyright" description="description">
    <Application name="PMMLlib" version="myVersion"/>
    <Annotation>Tests unitaires PMMLlib</Annotation>
  </Header>
  <DataDictionary>
    <DataField name="rw" displayName="rw" optype="continuous" dataType="float"/>
    <DataField name="r" displayName="r" optype="continuous" dataType="float"/>
    <DataField name="tu" displayName="tu" optype="continuous" dataType="float"/>
    <DataField name="tl" displayName="tl" optype="continuous" dataType="float"/>
    <DataField name="hu" displayName="hu" optype="continuous" dataType="float"/>
    <DataField name="hl" displayName="hl" optype="continuous" dataType="float"/>
    <DataField name="l" displayName="l" optype="continuous" dataType="float"/>
    <DataField name="kw" displayName="kw" optype="continuous" dataType="float"/>
    <DataField name="yhat" displayName="yhat" optype="continuous" dataType="float"/>
  </DataDictionary>
  <NeuralNetwork modelName="sANNName" functionName="regression" numberOfLayers="2">
    <MiningSchema>
      <MiningField name="rw" usageType="active"/>
      <MiningField name="r" usageType="active"/>
      <MiningField name="tu" usageType="active"/>
      <MiningField name="tl" usageType="active"/>
      <MiningField name="hu" usageType="active"/>
      <MiningField name="hl" usageType="active"/>
      <MiningField name="l" usageType="active"/>
      <MiningField name="kw" usageType="active"/>
      <MiningField name="yhat" usageType="predicted"/>
    </MiningSchema>
    <NeuralInputs numberOfInputs="8">
      <NeuralInput id="0">
        <DerivedField optype="continuous" dataType="float">
          <NormContinuous field="rw">
            <LinearNorm orig="0.000000e+00" norm="-2.889932e-01"/>
            <LinearNorm orig="9.999901e-02" norm="0.000000e+00"/>
          </NormContinuous>
        </DerivedField>
      </NeuralInput>
      <NeuralInput id="1">
        <DerivedField optype="continuous" dataType="float">
          <NormContinuous field="r">
            <LinearNorm orig="0.000000e+00" norm="-5.756638e-01"/>
            <LinearNorm orig="2.504894e+04" norm="0.000000e+00"/>
          </NormContinuous>
        </DerivedField>
      </NeuralInput>
      <NeuralInput id="2">
        <DerivedField optype="continuous" dataType="float">
          <NormContinuous field="tu">
            <LinearNorm orig="0.000000e+00" norm="-1.699313e-01"/>
            <LinearNorm orig="8.933486e+04" norm="0.000000e+00"/>
          </NormContinuous>
        </DerivedField>
      </NeuralInput>
      <NeuralInput id="3">
        <DerivedField optype="continuous" dataType="float">
          <NormContinuous field="tl">
            <LinearNorm orig="0.000000e+00" norm="-1.707007e-01"/>
            <LinearNorm orig="8.955232e+01" norm="0.000000e+00"/>
          </NormContinuous>
        </DerivedField>
      </NeuralInput>
      <NeuralInput id="4">
        <DerivedField optype="continuous" dataType="float">
          <NormContinuous field="hu">
            <LinearNorm orig="0.000000e+00" norm="-3.302777e-02"/>
            <LinearNorm orig="1.050003e+03" norm="0.000000e+00"/>
          </NormContinuous>
        </DerivedField>
      </NeuralInput>
      <NeuralInput id="5">
        <DerivedField optype="continuous" dataType="float">
          <NormContinuous field="hl">
            <LinearNorm orig="0.000000e+00" norm="-4.562070e-02"/>
            <LinearNorm orig="7.600007e+02" norm="0.000000e+00"/>
          </NormContinuous>
        </DerivedField>
      </NeuralInput>
      <NeuralInput id="6">
        <DerivedField optype="continuous" dataType="float">
          <NormContinuous field="l">
            <LinearNorm orig="0.000000e+00" norm="-1.155882e-01"/>
            <LinearNorm orig="1.400018e+03" norm="0.000000e+00"/>
          </NormContinuous>
        </DerivedField>
      </NeuralInput>
      <NeuralInput id="7">
        <DerivedField optype="continuous" dataType="float">
          <NormContinuous field="kw">
            <LinearNorm orig="0.000000e+00" norm="-5.780019e-02"/>
            <LinearNorm orig="1.095001e+04" norm="0.000000e+00"/>
          </NormContinuous>
        </DerivedField>
      </NeuralInput>
    </NeuralInputs>
    <NeuralLayer activationFunction="tanh" numberOfNeurons="1">
      <Neuron id="8" bias="-1.263572e+00">
        <Con from="0" weight="7.536629e-01"/>
        <Con from="1" weight="1.653660e-03"/>
        <Con from="2" weight="4.725001e-03"/>
        <Con from="3" weight="9.969786e-03"/>
        <Con from="4" weight="1.787976e-01"/>
        <Con from="5" weight="-1.809809e-01"/>
        <Con from="6" weight="-1.735688e-01"/>
        <Con from="7" weight="8.559675e-02"/>
      </Neuron>
    </NeuralLayer>
    <NeuralLayer activationFunction="identity" numberOfNeurons="1">
      <Neuron id="9" bias="-1.745483e+00">
        <Con from="8" weight="6.965512e+00"/>
      </Neuron>
  </DataDictionary>
    </NeuralLayer>
    <NeuralOutputs numberOfOutputs="1">
      <NeuralOutput outputNeuron="9">
        <DerivedField optype="continuous" dataType="float">
          <NormContinuous field="yhat">
            <LinearNorm orig="0.000000e+00" norm="-5.873935e-01"/>
            <LinearNorm orig="7.781171e+01" norm="0.000000e+00"/>
          </NormContinuous>
        </DerivedField>
      </NeuralOutput>
    </NeuralOutputs>
  </NeuralNetwork>
</PMML>

Create a regression model in new PMML file :

    PMMLlib::PMMLlib p;

    // Header node
    p.SetHeader("copyright", "description", "name", "version", "annotation");  

    // DataDictionnary node and its DataField nodes
    int nData = 3;
    vector<string>fieldName(nData);
    fieldName[0] = "x6";
    fieldName[1] = "x8";
    fieldName[2] = "x1";
    vector<string>displayName(nData);
    displayName[0] = " x_{6}";
    displayName[1] = " x_{8}";
    displayName[2] = " x_{1}";    
    vector<double>leftMargin(nData);
    leftMargin[0] = 1.1e+01;
    leftMargin[1] = 2.81e+01;
    leftMargin[2] = 6.36e+00;
    vector<double>rightMargin(nData);
    rightMargin[0] = 2.3e+01;
    rightMargin[1] = 7.67e+01;
    rightMargin[2] = 1.251e+01;
    for(int j=0; j<nData; j++)
    {
        p.AddDataField( fieldName[j], displayName[j], 
                       "continuous", "double", "ClosedClosed", 
                       leftMargin[j], rightMargin[j], true);
    }      

    // Add a model of type RegressionModel
    string modelName("sREGName");
    p.AddRegressionModel(modelName, PMMLlib::kREGRESSION, fieldName[2]);

    // Set MiningSchema
    for(int j=0 ; j<nData-1 ; j++)
    {
        p.AddMiningSchema(fieldName[j], "active");
    }
    p.AddMiningSchema(fieldName[nData-1], "predicted"); 

    // Set Regression table
    double intercept = 3.837365;
    p.AddRegressionTable(intercept);

    // Set NumericPredictor nodes
    vector<double>numPredCoeff(nData-1);
    numPredCoeff[0] = 0.4759134;
    numPredCoeff[1] = 0.1428838;    
    for(int j=0; j<nData-1; j++) 
    {       
        p.AddNumericPredictor(fieldName[j], 1, numPredCoeff[j]);
    }
    // Set PredictorTerm nodes
    vector<double>predTermCoeff(nData-1);
    predTermCoeff[0] = -0.02201903;
    predTermCoeff[1] = 0.000536256;     
    vector< vector<string> > fieldRefVect(nData-1);
    vector<string>fieldRef0(2);
    fieldRef0[0] = fieldName[0];
    fieldRef0[1] = fieldName[1];
    vector<string>fieldRef1(3);
    fieldRef1[0] = fieldName[0];
    fieldRef1[1] = fieldName[0];
    fieldRef1[2] = fieldName[1];
    fieldRefVect[0] = fieldRef0;
    fieldRefVect[nData-2] = fieldRef1; 
    for(int j=0; j<nData-1; j++) 
    {
        p.AddPredictorTerm(predTermCoeff[j], fieldRefVect[j]);
    }  

    // Generate the PMML file
    string pmmlFilename = "myPmmlFile.pmml";
    p.Write( pmmlFilename );

The matching PMML file is:

<?xml version="1.0"?>
<PMML xmlns="http://www.dmg.org/PMML-4_1" version="version">
  <Header copyright="copyright" description="description">
    <Application name="PMMLlib" version="myVersion"/>
    <Annotation>Tests unitaires PMMLlib</Annotation>
  </Header>
  <DataDictionary>
    <DataField name="x6" displayName=" x_{6}" optype="continuous" dataType="double">
      <Interval closure="ClosedClosed" leftMargin="1.100000e+01" rightMargin="2.300000e+01"/>
    </DataField>
    <DataField name="x8" displayName=" x_{8}" optype="continuous" dataType="double">
      <Interval closure="ClosedClosed" leftMargin="2.810000e+01" rightMargin="7.670000e+01"/>
    </DataField>
    <DataField name="x1" displayName=" x_{1}" optype="continuous" dataType="double">
      <Interval closure="ClosedClosed" leftMargin="6.360000e+00" rightMargin="1.251000e+01"/>
    </DataField>
  </DataDictionary>
  <RegressionModel functionName="regression" modelName="Modeler[LinearRegression]Tds[steamplant]Predictor[x6:x8:x6x8:x6x6x8]Target[x1]" targetFieldName="x1">
    <MiningSchema>
      <MiningField name="x6" usageType="active"/>
      <MiningField name="x8" usageType="active"/>
      <MiningField name="x1" usageType="predicted"/>
    </MiningSchema>
    <RegressionTable intercept="3.837365e+00">
      <NumericPredictor name="x6" exponent="1" coefficient="4.759134e-01"/>
      <NumericPredictor name="x8" exponent="1" coefficient="1.428838e-01"/>
      <PredictorTerm coefficient="-2.201903e-02">
        <FieldRef field="x6"/>
        <FieldRef field="x8"/>
      </PredictorTerm>
      <PredictorTerm coefficient="5.362560e-04">
        <FieldRef field="x6"/>
        <FieldRef field="x6"/>
        <FieldRef field="x8"/>
      </PredictorTerm>
    </RegressionTable>
  </RegressionModel>
</PMML>