Main Page   Modules   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   Related Pages  

dtest.cpp

Go to the documentation of this file.
00001 
00033 #include <iostream>
00034 #include <fstream>
00035 #include <sstream>
00036 #include "dneuron.h"
00037 #include "dsched.h"
00038 #include "dlogger.h"
00039 
00040 #include <mak/cmdopt.h>
00041 
00042 using namespace std;
00043 using namespace punnets_nodebug;
00044 using namespace mak;
00045 
00050 
00051 class tobserver : public tneuron_base
00052 {
00053     int npulses;
00054     bool show;
00055 public:
00057     tobserver(string iname, bool ishow = false) : tneuron_base(iname), show(ishow) { npulses = 0; }
00059     virtual void pulseArrive(tscheduler &, ntime_t current_time, real pulse_level)
00060     {
00061         npulses++;
00062         if( show )
00063             cout << current_time << " '" << name << "' Pulse observed " << pulse_level << "  fire=" << totalfire << ", pulse=" << totalpulse << endl;
00064     }
00065 
00067     int getNPulses() const { return npulses;}
00069     void clearNPulses() { npulses = 0; }
00070 };
00071 
00072 
00073 int main(int argc, char **argv)
00074 {
00075     cout << "Punnets performance test program  (c) 2003 Makino Takaki." << endl;
00076     cout << "Punnets is free software, covered by the GNU General Public License." << endl;
00077     cout << endl;
00078 
00079     cmdopt_parser p;
00080     cmdopt<int> nneurons("The number of neurons in the simulation.",
00081             'n', "neurons", 100, 0, 1000);
00082     cmdopt<int> nlogging("The number of neurons to be logged. (Default 5)",
00083             'l', "log", 5, 0, 1000);
00084     cmdopt<double> stepsize("Specify the time step for logging. (Default 0.125)",
00085             's', "step", 0.125, 0, 1000);
00086     p.add( New<cmdopt_help>("Show this help.", 
00087             'h', "help") );
00088     p.add(Ref(nneurons)); p.add(Ref(nlogging)); 
00089     p.parse(argc, argv);
00090     
00091     const unsigned int nconnections = 10;
00092     const ntime_t hv_time = 5;
00093     const ntime_t simulate_until = 1000;
00094     const char * const datafilename = "test.dat";
00095     const char * const plotfilename = "test.plt";
00096 
00097     cout << "Preparing network..." << endl;
00098 
00099     vector<tneuron_ext *> exts(nneurons.get());
00100 
00101     tobserver obs("ob");
00102 
00103     srand48(12345);
00104 
00105     tscheduler scheduler;
00106 
00107     cout << "Produce simulation log file '" << datafilename << "'." << endl;
00108     ofstream ofs(datafilename);
00109     tlogger logger(ofs, stepsize.get(), stepsize.get(), simulate_until);
00110     logger.schedule(scheduler);
00111     message_base *mess = new func_exp_diff::message_add_event_time;
00112 
00113     for( int i=0; i<nneurons.get(); i++ )
00114     {
00115         ostringstream oss;
00116         oss << "n" << i;
00117         exts[i] = new tneuron_ext(oss.str(), hv_time);
00118         exts[i]->addExt(new func_const(-0.55));
00119         exts[i]->addExt(new func_sine(0.5, 2.0, 0));
00120         exts[i]->addExt(new func_response(-3.0));
00121     }
00122     
00123     for( int i=0; i<nneurons.get(); i++ )
00124     {
00125         for( unsigned int j=0; j<nconnections; j++ )
00126         {
00127             unsigned int nsrc = lrand48() % nneurons.get();
00128             real power = drand48() * 7.0 - 4.0;
00129             real delay = drand48() * 1.25 + 0.25;
00130             ntime_t psi2 = drand48() * 3.0 + M_LN2 / hv_time;
00131             ntime_t psi1 = M_LN2 / hv_time;
00132             tsynapse_messfunc *sy = new tsynapse_messfunc(*exts[i], delay, new func_exp_diff(power, psi1, power, psi2, -1e+30), mess);
00133 //          sy->setDeb(true);
00134             exts[nsrc]->addSynapse(sy);
00135         }
00136         scheduler.scheduleEvent( drand48()*10, makePulse( * exts[ i ], 5.0 ) );
00137         scheduler.scheduleEvent( drand48()*simulate_until, makePulse( * exts[ i ], 5.0 ) );
00138 //      exts[i]->addSynapse(new tsynapse(obs, 0.1, 1.0));
00139 //      exts[i]->setDeb(true);
00140     }
00141 
00142     if( nlogging.get() > nneurons.get() )
00143         nlogging.set(nneurons.get());
00144     cout << "Logging " << nlogging.get() << " out of " << nneurons.get() << " neurons." << endl;
00145     for( int i=0; i<nlogging.get(); i++ )
00146         logger.add(*exts[i], 0.0, false, false, i*4 );
00147     
00148     cout << "Produce GNUPLOT plotting file '" << plotfilename << "'." << endl;
00149     ofstream ofs2(plotfilename);
00150     logger.gnuplot_def(ofs2, datafilename);
00151 
00153     cout << endl << "Start Test..." << endl;
00154 
00155     scheduler.run(simulate_until);
00156 
00157     cout << "Test Finished." << endl << endl;
00159 
00160     cout << "Total fire observed: " << obs.getNPulses() << endl;
00161 
00162     cout << "Total fires: " << totalfire << endl;
00163     cout << "Total pulses: " << totalpulse << endl;
00164     cout << "Total partitions: " << totalpartition << endl;
00165     cout << "Total peak search (peak not found / peak found / non-convex case): " << totalpeaksearch[0] << "/" << totalpeaksearch[1] << "/" << totalpeaksearch[2] << endl;
00166     cout << "Total peak enclosing: " << totalpeakenclosing << endl;
00167     cout << "Total partition no-newton (0th/1st/2nd/delta): " << totalpartition_nonewton[0] << "/" << totalpartition_nonewton[1] << "/" << totalpartition_nonewton[2] << "/" << totalpartition_nonewton[3] << endl;
00168     cout << "Total partition    newton (0th/1st/2nd/delta): " << totalpartition_newton[0] << "/" << totalpartition_newton[1] << "/" << totalpartition_newton[2] << "/" << totalpartition_newton[3] << endl;
00169     cout << "Total re-scheduled by new pulses: " << totalrescheduled << endl;
00170     cout << "Total filtered maxgrad:      " << totalfiltered_maxgrad << endl;
00171     cout << "Total filtered incontinuity: " << totalfiltered_incontinuity << endl;
00172     cout << "Total filtered nextpulse:    " << totalfiltered_nextpulse << endl;
00173     return 0;
00174 }
00175 
00176 

Generated on Mon Jun 16 15:42:25 2003 for Punnets by doxygen1.2.18