00001
00009 #include <vector>
00010 #include <functional>
00011 #include <string>
00012
00013 #include "inputs.h"
00014 #include "ipc.h"
00015 #include "cmdparam.h"
00016 #include "kernelfactory.h"
00017 #include "fixedwtregion.h"
00018 #include "retina.h"
00019 #include "pointermap.h"
00020 #include "kernelwrapper.h"
00021 #include "file_io.h"
00022 #include "stringutils.h"
00023 #include "worldviews.h"
00024 #include "generic_stdlib.h"
00025 #include "matrix.h"
00026 #include "tnt_gnuplot.h"
00027 #include "robj.h"
00028
00029
00030
00031
00032
00033
00034
00036 class NamedValueGenerators : public ValueGenContainer {
00037 public:
00038 virtual cmdstat create(StringArgs args);
00039 };
00040
00041
00043 cmdstat NamedValueGenerators::create(StringArgs args)
00044 {
00045 DistributedValueGeneratorFactory<double> vgf;
00046
00047 const string name = args.next(string(""));
00048 ValueGenerator<>* valgen = vgf.create(args.recursiveparser());
00049 const string helpstring = args.next(string(""));
00050
00051 if (params_define_param(name.c_str(), PARAM_DOUBLE, false,
00052 reinterpret_cast<char *>(valgen->valueptr())) == 1) {
00053 if (helpstring != "") params_define_doc(name.c_str(),cmdparam_dupstr(helpstring.c_str()));
00054 push_back(valgen);
00055 ipc_notify(IPC_ONE,IPC_STD,"Defined ValueGenerator %s",name.c_str());
00056 return CMD_NO_ERROR;
00057 }
00058 else {
00059 delete valgen;
00060 ipc_notify(IPC_ONE,IPC_STD,"Could not define ValueGenerator %s",name.c_str());
00061 return CMD_PARAMETER_ERROR;
00062 }
00063 }
00064
00065
00066
00067
00068
00069
00070
00076 class Eyes : public Inputs {
00077 public:
00078 Eyes() : last_object_drawn(&permanent_contents)
00079 { register_params_and_commands(); }
00080
00081 virtual ~Eyes() { }
00082
00083 virtual void uninit();
00084
00085 virtual void init();
00086
00089 virtual void reset() {
00090 permanent_contents.reset();
00091 namedgenerators.reset();
00092 }
00095 virtual void reset(long int seed) {
00096 permanent_contents.reset(seed);
00097 namedgenerators.reset();
00098 }
00099
00100 virtual bool next();
00101
00102 virtual void activate(bool learn=false, bool settle=true)
00103 { activate(permanent_contents,learn,settle); };
00104
00106 virtual void activate(const WorldViews& views,bool learn=false, bool settle=true);
00107
00108
00110 virtual bool is_active(int objnumber, int eye) const
00111 { return last_object_drawn->is_active(objnumber,eye); }
00112 virtual double angle_of_object(int objnumber, int eye) const
00113 { return last_object_drawn->angle_of_object(objnumber,eye); }
00114 virtual double angle_of_object_at_location(int i, int j, int eye) const
00115 { return last_object_drawn->angle_of_object_at_location(i,j,eye); }
00116
00117 private:
00118 virtual void register_params_and_commands( void );
00119 virtual void define_input_pathway( const string& eyename, const int eyenum, StringArgs& arglist );
00120
00121 CMDOBJ_DECLARE(Eyes,input_undefine);
00122 CMDOBJ_DECLARE(Eyes,input_define);
00123 CMDOBJ_DECLARE(Eyes,input_define_generator);
00124 CMDOBJ_DECLARE(Eyes,input_print);
00125 CMDOBJ_DECLARE(Eyes,input_reset);
00126 CMDOBJ_DECLARE(Eyes,input_clear);
00127 CMDOBJ_DECLARE(Eyes,input_draw);
00128 CMDOBJ_DECLARE(Eyes,input_present);
00129 CMDOBJ_DECLARE(Eyes,input_present_object);
00130
00131 CMDOBJ_DECLARE(Eyes,input_define_convolution);
00132 CMDOBJ_DECLARE(Eyes,input_plot_convolution);
00133
00134 SETFNOBJ_DECLARE(Eyes,inputs_pereye_setfn);
00135 SETFNOBJ_DECLARE(Eyes,blur_type_setfn);
00136 SETFNOBJ_DECLARE(Eyes,double_blur_setfn);
00137
00138
00139 SETFNOBJ_DECLARE(Eyes,distribution_setfn);
00140
00141 private:
00142
00144 NamedValueGenerators namedgenerators;
00145
00147 const WorldViews* last_object_drawn;
00148 WorldViews permanent_contents;
00149 WorldViews temporary_contents;
00150
00152 typedef Retina retina_type;
00153 typedef FixedWtRegion convolvingregion_type;
00154
00156 typedef PointerMap<NeuralRegion> neuralregions_type;
00157 PointerMap<NeuralRegion> neuralregions;
00158
00160 typedef std::vector<string> operation_order_type;
00161 typedef operation_order_type::iterator operation_order_iterator;
00162 operation_order_type activation_order;
00163
00164 KernelFactory kernel_factory;
00165
00166 private:
00167 static double input_threshold;
00168 static double world_size_scale;
00169
00170 static bool network_initialized;
00171 };
00172
00173
00174
00175
00176 double Eyes::input_threshold=1.0/(M_E*M_E);
00177 double Eyes::world_size_scale=1.0;
00178 bool Eyes::network_initialized=false;
00179
00180
00181
00184 void Eyes::init( void )
00185 {
00186
00187 permanent_contents.init();
00188 temporary_contents.define();
00189
00190
00191 cmd_input_define_convolution(0,NULL);
00192
00193
00194 if (activation_order.empty()) {
00195 activation_order.push_back("Eye");
00196 activation_order.push_back("Ganglia");
00197 activation_order.push_back("LGN");
00198 activation_order.push_back("WrapEye");
00199 activation_order.push_back("Primary");
00200 activation_order.push_back("WrapPrimary");
00201 activation_order.push_back("Secondary");
00202 activation_order.push_back("Association");
00203 activation_order.push_back("Frontal");
00204 }
00205
00206
00207 const string cortexname = "WrapPrimary";
00208 neuralregions.set(cortexname, new CortexMapWrapper(cortexname));
00209
00210 network_initialized=true;
00211 }
00212
00213
00214 void Eyes::uninit( void )
00215 {
00216 permanent_contents.uninit();
00217 neuralregions.erase();
00218 network_initialized=false;
00219 }
00220
00221
00222
00223 bool Eyes::next(void)
00224 {
00225
00226 00227
00228 ipc_barrier();
00229 bool status1 = namedgenerators.next();
00230 bool status2 = permanent_contents.next();
00231 return status1 && status2;
00232 }
00233
00234
00235
00236 void Eyes::activate(const WorldViews& views, bool learn, bool settle)
00237 {
00238
00239 for (WorldViews::const_iterator eye=views.begin(); eye!= views.end(); eye++) {
00240 retina_type* retina = dynamic_cast<retina_type*>(neuralregions.getptr((*eye)->get_name()));
00241 if (retina)
00242 retina->set_input(*eye);
00243 }
00244 last_object_drawn = &views;
00245
00246
00247 for (operation_order_iterator a=activation_order.begin(); a!=activation_order.end(); a++)
00248 for (neuralregions_type::iterator region=neuralregions.begin(); region!=neuralregions.end(); region++)
00249 if (String::non_numeric_basename_matches(*a,(*region).second->name()))
00250 (*region).second->activate(learn,settle);
00251 }
00252
00253
00254
00256 void Eyes::define_input_pathway( const string& eyename, const int eyenum, StringArgs& arglist )
00257 {
00258
00259
00260 const string wrapname = "Wrap"+eyename;
00261 InputVectorWrapper* new_wrap = new InputVectorWrapper(wrapname,eyenum);
00262 neuralregions.set(wrapname,new_wrap);
00263 InternalNeuralRegion* eye_output_region = new_wrap;
00264
00265
00266 KernelFactoryWrapper kfw(kernel_factory,arglist,eyenum);
00267 const string convolvename = "Ganglia" + String::numeric_extension<string>(eyename);
00268 if (mat::size(kfw(world_size_scale))) {
00269 convolvingregion_type* new_convolver = new convolvingregion_type(convolvename, RN, RN, input_threshold);
00270 new_wrap->add_input("Afferent",new_convolver->const_activity(), kfw, 1.0);
00271 eye_output_region = new_convolver;
00272 neuralregions.set(convolvename,new_convolver);
00273 }
00274 else {
00275 neuralregions.erase(convolvename);
00276 ipc_notify(IPC_ONE,IPC_VERBOSE,"Empty convolution defined");
00277 }
00278
00279
00280 neuralregions.set(eyename, new retina_type
00281 (eyename, eye_output_region->input_dimensions(kfw,world_size_scale),
00282 input_threshold));
00283 eye_output_region->add_input("Afferent",neuralregions.getptr(eyename)->const_activity(), kfw, world_size_scale);
00284 }
00285
00286
00287
00288 void Eyes::register_params_and_commands( void )
00289 {
00290 WorldViews::register_params_and_commands();
00291 kernel_factory.register_params_and_commands();
00292
00293 00294 00295 00296 00297 00298 00299
00300 SETFNOBJ_DEFINE(this,inputs_pereye,inputs_pereye_setfn);
00301 SETFNOBJ_DEFINE(this,distribution,distribution_setfn);
00302 SETFNOBJ_DEFINE(this,blur_radius,double_blur_setfn);
00303 SETFNOBJ_DEFINE(this,blur_type,blur_type_setfn);
00304 SETFNOBJ_DEFINE(this,blur_radius_surround_multiplier,double_blur_setfn);
00305 SETFNOBJ_DEFINE(this,blur_range_multiplier,double_blur_setfn);
00306 SETFNOBJ_DEFINE(this,blur_scale,double_blur_setfn);
00307
00308 CMDOBJ_DEFINE_CATCHUP(this,0,input_define,
00309 "%s [<name> [<parent> [<objtype> [<input_object_arguments>*]]]]",
00310
00311 "Define a new persistent input object with the given <name>.\n\n"
00312
00313 "The <parent> may be of the form EyeX, where X is a numeric digit\n"
00314 "representing a single eye, \"\" for all eyes, or the name of a\n"
00315 "previously defined Input_Composite object. (To keep yourself from\n"
00316 "getting confused about which eyes `all eyes' refers to, you should\n"
00317 "probably not change num_eyes after you call this command.)\n\n"
00318
00319 "The <objtype> may be any of the following (prefixed with `Input_'):\n\n"
00320
00321 " Composite,UniformRandomNoise,Gaussian,CircularGaussian,\n"
00322 " SineGrating,Gabor,FuzzyLine,PGM,Clone\n\n"
00323
00324 "See the documentation for the corresponding constants for more\n"
00325 "information on that particular object type.\n\n"
00326
00327 "The remaining parameters are determined by the <objtype>. They\n"
00328 "can generally be specified either by position, i.e. by listing\n"
00329 "them in order, or by name, e.g. by specifying xsigma=5. All\n"
00330 "named arguments must follow any positional arguments.\n\n"
00331
00332 "Most or all floating-point parameters may be a ValueGenerator, i.e.\n"
00333 "any <valuegenerator> accepted by the input_define_generator command.\n"
00334 "If the object is being defined in more than one eye, the specified\n"
00335 "<valuegenerator>s apply only to the first eye. Objects in the\n"
00336 "remaining eyes are created with references to the corresponding\n"
00337 "parameters in the first, so that e.g. random values are fully\n"
00338 "correlated between the eyes.\n\n"
00339
00340 "If you wish to introduce some degree of uncorrelation between\n"
00341 "objects defined in more than one eye, you may substitute for any\n"
00342 "ValueGenerator parameter the extended syntax:\n\n"
00343
00344 " \"Uncorrelate &<uncorrelation-ratio> <lower-bound> <upper-bound> <valuegenerator>\"\n\n"
00345
00346 "This will add or subtract a random value to the value generated\n"
00347 "in the first eye, scaled by the difference between the bounds times\n"
00348 "the uncorrelation-ratio, and cropped by the bounds. For instance,\n\n"
00349
00350 " \"Uncorrelate &uncorrelation 0 RN Random RN/2 RN/2\"\n\n"
00351
00352 "when uncorrelation=1.0 will create a random number generator\n"
00353 "in the range 0..RN in the first eye, and will effectively\n"
00354 "uncorrelate the value entirely within that range in all the\n"
00355 "other eyes. (This is the default for <cx> and <cy> parameters,\n"
00356 "except that uncorrelation is not necessarily 1.0.)\n\n"
00357
00358 "Since ValueGenerators and input objects are extremely flexible, be\n"
00359 "sure to look at images of the inputs for a number of sample iterations\n"
00360 "so that you can verify that the inputs are being generated as you expect.\n"
00361 "You can also look at the logfile (when input_log is true) to verify\n"
00362 "the average and range for some of the generated values.");
00363
00364 CMDOBJ_DEFINE_CATCHUP(this,2,input_define_generator,
00365 "%s <name> <valuegenerator> [<helpstring>]",
00366
00367 "Define a new ValueGenerator whose value is updated before every input\n"
00368 "presentation. A ValueGenerator is like a generalization of a parameter\n"
00369 "of type PARAM_DOUBLE which supports automatic updating from e.g. a\n"
00370 "random distribution. This command allows you to define a named\n"
00371 "ValueGenerator which can be referred to when later defining input\n"
00372 "objects; this enables you to e.g. define a single random number\n"
00373 "which controls multiple objects in unison. The value also\n"
00374 "becomes a parameter, so it will henceforth show up in documentation,\n"
00375 "online help, etc., and can be set or queried like any parameter.\n\n"
00376
00377 "Possible values for a <valuegenerator>:\n\n"
00378
00379 " <expr> A floating-point expression. (Ex: 2*PI)\n\n"
00380
00381 " &<param> A reference to a parameter. (Ex: &xsigma)\n"
00382 " Future changes to the parameter will be\n"
00383 " reflected in the ValueGenerator, so this\n"
00384 " form provides a means for controlling a\n"
00385 " ValueGenerator after creation and linking\n"
00386 " multiple ValueGenerators together. This form\n"
00387 " is also accepted for the arguments of\n"
00388 " certain of the other ValueGenerators\n"
00389 " defined below (try first to be sure).\n\n"
00390
00391 " \"Random <m> <r>\" A random number from the uniform distribution\n"
00392 " centered at mean <m> and extending radius <r>\n"
00393 " in either direction (inclusively on the lower\n"
00394 " side, exclusively on the higher).\n"
00395 " (Ex: \"Random PI/2 PI/2\" or \"Random &mean &radius\"\n\n"
00396
00397 " \"Normal <m> <r>\" A random number from the normal distribution\n"
00398 " centered at mean <m> with sigma (approx. half-width at\n"
00399 " half-height) <r>.\n"
00400 " (Ex: \"Normal PI/2 PI/2\" or \"Normal &mean &radius\")\n\n"
00401
00402 " \"Increment <s> <i>\" Starts at value <s>; before each presentation, it\n"
00403 " is incremented by <i> (which may be negative or\n"
00404 " non-integer). Note that increment occurs *before*\n"
00405 " each presentation, so decrement the starting\n"
00406 " value if needed.\n"
00407 " (Ex: \"Increment -1 1\" to count from 0 by 1)\n\n"
00408
00409 " \"Correlate &<m> &<u> <lb> <ub> \" Generate a value correlated with\n"
00410 " the given master variable <m> within a correlation\n"
00411 " constant of <u>. Optionally crops to the given\n"
00412 " range [<lb>..<ub>]. This description may be\n"
00413 " seriously incomplete, so study the code a bit first.\n\n"
00414
00415 " \"Expression <e>\" Before each presentation, the given expression <e>\n"
00416 " is evaluated to get a value.\n"
00417 " (Ex: \"Expression theta+PI/2\" to get the current\n"
00418 " value of theta, plus PI/2, each time)\n\n"
00419
00420 "Single or double quotes are required for any form that has an embedded space,\n"
00421 "and are optional for the others.\n\n"
00422
00423 "Calling this command multiple times for the same name is not an error,\n"
00424 "but subsequent calls are ignored.");
00425
00426 CMDOBJ_DEFINE_CATCHUP(this,0,input_define_convolution,
00427 "%s [<eye> [<blurtype> [<blurtype_arguments>*]]]",
00428 "Defines a convolution kernel for the given eye(s) (specified as in\n"
00429 "input_define) to perform input blurring, smoothing, edge detection or\n"
00430 "(in general) convolution. This command is called automatically at network\n"
00431 "initialization and when any of the parameters blur_type, blur_radius,\n"
00432 "blur_scale, or blur_range_multiplier are changed. It can also be called\n"
00433 "explicitly for more precise control. See the documentation for each type\n"
00434 "for more information. Convolution radii should be specified in terms of\n"
00435 "the retinal output; any scaling with respect to world_size_scale is handled\n"
00436 "automatically. Available types include the following (prefixed with\n"
00437 "'Blur_'):\n"
00438 " CircularAverage,SquareAverage,Gaussian,DoG,LoG,GoD,DoGGoD");
00439
00440 CMDOBJ_DOC(input_plot_convolution,NULL,this,0,
00441 "%s [<eye> [<filebase>]]",
00442 "Plots the currently-active convolution kernel matrix for the given eye(s)\n"
00443 "(as in input_define; all, by default) using gnuplot. If a filename is\n"
00444 "specified, the eye number and `.ps' are appended before using it for the\n"
00445 "PostScript output of the plot. Otherwise, if the session is interactive,\n"
00446 "the plot is saved in a temporary file and displayed, or else saved to a\n"
00447 "default filename.");
00448
00449 CMDOBJ_DOC(input_draw,"init_network",this,0,
00450 "%s [<parent> [<objtype> [<input_object_arguments>*]]]",
00451 "Same as input_define, but adds the unnamed object to a collection of\n"
00452 "temporary objects (e.g. for testing) to be presented using input_present.\n\n"
00453
00454 "The arguments are like those in input_define. If no arguments are supplied,\n"
00455 "the object specified by parameter input_default_object is created in all\n"
00456 "eyes, with default arguments.\n\n"
00457
00458 "The input_clear command can be called before this command to ensure\n"
00459 "that the object list is empty. This command may be called multiple times\n"
00460 "to define more than one object, either in the same or different eyes. The\n"
00461 "object is not seen by the network until input_present is called.\n\n"
00462
00463 "Note that objects created by this command are named 'input_draw'\n"
00464 "internally. Thus if an Input_Composite object is drawn first, subsequent\n"
00465 "objects can specify a parent of 'input_draw' to be defined under that\n"
00466 "composite.");
00467
00468 CMDOBJ_DOC(input_clear,"init_network",this,0,"%s [<eye>]",
00469 "Clears the temporary objects defined for the given eyes (all, by default)\n"
00470 "in preparation for e.g. input_draw.");
00471
00472 CMDOBJ_DOC(input_present,"init_network",this,0,"%s [<learn> [<plot>]]",
00473 "Presents the temporary objects currently defined by input_draw to the network,\n"
00474 "without advancing the iteration counter. If a True (non-zero) value\n"
00475 "is passed for <learn>, learning is enabled; otherwise it is not. Pictures\n"
00476 "are saved using plot_activity when the command completes unless False\n"
00477 "(aka zero) is supplied for <plot>.\n");
00478
00479 CMDOBJ_DOC(input_present_object,"init_network",this,0,
00480 "%s [<parent> [<objtype> [<input_object_arguments>*]]]",
00481 "Convenience macro for looking at the response to a single object.\n"
00482 "Calls input_clear, passes the given arguments to input_draw, and\n"
00483 "calls input_present with learning off.");
00484
00485 CMDOBJ_DOC(input_print,NULL,this,0,"%s [<name> [<parent>]]",
00486 "Print a textual representation of the specified input object in the specified\n"
00487 "parent. Parent defaults to all eyes, and name defaults to all persistent\n"
00488 "objects.");
00489
00490 CMDOBJ_DEFINE_CATCHUP(this,0,input_reset,
00491 "%s [seed]",
00492 "Reset all persistent retinal objects and the input random number generator to\n"
00493 "their starting states. For instance, if any Increment ValueGenerators have\n"
00494 "been defined (see input_define_generator), their values will be reset to the\n"
00495 "start value supplied initially.\n\n"
00496
00497 "The random number generator is reset to the specified seed (or the value of\n"
00498 "input_seed if none is given), so the same series of pseudo-random numbers will\n"
00499 "be seen as the last time this command was called. This means that the\n"
00500 "same sequence of input values will be generated unless other input settings\n"
00501 "have changed, which makes it possible to independently test the effect of\n"
00502 "unrelated changes such as to the network architecture.\n\n"
00503
00504 "This command is called automatically by init_network, so (in general) changes\n"
00505 "in architecture parameters or the number of PEs should not usually affect the\n"
00506 "input sequence generated. (Known exception: when Input_UniformRandom inputs\n"
00507 "are used, each processor computes the values independently instead of copying\n"
00508 "from a single master PE, so in that case the sequence will differ when the\n"
00509 "number of PEs changes.)");
00510
00511 CMDOBJ_DEFINE_CATCHUP(this,0,input_undefine,"%s [<name> [<parent>]]",
00512 "Remove specified input object from specified parent. Parent defaults to\n"
00513 "all eyes, and name defaults to all persistent objects.");
00514
00515 PARAM_LL(PARAM_DOUBLE,input_threshold,&input_threshold,0,
00516 "If an input receptor activation is below this value, it is set to zero to save\n"
00517 "computation time. The savings occurs because any cortical unit which receives\n"
00518 "no activation can be left out of calculations altogether. This parameter\n"
00519 "should be set low enough that inputs below it would rarely be likely to exceed\n"
00520 "the lower bound of the sigmoid cortical activation function, and thus the\n"
00521 "activity calculation would be essentially unaffected anyway. This parameter\n"
00522 "should rarely need adjustment in practice.");
00523
00524 PARAM_LL(PARAM_DOUBLE,world_size_scale,&world_size_scale,0,
00525 "Scale of world model relative to the size of the retina. When using\n"
00526 "input convolution, it can be useful for the world to have a higher\n"
00527 "resolution than the network input in order to avoid aliasing effects\n"
00528 "for such operations as rotation of image input.");
00529 SETFNOBJ_DEFINE(this,world_size_scale,double_blur_setfn);
00530 }
00531
00532
00533
00534
00535
00536
00537
00538
00539 cmdstat Eyes::cmd_input_define_generator( CMD_ARGS )
00540 {
00541 CMD_ARG_LIST;
00542 return namedgenerators.create(arglist);
00543 }
00544
00545
00546
00547 cmdstat Eyes::cmd_input_define_convolution( CMD_ARGS )
00548 {
00549 CMD_ARG_LIST;
00550
00551 bool parentfound = false;
00552 const string parent = arglist.next(string(""));
00553
00554
00555 int eyenum=0;
00556 for (WorldViews::const_iterator eye=permanent_contents.begin();
00557 eye!= permanent_contents.end(); eye++,eyenum++) {
00558 const string eyename = (*eye)->get_name();
00559 if (parent == "" || parent == eyename) {
00560 parentfound=true;
00561 define_input_pathway( eyename, eyenum, arglist );
00562 }
00563 }
00564
00565 if (!parentfound)
00566 ipc_notify(IPC_ONE,IPC_WARNING,"Could not locate specified parent object(s)");
00567
00568 return CMD_NO_ERROR;
00569 }
00570
00571
00572
00573 cmdstat Eyes::cmd_input_plot_convolution( CMD_ARGS )
00574 {
00575 const string filebase = string(argc>1 ? cmds(argv[1]) : (spawn_viewer? "" : "kernel_"));
00576 string status="";
00577 bool parentfound=false;
00578
00579
00580 for (neuralregions_type::const_iterator i=neuralregions.begin(); i!=neuralregions.end(); i++) {
00581 InternalNeuralRegion* ptr = dynamic_cast<convolvingregion_type*>((*i).second);
00582 const string parent = (argc>0)? cmds(argv[0]) : "";
00583 const string name = (*i).first;
00584 if (ptr && (parent == "" || name == parent)) {
00585 parentfound=true;
00586 const string outname = (filebase=="" ? "" : filebase+name+".ps");
00587 const string weightname = "Afferent";
00588 InternalNeuralRegion::WeightMatrix m = ptr->get_weights(weightname);
00589 const string newstatus = mat::gnuplot(m,weightname+" weights to "+name,outname);
00590 if (newstatus!="") {
00591 if (status!="") status += "; ";
00592 status += newstatus + " (" + name + "::" + weightname + ")";
00593 }
00594 }
00595 }
00596
00597 if (status != "")
00598 ipc_notify(IPC_ONE,IPC_WARNING,"Gnuplot wrapper: %s",status.c_str());
00599 else if (!parentfound)
00600 ipc_notify(IPC_ONE,IPC_WARNING,"Could not locate any parent object");
00601
00602 return CMD_NO_ERROR;
00603 }
00604
00605
00606
00607 cmdstat Eyes::cmd_input_clear( CMD_ARGS )
00608 {
00609 temporary_contents.remove_object((argc>0)? argv[0] : "","");
00610 ipc_notify(IPC_ONE,IPC_VERBOSE,"Cleared temporary objects");
00611 return CMD_NO_ERROR;
00612 }
00613
00614
00615
00616 cmdstat Eyes::cmd_input_draw( CMD_ARGS )
00617 {
00618 CMD_ARG_LIST;
00619
00620 temporary_contents.define();
00621 if (temporary_contents.create_object(arglist,"input_draw",permanent_contents, false) != 0) {
00622 ipc_notify(IPC_ONE,IPC_ERROR,"Could not draw input object");
00623 return CMD_PARAMETER_ERROR;
00624 }
00625
00626 return CMD_NO_ERROR;
00627 }
00628
00629
00630
00631 cmdstat Eyes::cmd_input_define( CMD_ARGS )
00632 {
00633 CMD_ARG_LIST;
00634
00635 const string name = arglist.next(string(""));
00636
00637 permanent_contents.define();
00638 if (permanent_contents.create_object(arglist,name,permanent_contents) != 0)
00639 ipc_notify(IPC_ONE,IPC_ERROR,"Could not define input object");
00640
00641 return CMD_NO_ERROR;
00642 }
00643
00644
00645
00646 cmdstat Eyes::cmd_input_present( CMD_ARGS )
00647 {
00648 const int learn = (argc>0 ? cmdi(argv[0]) : False);
00649 const int plot = (argc>1 ? cmdi(argv[1]) : True);
00650
00651 Eyes::activate(temporary_contents,learn);
00652 if (plot) cmd_plot_activity(0,NULL);
00653
00654 ipc_notify(IPC_ONE,IPC_VERBOSE,"Presented currently-defined temp input");
00655
00656 return CMD_NO_ERROR;
00657 }
00658
00659
00660
00662 cmdstat Eyes::cmd_input_present_object( CMD_ARGS )
00663 {
00664 cmdstat status=CMD_NO_ERROR;
00665
00666 cmd_input_clear(0,NULL);
00667 status = cmd_input_draw(argc,argv);
00668 if (status >= 0) cmd_input_present(0,NULL);
00669
00670 return status;
00671 }
00672
00673
00674
00675 cmdstat Eyes::cmd_input_print( CMD_ARGS )
00676 {
00677
00678 for (neuralregions_type::const_iterator e=neuralregions.begin(); e!=neuralregions.end(); e++) {
00679 const string name = (*e).first;
00680 ipc_notify(IPC_ONE,IPC_SUMMARY,name.c_str());
00681 }
00682
00683
00684 permanent_contents.print_object((argc>1)? argv[1] : "",(argc>0)? argv[0] : "");
00685 return CMD_NO_ERROR;
00686 }
00687
00688
00689
00690 cmdstat Eyes::cmd_input_reset( CMD_ARGS )
00691 {
00692 if (argc>0) Eyes::reset(cmdi(argv[0]));
00693 else Eyes::reset();
00694 return CMD_NO_ERROR;
00695 }
00696
00697
00698
00699 cmdstat Eyes::cmd_input_undefine( CMD_ARGS )
00700 {
00701
00702 permanent_contents.remove_object((argc>1)? argv[1] : "",(argc>0)? argv[0] : "");
00703 return CMD_NO_ERROR;
00704 }
00705
00706
00707
00708
00709
00710
00711
00712
00713 cmdstat Eyes::distribution_setfn(const char*, void*, const void* newval)
00714 {
00715 int dist = *(const int *)newval;
00716 bool changed=false;
00717
00718 cmdstat status = WorldViews::set_distribution(dist,changed);
00719
00720 00721 00722 00723 00724
00725 if (changed && !permanent_contents.is_empty()) {
00726 permanent_contents.remove_object();
00727 permanent_contents.init();
00728 }
00729
00730 return status;
00731 }
00732
00733
00734
00735 cmdstat Eyes::blur_type_setfn(const char*, void* param, const void* newval)
00736 {
00737 int newvalue= *(const int *)newval;
00738
00739 if (newvalue<0 || newvalue>kernel_factory.max_blur_type) {
00740 ipc_notify(IPC_ONE,IPC_WARNING,"No blur_type of %d is defined",newvalue);
00741 return CMD_PARAMETER_ERROR;
00742 }
00743
00744 *(int *)param = newvalue;
00745 if (network_initialized)
00746 cmd_input_define_convolution(0,NULL);
00747
00748 return CMD_NO_ERROR;
00749 }
00750
00751
00752
00753 cmdstat Eyes::double_blur_setfn(const char*, void* param, const void* newval)
00754 {
00755 double newvalue= *(const double *)newval;
00756
00757 *(double *)param = newvalue;
00758 if (network_initialized)
00759 cmd_input_define_convolution(0,NULL);
00760
00761 return CMD_NO_ERROR;
00762 }
00763
00764
00765
00766 cmdstat Eyes::inputs_pereye_setfn(const char*, void* param, const void* newval)
00767 {
00768 int oldvalue= *( int *)param;
00769 int newvalue= *(const int *)newval;
00770 *(int *)param = newvalue;
00771
00772
00773 if (network_initialized && oldvalue != newvalue ) {
00774 permanent_contents.remove_object();
00775 Eyes::init();
00776 }
00777
00778 return CMD_NO_ERROR;
00779 }
00780
00781
00782
00783
00784
00785
00787 Eyes eyes;
00788
00790 Inputs* inputs=&eyes;