OpenANN  1.1.0
An open source library for artificial neural networks.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Creating a data set

In order to train a neural network, we need a training set consisting of $ N $ inputs $ x_n $ and outputs $ y_n $ of an underlying unknown function $ f $ we want to approximate.

There are two ways to pass a data set to the neural network:

Arranging data in matrices

using namespace OpenANN;
int main()
{
const int N = 10; // data set size
const int D = 2; // input space dimension
const int F = 1; // output space dimension
// here we generate a random data set
Eigen::MatrixXf X = Eigen::MatrixXf::Random(N, D);
Eigen::MatrixXf T = Eigen::MatrixXf::Random(N, F);
// We could e. g. get the input vector x_n with X.row(n-1).
// Now we can train the neural network:
... // initialize net
mlp.trainingSet(X, T);
... // set stopping criteria
train(net, "LMA", SSE, stop);
}

Subclassing OpenANN::DataSet

using namespace OpenANN;
class MyDataSet : public DataSet
{
public:
MyDataSet(...)
{
...
}
virtual MyDataSet()
{
...
}
virtual int samples()
{
// return size of the data set here
}
virtual int inputs()
{
// return input space dimension
}
virtual int outputs()
{
// return output space dimension
}
virtual Eigen::VectorXd& getInstance(int i)
{
// return the i-th instance (x_i)
}
virtual Eigen::VectorXd& getTarget(int i);
{
// return the desired output for the i-th instance (y_i)
}
virtual void finishIteration(Learner& learner)
{
// Here you can place code that will be executed after every iteration
// of the optimization algorithm during the training phase. You could
// e. g. print the confusion matrix, error on a test set, etc.
}
};
int main()
{
MyDataSet dataSet = ...; // create a data set
// Now we can train the neural network:
... // initialize net
net.trainingSet(dataSet);
... // set stopping criteria
train(net, "LMA", SSE, stop);
}