Multilayer Backpropagation Library Reference


Advertisements

The feed forward neural network is a useful classifier for pattern recognition. This library makes easier the use and implementation of neural networks in your applications.

I invite you to check some of the examples included in this package.

Name Spaces

mlbp: This is the namespace where all data types, objects and functions are grouped.

Data types

bpHandle:
Generic pointer, not widely used in this library.
Declaration in bp_global.h
typedef void *bpHandle;

bpUint:
Base data type for 32 bit unsigned integer.
Declaration in bp_global.h
typedef unsigned int bpUint;

bpfloat:
Basic floating point data type, this type changes depending on if the DOUBLE_PRECISION macro is defined. If DOUBLE_PRECISION is defined then bpfloat is a double data type or else it is a float data type.
REMARKS: Enabling double precision requires to link to a different library.
-If double precision is enabled then link to library mlbp_stdfp.lib or mlbp_mtdfp.lib and use mlbp_stdfp.dll or mlbp_mtdfp.dll as the case may be.
-If double precision isn’t enabled then link to library mlbp_stsfp.lib or mlbp_mtsfp.lib and use mlbp_stsfp.dll or mlbp_mtsfp.dll as the case may be.
Declaration in bp_global.h

#ifdef DOUBLE_PRECISION
typedef double bpfloat ;
#else
typedef float bpfloat;
#endif

Class bpArray:
Utility class for handling bpfloat arrays. See more details on file bpArray.h

Class bpBuffer:
Utility class for handling byte arrays. See more details on file bpBuffer.h

Class IndexArray:
Utility class for handling integer arrays. See more details on file indexArray.h

Class bp: Represents the neural network object. This is the object you should use for your applications.

BP Class Reference

class bp
{
private:
    bpHandle m_handle;
public:  
    bp();
    bp(const bp &other);
    ~bp();
    bp &operator=(const bp &other);   
    bool create(bpUint InputSize,bpUint OutPutsize,bpUint InputNeuronsCount,
                 const indexArray &hiddenLayers=indexArray());
    void clear();
    void run();
    void run(const bpArray &input);   
    bpfloat train(const bpArray &desiredOutput, bpfloat alpha=0.09f, bpfloat Momentum=0.1f);
    bpfloat train(const bpArray &desiredOutput,const bpArray &input,bpfloat alpha=0.09f,bpfloat Momentum=0.1f);   
    bpfloat trainwec(const bpArray &desiredOutput,const bpArray &input,bpfloat alpha=0.09f,bpfloat Momentum=0.1f);   
    bool save(const char *file,bpUint cId=0,bpUint cId2=0);   
    bool load(const char *file,bpUint cid=0,bpUint cId2=0);   
    bpBuffer getRawData() const;
    bool setRawData(const bpBuffer &rawData);   
    bpUint getInputSize() const;
    bpUint getILNeuronCount() const;
    bpUint getOutPutSize() const;
    bpUint getHiddenLayerCount() const;
    bpUint getHLNeuronCount(bpUint layerIndex) const;   
    bpArray &getILNeuronWeights(bpUint neuronIndex);   
    const bpArray &getILNeuronWeights(bpUint neuronIndex) const;   
    bpArray &getHLNeuronWeights(bpUint layerindex,bpUint neuronIndex);  
    const bpArray &getHLNeuronWeights(bpUint layerindex,bpUint neuronIndex) const;
    bpArray &getOLNeuronWeights(bpUint neuronIndex);
    const bpArray &getOLNeuronWeights(bpUint neuronIndex) const;
    bpArray &getInput();
    const bpArray &getInput() const;
    bpArray &getHLNeuronInputs(bpUint layerIndex);
    const bpArray &getHLNeuronInputs(bpUint layerIndex) const;
    bpArray &getOLNeuronInputs();
    const bpArray &getOLNeuronInputs() const;
    bpArray &getOutput();   
    indexArray getHLNeuronSizes() const;   
    bool addHiddenLayer(bpUint position,bpUint neurons);
    bool removeHiddenLayer(bpUint position);
    bool addNeuronsToIL(bpUint numNeurons,bpUint position);
    bool addNeuronsToHL(bpUint layerIndex,bpUint numNeurons,bpUint position);
    bool removeNeuronsToIL(bpUint numNeurons,bpUint position);
    bool removeNeuronsToHL(bpUint layerIndex,bpUint numNeurons,bpUint position);
    bool addNeuronsToOL(bpUint numNeurons,bpUint position);
    bool removeNeuronsToOL(bpUint numNeurons,bpUint position);
    bool resizeInput(bpUint newSize);
    bool setInputValues(const bpArray &values);   
    bool setInputValue(bpfloat value,bpUint index);
    bool setHiddenLayerInput(const bpArray &input,bpUint index);
    bool setOutputLayerInput(const bpArray &input);
    void setUpdateBuffer(bool bUpdate);
    void setStartValues(START_VALUES type=BP_VAL_RANDOM_SIGNED,bpfloat fMax=0.5f,bpfloat fFixed=0,
                        bpfloat iGain=1);
    void initRandGen(int seed=0);
    bool runInputLayer();
    bool runHiddenLayer(bpUint index);
    bool runOutputLayer();

    BP_ERRORS getError() const;
    bool isEmpty() const;
    bool multiThreadSupport() const;
    void setMultiThreaded(bool bSet, bool terminateThreads=false);
    bool multiThreadEnabled() const;
    void stop() const;
    bpHandle h() const;
    void setAsReference(bool bSet);

 

};

Class bp Member Functions

 

Function

bool bp::create(bpUint InputSize,bpUint OutPutsize,bpUint InputNeuronsCount,
const indexArray&hiddenLayers=indexArray());

Description: Initializes the neural network. This is the first function you should call before doing everything.

Parameters:
InputSize: Determines the input size of the network. This value must match with the pattern size you want to set to the network.
For example, if you want to recognize 16 x 16 images then your input must be 16*16=256. This value can’t be 0. Input values in the array must be at most 1, so if you plan using values greater than 1, make sure to normalize them.

OutPutsize: Sets the output size of the network. This value must match with the desired output size. For example if you want to get an ascii value in binary form, your output size must be 8. Remember this neural network uses the sigmoid activation function, therefore only values from 0 to 1 are allowed. If you plan using values greater than 1 then make sure to normalize them.
This value can’t be 0.

InputNeuronsCont: Sets the size of the input layer neurons. This value can be whatever you like to be. These will be the quantity of neurons processing your network input so the less you use the faster the network will process your data. This value can’t be 0.

 

hiddenLayers: This parameter determines how many hidden layers the network will have and the neuron count per each hidden layer. It receives as an input a reference to an indexArray object. You must create and set the object values before passing it to the function. Or pass an empty constructor if no hiddenLayers are wanted. The quantity of elements in the array determines the hidden layer count and the value per array element sets the neuron count per hidden layer.

Return values: Returns true if network is created otherwise false. To get more details about the error call bp::getError()
Return Errors:
BP_E_NOMEMORY: Could not allocate memory for network.
BP_E_NOERROR: Everything went fine. This is when function returns true.

Function

void bp::clear()

Description:
Clears are references and objects of the network structure. This function is called on the destructor of the class.

 

Function

void bp::run()

Description:
Propagates and executes the neural network. This is the main operation function. When the network has been properly trained, after calling run you get your desired result by calling bp::getOutput().
Function ignores call if network is empty. Before calling this function make sure to set the input values with bp::setInputValues().
Return values by bp::GetError()
BP_E_EMPTY: Network has not been created.
BP_E_NOERROR: Everything went fine

Function

void bp::run(const bpArray &input);

Description: Overloaded function of bp::run(). It receives a parameter containing all input values to execute the network.
Parameters:
Input: Contains the vector values that the network will use to as input. Notice: the size of the array must match with the network input size or else the function does nothing. Values are copied to the internal array.
Return values by bp::GetError()
BP_E_EMPTY: Network has not been created.
BP_E_SIZEMISMATCH: Input size from parameter “input” doesn’t match with network input size.
BP_E_NOERROR: Everything went fine

Function

bpfloat bp::train(const bpArray &desiredOutput, bpfloat deltaValue, bpfloat Momentum);

Description:
It trains the network given a desired output as a parameter for the current pattern that has been set as an input. This function applies the backpropagation algorithm to train the neural network. It returns the general error. This function should be used inside an iteration loop until it returns an error close to 0.

Parameters:
desiredOutput: Specifies the desired output  for the current input values. This is the value you expect to get when calling “run” for the current given input. Parameter is a bpArray object type which must be filled with values before passing it to the function.

Alpha: Specifies the learning rate of the network. It must be a positive value from 0.05 to 0.25. The bigger this value is, the bigger steps the network does during training. If this value is small, the network will take longer to train but, it has less chance to miss the lowest error value.

Momentum: This is an optional value and can be 0. This value helps to accelerate the training rate of the network. If this parameter is included then values should be from 0.1 to 1

Function ignores call when network is empty.
Return values: The function returns the current delta error or general error. The network converges to its desired functionality when this value gets close to zero.

Return values by bp::GetError()
BP_E_EMPTY: Network has not been set yet.
BP_E_SIZEMISMATCH: Parameter desiredOutput has different dimensions than the network output count.
BP_E_NOERROR: No error whatsoever, everything went fine.

Function

bpfloat bp::train(const bpArray &desiredOutput, const bpArray &input, bpfloat alpha, bpfloat Momentum)

 

Description: Overloaded function. It specifies the additional parameter input which sets the input of the network pattern for the desiredOutput. It saves a step of calling setInputValues and then train.

Function

bpfloat bp::trainwec(const bpArray &desiredOutput, const bpArray &input, bpfloat alpha, bpfloat Momentum)

 

Description: This function works as the other two “train” functions, but this one does not perform any error checking or boundary tests on arrays. Since training is intensive, this function saves usage of CPU on other tasks such as error checking. This function is a little faster than the other two and its recommended to use it when your code is stable and you are absolutely sure no error could happen during execution on the client side.

Function

bool bp::save(const char *file,bpUint cId=0,bpUint cId2=0);

Description: Saves all the neural network info into a file.
Parameters:
File:  Null terminated string to the file path.
cId: This is a custom id to protect your file, a 32 bit integer unique identifier will be saved in the header of the file.
cid2:Custom bit unique 32 bit integer to save in the headers.

Returns true if file is saved successfully, false if failed. To get details of the error call bp::getError().

Returned errors by bp::getError():
BP_E_EMPTY: Returned when the network is empty and there‘s nothing to save.
BP_E_FILEWRITE_ERROR: Returned when the file could not be opened for writing.
BP_E_NULL: Returned when parameter file is 0
BP_E_NOERROR: File saved successfully. This is set when it returns true.

Function

bool bp::load(const char *file,bpUint cid=0,bpUint cId2=0);

Description: Loads the network data from a saved file.
Parameters
File: Null terminated string to the file path.
cid: Custom 32 bit integer. If file was not saved with this id then function won’t load any data.
cid2: Custom 32 bit integer. If file was not saved with this id2 then function won’t load any data.

Returns true if file is loaded successfully. Otherwise it returns false. To get specific details about the error call bp::getError().
Returned errors by bp::getError().
BP_E_FILEREAD_ERROR: Returned when the file could not be opened for reading.
BP_E_NULL: Returned when parameter file is 0
BP_E_NOERROR: File saved successfully. This is set when it returns true.
BP_E_TYPE: File cannot be recognized by the library or format is incorrect.
BP_E_VERSION: File version is not supported by library.
BP_E_CID: Custom id1 on file does not match with cid parameter.
BP_E_CID2: Custom id2 on file does not match with cid2 parameter.
BP_E_VERSION32: File was saved by 32-bit floating point library and it is trying to be accessed with 64 bit library.
BP_E_VERSION64: File was saved by 64-bit floating point library and it is trying to be accessed with 32 bit library.

Function

bpBuffer bp::getRawData()const;
Description: Saves a copy of the network data on a buffer. This is useful when you need to make a temporary copy of the network, or if you want to save it on a different file other than the file format used by the object.

Returns a bpBuffer object. See more details about class bpBuffer in bpBuffer.h. Returns an empty buffer if the network is empty. To get more details call bp::getError()
Returned errors:
BP_E_EMPTY: Returned when the network is empty.
BP_E_NOERROR: No error occurred everything went fine.

Function

bool bp::setRawData(const bpBuffer &rawData)

Description:
Creates the network based on a buffer created by bp::getRawData(). Notice the current network is cleared to set the new one.
Parameter:
Receives the bpBuffer object containing the raw data.

Return value: Returns true if successful or false if it fails. To get more details about the error call bp::getError()
Returned Errors:
BP_E_CORRUPTED_DATA: Data of the buffer cannot be recognized by the library.
BP_E_VERSION: Library does not support this buffer version.
BP_E_NOMEMORY: Could not allocate memory for the network.
BP_E_NOERROR: Everything went fine no error returned.
BP_E_VERSION64: Buffer was created from by the 64 bit floating point-library and it’s tried to be accessed with the 32 bit-floating version.
BP_E_VERSION32: Buffer was created from by the 32 bit floating point-library and it’s tried to be accessed with the 64 bit-floating version.

Function

bool bp::setInputValues(const bpArray &values)
Description: Set the input values to the network. Values passed to this function are the one to be set as the network input. Notice, the array size must match with network input size.
Parameters:
Values: An array of float values containing the input values. Values are copied to the network.
Return values: If the size of the array isn’t the same size it returns false else true.
ERROR returned by bp::getError()
BP_E_EMPTY: Network has not been created yet.
BP_E_NOERROR: Everything went fine.
BP_E_SIZEMISMATCH: Parameter values size does not match with network input size.

Function

bool bp::setInputValue(bpfloat value, bpUint index)
Description: Sets a single input value to the network by a given index of the neural network input array.
Parameters:
value: Value to be copied to the network.
Index: 0 based index of the internal array location.
Return values: If the index is bigger than the array size it returns false else true.
ERROR returned by bp::getError()
BP_E_EMPTY: Network has not been created yet.
BP_E_NOERROR: Everything went fine.
BP_E_INDEXERROR: Index bigger than array size.

 

Function

bool bp::setHiddenLayerInput(const bpArray &input, bpUint index)
Description: Sets all input values to a hidden layer.
Parameters:
Input: Array containing the input values.
Index: 0 based index of the layer.
Return values: If the index value is bigger or equal than the total count of layers, it returns false. Also if the input is bigger than the selected layer input then it returns false. If succeeded it returns true.
NOTE: The input size of the hiddenlayer is always the output size of the previous layer.
ERROR returned by bp::getError()
BP_E_EMPTY: Network has not been created yet.
BP_E_NOERROR: Everything went fine.
BP_E_INDEXERROR: Index value is bigger than total layer count.
BP_E_SIZEMISMATCH: Input size is bigger than the layer input size.

Function

bool bp::setOutputLayerInput(const bpArray &input)
Description: Sets all input values to the output layer.
Parameters:
Input: Array containing the input values.
Return values: If the input size is bigger than the output input size size then it returns false. If succeeded it returns true. NOTE: The input size of the output layer is always the output size of the previous layer.
ERROR returned by bp::getError()
BP_E_EMPTY: Network has not been created yet.
BP_E_NOERROR: Everything went fine.
BP_E_SIZEMISMATCH: Input is bigger than layer input.

Function

bpUint bp::getInputSize() const

Description: Returns the input size of the network. This is the same value of the first parameter used on bp::create().
Return values: It returns a 32 bit unsigned integer containing the input size value. 0 if fails.

ERROR returned by bp::getError()
BP_E_EMPTY: Network has not been created yet.
BP_E_NOERROR: Everything went fine.

Function

bpUint bp:: getILNeuronCount() const;

Description: Returns the number of neurons of the input layer.
Return values: Returns a 32 bit unsigned integer containing the count of neurons from the input layer. 0 if fails.

 

ERROR returned by bp::getError()
BP_E_EMPTY: Network has not been created yet.
BP_E_NOERROR: Everything went fine.

Function

bpUint bp::getOutPutSize() const;
Description: Returns the number of outputs from the neural network as well as the number of neurons from the output layer.

Return values: 32 bit unsigned integer containing the output count from the neural network. 0 if fails.
ERROR returned by bp::getError()
BP_E_EMPTY: Network has not been created yet.
BP_E_NOERROR: Everything went fine.

Function

bpUint bp::getHiddenLayerCount() const

Description: Returns the count of hidden layers of the neural network.
Return values: 32 bit unsigned integer containing the total count of hidden layers of the neural network.
ERROR returned by bp::getError()
BP_E_EMPTY: Network has not been created yet.
BP_E_NOERROR: Everything went fine.

Function

bpUint bp::getHLNeuronCount(bpUint layerIndex) const;
Description: Returns the count of neurons from a selected hidden layer.

Parameter:
layerIndex: The 0 based index pointing to the hiddenlayer.

Return values: The total count of neurons of the selected hidden layer. 0 if fails.

ERROR returned by bp::getError()
BP_E_EMPTY: Network has not been created yet.
BP_E_NOERROR: Everything went fine.
BP_E_INDEXERROR: layerIndex parameter is equal or greater than the total count of hidden layers. This is returned also if the network has no hidden layers.

Function

bpArray &getILNeuronWeights(bpUint neuronIndex);
Description: Gets the “weights” of a selected neuron from the input layer.
Parameters:
neuronIndex: 0 based index of the neuron from the input layer.
Return values: A reference to a bpArray object containing the weight values of the neuron. Notice, this can be modified. Returns an empty array if fails.

ERROR returned by bp::getError()
BP_E_EMPTY: Network has not been created yet.
BP_E_NOERROR: Everything went fine.
BP_E_INDEXERROR: neuronIndex parameter is equal or greater than the total count of neurons in the input layer.

Function

const bpArray &bp::getILNeuronWeights(bpUint neuronIndex) const;
Description: Overloaded function. It returns a non modifiable reference.

Function

bpArray & bp::getHLNeuronWeights(bpUint layerindex,bpUint neuronIndex);
Description: Retrieves the weights from a neuron of a hidden layer.

Parameters
layerIndex: 0 based index pointing to the hidden layer.
neuronIndex: 0 based index of the neuron from the selected layer.
Return values: A reference to a bpArray object containing the weight values of the neuron. Notice, this can be modified. Returns an empty array if fails.
ERROR returned by bp::getError()
BP_E_EMPTY: Network has not been created yet.
BP_E_NOERROR: Everything went fine.
BP_E_INDEXERROR: layerIndex parameter is equal or greater than the total count of hidden layers. This is returned also if the network has no hidden layers.
BP_E_INDEXERROR: neuronIndex parameter is equal or greather than the total count of neurons in the hidden layer.

Function

const bpArray &bp::getHLNeuronWeights(bpUint layerindex,bpUint neuronIndex) const;
Description: Overloaded member returns a non modifiable array.

Function

bpArray &getOLNeuronWeights(bpUint neuronIndex);
Description: Gets the weight values of a neuron from the output layer.
Parameters:
neuronIndex: 0 based index of the neuron location from the output layer.
Return Values: A reference to a bpArray object containing the weight values of the neuron. Notice, these values can be modified. Returns an empty array if fails

ERROR returned by bp::getError()
BP_E_EMPTY: Network has not been created yet.
BP_E_NOERROR: Everything went fine.
BP_E_INDEXERROR: neuronIndex parameter is equal or greater than the total count of neurons in the output layer.

Function

const bpArray &bp::getOLNeuronWeights(bpUint neuronIndex) const;
Description: Overloaded member. It returns a non modifiable reference to the array.

Function

bpArray &bp::getInput();
Description: Returns a reference to a bpArray object containing the input array.

Return values by bp::getError()

BP_E_EMPTY: Network has not been created yet.
BP_E_NOERROR: Everything went fine.

Function

const bpArray &bp::getInput() const
Description: Overloaded member. It returns the const version of the input array.

Function

bpArray &getOutput();
Description: Returns a reference object to the output of the network.

Function

bpArray &bp::getHLNeuronInputs(bpUint layerIndex)
Description: Retrieves the input values of a hidden layer.
Parameters:
layerIndex: 0 based index of the hidden layer to get the inputs from.

Return values by bp::getError()

BP_E_EMPTY: Network has not been created yet.
BP_E_NOERROR: Everything went fine.
BP_E_INDEXERROR: layerindex value is equal or greater than the quantity of hiddenlayers. This error is also returned when the network has no hidden layers whatsoever.

Function

const bpArray &bp::getHLNeuronInputs(bpUint layerIndex) const
Description: Overloaded member. It returns the non modifiable version of the array.

Function

bpArray &bp::getOLNeuronInputs()
Description: Gets the input array from the output layer.
Return values: A reference to a bpArray object containing the inputs. Empty array if fails.

ERROR returned by bp::getError()
BP_E_EMPTY: Network has not been created yet.
BP_E_NOERROR: Everything went fine.

Function

const bpArray &bp::getOLNeuronInputs()const

Description: Overloaded member. It returns the const version of the input array of the output layer.

Function

bool bp::runInputLayer()

Description: Calculates the neurons from just the input layer without propagating to the next layer.
Return values: Returns true if successful otherwise false.

ERROR returned by bp::getError()
BP_E_EMPTY: Network has not been created yet.
BP_E_NOERROR: Everything went fine.

 

Function

bool bp::runHiddenLayer
(bpUint index)

Description: Calculates the neurons of a hidden layer without propagating to the next layer.
Return values: Returns true if successful otherwise false.

Return values by bp::getError()

BP_E_EMPTY: Network has not been created yet.
BP_E_NOERROR: Everything went fine.
BP_E_INDEXERROR: layerindex value is equal or greather than the quantity of hiddenlayers. This error is also returned when the network has no hidden layers whatsoever.

 

Function

bool bp::runOutputLayer()

Description: Calculates the neurons of the output layer.
Return values: Returns true if successful otherwise false.

Return values by bp::getError()

BP_E_EMPTY: Network has not been created yet.
BP_E_NOERROR: Everything went fine.

Function

bool bp::multiThreadSupport() const
Description: Gets whether the library supports multithreading on both basic execution of the network and training.

Return values: Returns true if library can be enabled for multithreading or else false.

Function

void bp::setMultiThreaded(bool bSet, bool terminateThreads)

Description: Switches from single thread mode to multithreading and backwards.
NOTE: this function has no effect when library has no multithreading support or the machine has just a single processor or core.

Parameters:
bSet: Set it true to start the multithreading engine, false to stop it.
terminateThreads: Set it true to terminate all waiting threads. When the library is set to multithreaded mode for the first time, this parameter has no effect whatsoever.

Function

bool bp::multiThreadEnabled() const

Description: Returns whether the library has been set to multithreaded mode by the function bp::setMultiThreaded

Return values: True if library is multithread enabled else false.

 

Function

void bp::stop() const
Description: Stops all execution of the neural network. This function only works when the library is working in multithreading mode.

Function

BP_ERRORS bp::getError() const
Description:
Returns the last error code from the last operation. See detail per function.

Function

bool bp::isEmpty() const

Description:
Returns whether the neural network object is empty or not.

 

Dynamic modification of the neural network

Function

 

bool bp::addNeuronsToIL(bpUint numNeurons, bpUint position)

Description: Adds neurons to the input layer from the given neuron position.  The internal array of neurons is resized and all old neurons keep their old values.

Parameters:
numNeurons: Defines the quantity of neurons to be added to the input layer. This value can’t be 0.
position: Zero based position of the neuron array  where new neurons will be attached.

Return Values: Function return true if succeeded or else it returns false.
Return Values by bp::getError()
BP_E_EMPTY: Neural network object has not been initialized.
BP_E_NOERROR: No errors so far.

Function

bool bp::addNeuronsToHL(bpUint layerIndex, bpUint numNeurons, bpUint position)
Description: Adds neurons to a hidden layer selected by an index and from a given neuron position. Neuron array is resized and old data is preserved.
Parameters
layerIndex: Defines which layer is selected from all hidden layers.
numNeurons: Number of neurons to be added to the layers.
position: Position on the neuron array to start adding neurons.
Return values: Function returns true if successful else it returns false.
Return value by bp::getError()
BP_E_EMPTY: Network has not been initialized.
BP_E_INDEXERROR: layerIndex exceeds the current count of layers.
BP_E_NOERROR: Everything went fine.

Function

bool bp::addNeuronsToOL(bpUint numNeurons, bpUint position)
Description: Adds neurons to the output layer from the given neuron position.  The internal array of neurons is resized and all old neurons keep their old values. This function resizes the output size of the network.

 

Parameters:
numNeurons: Defines the quantity of neurons to be added to the output layer. This value can’t be 0.
position: Position of the neuron array  where new neurons will be attached.

Return Values: Function return true if succeeded or else it returns false.
Return Values by bp::getError()
BP_E_EMPTY: Neural network object has not been initialized.
BP_E_NOERROR: No errors so far.

Function

bool bp::removeNeuronsToIL(bpUint numNeurons, bpUint position)
Description: Removes neurons from the input layer from the given neuron position.  The internal array of neurons is resized and all old neurons keep their old values.

Parameters:
numNeurons: Defines the quantity of neurons to be removed from the input layer. This value can’t be 0.
position: Position of the neuron array  where new neurons will be removed.

Return Values: Function returns true if succeeded or else it returns false.
Return Values by bp::getError()
BP_E_EMPTY: Neural network object has not been initialized.
BP_E_NOERROR: No errors so far.

Function

bool bp::removeNeuronsToOL(bpUint numNeurons, bpUint position)
Description: Removes neurons from the output layer from the given position.  The internal array of neurons is resized and all old neurons keep their old values. This function actually resizes the network output.

Parameters:
numNeurons: Defines the quantity of neurons to be removed from the output layer. This value can’t be 0.
position: Position of the neuron array  where new neurons will be removed.

Return Values: Function returns true if succeeded or else it returns false.
Return Values by bp::getError()
BP_E_EMPTY: Neural network object has not been initialized.
BP_E_NOERROR: No errors so far.

Function

bool bp::removeNeuronsToHL(bpUint layerIndex, bpUint numNeurons, bpUint position)
Description: Removes neurons from a hidden layer selected by an index and from a given neuron position. Neuron array is resized and old data is preserved.
Parameters
layerIndex: Defines which layer is selected from all hidden layers.
numNeurons: Number of neurons to be removed from the layer.
position: Position on the neuron array to start adding neurons.
Return values: Function returns true if successful else it returns false.
Return value by bp::getError()
BP_E_EMPTY: Network has not been initialized.
BP_E_INDEXERROR: layerIndex exceeds the current count of layers.
BP_E_NOERROR: Everything went fine.

Function

bool bp::resizeInput(bpUint newSize)
Description: Changes the network input to a new size. This value is absolute.
Parameters
newSize: Defines the new size of the network input.
Return Values: Function returns true if succeeded or else it returns false.
Return Values by bp::getError()
BP_E_EMPTY: Neural network object has not been initialized.
BP_E_NOERROR: No errors so far.

Function

bool bp::addHiddenLayer(bpUint position, bpUint neurons)
Description: Adds a hidden layer to the network at a position in the layer array.
Parameters
position: Index on the layer array where hidden layer will be added. If this value is bigger or equal than layer array then the layer is added at the end.
Neurons: Quantity of neurons the layer would have.
Return Values: Function returns true if succeeded or else it returns false.
Return Values by bp::getError()
BP_E_EMPTY: Neural network object has not been initialized.
BP_E_NOERROR: No errors so far.

Function

bool bp::removeHiddenLayer(bpUint position)
Description: Removes a hidden layer from the network at a position in the layer array.
Parameters
position: Index of the layer to remove.
Return Values: Function returns true if succeeded or else it returns false.
Return Values by bp::getError()
BP_E_EMPTY: Neural network object has not been initialized.
BP_E_NOERROR: No errors so far.

Utility Functions

Function

void bp::setStartValues(START_VALUES type, bpfloat fMax, bpfloat fFixed,bpfloat iGain)
Description: Initializes all network weight to random values. This function should be used after creating the network.
Parameters
type:Defines the type of value generate. Can be any of the following constants:
BP_VAL_RANDOM_UNSIGNED: Initialize network values using random unsigned values
BP_VAL_RANDOM_SIGNED (DEFAULT): Initialize the network values using random signed values
BP_VAL_FIXED_UNSIGNED: Initialize network values with a fixed unsigned value
BP_VAL_FIXED_SIGNED: Initialize the network values with a fixed signed value
fmax: Maximum value when generating random values (default is 0.5)
fixed: Fixed value when generating fixed values. This is the value all weights would be initialized when using FIXED_UNSIGNED and FIXED_SIGNED. With FIXED_SIGNED the weights alternate signs. (default: 0)
gain:  Value to be set to all gain parameters per neuron. This value is usually one and it is ok leaving it as is. (default : 1)
Return values by bp::getError()
BP_E_NOERROR: Everything went fine.
BP_E_EMPTY: Network has not been initialized.

Function

void bp::setUpdateBuffer(bool bUpdate)
Description: Defines whether the output buffer is written every time bp:run() is called.
Parameter:
bUpdate: When this value is true means the buffer is updated every time bp:run() is called. When this value is false the buffer won’t be updated. (default value in the network is true).

Function

void bp::initRandGen(int seed)
Description: Initializes the random number generation engine.
Parameter:
Seed: seed to be used as “the seed” for the random generation engine.