| 
| void  | PMMLlib::PMMLlib::fillVectorsForExport (int nInput, int nOutput, int nHidden, int normType, std::vector< double > &minInput, std::vector< double > &maxInput, std::vector< double > &minOutput, std::vector< double > &maxOutput, std::vector< double > &valW) | 
|   | Specific to NeuralNetwork.  More...
  | 
|   | 
| PMMLLIB_EXPORT void  | PMMLlib::PMMLlib::ExportCpp (std::string file, std::string functionName, std::string header) | 
|   | 
| PMMLLIB_EXPORT void  | PMMLlib::PMMLlib::ExportFortran (std::string file, std::string functionName, std::string header) | 
|   | 
| PMMLLIB_EXPORT void  | PMMLlib::PMMLlib::ExportPython (std::string file, std::string functionName, std::string header) | 
|   | 
| PMMLLIB_EXPORT std::string  | PMMLlib::PMMLlib::ExportPyStr (std::string functionName, std::string header) | 
|   | 
| void  | PMMLlib::PMMLlib::ExportNeuralNetworkCpp (std::string file, std::string functionName, std::string header) | 
|   | Specific to NeuralNetwork.  More...
  | 
|   | 
| void  | PMMLlib::PMMLlib::ExportNeuralNetworkFortran (std::string file, std::string functionName, std::string header) | 
|   | Specific to NeuralNetwork.  More...
  | 
|   | 
| void  | PMMLlib::PMMLlib::ExportNeuralNetworkPython (std::string file, std::string functionName, std::string header) | 
|   | Specific to NeuralNetwork.  More...
  | 
|   | 
| std::string  | PMMLlib::PMMLlib::ExportNeuralNetworkPyStr (std::string functionName, std::string header) | 
|   | Specific to NeuralNetwork.  More...
  | 
|   | 
| void  | PMMLlib::PMMLlib::ExportLinearRegressionCpp (std::string, std::string, std::string) | 
|   | Specific to RegressionModel.  More...
  | 
|   | 
| void  | PMMLlib::PMMLlib::ExportLinearRegressionFortran (std::string, std::string, std::string) | 
|   | Specific to Regression.  More...
  | 
|   | 
| void  | PMMLlib::PMMLlib::ExportLinearRegressionPython (std::string, std::string, std::string) | 
|   | Specific to Regression.  More...
  | 
|   | 
| std::string  | PMMLlib::PMMLlib::ExportLinearRegressionPyStr (std::string functionName, std::string header) | 
|   | Specific to Regression.  More...
  | 
|   | 
  
  
      
        
          | void PMMLlib::PMMLlib::ExportLinearRegressionCpp  | 
          ( | 
          std::string  | 
          file,  | 
         
        
           | 
           | 
          std::string  | 
          functionName,  | 
         
        
           | 
           | 
          std::string  | 
          header  | 
         
        
           | 
          ) | 
           |  | 
         
       
   | 
  
private   | 
  
 
Specific to RegressionModel. 
Export the current model as a NeuralNetwork function in a Cpp file. 
- Parameters
 - 
  
    | file | Name of the file  | 
    | functionName | Name of the function  | 
    | header | Header of the function  | 
  
   
Definition at line 2641 of file PMMLlib.cxx.
References PMMLlib::PMMLlib::CheckRegression(), PMMLlib::PMMLlib::GetNumericPredictorCoefficient(), PMMLlib::PMMLlib::GetNumericPredictorName(), PMMLlib::PMMLlib::GetNumericPredictorNb(), PMMLlib::PMMLlib::GetPredictorTermCoefficient(), PMMLlib::PMMLlib::GetPredictorTermName(), PMMLlib::PMMLlib::GetPredictorTermNb(), PMMLlib::PMMLlib::GetRegressionTableIntercept(), PMMLlib::PMMLlib::HasIntercept(), and CORBAEngineTest::i.
Referenced by PMMLlib::PMMLlib::ExportCpp().
 2648     ofstream exportfile(file.c_str());
 
 2650     exportfile << 
"void " << functionName <<
"(double *param, double *res)" << endl;
 
 2651     exportfile << 
"{" << endl;    
 
 2653     exportfile << 
"  ////////////////////////////// " << endl;
 
 2654     exportfile << 
"  //" << endl;
 
 2656     header = 
"  // " + header;
 
 2658     while ((pos = header.find(
"\n", pos)) != std::string::npos) 
 
 2660         header.replace(pos, 1, 
"\n  //");
 
 2663     exportfile << header << endl;
 
 2664     exportfile << 
"  //" << endl;
 
 2665     exportfile << 
"  ////////////////////////////// " << endl << endl;  
 
 2667     double intercept = 0.0;    
 
 2670         exportfile << 
"  // Intercept"<< endl;
 
 2674         exportfile << 
"  // No Intercept"<< endl;
 
 2675     exportfile << 
"  double y = " << intercept << 
";";
 
 2676     exportfile << endl << endl;
 
 2679     for (
int i=0; 
i<nPred; 
i++)
 
 2683        exportfile << endl << endl;
 
 2686     for (
int i=0; 
i<nPred; 
i++)
 
 2690        exportfile << endl << endl;
 
 2693     exportfile << 
"  // Return the value"<< endl;
 
 2694     exportfile << 
"  res[0] = y;" << endl;
 
 2695     exportfile << 
"}" << endl;    
 
 
 
 
  
  
      
        
          | void PMMLlib::PMMLlib::ExportLinearRegressionFortran  | 
          ( | 
          std::string  | 
          file,  | 
         
        
           | 
           | 
          std::string  | 
          functionName,  | 
         
        
           | 
           | 
          std::string  | 
          header  | 
         
        
           | 
          ) | 
           |  | 
         
       
   | 
  
private   | 
  
 
Specific to Regression. 
Export the current model as a NeuralNetwork function in a Fortran file. 
- Parameters
 - 
  
    | file | Name of the file  | 
    | functionName | Name of the function  | 
    | header | Header of the function  | 
  
   
Definition at line 2706 of file PMMLlib.cxx.
References PMMLlib::PMMLlib::CheckRegression(), PMMLlib::PMMLlib::GetNumericPredictorCoefficient(), PMMLlib::PMMLlib::GetNumericPredictorName(), PMMLlib::PMMLlib::GetNumericPredictorNb(), PMMLlib::PMMLlib::GetPredictorTermCoefficient(), PMMLlib::PMMLlib::GetPredictorTermName(), PMMLlib::PMMLlib::GetPredictorTermNb(), PMMLlib::PMMLlib::GetRegressionTableIntercept(), PMMLlib::PMMLlib::HasIntercept(), CORBAEngineTest::i, and PMMLlib::NumberToString().
Referenced by PMMLlib::PMMLlib::ExportFortran().
 2714     vector<string>strParam(nNumPred+nPredTerm);
 
 2715     for(
int i=0; 
i<(nNumPred+nPredTerm); 
i++)
 
 2721     ofstream exportfile(file.c_str());
 
 2723     exportfile << 
"      SUBROUTINE " << functionName <<
"(";
 
 2724     for(
int i=0; 
i<(nNumPred+nPredTerm); 
i++)
 
 2726         exportfile << strParam[
i] << 
", ";
 
 2728     exportfile << 
"RES)" << endl;    
 
 2731     exportfile << 
"C --- *********************************************" << endl;
 
 2732     exportfile << 
"C --- " << endl;
 
 2734     header = 
"C ---  " + header;
 
 2736     while ((pos = header.find(
"\n", pos)) != std::string::npos) 
 
 2738         header.replace(pos, 1, 
"\nC --- ");
 
 2741     exportfile << header << endl;
 
 2742     exportfile << 
"C --- " << endl;
 
 2743     exportfile << 
"C --- *********************************************" << endl << endl;  
 
 2745     exportfile << 
"      IMPLICIT DOUBLE PRECISION (P)" << endl;
 
 2746     exportfile << 
"      DOUBLE PRECISION RES" << endl;    
 
 2747     exportfile << 
"      DOUBLE PRECISION Y" << endl;
 
 2750     double intercept = 0.0;    
 
 2753         exportfile << 
"C --- Intercept"<< endl;
 
 2757         exportfile << 
"C --- No Intercept"<< endl;
 
 2758     exportfile << 
"      Y = " << intercept << 
";";
 
 2759     exportfile << endl << endl;
 
 2761     for (
int i=0; 
i<nNumPred; 
i++)
 
 2765        exportfile << endl << endl;
 
 2768     for (
int i=0; 
i<nPredTerm; 
i++)
 
 2772        exportfile << endl << endl;
 
 2775     exportfile << 
"C --- Return the value"<< endl;
 
 2776     exportfile << 
"      RES = Y " << endl;
 
 2777     exportfile << 
"      RETURN" << endl;    
 
 2778     exportfile << 
"      END" << endl;    
 
 
 
 
  
  
      
        
          | std::string PMMLlib::PMMLlib::ExportLinearRegressionPyStr  | 
          ( | 
          std::string  | 
          functionName,  | 
         
        
           | 
           | 
          std::string  | 
          header  | 
         
        
           | 
          ) | 
           |  | 
         
       
   | 
  
private   | 
  
 
Specific to Regression. 
Export the current model as a NeuralNetwork function in a Python string. 
- Parameters
 - 
  
    | functionName | Name of the function  | 
    | header | Header of the function  | 
  
   
Definition at line 2806 of file PMMLlib.cxx.
References PMMLlib::PMMLlib::CheckRegression(), PMMLlib::PMMLlib::GetNumericPredictorCoefficient(), PMMLlib::PMMLlib::GetNumericPredictorName(), PMMLlib::PMMLlib::GetNumericPredictorNb(), PMMLlib::PMMLlib::GetPredictorTermCoefficient(), PMMLlib::PMMLlib::GetPredictorTermName(), PMMLlib::PMMLlib::GetPredictorTermNb(), PMMLlib::PMMLlib::GetRegressionTableIntercept(), PMMLlib::PMMLlib::HasIntercept(), and CORBAEngineTest::i.
Referenced by PMMLlib::PMMLlib::ExportLinearRegressionPython(), and PMMLlib::PMMLlib::ExportPyStr().
 2814     out << 
"#!/usr/bin/env python" << endl;
 
 2815     out << 
"# -*- coding: utf-8 -*-" << endl;
 
 2819     out << 
"def " << functionName <<
"(param):" << endl;
 
 2823     out << 
"    ############################## " << endl;
 
 2824     out << 
"    # " << endl;
 
 2826     header = 
"    # " + header;
 
 2828     while ((pos = header.find(
"\n", pos)) != std::string::npos) 
 
 2830         header.replace(pos, 1, 
"\n    #");
 
 2833     out << header << endl;
 
 2834     out << 
"    # " << endl;
 
 2835     out << 
"    ############################## " << endl << endl;  
 
 2837     double intercept = 0.0;    
 
 2840         out << 
"    #  Intercept"<< endl;
 
 2844         out << 
"    #  No Intercept"<< endl;
 
 2845     out << 
"    y = " << intercept << 
";";
 
 2846     out << endl << endl;
 
 2849     for (
int i=0; 
i<nPred; 
i++)
 
 2853        out << endl << endl;
 
 2856     for (
int i=0; 
i<nPred; 
i++)
 
 2860        out << endl << endl;
 
 2863     out << 
"    #  Return the value"<< endl;
 
 2864     out << 
"    return [y];" << endl;
 
 
 
 
  
  
      
        
          | void PMMLlib::PMMLlib::ExportNeuralNetworkCpp  | 
          ( | 
          std::string  | 
          file,  | 
         
        
           | 
           | 
          std::string  | 
          functionName,  | 
         
        
           | 
           | 
          std::string  | 
          header  | 
         
        
           | 
          ) | 
           |  | 
         
       
   | 
  
private   | 
  
 
Specific to NeuralNetwork. 
Export the current model as a NeuralNetwork function in a Cpp file. 
- Parameters
 - 
  
    | file | Name of the file  | 
    | functionName | Name of the function  | 
    | header | Header of the function  | 
  
   
Definition at line 1696 of file PMMLlib.cxx.
References PMMLlib::PMMLlib::CheckNeuralNetwork(), PMMLlib::PMMLlib::fillVectorsForExport(), PMMLlib::PMMLlib::GetNbInputs(), PMMLlib::PMMLlib::GetNbNeuronsAtLayer(), PMMLlib::PMMLlib::GetNbOutputs(), PMMLlib::PMMLlib::GetNormalizationType(), and CORBAEngineTest::i.
Referenced by PMMLlib::PMMLlib::ExportCpp().
 1706     int nNeurons = nInput+nOutput+nHidden;
 
 1707     int nWeights = nHidden*(nInput+nOutput+1)+nOutput;
 
 1710     vector<double> minInput(nInput);
 
 1711     vector<double> maxInput(nInput);
 
 1712     vector<double> minOutput(nOutput);
 
 1713     vector<double> maxOutput(nOutput);
 
 1714     vector<double> valW(nWeights);
 
 1715     fillVectorsForExport(nInput,nOutput,nHidden,normType,minInput,maxInput,minOutput,maxOutput,valW);
 
 1717     ofstream sourcefile(file.c_str());
 
 1721         sourcefile << 
"#define ActivationFunction(sum)         ( tanh(sum) )" << endl;
 
 1725         sourcefile << 
"#define ActivationFunction(sum) ( 1.0 / ( 1.0 + exp( -1.0 * sum )) )" << endl;
 
 1728     sourcefile << 
"void " << functionName <<
"(double *param, double *res)" << endl;
 
 1729     sourcefile << 
"{" << endl;
 
 1731     sourcefile << 
"  ////////////////////////////// " << endl;
 
 1732     sourcefile << 
"  //" << endl;
 
 1734     header = 
"  // " + header;
 
 1736     while ((pos = header.find(
"\n", pos)) != std::string::npos) 
 
 1738         header.replace(pos, 1, 
"\n  //");
 
 1741     sourcefile << header << endl;
 
 1742     sourcefile << 
"  //" << endl;
 
 1743     sourcefile << 
"  ////////////////////////////// " << endl;
 
 1745     sourcefile << 
"  int nInput   = " <<  nInput << 
";" << endl;
 
 1746     sourcefile << 
"  int nOutput   = " <<  nOutput << 
";" << endl;
 
 1748     sourcefile << 
"  int nHidden  = " <<  nHidden << 
";" << endl;
 
 1749     sourcefile << 
"  const int nNeurones  = " <<  nNeurons << 
";" << endl;
 
 1750     sourcefile << 
"  double " << functionName << 
"_act[nNeurones];" << endl;
 
 1752     sourcefile << 
"  // --- Preprocessing of the inputs and outputs" << endl;
 
 1753     sourcefile << 
"  double " << functionName << 
"_minInput[] = {" << endl << 
"  ";
 
 1754     for(
int i=0 ; 
i<nInput ; 
i++)
 
 1756         sourcefile << minInput[
i] << 
", ";
 
 1758             sourcefile << 
"\n  ";
 
 1762     sourcefile << 
"  };" << endl;
 
 1764     sourcefile << 
"  double " << functionName << 
"_minOutput[] = {" << endl << 
"  ";
 
 1765     sourcefile << minOutput[0] << 
", ";
 
 1766     sourcefile << 
"  };" << endl;
 
 1768     sourcefile << 
"  double " << functionName << 
"_maxInput[] = {" << endl << 
"  ";
 
 1769     for(
int i=0 ; 
i<nInput ; 
i++)
 
 1771         sourcefile << maxInput[
i] << 
", ";
 
 1773             sourcefile << 
"\n  ";
 
 1777     sourcefile << 
"  };" << endl;
 
 1779     sourcefile << 
"  double " << functionName << 
"_maxOutput[] = {" << endl << 
"  ";
 
 1780     sourcefile << maxOutput[0] << 
", ";
 
 1781     sourcefile << 
"  };" << endl;
 
 1784     sourcefile << 
"  // --- Values of the weights" << endl;
 
 1785     sourcefile << 
"  double " << functionName << 
"_valW[] = {" << endl << 
"  ";
 
 1786     for(
int i=0 ; 
i<nWeights ; 
i++)
 
 1788         sourcefile << valW[
i] << 
", ";
 
 1790             sourcefile << endl << 
"  ";
 
 1792     sourcefile << endl << 
"  };"<<endl;
 
 1794     sourcefile << 
"  // --- Constants";
 
 1796     sourcefile << 
"  int indNeurone = 0;"<<endl;
 
 1797     sourcefile << 
"  int CrtW;"<<endl;
 
 1798     sourcefile << 
"  double sum;"<<endl;
 
 1802     sourcefile << 
"  // --- Input Layers"<<endl;
 
 1803     sourcefile << 
"  for(int i = 0; i < nInput; i++) {"<<endl;
 
 1806         sourcefile << 
"     " << functionName << 
"_act[indNeurone++] = 2.0 * ( param[i] - " 
 1807                    << functionName << 
"_minInput[i] ) / ( " << functionName << 
"_maxInput[i] - " 
 1808                    << functionName << 
"_minInput[i] ) - 1.0;"<<endl;
 
 1812         sourcefile << 
"     " << functionName << 
"_act[indNeurone++] = ( param[i] - " 
 1813                    << functionName << 
"_minInput[i] ) / " << functionName << 
"_maxInput[i];" 
 1816     sourcefile << 
"  }"<<endl;
 
 1821     sourcefile << 
"  // --- Hidden Layers"<<endl;
 
 1822     sourcefile << 
"  for (int member = 0; member < nHidden; member++) {"<<endl;
 
 1823     sourcefile << 
"     int CrtW = member * ( nInput + 2) + 2;" << endl;
 
 1824     sourcefile << 
"     sum = " << functionName << 
"_valW[CrtW++];" << endl;
 
 1825     sourcefile << 
"     for (int source = 0; source < nInput; source++) {" << endl;
 
 1826     sourcefile << 
"         sum += " << functionName << 
"_act[source] * " << functionName << 
"_valW[CrtW++];" << endl;
 
 1827     sourcefile << 
"       }" << endl;
 
 1828     sourcefile << 
"       " << functionName << 
"_act[indNeurone++] = ActivationFunction(sum);" << endl;
 
 1829     sourcefile << 
"  }"<<endl;
 
 1832     sourcefile << 
"  // --- Output"<<endl;
 
 1833     sourcefile << 
"  for (int member = 0; member < nOutput; member++) {"<<endl;
 
 1834     sourcefile << 
"    sum = " << functionName << 
"_valW[0];"<<endl;
 
 1835     sourcefile << 
"    for (int source = 0; source < nHidden; source++) {"<<endl;
 
 1836     sourcefile << 
"      CrtW = source * ( nInput + 2) + 1;"<<endl;
 
 1837     sourcefile << 
"      sum += " << functionName << 
"_act[nInput+source] * " << functionName << 
"_valW[CrtW];"<<endl;
 
 1838     sourcefile << 
"    }"<<endl;
 
 1839     sourcefile << 
"    " << functionName << 
"_act[indNeurone++] = sum;"<<endl;
 
 1842         sourcefile << 
"    res[member] = " << functionName
 
 1843                    << 
"_minOutput[member] + 0.5 * ( " << functionName
 
 1844                    << 
"_maxOutput[member] - " << functionName
 
 1845                    << 
"_minOutput[member] ) * ( sum + 1.0);" << endl;
 
 1849         sourcefile << 
"    res[member] = " << functionName
 
 1850                    << 
"_minOutput[member] + " << functionName
 
 1851                    << 
"_maxOutput[member] * sum;" << endl;
 
 1853     sourcefile << 
"  }"<<endl;
 
 1855     sourcefile << 
"}" << endl;
 
 
 
 
  
  
      
        
          | void PMMLlib::PMMLlib::ExportNeuralNetworkFortran  | 
          ( | 
          std::string  | 
          file,  | 
         
        
           | 
           | 
          std::string  | 
          functionName,  | 
         
        
           | 
           | 
          std::string  | 
          header  | 
         
        
           | 
          ) | 
           |  | 
         
       
   | 
  
private   | 
  
 
Specific to NeuralNetwork. 
Export the current model as a NeuralNetwork function in a Fortran file. 
- Parameters
 - 
  
    | file | Name of the file  | 
    | functionName | Name of the function  | 
    | header | Header of the function  | 
  
   
Definition at line 1866 of file PMMLlib.cxx.
References PMMLlib::PMMLlib::CheckNeuralNetwork(), PMMLlib::PMMLlib::fillVectorsForExport(), PMMLlib::PMMLlib::GetNameInput(), PMMLlib::PMMLlib::GetNameOutput(), PMMLlib::PMMLlib::GetNbInputs(), PMMLlib::PMMLlib::GetNbNeuronsAtLayer(), PMMLlib::PMMLlib::GetNbOutputs(), PMMLlib::PMMLlib::GetNormalizationType(), and CORBAEngineTest::i.
Referenced by PMMLlib::PMMLlib::ExportFortran().
 1876     int nWeights = nHidden*(nInput+nOutput+1)+nOutput;
 
 1879     vector<double> minInput(nInput);
 
 1880     vector<double> maxInput(nInput);
 
 1881     vector<double> minOutput(nOutput);
 
 1882     vector<double> maxOutput(nOutput);
 
 1883     vector<double> valW(nWeights);
 
 1884     fillVectorsForExport(nInput,nOutput,nHidden,normType,minInput,maxInput,minOutput,maxOutput,valW);
 
 1886     ofstream sourcefile(file.c_str());
 
 1888     sourcefile << 
"      SUBROUTINE " << functionName << 
"(";
 
 1895     sourcefile << 
"C --- *********************************************" << endl;
 
 1896     sourcefile << 
"C --- " << endl;
 
 1898     header = 
"C ---  " + header;
 
 1900     while ((pos = header.find(
"\n", pos)) != std::string::npos) 
 
 1902         header.replace(pos, 1, 
"\nC --- ");
 
 1905     sourcefile << header << endl;
 
 1906     sourcefile << 
"C --- " << endl;
 
 1907     sourcefile << 
"C --- *********************************************" << endl;
 
 1909     sourcefile << 
"      IMPLICIT DOUBLE PRECISION (V)" << endl;
 
 1912         sourcefile << 
"      DOUBLE PRECISION " << 
GetNameInput(
i) << endl;
 
 1914     sourcefile << 
"      DOUBLE PRECISION " << 
GetNameOutput(0) << endl;
 
 1917     sourcefile << 
"C --- Preprocessing of the inputs" << endl;
 
 1924             sourcefile << 
"2.D0 * ( " << 
GetNameInput(
i) << 
" - " << minInput[
i] << 
"D0 ) / " << maxInput[
i] - minInput[
i] << 
"D0 - 1.0" << endl;
 
 1928             sourcefile << 
"( " << 
GetNameInput(
i) << 
" - " << minInput[
i] << 
"D0 ) / " << maxInput[
i] << 
"D0" << endl;
 
 1934     sourcefile << 
"C --- Values of the weights" << endl;
 
 1935     for(
int i=0 ; 
i<nWeights ; 
i++)
 
 1937         sourcefile << 
"      VW" << 
i+1 << 
" = " << valW[
i] << endl;
 
 1941     for(
int member = 0; member < nHidden; member++) 
 
 1943         sourcefile << 
"C --- hidden neural number " << member+1 << endl;
 
 1944         int CrtW = member * ( nInput + 2) + 3;
 
 1945         sourcefile << 
"      VAct" << member+1 << 
" = VW" << CrtW++ << endl;
 
 1946         for (
int source = 0; source < nInput; source++)
 
 1948             sourcefile << 
"     1      + VW"<< CrtW++ << 
" * VXN" << 
GetNameInput(source) << endl;
 
 1955             sourcefile << 
"      VPot" << member+1 << 
" = 2.D0 / (1.D0 + DEXP(-2.D0 * VAct" << member+1 <<
")) - 1.D0" << endl;
 
 1959             sourcefile << 
"      VPot" << member+1 << 
" = 1.D0 / (1.D0 + DEXP(-1.D0 * VAct" << member+1 <<
"))" << endl;
 
 1965     sourcefile << 
"C --- Output" << endl;
 
 1966     sourcefile << 
"      VOut = VW1" << endl;
 
 1967     for(
int source=0 ; source < nHidden ; source++)
 
 1969         int CrtW = source * ( nInput + 2) + 2;
 
 1970         sourcefile << 
"     1    + VW"<< CrtW  << 
" * VPot" << source+1 << endl;
 
 1975     sourcefile << 
"C --- Pretraitment of the output" << endl;
 
 1978         sourcefile << 
"      VDelta = " << 0.5*(maxOutput[0]-minOutput[0]) << 
"D0 * ( VOut + 1.0D0)" << endl;
 
 1979         sourcefile << 
"      " << 
GetNameOutput(0) << 
" = " << minOutput[0] << 
"D0 + VDelta" << endl;
 
 1984         sourcefile << 
"      " << 
GetNameOutput(0) << 
" = "<< minOutput[0] << 
"D0 + " << maxOutput[0] << 
"D0 * VOut;" << endl;
 
 1988     sourcefile << 
"C --- " << endl;
 
 1989     sourcefile << 
"      RETURN" << endl;
 
 1990     sourcefile << 
"      END" << endl;
 
 
 
 
  
  
      
        
          | std::string PMMLlib::PMMLlib::ExportNeuralNetworkPyStr  | 
          ( | 
          std::string  | 
          functionName,  | 
         
        
           | 
           | 
          std::string  | 
          header  | 
         
        
           | 
          ) | 
           |  | 
         
       
   | 
  
private   | 
  
 
Specific to NeuralNetwork. 
Export the current model as a function in a Python string. 
- Parameters
 - 
  
    | functionName | Name of the function  | 
    | header | Header of the function  | 
  
   
- Returns
 - Function as a string 
 
Definition at line 2021 of file PMMLlib.cxx.
References PMMLlib::PMMLlib::CheckNeuralNetwork(), PMMLlib::PMMLlib::fillVectorsForExport(), PMMLlib::PMMLlib::GetNbInputs(), PMMLlib::PMMLlib::GetNbNeuronsAtLayer(), PMMLlib::PMMLlib::GetNbOutputs(), PMMLlib::PMMLlib::GetNormalizationType(), and CORBAEngineTest::i.
Referenced by PMMLlib::PMMLlib::ExportNeuralNetworkPython(), and PMMLlib::PMMLlib::ExportPyStr().
 2032     int nNeurons = nInput+nOutput+nHidden;
 
 2033     int nWeights = nHidden*(nInput+nOutput+1)+nOutput;
 
 2036     vector<double> minInput(nInput);
 
 2037     vector<double> maxInput(nInput);
 
 2038     vector<double> minOutput(nOutput);
 
 2039     vector<double> maxOutput(nOutput);
 
 2040     vector<double> valW(nWeights);
 
 2041     fillVectorsForExport(nInput,nOutput,nHidden,normType,minInput,maxInput,minOutput,maxOutput,valW);
 
 2044     out << 
"#!/usr/bin/env python" << endl;
 
 2045     out << 
"# -*- coding: utf-8 -*-" << endl;
 
 2047     out << 
"from math import tanh, exp" << endl;
 
 2053         out << 
"def ActivationFunction(sum): " << endl;
 
 2054         out << 
"    return tanh(sum); " << endl;
 
 2058         out << 
"def ActivationFunction(sum): " << endl;
 
 2059         out << 
"    return ( 1.0 / ( 1.0 + exp( -1.0 * sum ) ) ); " << endl;        
 
 2063     out << 
"def " << functionName <<
"(param):" << endl;
 
 2067     out << 
"    ############################## " << endl;
 
 2068     out << 
"    #" << endl;
 
 2070     header = 
"    # " + header;
 
 2072     while ((pos = header.find(
"\n", pos)) != std::string::npos) 
 
 2074         header.replace(pos, 1, 
"\n    #");
 
 2077     out << header << endl;
 
 2078     out << 
"    #" << endl;
 
 2079     out << 
"    ############################## " << endl;
 
 2083     out << 
"    nInput = " << nInput << 
";" << endl;
 
 2084     out << 
"    nOutput = " << nOutput << 
";" << endl;
 
 2085     out << 
"    nHidden = " <<  nHidden << 
";" << endl;
 
 2086     out << 
"    nNeurones = " <<  nNeurons << 
";" << endl;
 
 2087     out << 
"    " << functionName << 
"_act = [];" << endl;
 
 2088     out << 
"    res = [];" << endl;    
 
 2091     out << 
"    # --- Preprocessing of the inputs and outputs" << endl;
 
 2092     out << 
"    " << functionName << 
"_minInput = [" << endl << 
"  ";
 
 2094     for(
int i=0 ; 
i<nInput ; 
i++)
 
 2096         out << minInput[
i] << 
", ";
 
 2103     out << endl <<  
"    ];" << endl;
 
 2105     out << 
"    " << functionName << 
"_minOutput = [" << endl << 
"    ";
 
 2106     out << 
"    " << minOutput[0] ;
 
 2107     out << endl << 
"    ];" << endl;
 
 2109     out << 
"    " << functionName << 
"_maxInput = [" << endl << 
"    ";
 
 2110     for(
int i=0 ; 
i<nInput ; 
i++)
 
 2112         out << maxInput[
i] << 
", ";
 
 2119     out << endl << 
"    ];" << endl;
 
 2121     out << 
"    " << functionName << 
"_maxOutput = [" << endl << 
"    ";
 
 2122     out << 
"    " << maxOutput[0] ;
 
 2123     out << endl << 
"    ];" << endl;
 
 2126     out << 
"    # --- Values of the weights" << endl;
 
 2127     out << 
"    " << functionName << 
"_valW = [" << endl << 
"    ";
 
 2128     for(
int i=0 ; 
i<nWeights ; 
i++)
 
 2130         out << valW[
i] << 
", ";
 
 2137     out << endl << 
"    ];"<<endl;
 
 2139     out << 
"    # --- Constants" << endl;
 
 2140     out << 
"    indNeurone = 0;" << endl;
 
 2144     out << 
"    # --- Input Layers" << endl;
 
 2145     out << 
"    for i in range(nInput) :" << endl;
 
 2148         out << 
"        " << functionName << 
"_act.append( 2.0 * ( param[i] - " 
 2149                    << functionName << 
"_minInput[i] ) / ( " << functionName << 
"_maxInput[i] - " 
 2150                    << functionName << 
"_minInput[i] ) - 1.0 ) ;" 
 2155         out << 
"        " << functionName << 
"_act.append( ( param[i] - " 
 2156                    << functionName << 
"_minInput[i] ) / " << functionName << 
"_maxInput[i] ) ;" 
 2159     out << 
"        indNeurone += 1 ;" << endl;
 
 2160     out << 
"        pass" << endl;
 
 2164     out << 
"    # --- Hidden Layers" << endl;
 
 2165     out << 
"    for member in range(nHidden):" << endl;
 
 2166     out << 
"        CrtW = member * ( nInput + 2) + 2;" << endl;
 
 2167     out << 
"        sum = " << functionName << 
"_valW[CrtW];" << endl;
 
 2168     out << 
"        CrtW += 1 ;" << endl;     
 
 2169     out << 
"        for source in range(nInput) :" << endl;
 
 2170     out << 
"            sum += " << functionName << 
"_act[source] * " << functionName << 
"_valW[CrtW];" << endl;
 
 2171     out << 
"            CrtW += 1 ;" << endl; 
 
 2172     out << 
"            pass" << endl;
 
 2173     out << 
"        " << functionName << 
"_act.append( ActivationFunction(sum) ) ;" << endl;
 
 2174     out << 
"        indNeurone += 1 ;" << endl;
 
 2175     out << 
"        pass" << endl;
 
 2179     out << 
"    # --- Output"<<endl;
 
 2180     out << 
"    for member in range(nOutput):" << endl; 
 
 2181     out << 
"        sum = " << functionName << 
"_valW[0];" << endl;
 
 2182     out << 
"        for source in range(nHidden):" << endl;
 
 2183     out << 
"            CrtW = source * ( nInput + 2) + 1;"<<endl;
 
 2184     out << 
"            sum += " << functionName << 
"_act[nInput+source] * " << functionName << 
"_valW[CrtW];" << endl;
 
 2185     out << 
"            pass" << endl;
 
 2186     out << 
"        " << functionName << 
"_act.append( sum );" << endl;
 
 2187     out << 
"        indNeurone += 1 ;" << endl;
 
 2190         out << 
"        res[member] = " << functionName
 
 2191                    << 
"_minOutput[member] + 0.5 * ( " << functionName
 
 2192                    << 
"_maxOutput[member] - " << functionName
 
 2193                    << 
"_minOutput[member] ) * ( sum + 1.0);" << endl;
 
 2197         out << 
"        res.append( " << functionName
 
 2198                    << 
"_minOutput[member] + " << functionName
 
 2199                    << 
"_maxOutput[member] * sum );" << endl;
 
 2201     out << 
"        pass" << endl;
 
 2205     out << 
"    return res;" << endl << endl;
 
 
 
 
  
  
      
        
          | void PMMLlib::PMMLlib::fillVectorsForExport  | 
          ( | 
          int  | 
          nInput,  | 
         
        
           | 
           | 
          int  | 
          nOutput,  | 
         
        
           | 
           | 
          int  | 
          nHidden,  | 
         
        
           | 
           | 
          int  | 
          normType,  | 
         
        
           | 
           | 
          std::vector< double > &  | 
          minInput,  | 
         
        
           | 
           | 
          std::vector< double > &  | 
          maxInput,  | 
         
        
           | 
           | 
          std::vector< double > &  | 
          minOutput,  | 
         
        
           | 
           | 
          std::vector< double > &  | 
          maxOutput,  | 
         
        
           | 
           | 
          std::vector< double > &  | 
          valW  | 
         
        
           | 
          ) | 
           |  | 
         
       
   | 
  
private   | 
  
 
Specific to NeuralNetwork. 
Fill the vectors used by the ExportXXX methods. 
- Parameters
 - 
  
    | nInput |  | 
    | nOutput |  | 
    | nHidden |  | 
    | normType |  | 
    | minInput |  | 
    | maxInput |  | 
    | minOutput |  | 
    | maxOutput |  | 
    | valW |  | 
  
   
Definition at line 1603 of file PMMLlib.cxx.
References PMMLlib::PMMLlib::_currentModelNode, PMMLlib::PMMLlib::_getProp(), PMMLlib::PMMLlib::CheckNeuralNetwork(), PMMLlib::PMMLlib::GetChildByName(), PMMLlib::PMMLlib::GetNeuronBias(), PMMLlib::PMMLlib::GetPrecNeuronSynapse(), and CORBAEngineTest::i.
Referenced by PMMLlib::PMMLlib::ExportNeuralNetworkCpp(), PMMLlib::PMMLlib::ExportNeuralNetworkFortran(), and PMMLlib::PMMLlib::ExportNeuralNetworkPyStr().
 1618     for(
int i=0 ; 
i<nInput ; 
i++)
 
 1621         node_inputs = node_inputs->children;
 
 1622         for(
int j = 0;j<
i;j++)
 
 1624             node_inputs = node_inputs->next;
 
 1626         node_inputs = node_inputs->children; 
 
 1627         node_inputs = node_inputs->children; 
 
 1628         node_inputs = node_inputs->children; 
 
 1629         string strOrig1 = 
_getProp(node_inputs, 
string(
"orig") );
 
 1630         double orig1 = atof( strOrig1.c_str() );
 
 1631         string strNorm1 = 
_getProp(node_inputs, 
string(
"norm") );        
 
 1632         double norm1 = atof( strNorm1.c_str() );
 
 1633         node_inputs = node_inputs->next;
 
 1634         string strOrig2 = 
_getProp(node_inputs, 
string(
"orig") );
 
 1635         double orig2 = atof( strOrig2.c_str() );
 
 1636         string strNorm2 = 
_getProp(node_inputs, 
string(
"norm") );    
 
 1639             minInput[
i] = orig1;
 
 1640             maxInput[
i] = orig2;
 
 1644             minInput[
i] = orig2;
 
 1645             maxInput[
i] = -1.0*norm1*orig2;
 
 1648     xmlNodePtr node_outputs = 
GetChildByName(netNode,
"NeuralOutputs");
 
 1649     node_outputs = node_outputs->children;
 
 1650     node_outputs = node_outputs->children; 
 
 1651     node_outputs = node_outputs->children; 
 
 1652     node_outputs = node_outputs->children; 
 
 1653     string strOrig1 = 
_getProp(node_outputs, 
string(
"orig") );
 
 1654     double orig1 = atof( strOrig1.c_str() );
 
 1655     string strNorm1 = 
_getProp(node_outputs, 
string(
"norm") );        
 
 1656     double norm1 = atof( strNorm1.c_str() ); 
 
 1657     node_outputs = node_outputs->next;
 
 1658     string strOrig2 = 
_getProp(node_outputs, 
string(
"orig") );
 
 1659     double orig2 = atof( strOrig2.c_str() );    
 
 1662         minOutput[0] = orig1;
 
 1663         maxOutput[0] = orig2;
 
 1667         minOutput[0] = orig2;
 
 1668         maxOutput[0] = -1.0*norm1*orig2;
 
 1671     for(
int j=0 ; j<nHidden ; j++) 
 
 1674         for(
int i=0 ; i<nInput ; i++)
 
 1679     for(
int j=0 ; j<nOutput ; j++) 
 
 1682         for(
int i=0 ; i<nHidden ; i++)