Version: 9.15.0
Methods dedicated to neural networks

Functions

PMMLLIB_EXPORT void PMMLlib::PMMLlib::AddNeuralNetwork (std::string modelName, PMMLMiningFunction functionName)
 Specific to NeuralNetwork. More...
 
PMMLLIB_EXPORT void PMMLlib::PMMLlib::AddNeuralInput (int id, std::string inputName, std::string optype, std::string dataType, double orig1, double norm1, double orig2, double norm2)
 Specific to NeuralNetwork. More...
 
PMMLLIB_EXPORT void PMMLlib::PMMLlib::AddNeuralLayer (PMMLActivationFunction activationFunction)
 Specific to NeuralNetwork. More...
 
PMMLLIB_EXPORT void PMMLlib::PMMLlib::AddNeuron (int id, double bias, int conNb, int firstFrom, std::vector< double > weights)
 Specific to NeuralNetwork. More...
 
PMMLLIB_EXPORT void PMMLlib::PMMLlib::AddNeuralOutput (int outputNeuron, std::string outputName, std::string optype, std::string dataType, double orig1, double norm1, double orig2, double norm2)
 Specific to NeuralNetwork. More...
 
PMMLLIB_EXPORT int PMMLlib::PMMLlib::GetNbInputs ()
 Specific to NeuralNetwork. More...
 
PMMLLIB_EXPORT int PMMLlib::PMMLlib::GetNbOutputs ()
 Specific to NeuralNetwork. More...
 
PMMLLIB_EXPORT std::string PMMLlib::PMMLlib::GetNameInput (int input_index)
 Specific to NeuralNetwork. More...
 
PMMLLIB_EXPORT std::string PMMLlib::PMMLlib::GetNameOutput (int output_index)
 Specific to NeuralNetwork. More...
 
PMMLLIB_EXPORT int PMMLlib::PMMLlib::GetNormalizationType ()
 Specific to NeuralNetwork. More...
 
PMMLLIB_EXPORT void PMMLlib::PMMLlib::GetNormalisationInput (int input_index, double *dnorm)
 Specific to NeuralNetwork. More...
 
PMMLLIB_EXPORT void PMMLlib::PMMLlib::GetNormalisationOutput (int output_index, double *dnorm)
 Specific to NeuralNetwork. More...
 
PMMLLIB_EXPORT int PMMLlib::PMMLlib::GetNbHiddenLayers ()
 Specific to NeuralNetwork. More...
 
PMMLLIB_EXPORT int PMMLlib::PMMLlib::GetNbLayers ()
 
PMMLLIB_EXPORT int PMMLlib::PMMLlib::GetNbNeuronsAtLayer (int layer_index)
 
PMMLLIB_EXPORT double PMMLlib::PMMLlib::GetNeuronBias (int layer_index, int neu_index)
 Specific to NeuralNetwork. More...
 
PMMLLIB_EXPORT double PMMLlib::PMMLlib::GetPrecNeuronSynapse (int layer_index, int neu_index, int prec_index)
 Specific to NeuralNetwork. More...
 
PMMLLIB_EXPORT void PMMLlib::PMMLlib::SetNeuralNetName (int ann_index, std::string ann_name)
 Not tested. More...
 
PMMLLIB_EXPORT std::string PMMLlib::PMMLlib::ReadNetworkStructure ()
 Specific to NeuralNetwork. More...
 
xmlNodePtr PMMLlib::PMMLlib::GetNeuralNetPtr (std::string ann_name)
 
xmlNodePtr PMMLlib::PMMLlib::GetNeuralNetPtr (int ann_index)
 
void PMMLlib::PMMLlib::CheckNeuralNetwork ()
 Called in all methods specific to the NeuralNetwork model. More...
 

Detailed Description

Methods dedicated to neural networks

Function Documentation

◆ AddNeuralInput()

void PMMLlib::PMMLlib::AddNeuralInput ( int  id,
std::string  inputName,
std::string  optype,
std::string  dataType,
double  orig1,
double  norm1,
double  orig2,
double  norm2 
)

Specific to NeuralNetwork.

Add a NeuralInput node to the current model.

Parameters
idId of the input
inputNameName of the input
optypeValue of property "optype"
dataTypeValue of property "dataType"
orig1Value of the first origin
norm1Value of the first norm
orig2Value of the second origin
norm2Value of the second norm

Definition at line 1394 of file PMMLlib.cxx.

1400 {
1402 
1403  xmlNodePtr netNode = _currentModelNode;
1404  // if 'NeuralInputs' node does not exist, create it
1405  xmlNodePtr neuralInputsNode = GetChildByName(netNode, "NeuralInputs");
1406  if(!neuralInputsNode)
1407  {
1408  neuralInputsNode = xmlNewChild(netNode, 0, (const xmlChar*)"NeuralInputs", 0);
1409  xmlNewProp(neuralInputsNode, (const xmlChar*)"numberOfInputs", (const xmlChar*)"0" );
1410  }
1411  // increment the number of inputs
1412  string numberOfInputsStr = _getProp(neuralInputsNode, string("numberOfInputs"));
1413  int numberOfInputs;
1414  istringstream( numberOfInputsStr ) >> numberOfInputs;
1415  numberOfInputs++;
1416  stringstream ss;
1417  ss << numberOfInputs;
1418  xmlSetProp(neuralInputsNode, (const xmlChar*)"numberOfInputs", (const xmlChar*)(ss.str().c_str()) );
1419  // then append the node and its children
1420  xmlNodePtr neuralInputNode = xmlNewChild(neuralInputsNode, 0, (const xmlChar*)"NeuralInput", 0);
1421  ss.str(""); ss << id;
1422  xmlNewProp(neuralInputNode, (const xmlChar*)"id", (const xmlChar*)(ss.str().c_str()) );
1423 
1424  xmlNodePtr derivedFieldNode = xmlNewChild(neuralInputNode, 0, (const xmlChar*)"DerivedField", 0);
1425  xmlNewProp(derivedFieldNode, (const xmlChar*)"optype", (const xmlChar*)(optype.c_str()) );
1426  xmlNewProp(derivedFieldNode, (const xmlChar*)"dataType", (const xmlChar*)(dataType.c_str()) );
1427 
1428  xmlNodePtr normcontNode = xmlNewChild(derivedFieldNode, 0, (const xmlChar*)"NormContinuous", 0);
1429  xmlNewProp(normcontNode, (const xmlChar*)"field", (const xmlChar*)(inputName.c_str()) );
1430 
1431  xmlNodePtr node_linearnorm1 = xmlNewChild(normcontNode, 0, (const xmlChar*)"LinearNorm", 0);
1432  ss.str(""); ss << scientific << orig1;
1433  xmlNewProp(node_linearnorm1, (const xmlChar*)"orig", (const xmlChar*)(ss.str().c_str()) );
1434  ss.str(""); ss << scientific << norm1;
1435  xmlNewProp(node_linearnorm1, (const xmlChar*)"norm", (const xmlChar*)(ss.str().c_str()) );
1436  xmlNodePtr node_linearnorm2 = xmlNewChild(normcontNode, 0, (const xmlChar*)"LinearNorm", 0);
1437  ss.str(""); ss << scientific << orig2;
1438  xmlNewProp(node_linearnorm2, (const xmlChar*)"orig", (const xmlChar*)(ss.str().c_str()) );
1439  ss.str(""); ss << scientific << norm2;
1440  xmlNewProp(node_linearnorm2, (const xmlChar*)"norm", (const xmlChar*)(ss.str().c_str()) );
1441 }
xmlNodePtr _currentModelNode
Pointer to the current model node
Definition: PMMLlib.hxx:84
std::string _getProp(const xmlNodePtr node, std::string const &prop) const
Definition: PMMLlib.cxx:694
void CheckNeuralNetwork()
Called in all methods specific to the NeuralNetwork model.
Definition: PMMLlib.cxx:728
xmlNodePtr GetChildByName(xmlNodePtr node, std::string nodename)
Definition: PMMLlib.cxx:310

◆ AddNeuralLayer()

void PMMLlib::PMMLlib::AddNeuralLayer ( PMMLActivationFunction  activationFunction)

Specific to NeuralNetwork.

Add a NeuralLayer node to the current model.

Parameters
activationFunctionActivation function. One of kIDENTITY, kTANH, kLOGISTIC.

Definition at line 1510 of file PMMLlib.cxx.

1511 {
1513 
1514  string functionName;
1515  switch(activationFunction)
1516  {
1517  case kIDENTITY:
1518  functionName = "identity";
1519  break;
1520  case kTANH:
1521  functionName = "tanh";
1522  break;
1523  case kLOGISTIC:
1524  functionName = "logistic";
1525  break;
1526  }
1527  xmlNodePtr netNode = _currentModelNode;
1528  // Increment the number of layers
1529  string numberOfLayersStr = _getProp(_currentModelNode, string("numberOfLayers"));
1530  int numberOfLayers;
1531  istringstream( numberOfLayersStr ) >> numberOfLayers;
1532  numberOfLayers++;
1533  stringstream ss;
1534  ss << numberOfLayers;
1535  xmlSetProp(netNode, (const xmlChar*)"numberOfLayers", (const xmlChar*)(ss.str().c_str()) );
1536  // Add the neural layer node
1537  xmlNodePtr neuralLayerNode = xmlNewChild(netNode, 0, (const xmlChar*)"NeuralLayer", 0);
1538  xmlNewProp(neuralLayerNode, (const xmlChar*)"activationFunction", (const xmlChar*)(functionName.c_str()) );
1539  xmlNewProp(neuralLayerNode, (const xmlChar*)"numberOfNeurons", (const xmlChar*)"0" );
1540  // Save the current layer in the _currentNode attribute
1541  _currentNode = neuralLayerNode;
1542 }
xmlNodePtr _currentNode
Pointer to the current node
Definition: PMMLlib.hxx:80
@ kIDENTITY
Definition: PMMLlib.hxx:60
@ kTANH
Definition: PMMLlib.hxx:60
@ kLOGISTIC
Definition: PMMLlib.hxx:60

References PMMLlib::kIDENTITY, PMMLlib::kLOGISTIC, and PMMLlib::kTANH.

◆ AddNeuralNetwork()

void PMMLlib::PMMLlib::AddNeuralNetwork ( std::string  modelName,
PMMLMiningFunction  functionName 
)

Specific to NeuralNetwork.

Add a NeuralNetwork node to the root node

Parameters
modelNameModel name
functionNamePMMLMiningFunction. One of : kREGRESSION.

Definition at line 1359 of file PMMLlib.cxx.

1361 {
1363  _currentModelName = modelName;
1364 
1366 
1367  string function;
1368  switch(functionName)
1369  {
1370  case kREGRESSION:
1371  function = "regression";
1372  break;
1373  }
1374 
1375  xmlNodePtr netNode = xmlNewChild(_rootNode, 0, (const xmlChar*)"NeuralNetwork", 0);
1376  xmlNewProp(netNode, (const xmlChar*)"modelName", (const xmlChar*)(_currentModelName.c_str()) );
1377  xmlNewProp(netNode, (const xmlChar*)"functionName", (const xmlChar*)(function.c_str()) );
1378  xmlNewProp(netNode, (const xmlChar*)"numberOfLayers", (const xmlChar*)"0" );
1379  _currentModelNode = netNode;
1380 }
std::string _currentModelName
Name of the current model
Definition: PMMLlib.hxx:82
PMMLType _currentModelType
Type of the current model.
Definition: PMMLlib.hxx:83
xmlNodePtr _rootNode
Root node of the document.
Definition: PMMLlib.hxx:79
@ kANN
Definition: PMMLlib.hxx:54
@ kREGRESSION
Definition: PMMLlib.hxx:66

References PMMLlib::kANN, and PMMLlib::kREGRESSION.

◆ AddNeuralOutput()

void PMMLlib::PMMLlib::AddNeuralOutput ( int  outputNeuron,
std::string  outputName,
std::string  optype,
std::string  dataType,
double  orig1,
double  norm1,
double  orig2,
double  norm2 
)

Specific to NeuralNetwork.

Add a NeuralOutput node to the current model.

Parameters
outputNeuronId of the output
outputNameName of the output
optypeValue of property "optype"
dataTypeValue of property "dataType"
orig1Value of the first origin
norm1Value of the first norm
orig2Value of the second origin
norm2Value of the second norm

Definition at line 1455 of file PMMLlib.cxx.

1461 {
1463 
1464  xmlNodePtr netNode = _currentModelNode;
1465  // if 'NeuralOutputs' node does not exist, create it
1466  xmlNodePtr neuralOutputsNode = GetChildByName(netNode, "NeuralOutputs");
1467  if(!neuralOutputsNode)
1468  {
1469  neuralOutputsNode = xmlNewChild(netNode, 0, (const xmlChar*)"NeuralOutputs", 0);
1470  xmlNewProp(neuralOutputsNode, (const xmlChar*)"numberOfOutputs", (const xmlChar*)"0" );
1471  }
1472  // increment the number of inputs
1473  string numberOfOutputsStr = _getProp(neuralOutputsNode, string("numberOfOutputs"));
1474  int numberOfOutputs;
1475  istringstream( numberOfOutputsStr ) >> numberOfOutputs;
1476  numberOfOutputs++;
1477  stringstream ss;
1478  ss << numberOfOutputs;
1479  xmlSetProp(neuralOutputsNode, (const xmlChar*)"numberOfOutputs", (const xmlChar*)(ss.str().c_str()) );
1480 
1481  // then append the node and its children
1482  xmlNodePtr neuralOutputNode = xmlNewChild(neuralOutputsNode, 0, (const xmlChar*)"NeuralOutput", 0);
1483  ss.str(""); ss << outputNeuron;
1484  xmlNewProp(neuralOutputNode, (const xmlChar*)"outputNeuron", (const xmlChar*)(ss.str().c_str()) );
1485 
1486  xmlNodePtr derivedFieldNode = xmlNewChild(neuralOutputNode, 0, (const xmlChar*)"DerivedField", 0);
1487  xmlNewProp(derivedFieldNode, (const xmlChar*)"optype", (const xmlChar*)(optype.c_str()) );
1488  xmlNewProp(derivedFieldNode, (const xmlChar*)"dataType", (const xmlChar*)(dataType.c_str()) );
1489 
1490  xmlNodePtr normcontNode = xmlNewChild(derivedFieldNode, 0, (const xmlChar*)"NormContinuous", 0);
1491  xmlNewProp(normcontNode, (const xmlChar*)"field", (const xmlChar*)(outputName.c_str()) );
1492 
1493  xmlNodePtr node_linearnorm1 = xmlNewChild(normcontNode, 0, (const xmlChar*)"LinearNorm", 0);
1494  ss.str(""); ss << scientific << orig1;
1495  xmlNewProp(node_linearnorm1, (const xmlChar*)"orig", (const xmlChar*)(ss.str().c_str()) );
1496  ss.str(""); ss << scientific << norm1;
1497  xmlNewProp(node_linearnorm1, (const xmlChar*)"norm", (const xmlChar*)(ss.str().c_str()) );
1498  xmlNodePtr node_linearnorm2 = xmlNewChild(normcontNode, 0, (const xmlChar*)"LinearNorm", 0);
1499  ss.str(""); ss << scientific << orig2;
1500  xmlNewProp(node_linearnorm2, (const xmlChar*)"orig", (const xmlChar*)(ss.str().c_str()) );
1501  ss.str(""); ss << scientific << norm2;
1502  xmlNewProp(node_linearnorm2, (const xmlChar*)"norm", (const xmlChar*)(ss.str().c_str()) );
1503 }

◆ AddNeuron()

void PMMLlib::PMMLlib::AddNeuron ( int  id,
double  bias,
int  conNb,
int  firstFrom,
std::vector< double >  weights 
)

Specific to NeuralNetwork.

Add a NeuralLayer node to the current model.

Parameters
idId of the layer
biasValue of property "bias"
conNbNumber of Con nodes
firstFromValue of property "from" for the first Con
weightsVector of weights (One per Con node)

Definition at line 1553 of file PMMLlib.cxx.

1558 {
1560 
1561  stringstream ss;
1562 
1563  // increment the number of neurons
1564  string numberOfNeuronsStr = _getProp(_currentNode, string("numberOfNeurons"));
1565  int numberOfNeurons;
1566  istringstream( numberOfNeuronsStr ) >> numberOfNeurons;
1567  numberOfNeurons++;
1568  ss << numberOfNeurons;
1569  xmlSetProp(_currentNode, (const xmlChar*)"numberOfNeurons", (const xmlChar*)(ss.str().c_str()) );
1570 
1571  // append a neuron
1572  xmlNodePtr neuronNode = xmlNewChild(_currentNode, 0, (const xmlChar*)"Neuron", 0);
1573  ss.str(""); ss << id;
1574  xmlNewProp(neuronNode, (const xmlChar*)"id", (const xmlChar*)(ss.str().c_str()) );
1575  ss.str(""); ss << scientific << bias;
1576  xmlNewProp(neuronNode, (const xmlChar*)"bias", (const xmlChar*)(ss.str().c_str()) );
1577 
1578  // append multiple 'Con' to the neuron
1579  for(int k=0 ; k<conNb ; k++)
1580  {
1581  xmlNodePtr conNode = xmlNewChild(neuronNode, 0, (const xmlChar*)"Con", 0);
1582  ss.str(""); ss << firstFrom+k;
1583  xmlNewProp(conNode, (const xmlChar*)"from", (const xmlChar*)(ss.str().c_str()) ); // !!! ce n'est pas k !!!
1584  ss.str(""); ss << scientific << weights[k];
1585  xmlNewProp(conNode, (const xmlChar*)"weight", (const xmlChar*)(ss.str().c_str()) );
1586  }
1587 }

◆ CheckNeuralNetwork()

void PMMLlib::PMMLlib::CheckNeuralNetwork ( )
private

Called in all methods specific to the NeuralNetwork model.

Check if the current model type is kANN.

Throw an exception if the model type is not kANN.

Definition at line 728 of file PMMLlib.cxx.

729 {
730  if ( _currentModelType != kANN )
731  throw string("Use this method with NeuralNetwork models.");
732 }

References PMMLlib::kANN.

◆ GetNameInput()

std::string PMMLlib::PMMLlib::GetNameInput ( int  index)

Specific to NeuralNetwork.

Recovery of the name of an input in the current model.

Parameters
indexIndex of the input
Returns
Name of the input

Definition at line 897 of file PMMLlib.cxx.

898 {
900 
901  string name("");
902  xmlNodePtr node_inputs = GetChildByName(_currentModelNode,"NeuralInputs");
903  if ( node_inputs == NULL )
904  return name;
905 
906  node_inputs = node_inputs->children;
907  if ( node_inputs == NULL )
908  return name;
909 
910  for(int i = 0;i<index;i++)
911  {
912  node_inputs = node_inputs->next;
913  if ( node_inputs == NULL )
914  return name;
915  }
916 
917  node_inputs = node_inputs->children;
918  if ( node_inputs == NULL )
919  return name;
920 
921  node_inputs = node_inputs->children;
922  if ( node_inputs == NULL )
923  return name;
924 
925  name = _getProp(node_inputs, string("field"));
926 
927  return name;
928 }

References yacsorb.CORBAEngineTest::i.

◆ GetNameOutput()

std::string PMMLlib::PMMLlib::GetNameOutput ( int  index)

Specific to NeuralNetwork.

Get the name of an output in the current model.

Parameters
indexIndex of the output
Returns
Name of the output

Definition at line 936 of file PMMLlib.cxx.

937 {
939 
940  string name("");
941  xmlNodePtr node_outputs = GetChildByName(_currentModelNode,"NeuralOutputs");
942  if ( node_outputs == NULL )
943  return name;
944  node_outputs = node_outputs->children;
945  if ( node_outputs == NULL )
946  return name;
947  for(int i = 0;i<index;i++)
948  {
949  node_outputs = node_outputs->next;
950  if ( node_outputs == NULL )
951  return name;
952  }
953 
954  node_outputs = node_outputs->children;
955  if ( node_outputs == NULL )
956  return name;
957  node_outputs = node_outputs->children;
958  if ( node_outputs == NULL )
959  return name;
960 
961  name = _getProp(node_outputs, string("field") );
962 
963  return name;
964 }

References yacsorb.CORBAEngineTest::i.

◆ GetNbHiddenLayers()

int PMMLlib::PMMLlib::GetNbHiddenLayers ( )

Specific to NeuralNetwork.

Get the number of hidden layers

Returns
Number of hidden layers

Definition at line 1137 of file PMMLlib.cxx.

1138 {
1140 
1141  int nb_layers = 0;
1142  xmlNodePtr node_layers = GetChildByName(_currentModelNode,"NeuralLayer");
1143  if ( node_layers == NULL )
1144  return nb_layers;
1145 
1146  while (string((const char*)(node_layers->name)) == "NeuralLayer")
1147  {
1148  nb_layers++;
1149  node_layers = node_layers->next;
1150  if ( node_layers == NULL )
1151  return nb_layers;
1152  }
1153  return nb_layers;
1154 }

◆ GetNbInputs()

int PMMLlib::PMMLlib::GetNbInputs ( )

Specific to NeuralNetwork.

Get the number of inputs, ie the number of NeuralInputs nodes.

Returns
Number of input nodes

Definition at line 847 of file PMMLlib.cxx.

848 {
850 
851  int nb=0;
852  xmlNodePtr node_inputs = GetChildByName(_currentModelNode,"NeuralInputs");
853  if ( node_inputs == NULL )
854  return nb;
855 
856  node_inputs = node_inputs->children;
857  while (node_inputs != NULL)
858  {
859  nb++;
860  node_inputs = node_inputs->next;
861  }
862 
863  return nb;
864 }

◆ GetNbLayers()

int PMMLlib::PMMLlib::GetNbLayers ( )

Get the total number of layers

Returns
Total number of layers

Definition at line 1160 of file PMMLlib.cxx.

1161 {
1162  return (GetNbHiddenLayers() + 2);
1163 }
PMMLLIB_EXPORT int GetNbHiddenLayers()
Specific to NeuralNetwork.
Definition: PMMLlib.cxx:1137

◆ GetNbNeuronsAtLayer()

int PMMLlib::PMMLlib::GetNbNeuronsAtLayer ( int  index)

Get the number of neurons at a given layer

Parameters
indexIndex of the layer
Returns
Number of neurons at given layer

Definition at line 1170 of file PMMLlib.cxx.

1171 {
1172  CheckNeuralNetwork();
1173 
1174  int nb_neurons = 0;
1175  xmlNodePtr node_layers = GetChildByName(_currentModelNode,"NeuralLayer");
1176  if ( node_layers == NULL )
1177  return nb_neurons;
1178 
1179  // Positionnement à la bonne couche
1180  for(int i=0;i<index;i++)
1181  {
1182  node_layers = node_layers->next;
1183  if ( node_layers == NULL )
1184  return nb_neurons;
1185  }
1186 
1187  xmlNodePtr node_neurons = GetChildByName(node_layers,"Neuron");
1188  while(node_neurons != NULL)
1189  {
1190  nb_neurons++;
1191  node_neurons = node_neurons->next;
1192  }
1193 
1194  return nb_neurons;
1195 }

References yacsorb.CORBAEngineTest::i.

◆ GetNbOutputs()

int PMMLlib::PMMLlib::GetNbOutputs ( )

Specific to NeuralNetwork.

Recover the number of outputs

Returns
Number of outputs

Definition at line 871 of file PMMLlib.cxx.

872 {
874 
875  int nb=0;
876  xmlNodePtr node_outputs = GetChildByName(_currentModelNode,"NeuralOutputs");
877  if ( node_outputs == NULL )
878  return nb;
879 
880  node_outputs = node_outputs->children;
881 
882  while (node_outputs != NULL)
883  {
884  nb++;
885  node_outputs = node_outputs->next;
886  }
887 
888  return nb;
889 }

◆ GetNeuralNetPtr() [1/2]

xmlNodePtr PMMLlib::PMMLlib::GetNeuralNetPtr ( int  index)
private

Get the XML node of a given network from the index

Parameters
indexIndex of the neural network
Returns
Pointer to the XML node

Definition at line 739 of file PMMLlib.cxx.

740 {
741  return GetPtr(index, GetTypeString() );
742 }
std::string GetTypeString()
Definition: PMMLlib.cxx:473
xmlNodePtr GetPtr(int ann_index, std::string name)
Definition: PMMLlib.cxx:419

◆ GetNeuralNetPtr() [2/2]

xmlNodePtr PMMLlib::PMMLlib::GetNeuralNetPtr ( std::string  name)
private

Get the XML node of a given network model

Parameters
nameName of the neural network
Returns
Pointer to the XML node

Definition at line 749 of file PMMLlib.cxx.

750 {
751  return GetPtr(name, GetTypeString() );
752 }

◆ GetNeuronBias()

double PMMLlib::PMMLlib::GetNeuronBias ( int  layer_index,
int  neu_index 
)

Specific to NeuralNetwork.

Get the bias of a neuron

Parameters
layer_indexIndex of the layer to get bias
neu_indexIndex of the neuron
Returns
Bias of the specified neuron

Definition at line 1204 of file PMMLlib.cxx.

1206 {
1207  CheckNeuralNetwork();
1208 
1209  double bias = 0.;
1210  xmlNodePtr node_layers = GetChildByName(_currentModelNode,"NeuralLayer");
1211  if ( node_layers == NULL )
1212  return bias;
1213  // Positionnement a la bonne couche
1214  for(int i=0;i<layer_index;i++)
1215  {
1216  node_layers = node_layers->next;
1217  if ( node_layers == NULL )
1218  return bias;
1219  }
1220  xmlNodePtr node_neurons = GetChildByName(node_layers,"Neuron");
1221  // Positionnement sur le bon neurone
1222  for(int j=0;j<neu_index;j++)
1223  {
1224  node_neurons = node_neurons->next;
1225  if ( node_neurons == NULL )
1226  return bias;
1227  }
1228  string str_tmp = _getProp(node_neurons, string("bias"));
1229  bias = atof(str_tmp.c_str());
1230  return bias;
1231 }

References yacsorb.CORBAEngineTest::i.

◆ GetNormalisationInput()

void PMMLlib::PMMLlib::GetNormalisationInput ( int  index,
double *  dnorm 
)

Specific to NeuralNetwork.

Get the input parameters on the normalization

Parameters
node_annNeural network node
indexIndex of the input
[out]dnormArray that contains the mean and the standard deviation

Definition at line 1016 of file PMMLlib.cxx.

1018 {
1019  CheckNeuralNetwork();
1020  dnorm[0] = 0.0;
1021  dnorm[1] = 0.0;
1022  xmlNodePtr node_inputs = GetChildByName(_currentModelNode,"NeuralInputs");
1023  if ( node_inputs == NULL )
1024  return ;
1025  node_inputs = GetChildByName(node_inputs,"NeuralInput");
1026  if ( node_inputs == NULL )
1027  return ;
1028  // Positionnement sur la bonne entree
1029  for(int i=0;i<index;i++)
1030  {
1031  node_inputs = node_inputs->next;
1032  if ( node_inputs == NULL )
1033  return ;
1034  }
1035  xmlNodePtr tmpNode = GetChildByName(node_inputs,"DerivedField");
1036  if ( tmpNode == NULL )
1037  return ;
1038  xmlNodePtr node_field = GetChildByName(tmpNode,"NormContinuous");
1039  if ( node_field == NULL )
1040  return ;
1041  if (string((const char*)(node_field->name)) == "NormContinuous")
1042  {
1043  //Get mean and standard deviation
1044  string str_tmp;
1045  xmlNodePtr node_linearnorm = node_field->children;
1046  str_tmp = _getProp(node_linearnorm, string("orig"));
1047  double dorig1 = atof(str_tmp.c_str());
1048  str_tmp = _getProp(node_linearnorm, string("norm"));
1049  double dnorm1 = atof(str_tmp.c_str());
1050  node_linearnorm = node_linearnorm->next;
1051  str_tmp = _getProp(node_linearnorm, string("orig"));
1052  double dorig2 = atof(str_tmp.c_str());
1053  str_tmp = _getProp(node_linearnorm, string("norm"));
1054  double dnorm2 = atof(str_tmp.c_str());
1055  if ( dnorm1 * dnorm2 < -0.5 ) // <=> GetNormalizationType == 0
1056  {
1057  // case of kMinusOneOne
1058  dnorm[0] = dorig1;
1059  dnorm[1] = dorig2;
1060  }
1061  else // <=> GetNormalizationType == 1
1062  {
1063  // case of kCR, kZeroOne
1064  dnorm[0] = dorig2;
1065  dnorm[1] = -1.0 * dnorm1 * dorig2; //dorig2 / dnorm1;
1066  }
1067  }
1068 }

References yacsorb.CORBAEngineTest::i.

◆ GetNormalisationOutput()

void PMMLlib::PMMLlib::GetNormalisationOutput ( int  index,
double *  dnorm 
)

Specific to NeuralNetwork.

Get the parameters on the normalization of an output for the current model.

Parameters
indexOutput index
[out]dnormArray that contains the mean and the standard deviation

Definition at line 1076 of file PMMLlib.cxx.

1078 {
1079  CheckNeuralNetwork();
1080  dnorm[0] = 0.0;
1081  dnorm[1] = 0.0;
1082 
1083  xmlNodePtr node_outputs = GetChildByName(_currentModelNode,"NeuralOutputs");
1084  if ( node_outputs == NULL )
1085  return ;
1086  node_outputs = GetChildByName(node_outputs,"NeuralOutput");
1087  if ( node_outputs == NULL )
1088  return ;
1089  // Positionnement sur la bonne sortie
1090  for(int i=0;i< index;i++)
1091  {
1092  node_outputs = node_outputs->next;
1093  if ( node_outputs == NULL )
1094  return ;
1095  }
1096  xmlNodePtr tmpNode = GetChildByName(node_outputs,"DerivedField");
1097  if ( tmpNode == NULL )
1098  return ;
1099  xmlNodePtr node_field = GetChildByName(tmpNode,"NormContinuous");
1100  if ( node_field == NULL )
1101  return ;
1102 
1103  if (string((const char*)(node_field->name)) == "NormContinuous")
1104  {
1105  // Recuperation de la moyenne et de l'ecart type
1106  string str_tmp;
1107  xmlNodePtr node_linearnorm = node_field->children;
1108  str_tmp = _getProp(node_linearnorm, string("orig"));
1109  double dorig1 = atof(str_tmp.c_str());
1110  str_tmp = _getProp(node_linearnorm, string("norm"));
1111  double dnorm1 = atof(str_tmp.c_str());
1112  node_linearnorm = node_linearnorm->next;
1113  str_tmp = _getProp(node_linearnorm,string("orig"));
1114  double dorig2 = atof(str_tmp.c_str());
1115  str_tmp = _getProp(node_linearnorm, string("norm"));
1116  double dnorm2 = atof(str_tmp.c_str());
1117  if ( dnorm1 * dnorm2 < -0.5 )
1118  {
1119  // case of kMinusOneOne
1120  dnorm[0] = dorig1;
1121  dnorm[1] = dorig2;
1122  }
1123  else
1124  {
1125  // case of kCR, kZeroOne
1126  dnorm[0] = dorig2;
1127  dnorm[1] = -1.0 * dorig2 * dnorm1; //-1.0 * dorig2 / dnorm1;
1128  }
1129  }
1130 }

References yacsorb.CORBAEngineTest::i.

◆ GetNormalizationType()

int PMMLlib::PMMLlib::GetNormalizationType ( )

Specific to NeuralNetwork.

Get the normalization type of the current model

Returns
Normalization type of the neural network

Definition at line 971 of file PMMLlib.cxx.

972 {
974 
975  xmlNodePtr node_inputs = GetChildByName(_currentModelNode,"NeuralInputs");
976  node_inputs = GetChildByName(node_inputs,"NeuralInput");
977  xmlNodePtr nodeTmp = GetChildByName(node_inputs,"DerivedField");
978  xmlNodePtr node_field = nodeTmp->children;
979  xmlNodePtr node_linearnorm;
980  string str_tmp;
981  double dorig1, dnorm1;
982  double dorig2, dnorm2;
983  if (string((const char*)(node_field->name)) == "NormContinuous")
984  {
985  // Get mean and standard deviation
986  node_linearnorm = node_field->children;
987  str_tmp = _getProp(node_linearnorm, string("orig"));
988  dorig1 = atof(str_tmp.c_str());
989  str_tmp = _getProp(node_linearnorm, string("norm"));
990  dnorm1 = atof(str_tmp.c_str());
991  node_linearnorm = node_linearnorm->next;
992  str_tmp = _getProp(node_linearnorm, string("orig"));
993  dorig2 = atof(str_tmp.c_str());
994  str_tmp = _getProp(node_linearnorm, string("norm"));
995  dnorm2 = atof(str_tmp.c_str());
996  if ( dnorm1 * dnorm2 < -0.5 )
997  { // case of kMinusOneOne
998  return 0;
999  }
1000  else
1001  { // case of kCR, kZeroOne
1002  return 1;
1003  }
1004  }
1005  string msg("Unable to retrieve the normalization type.");
1006  throw msg;
1007 }

◆ GetPrecNeuronSynapse()

double PMMLlib::PMMLlib::GetPrecNeuronSynapse ( int  layer_index,
int  neu_index,
int  prec_index 
)

Specific to NeuralNetwork.

Get the synaptic weight

Parameters
layer_indexIndex of the layer to get synaptic weight
neu_indexIndex of the neuron
prec_indexIndex of the synapse
Returns
Synaptic weight

Definition at line 1241 of file PMMLlib.cxx.

1244 {
1246 
1247  double weight = 0.;
1248  xmlNodePtr node_layers = GetChildByName(_currentModelNode,"NeuralLayer");
1249  if ( node_layers == NULL )
1250  return weight;
1251  // Positionnement a la bonne couche
1252  for(int i=0;i<layer_index;i++)
1253  {
1254  node_layers = node_layers->next;
1255  if ( node_layers == NULL )
1256  return weight;
1257  }
1258  xmlNodePtr node_neurons = GetChildByName(node_layers,"Neuron");
1259  // Positionnement sur le bon neurone
1260  for(int i=0;i<neu_index;i++)
1261  {
1262  node_neurons = node_neurons->next;
1263  if ( node_neurons == NULL )
1264  return weight;
1265  }
1266  xmlNodePtr node_con = GetChildByName(node_neurons,"Con");
1267  // Positionnement sur la bonne synapse
1268  for(int i=0;i<prec_index;i++)
1269  {
1270  node_con = node_con->next;
1271  if ( node_con == NULL )
1272  return weight;
1273  }
1274  string str_tmp = _getProp(node_con, string("weight"));
1275  weight = atof(str_tmp.c_str());
1276  return weight;
1277 }

References yacsorb.CORBAEngineTest::i.

◆ ReadNetworkStructure()

std::string PMMLlib::PMMLlib::ReadNetworkStructure ( )

Specific to NeuralNetwork.

Read the structure of the network

Returns
Structure read

Definition at line 759 of file PMMLlib.cxx.

760 {
762 
763  string structure("");
764  // Treatment of the input
765  xmlNodePtr inputNodes = GetChildByName(_currentModelNode,"NeuralInputs");
766  if ( inputNodes != NULL )
767  {
768  xmlNodePtr inputNode = GetChildByName(inputNodes,"NeuralInput");
769  if ( inputNode != NULL )
770  {
771  while (inputNode != NULL)
772  {
773  xmlNodePtr child = GetChildByName(inputNode,"DerivedField");
774  if ( child != NULL )
775  {
776  xmlNodePtr fieldName = child->children; // NormContinuous
777  if ( fieldName != NULL )
778  {
779  string field = _getProp(fieldName, string("field"));
780  structure += field;
781  structure += ":";
782  }
783  }
784  inputNode = inputNode->next;
785  }
786  // Delete the last comma
787  structure.erase(structure.size()-1);
788  }
789  }
790  // Intermediary layers
791  xmlNodePtr node_layer = GetChildByName(_currentModelNode,"NeuralLayer");
792  if ( node_layer != NULL )
793  {
794  string name = string((const char*)(node_layer->name));
795  structure += ",";
796 
797  while ( node_layer != NULL &&
798  (string((const char*)(node_layer->name)) == "NeuralLayer") &&
799  node_layer->next != NULL &&
800  (string((const char*)(node_layer->next->name)) != "NeuralOutputs") )
801  {
802  // Get the number of neurons of the current layer
803  string nbneurons = _getProp(node_layer, string("numberOfNeurons"));
804  structure += nbneurons;
805  structure += ",";
806  node_layer = node_layer->next;
807  }
808  }
809  // Output layers
810  xmlNodePtr node_outputs = GetChildByName(_currentModelNode,"NeuralOutputs");
811  if ( node_outputs != NULL )
812  {
813  xmlNodePtr node_output = GetChildByName(node_outputs,"NeuralOutput");
814  if ( node_output != NULL )
815  {
816  while (node_output != NULL)
817  {
818  // Get the input of the current layer
819  xmlNodePtr child = GetChildByName(node_output,"DerivedField");
820  if ( child != NULL )
821  {
822  xmlNodePtr fieldName = child->children; // NormContinuous
823  if ( fieldName != NULL )
824  {
825  if (string((const char*)(fieldName->name)) == "NormContinuous")
826  structure += "@";
827 
828  string field = _getProp(fieldName, string("field"));
829  structure += field;
830  structure += ":";
831  }
832  }
833  node_output = node_output->next;
834  }
835  // Delete the last comma
836  structure.erase(structure.size()-1);
837  }
838  }
839  return structure;
840 }

◆ SetNeuralNetName()

void PMMLlib::PMMLlib::SetNeuralNetName ( int  index,
std::string  name 
)

Not tested.

Set the name of the neural network

Parameters
indexNeural network index
nameNeural network name to set

Definition at line 1286 of file PMMLlib.cxx.

1288 {
1290 
1291  int i=0;
1292  if (_doc != NULL)
1293  {
1294  xmlNodePtr node_ann = GetChildByName(_rootNode,"NeuralNetwork");
1295  while ((i != index) && (node_ann != NULL))
1296  {
1297  node_ann = node_ann->next;
1298  i++;
1299  }
1300  xmlNewProp(node_ann, (const xmlChar*)"modelName", (const xmlChar*)(name.c_str()));
1301  }
1302  xmlSaveFormatFile( string(_pmmlFile+".pmml").c_str(), _doc, 1);
1303 }
std::string _pmmlFile
Name of the associated PMML file.
Definition: PMMLlib.hxx:77
xmlDocPtr _doc
Associated DOM documents.
Definition: PMMLlib.hxx:78

References yacsorb.CORBAEngineTest::i.