00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 
00032 
#ifndef __INVERTMOTORBIGMODEL_H
00033 
#define __INVERTMOTORBIGMODEL_H
00034 
00035 
#include "invertmotorcontroller.h"
00036 
00037 
#include <assert.h>
00038 
#include <math.h>
00039 
00040 
#include "matrix.h"
00041 
#include "noisegenerator.h"
00042 
#include "invertablemodel.h"
00043 
00044 typedef struct InvertMotorBigModelConf {
00045   int buffersize;  
00046   double cInit;    
00047   double cNonDiag; 
00048   bool modelInit;  
00049   bool someInternalParams;  
00050   bool useTeaching;         
00051 
00052   InvertableModel* 
model;   
00053 } 
InvertMotorNStepConf;
00054 
00055 
00056 
00057 
00058 
00059 
00060 
00061 
00062 
00063 
00064 class InvertMotorBigModel : 
public InvertMotorController {
00065 
00066 
public:
00067   
InvertMotorBigModel(
const InvertMotorBigModelConf& 
conf = 
getDefaultConf());
00068   
virtual void init(
int sensornumber, 
int motornumber);
00069 
00070   
virtual ~InvertMotorBigModel();
00071 
00072 
00073   virtual int getSensorNumber()
 const { 
return number_sensors; }
00074 
00075   virtual int getMotorNumber()
 const  { 
return number_motors; }
00076 
00077 
00078 
00079   
virtual void step(
const sensor* , 
int number_sensors, 
motor* , 
int number_motors);
00080 
00081 
00082   
virtual void stepNoLearning(
const sensor* , 
int number_sensors, 
00083                               
motor* , 
int number_motors);
00084 
00085 
00086   
00087 
00088   
virtual bool store(FILE* f) 
const;
00089 
00090   
virtual bool restore(FILE* f);  
00091 
00092   
00093   
virtual iparamkeylist 
getInternalParamNames() const;
00094   virtual iparamvallist getInternalParams() const;  
00095   virtual ilayerlist getStructuralLayers() const;
00096   virtual iconnectionlist getStructuralConnections() const;
00097 
00098   
00099   virtual paramval getParam(const paramkey& key) const;
00100   virtual 
bool setParam(const paramkey& key, paramval val);
00101   virtual paramlist getParamList() const;
00102 
00103 
00104 
00105   
00106   virtual 
void setTeachingMode(
bool onOff);
00107   virtual 
bool getTeachingMode();
00108   virtual 
void setMotorTeachingSignal(const 
motor* teaching, 
int len);
00109   
void calcCandHUpdatesTeaching(matrix::
Matrix& C_update, matrix::
Matrix& H_update, 
int y_delay);
00110 
00111 
00112   static 
InvertMotorBigModelConf getDefaultConf(){
00113     
InvertMotorBigModelConf c;
00114     c.
buffersize = 50;
00115     c.
cInit = 1.0;
00116     c.
cNonDiag = 0;
00117     c.
modelInit  = 1.0;
00118     c.
someInternalParams = 
true;
00119     c.
useTeaching = 
false;
00120     c.
model = 0;
00121     
return c;
00122   }
00123 
00124   
void getLastMotors(
motor* motors, 
int len);
00125 
00126 
protected:
00127   unsigned short number_sensors;
00128   unsigned short number_motors;
00129   
00130   matrix::Matrix A; 
00131 
00132   matrix::Matrix C; 
00133   matrix::Matrix H; 
00134 
00135   matrix::Matrix R; 
00136   matrix::Matrix SmallID; 
00137   matrix::Matrix xsi; 
00138   double xsi_norm; 
00139   double xsi_norm_avg; 
00140   double pain;         
00141   matrix::Matrix* 
x_buffer;
00142   matrix::Matrix* 
y_buffer;
00143   matrix::Matrix* 
eta_buffer;
00144   matrix::Matrix zero_eta; 
00145   matrix::Matrix x_smooth;
00146   
00147 
00148   matrix::Matrix y_teaching; 
00149 
00150   InvertMotorBigModelConf conf;
00151 
00152 
00153   
00154   
virtual void fillBuffersAndControl(
const sensor* x_, 
int number_sensors, 
00155                              
motor* y_, 
int number_motors);
00156 
00157 
00158   
00159   
virtual void calcEtaAndBufferIt(
int delay);
00160 
00161 
00162   
virtual void learnController();
00163 
00164 
00165   
00166   
00167   
00168   
virtual void calcCandHUpdates(
matrix::Matrix& C_update, 
matrix::Matrix& H_update, 
int y_delay);
00169 
00170 
00171   
virtual void updateCandH(
const matrix::Matrix& C_update, 
const matrix::Matrix& H_update, 
double squashSize);
00172 
00173 
00174   
00175   
virtual void learnModel(
int delay);
00176 
00177 
00178   
virtual matrix::Matrix calculateControllerValues(
const matrix::Matrix& x_smooth);
00179     
00180 
00181   
virtual double calcErrorFactor(
const matrix::Matrix& e, 
bool loga, 
bool root);
00182    
00183  
00184 };
00185 
00186 
#endif