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

connection.cc

Go to the documentation of this file.
00001 
00025 #include <magic/mclass.h>
00026 #include <magic/mtextstream.h>
00027 
00028 #include "inanna/neuron.h"
00029 #include "inanna/connection.h"
00030 
00031 impl_dynamic (Connection, {Object});
00032 
00033 
00035 //             ___                                   o                       //
00036 //            /   \        _     _    ___   ___   |           _              //
00037 //            |      __  |/ \  |/ \  /   ) |   \ -+- |  __  |/ \             //
00038 //            |     /  \ |   | |   | |---  |      |  | /  \ |   |            //
00039 //            \___/ \__/ |   | |   |  \__   \__/   \ | \__/ |   |            //
00041 
00042 Connection::Connection (const Neuron* source, const Neuron* target, double weight)
00043 {
00044     mpSource = const_cast<Neuron*>(source);
00045     mpTarget = const_cast<Neuron*>(target);
00046     mWeight  = weight;
00047 }
00048 
00049 Connection::~Connection ()
00050 {
00051     if (mpSource)
00052         mpSource->disconnectTo (*this);
00053     if (mpTarget)
00054         mpTarget->disconnectFrom (*this);
00055 }
00056 
00057 void Connection::init (double r)
00058 {
00059     mWeight = 2*r*frnd()-r;
00060 }
00061 
00062 double Connection::transfer ()
00063 {
00064     return mWeight * mpSource->output();
00065 }
00066 
00067 void Connection::copy (const Connection& other)
00068 {
00069     mWeight = other.weight();
00070 #ifdef CMP_WARNINGS
00071 #warning "TODO: Copying connections not implemented"
00072 #endif
00073     mpSource = NULL;
00074     mpTarget = NULL;
00075 }
00076 
00077 
00078 void Connection::check (int netSize) const
00079 {
00080     ASSERT (mpSource!=NULL);
00081     ASSERT (mpTarget!=NULL);
00082 }
00083 
00084 void Connection::writeXML (TextOStream& out) const
00085 {
00086     sout.printf ("\t\t<%s>", (CONSTR) getclassname());
00087     if (mpSource)
00088         sout.printf ("<SOURCEID>%d</SOURCEID>", mpSource->id());
00089     sout.printf ("<WEIGHT>%f</WEIGHT>", mWeight);
00090     sout.printf ("</%s>\n", (CONSTR) getclassname());
00091 }
00092 

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