#ifndef LAYER_H #define LAYER_H /////////////////////////////////////////////////////////////// // layer.h - layer is a container of neurons // // ver 1.0 // // // // Language: Visual C++, ver 6.0 // // Platform: Dell XPS B1000r, Windows 2000 // // Application: Prototype for Pr#1, ELE 591/791 // // Author: Jim Fawcett, CST 2-187, Syracuse Univ // // (315) 443-3948, jfawcett@twcny.rr.com // /////////////////////////////////////////////////////////////// /* Module Contents =============== This module defines a layer class. Its operations are simple. When a layer is constructed it is passed the address of a proto- typical neuron. It uses the neuron's clone function to populate itself with a specified number of neurons, all of the clones type. The ith layer input is passed directly to the ith input of each neuron in the layer. Each neuron output is a layer output. Operations ========== linearNeuron ln(3); layer hidden(5,&ln); Creates a layer with 5 linear neurons hidden.input(1,value); sets 2nd input of each neuron to value hidden.weight(2,1,value); sets 3rd weight of 2nd neuron to value hidden.output(2); returns output of 3rd neuron in layer */ // /////////////////////////////////////////////////////////////// // Build Process // /////////////////////////////////////////////////////////////// // Required Files: // // layer.h, layer.cpp, neuron.h, neuron.cpp // // // // Compiler Command: // // cl /GX /DTEST_LAYER layer.cpp neuron.cpp // /////////////////////////////////////////////////////////////// /* Maintenance History =================== ver 1.0 : 8 Jun 2000 - first release - this is a prototype defining only linear neurons */ /////////////////////////////////////////////////////////////// // layer class - container for neurons of a fixed type #include #include #include "neuron.h" class layer { public: layer(int numNeurons, neuron *pN); ~layer(); int size(); int numInputs(); int numOutputs(); void showInputs(std::ostream &out, const char* msg); void showWeights(std::ostream &out, const char *msg); void showOutputs(std::ostream &out, const char *msg); double output(int selectOutput); void input(int selectInput, double value); void weight(int selectWeight, int selectNeuron, double value); private: std::vector _neurons; }; //----< return number of neurons in layer >-------------------- inline int layer::size() { return _neurons.size(); } //----< return number of layer inputs >------------------------ // // assumes that: // - all neurons in a layer have the same number of inputs // - every layer input connects to every neuron // inline int layer::numInputs() { return _neurons[0]->size(); } //----< return number of layer outputs >----------------------- // // assumes that each neuron output is a layer output // inline int layer::numOutputs() { return size(); } #endif