#ifndef LAYER_H #define LAYER_H /////////////////////////////////////////////////////////////// // // // layer.h - neural net layer // // // // version: 1.0 // // Language: Visual C++, ver 5.0 // // Platform: Micron Dual Pentium Pro 200 // // Windows NT 4.0, service pack 3 // // Application: ELE591/791 Example // // Author: Jim Fawcett // // CST 2-187, (315) 443-3948 // // fawcett@neptune.syr.edu // // // /////////////////////////////////////////////////////////////// /* Layer Operations ================ This class models the operation of a neural network layer. Each object of the class contains an array of neurons which may be neurons or any type derived from the neuron class. Layer Public Interface: ======================= layer myLayer; // void layer construction layer yourLayer = myLayer; // construct from copy layer myLayer(myNeuron,5); // constructs a layer of 5 clones // of myNeuron myLayer = yourLayer; // assign yourLayer state to myLayer sneuron = myLayer[2]; // return reference to internal node myLayer.randWts(double min, double max, bool newSeed); // give weights random values in (min,max) myLayer.weights(wts); // reads a vec< vec > and // stores as weights myLayer.outputs(inputs, outputs); // reads a vec of inputs, // calculates a vec of outputs myLayer.size(); // returns number of neurons in layer myLayer.checkSizes(vi,vo); // checks neuron input size with input // vector size and checks number of // neurons with output vector size myLayer.display(cout,".."); // send myLayer state to cout with // message myLayer.disconnect(); // a protected function you can // override to zero weights selectively // -- called every time outputs is called */ // /////////////////////////////////////////////////////////////// // // // Build Process // // ------------- // // Files required: // // layer.h, layer.cpp, bneuron.h, bneuron.cpp, // // vec.h, vec.cpp // // // // build command for Neptune cluster with VC++ 5.0: // // I:\fawcett\ecs500\setenv.bat (neptune only) // // cl -GX -DTEST_LAYER layer.cpp bneuron.cpp // // // /////////////////////////////////////////////////////////////// /* Maintenance History ------------------- ver 1.1 : 11 July 98 - added void and copy constructors and assignment operator - add display function - added tests for all of the above ver 1.0 : 28 June 98 - first release */ // #include #include #include "bneuron.h" #include "vec.h" using namespace std; //----< declare class for neural net layer >------------------- class layer { vec nPtrArray; // vec of ptrs to neurons int numNeurons; // size of layer string _name; public: layer(); layer(const neuron &nModel, int number, const string &name=""); layer(const layer &l); virtual ~layer(); int size(); string& name(); neuron& operator[](int index); layer& operator=(const layer &l); void outputs(const vec &vin, vec &vout); void weights(const vec< vec > &wts); void randWts(double min, double max, bool newSeed); bool checkSizes(int vinSize, int voutSize); void display(ostream &out, char *msg=0); protected: virtual void disconnect() { }; }; inline int layer::size() { return numNeurons; } inline string& layer::name() { return _name; } #endif