00001
00007 #ifndef __NEURALREGIONMAP_H__
00008 #define __NEURALREGIONMAP_H__
00009
00010 #include <string>
00011 using std::string;
00012
00013 #include "pointermap.h"
00014 #include "neuralregionmanager.h"
00015 #include "parammap.h"
00016 #include "cmdparam.h"
00017
00018
00021 class NeuralRegionMap : public PointerMap<NeuralRegionManager> {
00022 public:
00023 NeuralRegionMap(const string& name, ParamMap& parentparams)
00024 : params(parentparams.new_child(name),true) { define_globals(); }
00025 virtual ~NeuralRegionMap() { }
00026
00027 typedef NeuralRegionManager RegionManager;
00028
00029 void activate(bool learn, bool settle, bool activatefn, bool verbose=false) const;
00030
00031 const bool plot_write_unit(const ParamMap& argparams, const NeuralRegionManager* rm,
00032 const int ui, const int uj) const;
00033
00035 const bool measure_stimulus_map(StringArgs& arglist, ParameterMap<>& argparams);
00036
00037 virtual void register_params_and_commands( void );
00038
00039 static void message(Msg::MessageLevel m, const string& s, const bool terminate=True)
00040 { NeuralRegionManager::PlotSpec::message(m,s,terminate); }
00041
00045 NeuralRegionManager* new_manager(NeuralRegion& region, ParamMap* existing_params=0) {
00046 erase(region.name());
00047 NeuralRegionManager* nm = new
00048 NeuralRegionManager(®ion,(existing_params? *existing_params
00049 : *params->new_child(region.name())),
00050 (existing_params==0));
00051 set(region.name(),nm);
00052 return nm;
00053 }
00054
00055 bool restore_state(const ParamMap& argparams, const int iteration, const string& filenamebase);
00056
00057 double size_connection_bytes() const { return Generic::accumulate(begin(),end(),0.0,&size_bytes); }
00058 double size_unique_connections() const { return Generic::accumulate(begin(),end(),0.0,&size_conns); }
00059
00060 private:
00061 static double size_bytes(const value_type& v) { return v.second->region()->size_connection_bytes(); }
00062 static double size_conns(const value_type& v) { return v.second->region()->size_unique_connections(); }
00063
00064 void ppm_init_hook( void );
00065 int ppm_post_write_hook(const char* filename ) const;
00066
00067
00075 static int rm_nrows(const value_type& p) { return p.second->region()->nrows(); }
00076 static int rm_ncols(const value_type& p) { return p.second->region()->ncols(); }
00077 static int max_int( const int a, const int b) { return std::max(a,b); }
00078 int min_of_max_dimensions() const {
00079 int max_width = Generic::accumulate(begin(), end(), 0, &rm_nrows, &max_int);
00080 int max_height = Generic::accumulate(begin(), end(), 0, &rm_ncols, &max_int);
00081 return std::min(max_height,max_width);
00082 }
00084
00085
00086
00087 typedef std::vector<RegionManager*> RegionManagerList;
00088
00089 RegionManagerList retrieve_matching_regions(const string& region_names_string,
00090 Tristate plastic=Uninitialized,
00091 Tristate internal=Uninitialized) const;
00092
00093 RegionManagerList retrieve_matching_regions(const ParamMap& params,
00094 const string& name_of_regionlist_param="regions",
00095 const bool uselimits=true) const;
00096
00097 typedef NeuralRegionManager::PlotSpecList PlotSpecList;
00098 const PlotSpecList retrieve_matching_plots
00099 (const PlotSpecList::const_iterator& plotsbegin,
00100 const PlotSpecList::const_iterator& plotsend,
00101 const string& names_string) const;
00102
00103 const bool plot_write_unit_range
00104 (const ParamMap& argparams, const NeuralRegionManager* rm, const string& plotitem,
00105 int ui_start, int uj_start, int ui_end, int uj_end, int step) const;
00106
00107 const NeuralRegionManager* lookup_internal_region(const string& name) const;
00108 const NeuralRegionManager* lookup_region( const string& name) const;
00109
00110 typedef Plot::RGBPixel<> Color;
00111
00114 Color lookup_param(const ParamMap& parammap, const char* basename, const Color& default_val) const
00115 { return lookup_color(parammap,basename,default_val); }
00116
00117 typedef NeuralRegionManager::PlotSpec::SubRegion SpecRegion;
00118
00125 SpecRegion max_subregion() const {
00126 double maxheight=0;
00127 double maxwidth=0;
00128 for (const_iterator ri=begin(); ri!=end(); ri++) {
00129 const data_type region = (*ri).second;
00130 SpecRegion specified = lookup_subregion(region->param_map(),SpecRegion());
00131 const double height = (!specified.isinfinite()? specified.height() : region->region()->nrows());
00132 const double width = (!specified.isinfinite()? specified.width() : region->region()->ncols());
00133 if (height > maxheight) maxheight = height;
00134 if (width > maxwidth) maxwidth = width;
00135 }
00136
00137 return SpecRegion(0,0,maxwidth,maxheight);
00138 }
00139
00140
00141 const string overriding_colorspec(const NeuralRegionManager* rm, int ui, int uj, const string colorspec) const;
00142
00143
00144
00145
00146
00147 static void define_globals(const RegionManager* rm=0, const int ui=-1, const int uj=-1, const string& plotname=string()) {
00148 const NeuralRegion* r = (rm? rm->region() : 0);
00149 current_region = (r? r->name() : string());
00150 current_width = (r? r->nrows() : -1);
00151 current_height = (r? r->ncols() : -1);
00152 current_ui = ui;
00153 current_uj = uj;
00154 current_plot = plotname;
00155 }
00156
00157
00158 static int current_width, current_height, current_ui, current_uj;
00159 static string current_region, current_plot;
00160
00161
00162 typedef std::vector<Plot::AARImage<>*> ImagePList;
00163 typedef std::vector<ImagePList*> ImagePListList;
00164
00165 const bool add_maps_for_unit(NeuralRegionManager::PlotSpec::MatrixTable& tempmaps,
00166 const NeuralRegionManager& rm,
00167 const NeuralRegionManager::PlotSpec& plotspec,
00168 const int ui, const int uj) const;
00169
00170 bool unit_bitmap(const double master_scale, ImagePList& imagelist,
00171 const NeuralRegionManager::PlotSpec& plotspec,
00172 const NeuralRegionManager::PlotSpec::MatrixTable* tempmaps,
00173 const InternalNeuralRegion::WeightBounds& bounds,
00174 const Color& pagecolor,
00175 bool draw_outline=true, int outline_width=1,
00176 bool situate=true, bool mainplot=true,
00177 bool separate_plots=false, bool combined_plots=false,
00178 const string& filebase="", bool histograms=true,
00179 int border_width=-1, bool fill_bg=false,
00180 const string& overriding_colorspec="") const;
00181
00182 const bool ppmgrid_write(const string& filebase,
00183 const ImagePListList& imagelists, int interior_border,
00184 const Color& pagecolor, bool column_major=true) const;
00185
00186 const bool gnuplot_image(const ParamMap& argparams,
00187 NeuralRegionManager::PlotSpec& plotspec,
00188 const string& filebase,
00189 const NeuralRegionManager::PlotSpec::MatrixTable* tempmaps,
00190 const SpecRegion& subregion=SpecRegion()) const;
00191
00192 bool unit_gnuplot(const ParamMap& argparams,
00193 NeuralRegionManager::PlotSpec& plotspec,
00194 const string& filebase,
00195 const NeuralRegionManager::PlotSpec::MatrixTable* tempmaps,
00196 const InternalNeuralRegion::WeightBounds& bounds,
00197 bool situate) const;
00198
00199 const string filenamebase(const string& plotgroup,
00200 const string& suppliedformat) const;
00201
00202 OwningPointer<ParamMap> params;
00203
00205 template<class LoopContainer, class SPMRContainer>
00206 class measure_stimulus_map_iteration;
00207
00208 bool define_plotgroup(const string plotgroup, const string filename_format="");
00209 CMDOBJ_DECLARE(NeuralRegionMap,define_plot);
00210 CMDOBJ_DECLARE(NeuralRegionMap,measure_stimulus_map);
00211 CMDOBJ_DECLARE(NeuralRegionMap,kill_connections);
00212 CMDOBJ_DECLARE(NeuralRegionMap,child_set);
00213 CMDOBJ_DECLARE(NeuralRegionMap,map_statistics);
00214 CMDOBJ_DECLARE(NeuralRegionMap,plot);
00215 CMDOBJ_DECLARE(NeuralRegionMap,plot_unit);
00216 CMDOBJ_DECLARE(NeuralRegionMap,plot_unit_range);
00217 CMDOBJ_DECLARE(NeuralRegionMap,save_snapshot);
00218 CMDOBJ_DECLARE(NeuralRegionMap,backproject);
00219 #ifdef OBJ_LISSOM
00220 CMDOBJ_DECLARE(NeuralRegionMap,resp_to_residual);
00221 CMDOBJ_DECLARE(NeuralRegionMap,train_obj_weights);
00222 CMDOBJ_DECLARE(NeuralRegionMap,randomize_lat_wts);
00223 #endif
00224
00226 const string pe_extension () const;
00227 static int plot_pe;
00228
00229 SETFNOBJ_DECLARE2(NeuralRegionMap,color_param_setfn2);
00230 };
00231
00232
00233
00234 #endif