00001
00007 #ifndef __RETINA_H__
00008 #define __RETINA_H__
00009
00010 #include <assert.h>
00011 #include <algorithm>
00012
00013 #include "genericalgs.h"
00014 #include "robj.h"
00015 #include "neuralregion.h"
00016 #include "matrix.h"
00017 #include "allocatingpointer.h"
00018
00019
00020
00021
00022
00023
00024
00036 template <class Matrix>
00037 void draw(Matrix& area, const Retinal_Obj* obj,
00038 const typename Matrix::value_type xoff=0.5,
00039 const typename Matrix::value_type yoff=0.5,
00040 const typename Matrix::value_type size_scale=1.0)
00041 {
00042 if (!obj) return;
00043
00044 typedef typename Matrix::value_type T;
00045 typedef typename Matrix::size_type Subscript;
00046
00047 obj->update();
00048 const T s=1/size_scale;
00049 const T xo=xoff*s;
00050 const T yo=yoff*s;
00051 for (Subscript r=0; r<area.nrows(); r++) {
00052 const T y = (area.nrows()-r-1)*s+yo;
00053 for (Subscript c=0; c<area.ncols(); c++) {
00054 const T x = c*s+xo;
00055 const T act = (obj? obj->activation(x,y) : 0);
00056 area[r][c]=act;
00057 }
00058 }
00059
00060 }
00061
00062
00063
00064
00065
00066
00067
00068
00070 class Retina : public NeuralRegion {
00071 public:
00072 Retina(string name_i, Dimensions dims,
00073 ActivationFunction* actfn_=0,
00074 Activity size_scale_=1.0)
00075 : NeuralRegion(name_i, dims), world_model(0), actfn(actfn_),
00076 xo(dims.xoffset), yo(dims.yoffset), size_scale(size_scale_) { }
00077
00078 virtual ~Retina() { };
00079
00080 virtual void activate(bool=false,bool=false,bool=false) {
00081 draw(output, world_model, xo, yo, size_scale);
00082 if (actfn) (*actfn)(output,output);
00083 }
00084
00086 void set_input(const Retinal_Obj* const obj) { world_model=obj; };
00087
00088 virtual bool is_plastic() const { return false; }
00089
00090 double size_connection_bytes() const { return 0; }
00091 double size_unique_connections() const { return 0; }
00092
00093
00094
00095 protected:
00097 const Retinal_Obj* world_model;
00099 const OwningPointer<ActivationFunction> actfn;
00102 const Activity xo,yo;
00106 const Activity size_scale;
00107 };
00108
00109
00110 #endif