MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
DynamicForgettingFactor2 Class Reference

#include <forgfact.h>

Inheritance diagram for DynamicForgettingFactor2:
Collaboration diagram for DynamicForgettingFactor2:

Public Member Functions

 DynamicForgettingFactor2 (integer n1, integer n2, integer i, doublereal r, doublereal f, doublereal kr, doublereal kl)
 
 ~DynamicForgettingFactor2 (void)
 
void Update (const doublereal *pErr=NULL)
 
doublereal dGet (void) const
 
- Public Member Functions inherited from ForgettingFactor
 ForgettingFactor (integer i)
 
virtual ~ForgettingFactor (void)
 

Protected Attributes

integer N1
 
integer N2
 
doublereal dRho
 
doublereal dFact
 
doublereal dkRef
 
doublereal dkLim
 
doublereal dk
 
doublerealpdErr
 
doublereal ** ppdErr
 
integer iRef1
 
integer iRef2
 
doublerealpdErr1M
 
doublerealpdErr1S
 
doublerealpdErr2M
 
doublerealpdErr2S
 
- Protected Attributes inherited from ForgettingFactor
integer iNumErr
 

Detailed Description

Definition at line 115 of file forgfact.h.

Constructor & Destructor Documentation

DynamicForgettingFactor2::DynamicForgettingFactor2 ( integer  n1,
integer  n2,
integer  i,
doublereal  r,
doublereal  f,
doublereal  kr,
doublereal  kl 
)

Definition at line 156 of file forgfact.cc.

References ASSERT, dFact, dkLim, dkRef, dRho, ForgettingFactor::iNumErr, N1, N2, pdErr, pdErr1M, pdErr1S, pdErr2M, pdErr2S, ppdErr, and SAFENEWARR.

163 : ForgettingFactor(i),
164 N1(n1), N2(n2), dRho(r), dFact(f), dkRef(kr), dkLim(kl),
165 dk(kr), pdErr(NULL), ppdErr(NULL), iRef1(n1-1), iRef2(n1-n2-1),
166 pdErr1M(NULL), pdErr1S(NULL), pdErr2M(NULL), pdErr2S(NULL) {
167  ASSERT(N1 > 0);
168  ASSERT(N2 > 0);
169  ASSERT(N2 < N1);
170  ASSERT(dRho > 0. && dRho < 1.);
171  ASSERT(dFact > 0. && dFact < 1.);
172  ASSERT(dkRef > 0. && dkRef < 1.);
173  ASSERT(dkLim > dkRef && dkLim <= 1.);
174 
175  integer sz = (N1+4)*iNumErr;
176 
179 
184  for (integer i = sz; i-- > 0; ) {
185  pdErr[i] = 0.;
186  }
187  for (integer i = N1; i-- > 0; ) {
188  ppdErr[i] = pdErr+i*iNumErr;
189  }
190 }
integer iNumErr
Definition: forgfact.h:47
doublereal * pdErr
Definition: forgfact.h:127
ForgettingFactor(integer i)
Definition: forgfact.cc:39
doublereal ** ppdErr
Definition: forgfact.h:128
doublereal * pdErr1S
Definition: forgfact.h:133
#define ASSERT(expression)
Definition: colamd.c:977
#define SAFENEWARR(pnt, item, sz)
Definition: mynewmem.h:701
doublereal * pdErr2S
Definition: forgfact.h:135
double doublereal
Definition: colamd.c:52
long int integer
Definition: colamd.c:51
doublereal * pdErr1M
Definition: forgfact.h:132
doublereal * pdErr2M
Definition: forgfact.h:134
DynamicForgettingFactor2::~DynamicForgettingFactor2 ( void  )

Definition at line 192 of file forgfact.cc.

References pdErr, ppdErr, and SAFEDELETEARR.

192  {
193  /* pdErr must be non-null */
196 }
doublereal * pdErr
Definition: forgfact.h:127
#define SAFEDELETEARR(pnt)
Definition: mynewmem.h:713
doublereal ** ppdErr
Definition: forgfact.h:128

Member Function Documentation

doublereal DynamicForgettingFactor2::dGet ( void  ) const
inlinevirtual

Implements ForgettingFactor.

Definition at line 148 of file forgfact.h.

References dk.

149 {
150  return dk;
151 }
void DynamicForgettingFactor2::Update ( const doublereal pErr = NULL)
virtual

Implements ForgettingFactor.

Definition at line 198 of file forgfact.cc.

References dFact, dk, dkLim, dkRef, dRho, grad::exp(), grad::fabs(), ForgettingFactor::iNumErr, iRef1, iRef2, N1, N2, pdErr1M, pdErr1S, pdErr2M, pdErr2S, grad::pow(), and ppdErr.

198  {
199  /* setta i riferimenti */
200  if (++iRef1 == N1) {
201  iRef1 = 0;
202  }
203  if (++iRef2 == N1) {
204  iRef2 = 0;
205  }
206 
207  /* somma agli errori la norma dell'errore corrente, poi sottrae
208  * l'errore al limite posteriore delle rispettive finestre */
209  doublereal dS1 = 0.;
210  doublereal dS2 = 0.;
211  for (integer i = iNumErr; i-- > 0; ) {
212  doublereal d = pE[i]*pE[i];
213  pdErr1S[i] += d;
214  pdErr1S[i] -= ppdErr[iRef1][i]*ppdErr[iRef1][i];
215  pdErr1M[i] += pE[i];
216  pdErr1M[i] -= ppdErr[iRef1][i];
217  dS1 += pdErr1S[i]/N1-pow(pdErr1M[i]/N1,2);
218  pdErr2S[i] += d;
219  pdErr2S[i] -= ppdErr[iRef2][i]*ppdErr[iRef2][i];
220  pdErr2M[i] += pE[i];
221  pdErr2M[i] -= ppdErr[iRef2][i];
222  dS2 += pdErr2S[i]/N2-pow(pdErr2M[i]/N2,2);
223 
224  /* aggiorna il limite superiore della finestra "lunga" */
225  ppdErr[iRef1][i] = pE[i];
226  }
227 
228 
229 
230  /* per debug
231  cout << setw(16) << dS1 << setw(16) << dS2 << setw(16)
232  << (dS1 != 0. ? 1.-dS2/dS1 : 0.) << endl;
233  */
234 
235 
236 
237  /* differenza tra la varianza dell'errore "corto"
238  * rispetto a quello "lungo"
239  * se viene superato il limite, il forgetting factor scatta al valore
240  * minimo (massima dimenticanza) */
241  doublereal d = 0.;
242  if (fabs(dS1) > std::numeric_limits<doublereal>::epsilon() && (d = fabs(1.-dS2/dS1)) > dFact) {
243 #if 0
244  dk = (dkLim-dkRef)*exp(-d)+dkRef;
245 #else
246  dk = dkRef;
247 #endif
248  } else {
249  /* il forgetting factor viene fatto variare con una sua dinamica */
250  dk = dRho*dk+(1-dRho)*dkLim;
251  }
252 }
GradientExpression< UnaryExpr< FuncExp, Expr > > exp(const GradientExpression< Expr > &u)
Definition: gradient.h:2975
integer iNumErr
Definition: forgfact.h:47
GradientExpression< BinaryExpr< FuncPow, LhsExpr, RhsExpr > > pow(const GradientExpression< LhsExpr > &u, const GradientExpression< RhsExpr > &v)
Definition: gradient.h:2961
doublereal ** ppdErr
Definition: forgfact.h:128
GradientExpression< UnaryExpr< FuncFabs, Expr > > fabs(const GradientExpression< Expr > &u)
Definition: gradient.h:2973
doublereal * pdErr1S
Definition: forgfact.h:133
doublereal * pdErr2S
Definition: forgfact.h:135
double doublereal
Definition: colamd.c:52
long int integer
Definition: colamd.c:51
doublereal * pdErr1M
Definition: forgfact.h:132
doublereal * pdErr2M
Definition: forgfact.h:134

Here is the call graph for this function:

Member Data Documentation

doublereal DynamicForgettingFactor2::dFact
protected

Definition at line 121 of file forgfact.h.

Referenced by DynamicForgettingFactor2(), and Update().

doublereal DynamicForgettingFactor2::dk
protected

Definition at line 125 of file forgfact.h.

Referenced by dGet(), and Update().

doublereal DynamicForgettingFactor2::dkLim
protected

Definition at line 123 of file forgfact.h.

Referenced by DynamicForgettingFactor2(), and Update().

doublereal DynamicForgettingFactor2::dkRef
protected

Definition at line 122 of file forgfact.h.

Referenced by DynamicForgettingFactor2(), and Update().

doublereal DynamicForgettingFactor2::dRho
protected

Definition at line 120 of file forgfact.h.

Referenced by DynamicForgettingFactor2(), and Update().

integer DynamicForgettingFactor2::iRef1
protected

Definition at line 129 of file forgfact.h.

Referenced by Update().

integer DynamicForgettingFactor2::iRef2
protected

Definition at line 130 of file forgfact.h.

Referenced by Update().

integer DynamicForgettingFactor2::N1
protected

Definition at line 117 of file forgfact.h.

Referenced by DynamicForgettingFactor2(), and Update().

integer DynamicForgettingFactor2::N2
protected

Definition at line 118 of file forgfact.h.

Referenced by DynamicForgettingFactor2(), and Update().

doublereal* DynamicForgettingFactor2::pdErr
protected

Definition at line 127 of file forgfact.h.

Referenced by DynamicForgettingFactor2(), and ~DynamicForgettingFactor2().

doublereal* DynamicForgettingFactor2::pdErr1M
protected

Definition at line 132 of file forgfact.h.

Referenced by DynamicForgettingFactor2(), and Update().

doublereal* DynamicForgettingFactor2::pdErr1S
protected

Definition at line 133 of file forgfact.h.

Referenced by DynamicForgettingFactor2(), and Update().

doublereal* DynamicForgettingFactor2::pdErr2M
protected

Definition at line 134 of file forgfact.h.

Referenced by DynamicForgettingFactor2(), and Update().

doublereal* DynamicForgettingFactor2::pdErr2S
protected

Definition at line 135 of file forgfact.h.

Referenced by DynamicForgettingFactor2(), and Update().

doublereal** DynamicForgettingFactor2::ppdErr
protected

Definition at line 128 of file forgfact.h.

Referenced by DynamicForgettingFactor2(), Update(), and ~DynamicForgettingFactor2().


The documentation for this class was generated from the following files: