Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

neuron.h

Go to the documentation of this file.
00001 
00025 #ifndef __NEURON_H__
00026 #define __NEURON_H__
00027 
00028 #include <magic/mobject.h>
00029 #include <magic/mcoord.h>
00030 #include <magic/mpararr.h>
00031 
00032 #include "connection.h"
00033 
00034 // Externals
00035 class NeuronInitializer;
00036 class NeuronContainer;      // In freenet.h
00037 
00038 
00039 // We can not be truly free before we can freely connect ourself in a
00040 // global free network where we can freely control each other!
00041 
00042 
00044 //                 ___          o                  __  ___                  //
00045 //                |   | |          ___   ___   |  /  \ |  \                 //
00046 //                |   | |---    | /   ) |   \ -+-  __/ |   |                //
00047 //                |   | |   )   | |---  |      |     \ |   |                //
00048 //                `___´ |__/  \_|  \__   \__/   \ \__/ |__/                 //
00050 
00051 class Object3D {
00052   public:
00053 
00054     void                    copy            (const Object3D& other);
00055     
00059     const Coord3D&          getPlace        () const {return mCoord;}
00060 
00065     void                    getPlace        (double& x, double& y, double& z) const;
00066 
00070     void                    moveTo          (const Coord3D& o) {mCoord = o;}
00071 
00075     void                    moveTo          (double x, double y, double z=0.0) {mCoord.moveTo (x,y,z);}
00076 
00077   protected:
00079     Coord3D         mCoord;
00080 };
00081 
00082 
00083 
00085 //                      ----  o |   |          |                            //
00086 //                      |   )   |\  |          |  ___                       //
00087 //                      |---  | | \ |  __   ---| /   )                      //
00088 //                      |   ) | |  \| /  \ (   | |---                       //
00089 //                      |___  | |   | \__/  ---|  \__                       //
00091 
00094 class BiNode : public Object {
00095     decl_dynamic (BiNode);
00096   public:
00097                             BiNode          () {}
00098                             BiNode          (const BiNode& orig) {copy (orig);}
00099     virtual                 ~BiNode         ();
00100     
00104     void                    addIncoming     (Connection* conn) {mIncoming.add (conn);}
00105 
00109     void                    addOutgoing     (Connection* conn) {mOutgoing.add (conn);}
00110 
00112     void                    connectFrom     (const BiNode& source);
00113 
00117     bool                    connectedFrom   (const BiNode& source) const;
00118 
00119     // Disconnecting
00120 
00123     void                    disconnectFrom  (const Connection& incoming);
00124     
00127     void                    disconnectTo    (const Connection& outgoing);
00128 
00131     void                    disconnectFrom  (const BiNode& source);
00132 
00135     void                    disconnectTo    (const BiNode& target);
00136     
00138     void                    disconnectAll   ();
00139 
00140     // Connection access
00141     
00142     Connection&             incoming        (int i) {return mIncoming[i];}
00143     const Connection&       incoming        (int i) const {return mIncoming[i];}
00144 
00145     Connection&             outgoing        (int i) {return mOutgoing[i];}
00146     const Connection&       outgoing        (int i) const {return mOutgoing[i];}
00147 
00149     int                     incomings       () const {return mIncoming.size();}
00150 
00152     int                     outgoings       () const {return mOutgoing.size();}
00153 
00154     int                     id              () const {return mId;}
00155 
00157     virtual void            copy            (const BiNode& orig);
00158 
00160     virtual void            check           (int netSize) const;
00161 
00162     //virtual void          writeXML        (OStream& out) const;
00163 
00164   private:
00165     int                 mId;
00166 
00168     Array<Connection>   mIncoming;
00169 
00171     Array<Connection>   mOutgoing;
00172     
00174     void                setId           (int id) {mId = id;}
00175 
00179     void                shallowDisconnectAll    ();
00180     
00181     friend class NeuronContainer;
00182 };
00183 
00185 //                     |   |                                                //
00186 //                     |\  |  ___                   _                       //
00187 //                     | \ | /   ) |   | |/\  __  |/ \                      //
00188 //                     |  \| |---  |   | |   /  \ |   |                     //
00189 //                     |   |  \__   \__! |   \__/ |   |                     //
00191 
00199 class Neuron : public BiNode, public Object3D {
00200     decl_dynamic (Neuron);
00201   public:
00202 
00203                             Neuron      ();
00204                             Neuron      (const Neuron& orig) : mBias (0,0) {copy(orig);}
00205                             ~Neuron     ();
00206 
00209     virtual void            init            (double r=0.0);
00210 
00213     void                    reset           () {mActivation=0.0;}
00214 
00220     virtual void            transfer        (ANNetwork& net);
00221 
00222     // Manipulation
00223 
00230     inline double           activation      () const {return mActivation;}
00231 
00233     virtual void            setActivation   (double a) {mActivation = a;}
00234     
00236     void                    operator=		(double a) {mActivation=a;}
00237     
00244     virtual double          output          () const {return mActivation;}
00245     
00250                             operator const double	() const {return mActivation;}
00251 
00253     double                  bias            () const {return mBias.weight();}
00254 
00256     void                    setBias         (double b) {mBias = b;}
00257 
00258     Connection&             getBiasObj      () {return mBias;}
00259 
00264     int                     getType         () const {return mType;}
00265     
00270     void                    setType         (int t) {mType = t;}
00271 
00276     int                     transferFunc    () const {return mTransferFunc;}
00277 
00282     void                    setTFunc        (int f) {mTransferFunc = f;}
00283 
00291     void                    enable          (bool s=true) {mExists=s;}
00292 
00297     bool                    isEnabled       () const {return mExists;}
00298 
00299     // Connection manipulation
00300 
00302     void                    copy            (const Neuron& orig);
00303 
00305     virtual Neuron*     clone           () const {return new Neuron(*this);}
00306 
00308     virtual void            check           (int netSize) const;
00309 
00311     //virtual void          writeXML        (OStream& out) const;
00312 
00314     enum unitTypes {INPUTUNIT=0, HIDDENUNIT=1, OUTPUTUNIT=2};
00315 
00317     enum tfuncs {LOGISTIC_TF=0, LINEAR_TF=1, ELLIOTT_TF=2};
00318 
00319   protected:
00320     
00322     double          mActivation;
00323 
00325     Connection      mBias;
00326 
00328     int             mType;
00329 
00331     int             mTransferFunc;
00332     
00334     bool            mExists;
00335     
00336   private:
00340     //void          adjustAbove     (int targetIndex);
00341 
00342     void operator= (const Neuron& other); // Prevent
00343 
00344     friend class NeuronContainer;
00345     friend class ANNetwork;
00346 };
00347 
00348 
00349 
00351 //       |   |                            |   | o       o                    //
00352 //       |\  |  ___                   _   |   |    ____    |                 //
00353 //       | \ | /   ) |   | |/\  __  |/ \  |   | | (     | -+-  __  |/\       //
00354 //       |  \| |---  |   | |   /  \ |   |  \ /  |  \__  |  |  /  \ |         //
00355 //       |   |  \__   \__! |   \__/ |   |   V   | ____) |   \ \__/ |         //
00357 
00362 class NeuronVisitor {
00363   public:
00364     virtual void    visit   (Neuron& neuron) const=0;
00365 };
00366 
00367 #endif
00368 

Generated on Thu Feb 10 20:06:44 2005 for Inanna by doxygen1.2.18