printInternals.cpp

Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <iostream>
00003 using namespace std;
00004 #include <stdlib.h>
00005 #include <assert.h>
00006 #include "printInternals.h"
00007 #include "inspectable.h"
00008  
00009 void printNetworkDescription(FILE* f, const string& name, const Inspectable* inspectable){
00010   assert(inspectable);
00011   time_t t = time(0);
00012   fprintf(f,"#Start %s", ctime(&t));  
00013   fprintf(f,"#N network %s\n", name.c_str());  
00014   list< Inspectable::ILayer> layers      = inspectable->getStructuralLayers();
00015   list< Inspectable::IConnection> conns  = inspectable->getStructuralConnections();
00016   // print layers with neurons
00017   for(list<Inspectable::ILayer>::iterator i = layers.begin(); i != layers.end(); i++){    
00018     Inspectable::ILayer& l = (*i);
00019     fprintf(f, "#N layer %s %i\n", l.layername.c_str(), l.rank);
00020     for(int n = 0; n < l.dimension; n++){      
00021       fprintf(f, "#N neuron %s[%i]\n", l.vectorname.c_str(), n);
00022     }
00023   }
00024 
00025   // print connections
00026   for(list<Inspectable::IConnection>::iterator i = conns.begin(); i != conns.end(); i++){    
00027     Inspectable::IConnection& c = (*i);
00028     // find the layers refered in the connection description
00029     list<Inspectable::ILayer>::iterator l1it 
00030       = find_if(layers.begin(), layers.end(), Inspectable::matchName(c.vector1) );
00031     list<Inspectable::ILayer>::iterator l2it
00032       = find_if(layers.begin(), layers.end(), Inspectable::matchName(c.vector2) );
00033     assert(l1it != layers.end()); // we need to find them otherwise
00034     assert(l2it != layers.end());
00035 
00036     Inspectable::ILayer& l1 = (*l1it);
00037     Inspectable::ILayer& l2 = (*l2it);
00038     for(int j=0; j < l1.dimension; j++){
00039       for(int k=0; k < l2.dimension; k++){
00040         fprintf(f, "#N connection %s[%i][%i] %s[%i] %s[%i]\n", 
00041                 c.matrixname.c_str(), k, j, l1.vectorname.c_str(), j, l2.vectorname.c_str(), k);
00042       }
00043     }
00044   }
00045  
00046 }
00047 
00048 void printInternalParameterNames(FILE* f, 
00049                                 int sensornumber, int motornumber, 
00050                                 Inspectable** inspectables, int len) {
00051   assert(inspectables);
00052   fprintf(f,"#C");
00053   for(int i = 0; i < sensornumber; i++){
00054     fprintf(f, " x[%i]", i);
00055   }
00056   for(int i = 0; i < motornumber; i++){
00057     fprintf(f, " y[%i]", i);
00058   }
00059   for(int k=0; k<len; k++){
00060     if(inspectables[k]){
00061       // then the internal parameters
00062       list<Inspectable::iparamkey> l = inspectables[k]->getInternalParamNames();
00063       for(list<Inspectable::iparamkey>::iterator i = l.begin(); i != l.end(); i++){
00064         fprintf(f, " %s", (*i).c_str());
00065       }
00066     }
00067   }   
00068   fprintf(f,"\n"); // terminate line
00069 }
00070 
00071 void printInternalParameters(FILE* f, 
00072                              const sensor* x, int sensornumber, 
00073                              const motor* y,  int motornumber,
00074                              Inspectable** inspectables, int len){
00075   assert(inspectables);
00076   
00077   for(int i = 0; i < sensornumber; i++){
00078     fprintf(f, " %f", x[i]);
00079   }
00080   for(int i = 0; i < motornumber; i++){
00081     fprintf(f, " %f", y[i]);
00082   }  
00083   // internal parameters ( we allocate one place more to be able to realise when the number raises)
00084   list<Inspectable::iparamval> l;
00085   for(int k=0; k<len; k++){
00086     if(inspectables[k]){    
00087       l = inspectables[k]->getInternalParams();
00088       for(list<Inspectable::iparamval>::iterator i = l.begin(); i != l.end(); i++){
00089         fprintf(f, " %f", (*i));
00090       }  
00091     }
00092   }
00093   fprintf(f,"\n"); // terminate line  
00094 
00095 }

Generated on Tue Apr 4 19:05:04 2006 for Robotsystem from Robot Group Leipzig by  doxygen 1.4.5