Boost logo

Ublas :

From: Janek Kozicki (janek_listy_at_[hidden])
Date: 2006-02-20 18:27:44


hello

I'm writing a small neural network, to make things quickly I decided to
use ublas::vector and ublas::matrix to store neural layers and their
weights. The only actual operation needed for neural network to work is
simple vector matrix multiplication.

However I was surprised to discover that things are not easy when it
comes to saving/loading my neural network. Looks like boost serializtion
does not support ublas ?

Do I need to write ugly looking nested loops to serialize my data?

class NeuralNetwork
{
        public :
                typedef boost::numeric::ublas::vector<double> Layer; // actual values
                typedef boost::numeric::ublas::matrix<double> Weight; // weights which connect layers
                typedef std::vector< Layer > Layers;
                typedef std::vector< Weight > Weights;

        private :
                Layers layers;
                Weights weights;

        public :
                NeuralNetwork() {};
                NeuralNetwork(boost::numeric::ublas::vector<int> layerSizes);
                void clearLayers();
                void randomizeWeights();
        
        private :
                friend class boost::serialization::access;
                template<class Archive>
                void serialize(Archive & ar, const unsigned int version)
                {
                        ar & layers;
                        ar & weights;
                }
};

-- 
Janek Kozicki                                                         |