Version: 8.3.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

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 1395 of file PMMLlib.cxx.

References PMMLlib::PMMLlib::_currentModelNode, PMMLlib::PMMLlib::_getProp(), PMMLlib::PMMLlib::CheckNeuralNetwork(), and PMMLlib::PMMLlib::GetChildByName().

1401 {
1403 
1404  xmlNodePtr netNode = _currentModelNode;
1405  // if 'NeuralInputs' node does not exist, create it
1406  xmlNodePtr neuralInputsNode = GetChildByName(netNode, "NeuralInputs");
1407  if(!neuralInputsNode)
1408  {
1409  neuralInputsNode = xmlNewChild(netNode, 0, (const xmlChar*)"NeuralInputs", 0);
1410  xmlNewProp(neuralInputsNode, (const xmlChar*)"numberOfInputs", (const xmlChar*)"0" );
1411  }
1412  // increment the number of inputs
1413  string numberOfInputsStr = _getProp(neuralInputsNode, string("numberOfInputs"));
1414  int numberOfInputs;
1415  istringstream( numberOfInputsStr ) >> numberOfInputs;
1416  numberOfInputs++;
1417  stringstream ss;
1418  ss << numberOfInputs;
1419  xmlSetProp(neuralInputsNode, (const xmlChar*)"numberOfInputs", (const xmlChar*)(ss.str().c_str()) );
1420  // then append the node and its children
1421  xmlNodePtr neuralInputNode = xmlNewChild(neuralInputsNode, 0, (const xmlChar*)"NeuralInput", 0);
1422  ss.str(""); ss << id;
1423  xmlNewProp(neuralInputNode, (const xmlChar*)"id", (const xmlChar*)(ss.str().c_str()) );
1424 
1425  xmlNodePtr derivedFieldNode = xmlNewChild(neuralInputNode, 0, (const xmlChar*)"DerivedField", 0);
1426  xmlNewProp(derivedFieldNode, (const xmlChar*)"optype", (const xmlChar*)(optype.c_str()) );
1427  xmlNewProp(derivedFieldNode, (const xmlChar*)"dataType", (const xmlChar*)(dataType.c_str()) );
1428 
1429  xmlNodePtr normcontNode = xmlNewChild(derivedFieldNode, 0, (const xmlChar*)"NormContinuous", 0);
1430  xmlNewProp(normcontNode, (const xmlChar*)"field", (const xmlChar*)(inputName.c_str()) );
1431 
1432  xmlNodePtr node_linearnorm1 = xmlNewChild(normcontNode, 0, (const xmlChar*)"LinearNorm", 0);
1433  ss.str(""); ss << scientific << orig1;
1434  xmlNewProp(node_linearnorm1, (const xmlChar*)"orig", (const xmlChar*)(ss.str().c_str()) );
1435  ss.str(""); ss << scientific << norm1;
1436  xmlNewProp(node_linearnorm1, (const xmlChar*)"norm", (const xmlChar*)(ss.str().c_str()) );
1437  xmlNodePtr node_linearnorm2 = xmlNewChild(normcontNode, 0, (const xmlChar*)"LinearNorm", 0);
1438  ss.str(""); ss << scientific << orig2;
1439  xmlNewProp(node_linearnorm2, (const xmlChar*)"orig", (const xmlChar*)(ss.str().c_str()) );
1440  ss.str(""); ss << scientific << norm2;
1441  xmlNewProp(node_linearnorm2, (const xmlChar*)"norm", (const xmlChar*)(ss.str().c_str()) );
1442 }
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 1511 of file PMMLlib.cxx.

References PMMLlib::PMMLlib::_currentModelNode, PMMLlib::PMMLlib::_currentNode, PMMLlib::PMMLlib::_getProp(), PMMLlib::PMMLlib::CheckNeuralNetwork(), PMMLlib::kIDENTITY, PMMLlib::kLOGISTIC, and PMMLlib::kTANH.

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

References PMMLlib::PMMLlib::_currentModelName, PMMLlib::PMMLlib::_currentModelNode, PMMLlib::PMMLlib::_currentModelType, PMMLlib::PMMLlib::_rootNode, PMMLlib::PMMLlib::CheckNeuralNetwork(), PMMLlib::kANN, and PMMLlib::kREGRESSION.

1362 {
1364  _currentModelName = modelName;
1365 
1367 
1368  string function;
1369  switch(functionName)
1370  {
1371  case kREGRESSION:
1372  function = "regression";
1373  break;
1374  }
1375 
1376  xmlNodePtr netNode = xmlNewChild(_rootNode, 0, (const xmlChar*)"NeuralNetwork", 0);
1377  xmlNewProp(netNode, (const xmlChar*)"modelName", (const xmlChar*)(_currentModelName.c_str()) );
1378  xmlNewProp(netNode, (const xmlChar*)"functionName", (const xmlChar*)(function.c_str()) );
1379  xmlNewProp(netNode, (const xmlChar*)"numberOfLayers", (const xmlChar*)"0" );
1380  _currentModelNode = netNode;
1381 }
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 1456 of file PMMLlib.cxx.

References PMMLlib::PMMLlib::_currentModelNode, PMMLlib::PMMLlib::_getProp(), PMMLlib::PMMLlib::CheckNeuralNetwork(), and PMMLlib::PMMLlib::GetChildByName().

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

References PMMLlib::PMMLlib::_currentNode, PMMLlib::PMMLlib::_getProp(), and PMMLlib::PMMLlib::CheckNeuralNetwork().

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

References PMMLlib::PMMLlib::_currentModelNode, PMMLlib::PMMLlib::_getProp(), PMMLlib::PMMLlib::CheckNeuralNetwork(), PMMLlib::PMMLlib::GetChildByName(), and CORBAEngineTest::i.

Referenced by PMMLlib::PMMLlib::ExportNeuralNetworkFortran().

899 {
901 
902  string name("");
903  xmlNodePtr node_inputs = GetChildByName(_currentModelNode,"NeuralInputs");
904  if ( node_inputs == NULL )
905  return name;
906 
907  node_inputs = node_inputs->children;
908  if ( node_inputs == NULL )
909  return name;
910 
911  for(int i = 0;i<index;i++)
912  {
913  node_inputs = node_inputs->next;
914  if ( node_inputs == NULL )
915  return name;
916  }
917 
918  node_inputs = node_inputs->children;
919  if ( node_inputs == NULL )
920  return name;
921 
922  node_inputs = node_inputs->children;
923  if ( node_inputs == NULL )
924  return name;
925 
926  name = _getProp(node_inputs, string("field"));
927 
928  return name;
929 }
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 937 of file PMMLlib.cxx.

References PMMLlib::PMMLlib::_currentModelNode, PMMLlib::PMMLlib::_getProp(), PMMLlib::PMMLlib::CheckNeuralNetwork(), PMMLlib::PMMLlib::GetChildByName(), and CORBAEngineTest::i.

Referenced by PMMLlib::PMMLlib::ExportNeuralNetworkFortran().

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

Specific to NeuralNetwork.

Get the number of hidden layers

Returns
Number of hidden layers

Definition at line 1138 of file PMMLlib.cxx.

References PMMLlib::PMMLlib::_currentModelNode, PMMLlib::PMMLlib::CheckNeuralNetwork(), and PMMLlib::PMMLlib::GetChildByName().

Referenced by PMMLlib::PMMLlib::GetNbLayers().

1139 {
1141 
1142  int nb_layers = 0;
1143  xmlNodePtr node_layers = GetChildByName(_currentModelNode,"NeuralLayer");
1144  if ( node_layers == NULL )
1145  return nb_layers;
1146 
1147  while (string((const char*)(node_layers->name)) == "NeuralLayer")
1148  {
1149  nb_layers++;
1150  node_layers = node_layers->next;
1151  if ( node_layers == NULL )
1152  return nb_layers;
1153  }
1154  return nb_layers;
1155 }
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 848 of file PMMLlib.cxx.

References PMMLlib::PMMLlib::_currentModelNode, PMMLlib::PMMLlib::CheckNeuralNetwork(), and PMMLlib::PMMLlib::GetChildByName().

Referenced by PMMLlib::PMMLlib::ExportNeuralNetworkCpp(), PMMLlib::PMMLlib::ExportNeuralNetworkFortran(), and PMMLlib::PMMLlib::ExportNeuralNetworkPyStr().

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

Get the total number of layers

Returns
Total number of layers

Definition at line 1161 of file PMMLlib.cxx.

References PMMLlib::PMMLlib::GetNbHiddenLayers().

1162 {
1163  return (GetNbHiddenLayers() + 2);
1164 }
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 1171 of file PMMLlib.cxx.

References PMMLlib::PMMLlib::_currentModelNode, PMMLlib::PMMLlib::CheckNeuralNetwork(), PMMLlib::PMMLlib::GetChildByName(), and CORBAEngineTest::i.

Referenced by PMMLlib::PMMLlib::ExportNeuralNetworkCpp(), PMMLlib::PMMLlib::ExportNeuralNetworkFortran(), and PMMLlib::PMMLlib::ExportNeuralNetworkPyStr().

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

Specific to NeuralNetwork.

Recover the number of outputs

Returns
Number of outputs

Definition at line 872 of file PMMLlib.cxx.

References PMMLlib::PMMLlib::_currentModelNode, PMMLlib::PMMLlib::CheckNeuralNetwork(), and PMMLlib::PMMLlib::GetChildByName().

Referenced by PMMLlib::PMMLlib::ExportNeuralNetworkCpp(), PMMLlib::PMMLlib::ExportNeuralNetworkFortran(), and PMMLlib::PMMLlib::ExportNeuralNetworkPyStr().

873 {
875 
876  int nb=0;
877  xmlNodePtr node_outputs = GetChildByName(_currentModelNode,"NeuralOutputs");
878  if ( node_outputs == NULL )
879  return nb;
880 
881  node_outputs = node_outputs->children;
882 
883  while (node_outputs != NULL)
884  {
885  nb++;
886  node_outputs = node_outputs->next;
887  }
888 
889  return nb;
890 }
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 750 of file PMMLlib.cxx.

References PMMLlib::PMMLlib::GetPtr(), and PMMLlib::PMMLlib::GetTypeString().

Referenced by PMMLlib::PMMLlib::SetCurrentModel().

751 {
752  return GetPtr(name, GetTypeString() );
753 }
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 740 of file PMMLlib.cxx.

References PMMLlib::PMMLlib::GetPtr(), and PMMLlib::PMMLlib::GetTypeString().

741 {
742  return GetPtr(index, GetTypeString() );
743 }
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 1205 of file PMMLlib.cxx.

References PMMLlib::PMMLlib::_currentModelNode, PMMLlib::PMMLlib::_getProp(), PMMLlib::PMMLlib::CheckNeuralNetwork(), PMMLlib::PMMLlib::GetChildByName(), and CORBAEngineTest::i.

Referenced by PMMLlib::PMMLlib::fillVectorsForExport().

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

References PMMLlib::PMMLlib::_currentModelNode, PMMLlib::PMMLlib::_getProp(), PMMLlib::PMMLlib::CheckNeuralNetwork(), PMMLlib::PMMLlib::GetChildByName(), and CORBAEngineTest::i.

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

References PMMLlib::PMMLlib::_currentModelNode, PMMLlib::PMMLlib::_getProp(), PMMLlib::PMMLlib::CheckNeuralNetwork(), PMMLlib::PMMLlib::GetChildByName(), and CORBAEngineTest::i.

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

References PMMLlib::PMMLlib::_currentModelNode, PMMLlib::PMMLlib::_getProp(), PMMLlib::PMMLlib::CheckNeuralNetwork(), and PMMLlib::PMMLlib::GetChildByName().

Referenced by PMMLlib::PMMLlib::ExportNeuralNetworkCpp(), PMMLlib::PMMLlib::ExportNeuralNetworkFortran(), and PMMLlib::PMMLlib::ExportNeuralNetworkPyStr().

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

References PMMLlib::PMMLlib::_currentModelNode, PMMLlib::PMMLlib::_getProp(), PMMLlib::PMMLlib::CheckNeuralNetwork(), PMMLlib::PMMLlib::GetChildByName(), and CORBAEngineTest::i.

Referenced by PMMLlib::PMMLlib::fillVectorsForExport().

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

Specific to NeuralNetwork.

Read the structure of the network

Returns
Structure read

Definition at line 760 of file PMMLlib.cxx.

References PMMLlib::PMMLlib::_currentModelNode, PMMLlib::PMMLlib::_getProp(), PMMLlib::PMMLlib::CheckNeuralNetwork(), and PMMLlib::PMMLlib::GetChildByName().

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

References PMMLlib::PMMLlib::_doc, PMMLlib::PMMLlib::_pmmlFile, PMMLlib::PMMLlib::_rootNode, PMMLlib::PMMLlib::CheckNeuralNetwork(), PMMLlib::PMMLlib::GetChildByName(), and CORBAEngineTest::i.

1289 {
1291 
1292  int i=0;
1293  if (_doc != NULL)
1294  {
1295  xmlNodePtr node_ann = GetChildByName(_rootNode,"NeuralNetwork");
1296  while ((i != index) && (node_ann != NULL))
1297  {
1298  node_ann = node_ann->next;
1299  i++;
1300  }
1301  xmlNewProp(node_ann, (const xmlChar*)"modelName", (const xmlChar*)(name.c_str()));
1302  }
1303  xmlSaveFormatFile( string(_pmmlFile+".pmml").c_str(), _doc, 1);
1304 }