Changeset bc1dd97 in tol
- Timestamp:
- Apr 24, 2012, 5:33:49 PM (15 years ago)
- Branches:
- 1941-docker-image-to-test, devel, master
- Children:
- 1466af1
- Parents:
- 736be83
- Location:
- tol
- Files:
-
- 8 edited
-
bmath/bstat/ar.cpp (modified) (1 diff)
-
bmath/bstat/arma.cpp (modified) (5 diffs)
-
bmath/bstat/tol_bar.h (modified) (1 diff)
-
bmath/bstat/unitroot.cpp (modified) (2 diffs)
-
bmath/mathobjects/tol_bpolyn.h (modified) (3 diffs)
-
btol/bmodel/modcalc.cpp (modified) (4 diffs)
-
btol/bmodel/moddiag.cpp (modified) (2 diffs)
-
btol/real_type/datgrav.cpp (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
tol/bmath/bstat/ar.cpp
r736be83 rbc1dd97 298 298 IdentifyAutoRegIntegrated(z,err,s,sw,w,dif,ar,period); 299 299 } 300 301 //-------------------------------------------------------------------- 302 BArray<BDat> NextSchur(const BArray<BDat>& pol) 303 //-------------------------------------------------------------------- 304 { 305 int k, s = pol.Size(); 306 BArray<BDat> b(s-1); 307 b.AllocBuffer(s-1); 308 double* B = (double*)b.GetBuffer(); 309 const double* A = (const double*)pol.Buffer(); 310 const double* A_ = (const double*)pol.Buffer()+s-1; 311 double a = *A; 312 double a_ = *A_; 313 double c = a / a_; 314 /* * / 315 Std(BText("\nNextSchur a0=")+a+" an="+a_+" c="+c); 316 if(BDat(c).IsUnknown()) 317 printf(""); 318 /* */ 319 A++; 320 A_--; 321 for(k=0; k<s-1; k++, A++, A_--, B++) 322 { 323 *B = (*A - c * *A_); 324 } 325 return(b); 326 } 327 328 //-------------------------------------------------------------------- 329 BDat SchurValue(const BArray<BDat>& a, BDat toleranceBase, BDat& tolerance, bool &isSchur) 330 //-------------------------------------------------------------------- 331 { 332 int sld = sizeof(long double); 333 int s = a.Size(); 334 BDat a0 = Abs(a[0]); 335 BDat an = Abs(a[s-1]); 336 BDat sv = (2*an)/(an+a0); 337 isSchur = an-a0 > tolerance; 338 /* * / 339 //Std(BText("\nSchurValue a=")); for(int k=0; k<s; k++) { Std(BText("|")+a[k]); } 340 Std(BText("\nSchurValue tolerance=")+tolerance+" a0=")+a0+" an="+an+" sv="+sv+" isSchur="+isSchur); 341 /* */ 342 if(!isSchur || (s==2)) 343 { 344 return(sv); 345 } 346 else 347 { 348 tolerance += toleranceBase*(1+2*(s-1)); 349 return(SchurValue(NextSchur(a),toleranceBase,tolerance,isSchur)); 350 } 351 } 352 353 354 //-------------------------------------------------------------------- 355 BDat StationaryValue( 356 const BPolyn<BDat>& pol, 357 BDat toleranceBase, 358 BDat& tolerance, 359 bool& isStationary) 360 //-------------------------------------------------------------------- 361 { 362 363 if(toleranceBase.IsUnknown() || toleranceBase<0) { toleranceBase = DEpsilon(); } 364 tolerance = toleranceBase; 365 int i,j, deg; 366 BDat coef; 367 int s = pol.Size(); 368 int n = pol.Degree(); 369 if(s==1) 370 { 371 if(n==0) { isStationary=true; return(2); } 372 else { isStationary=false; return(0); } 373 } 374 int gcd = pol.Period(); 375 int m = n/gcd; 376 BArray<BDat> a(BDat(0),m+1); 377 for(i=0; i<s; i++) 378 { 379 j = s-1-i; 380 deg = pol(i).Degree(); 381 coef = pol(i).Coef(); 382 a[m-deg/gcd] = coef; 383 } 384 BDat sv = SchurValue(a,toleranceBase,tolerance,isStationary); 385 if(sv.IsUnknown()) 386 { 387 Warning("StationaryValue returns unknown value."); 388 } 389 return(sv); 390 } 391 392 //-------------------------------------------------------------------- 393 bool IsStationary(const BPolyn<BDat>& pol, BDat& tolerance) 394 //-------------------------------------------------------------------- 395 { 396 bool isStationary; 397 BDat toleranceBase = tolerance; 398 BDat sv = StationaryValue(pol,toleranceBase,tolerance,isStationary); 399 return(isStationary); 400 } 401 402 //-------------------------------------------------------------------- 403 BDat StationaryValue(const BPolyn<BDat>& pol) 404 //-------------------------------------------------------------------- 405 { 406 BDat tolerance, toleranceBase = BDat::Unknown(); 407 bool isStationary; 408 return(StationaryValue(pol,toleranceBase,tolerance,isStationary)); 409 } 410 411 //-------------------------------------------------------------------- 412 bool IsStationary(const BPolyn<BDat>& pol) 413 //-------------------------------------------------------------------- 414 { 415 BDat tolerance = BDat::Unknown(); 416 return(IsStationary(pol,tolerance)); 417 } -
tol/bmath/bstat/arma.cpp
r736be83 rbc1dd97 35 35 #include <tol/tol_bvmat.h> 36 36 #include <tol/tol_bratgra.h> 37 #include <tol/tol_bar.h> 37 38 38 39 //-------------------------------------------------------------------- … … 330 331 MatBackwardDifEq (R, ZEROp, ZB<<Z, ZEROq, A0A); 331 332 332 if( ar.IsStationary() && ma.IsStationary())333 if(IsStationary(ar) && IsStationary(ma)) 333 334 { 334 335 BMatrix<BDat> oldA0A; … … 700 701 int i, j; 701 702 BArray<BDat> gn; 702 //BBool isStationary = ar.IsStationary() && ma.IsStationary();703 //BBool isStationary = IsStationary(ar) && IsStationary(ma); 703 704 ARMAAutoCovarianzeVector(gn, ar, ma, n0, sigma); 704 705 BSymMatrix<BDat> G(n0); … … 1283 1284 BPolyn<BDat> ar_i = factor_(i).ar_; ar_i.Aggregate(); 1284 1285 BPolyn<BDat> ma_i = factor_(i).ma_; ma_i.Aggregate(); 1285 arOk = arOk && ar_i.IsStationary();1286 maOk = maOk && ma_i.IsStationary();1286 arOk = arOk && IsStationary(ar_i); 1287 maOk = maOk && IsStationary(ma_i); 1287 1288 } 1288 1289 bool ok = arOk && maOk; … … 1297 1298 ar_i.Aggregate(); 1298 1299 ma_i.Aggregate(); 1299 bool arOk = ar_i.IsStationary()!=0;1300 bool maOk = ma_i.IsStationary()!=0;1300 bool arOk = IsStationary(ar_i)!=0; 1301 bool maOk = IsStationary(ma_i)!=0; 1301 1302 Std(BText("\nStationary?[")<<(arOk?"YES":"NOT")<<"] AR("<<factor_(i).s_<<")="<<factor_(i).ar_.Name()); 1302 1303 Std(BText("\nStationary?[")<<(maOk?"YES":"NOT")<<"] MA("<<factor_(i).s_<<")="<<factor_(i).ma_.Name()); -
tol/bmath/bstat/tol_bar.h
r736be83 rbc1dd97 67 67 BInt period=1); 68 68 69 BDat StationaryValue( 70 const BPolyn<BDat>& pol, 71 BDat toleranceBase, 72 BDat& tolerance, 73 bool& isStationary); 74 bool IsStationary(const BPolyn<BDat>& pol, BDat& tolerance); 75 BDat StationaryValue(const BPolyn<BDat>& pol); 76 bool IsStationary(const BPolyn<BDat>& pol); 77 78 69 79 70 80 #endif // TOL_BAR_H -
tol/bmath/bstat/unitroot.cpp
r736be83 rbc1dd97 104 104 else 105 105 { 106 ok = p.IsStationary();106 ok = IsStationary(p); 107 107 } 108 108 if(changed && name.HasName()) … … 180 180 rAr[0].PutCoef(1); 181 181 for(i=0; i<q-d; i++) { rAr[i+1].PutCoef(-(rNU(i,0)+NU(i,0))); } 182 if( rAr.IsStationary()) { prob+=1; }182 if(IsStationary(rAr)) { prob+=1; } 183 183 } 184 184 detChoCOV = 1; -
tol/bmath/mathobjects/tol_bpolyn.h
r736be83 rbc1dd97 98 98 void ChangeBF(const BPolyn<Any>& pol); 99 99 void InverseRoots(const BPolyn<Any>& pol); 100 BPolyn<Any> NextSchur() const;101 Any Schur(BBool complete) const;102 Any StationaryValue(BBool complete) const;103 BBool IsStationary() const;104 100 105 101 BBool IsKnown() const { … … 348 344 } 349 345 350 //--------------------------------------------------------------------351 template <class Any>352 BPolyn<Any> BPolyn<Any>::NextSchur() const353 //--------------------------------------------------------------------354 {355 //Std(BText("\nTRACE NextSchur 1 this=")+Name());356 BInt n = Degree();357 BArray<Any> a(n+1);358 int k;359 for(k=0; k<=n; k++) { a[k] = Coef(k); }360 Any a0 = a[0];361 Any an = a[n];362 Any c;363 //Std(BText("\na[0]: ")+a0.Name()+"; a[n]:"+an.Name());364 BPolyn<Any> next;365 next.ReallocBuffer(n);366 for(k=0; k<n; k++)367 {368 c = an*a[k+1] - a0*a[n-k-1];369 next(k).PutCoef(c);370 next(k).PutDegree(k);371 //Std(BText("\na[k+1]: ")+a[k+1].Name()+"; a[n-k-1]:"+a[n-k-1].Name()+"; next(i-1):"+c.Name());372 }373 //Std(BText("\nTRACE NextSchur 2 next=")+next.Name());374 next.Aggregate();375 //Std(BText("\nNextSchur 3 next=")+next.Name());376 //if(next.Degree()>0) { next /= next.Coef(next.Degree()); }377 //Std(BText("\nTRACE NextSchur 4 next=")+next.Name());378 return(next);379 }380 381 382 //--------------------------------------------------------------------383 template <class Any>384 Any BPolyn<Any>::Schur(BBool complete) const385 386 /*! Returns a value great than 1 if there are no roots out of387 * the unit circle388 */389 //--------------------------------------------------------------------390 {391 //Std(BText("\nTRACE Schur : ")+Name());392 int s = this->Size();393 int n = this->Degree();394 if(s==1) { return(2); }395 Any a0 = Abs(this->Coef(0));396 Any an = Abs(this->Coef(n));397 Any v = 1.0+(an-a0)/(an+a0);398 if((!complete && (v<=1)) || (s==2))399 {400 return(v);401 }402 else403 {404 return(NextSchur().Schur(complete));405 }406 }407 346 408 347 //-------------------------------------------------------------------- … … 423 362 } 424 363 425 //--------------------------------------------------------------------426 template <class Any>427 Any BPolyn<Any>::StationaryValue(BBool complete) const428 429 /*! Returns a value great than 1 if there are no roots inside430 * the unit circle431 */432 //--------------------------------------------------------------------433 {434 //Std(BText("\nTRACE StationaryValue : ")+Name());435 int s = this->Size();436 int n = this->Degree();437 if(s==1)438 {439 if(n==0) { return(2); }440 else { return(0); }441 }442 int i, j;443 int deg;444 Any coef;445 BPolyn sym;446 int gcd = Period();447 //Std(BText("\nTRACE StationaryValue gcd=")+gcd);448 int m = n/gcd;449 sym.ReallocBuffer(s);450 for(i=0; i<s; i++)451 {452 j = s-1-i;453 deg = (*this)(i).Degree();454 coef = (*this)(i).Coef();455 sym(j).PutDegree(m-deg/gcd);456 sym(j).PutCoef(coef);457 }458 return(sym.Schur(complete));459 }460 461 462 //--------------------------------------------------------------------463 template <class Any>464 BBool BPolyn<Any>::IsStationary() const465 466 /*! Returns true if all roots in this polyn are outside of the unit467 * circle468 */469 //--------------------------------------------------------------------470 {471 if(this->Size ()==0) { return(BFALSE); }472 if(this->Degree()==0) { return(BTRUE); }473 else { return(this->StationaryValue(BFALSE)>1); }474 }475 476 364 477 365 //-------------------------------------------------------------------- -
tol/btol/bmodel/modcalc.cpp
r736be83 rbc1dd97 33 33 #include <tol/tol_bsparse.h> 34 34 #include <tol/tol_bsvdsep.h> 35 #include <tol/tol_bar.h> 35 36 36 37 #include <gsl/gsl_math.h> … … 1003 1004 for(i=0; i<arma_.factor_.Size(); i++) 1004 1005 { 1005 bool arOk = arma_.factor_(i).ar_.IsStationary();1006 bool maOk = arma_.factor_(i).ma_.IsStationary();1006 bool arOk = IsStationary(arma_.factor_(i).ar_); 1007 bool maOk = IsStationary(arma_.factor_(i).ma_); 1007 1008 Std(BText("\nStationary?[")<<(arOk?"YES":"NOT")<<"] AR("<<arma_.factor_(i).s_<<")="<<arma_.factor_(i).ar_.Name()); 1008 1009 Std(BText("\nStationary?[")<<(maOk?"YES":"NOT")<<"] MA("<<arma_.factor_(i).s_<<")="<<arma_.factor_(i).ma_.Name()); … … 1104 1105 for(i=0; i<arma_.factor_.Size(); i++) 1105 1106 { 1106 bool arOk = arma_.factor_(i).ar_.IsStationary();1107 bool maOk = arma_.factor_(i).ma_.IsStationary();1107 bool arOk = IsStationary(arma_.factor_(i).ar_); 1108 bool maOk = IsStationary(arma_.factor_(i).ma_); 1108 1109 Std(BText("\nStationary?[")<<(arOk?"YES":"NOT")<<"] AR("<<arma_.factor_(i).s_<<")="<<arma_.factor_(i).ar_.Name()); 1109 1110 Std(BText("\nStationary?[")<<(maOk?"YES":"NOT")<<"] MA("<<arma_.factor_(i).s_<<")="<<arma_.factor_(i).ma_.Name()); … … 1297 1298 //-------------------------------------------------------------------- 1298 1299 { 1299 BDat y = p_.StationaryValue(BTRUE);1300 BDat y = StationaryValue(p_); 1300 1301 //Std(BText("\nS(")+p_.Name()+")="+(y-1)); 1301 1302 return(y-1); -
tol/btol/bmodel/moddiag.cpp
r736be83 rbc1dd97 33 33 #include <tol/tol_bmultvar.h> 34 34 #include <tol/tol_bsetgra.h> 35 #include <tol/tol_bar.h> 35 36 36 37 //-------------------------------------------------------------------- … … 468 469 // Std(BText("\nFactor[")+j+"]"+factors[j].Name() + 469 470 // " Stationary = " + factors[j].Stationary()); 470 if(!( factors[j].IsStationary())) { unarys[j]+=1; }471 if(!(IsStationary(factors[j]))) { unarys[j]+=1; } 471 472 } 472 473 } -
tol/btol/real_type/datgrav.cpp
r736be83 rbc1dd97 40 40 #include <tol/tol_bdtegra.h> 41 41 #include <tol/tol_bnameblock.h> 42 #include <tol/tol_bar.h> 42 43 #ifdef __USE_TC__ 43 44 # include <tol/tol_bctmigra.h> … … 1311 1312 //-------------------------------------------------------------------- 1312 1313 DeclareContensClass(BDat, BDatTemporary, BDatIsStationary); 1313 DefExtOpr(1, BDatIsStationary, "IsStationary", 1, 1, "Polyn",1314 "(Polyn pol )",1314 DefExtOpr(1, BDatIsStationary, "IsStationary", 1, 2, "Polyn Real", 1315 "(Polyn pol [, Real tolerance=MachineEpsilon])", 1315 1316 I2("Returns true if all the roots of the polynomial are would be of the " 1316 1317 "unit circle.", … … 1321 1322 //-------------------------------------------------------------------- 1322 1323 { 1323 BPol p = Pol(Arg(1)); 1324 p.Aggregate(); 1325 contens_ = p.IsStationary(); 1324 BPol& p = Pol(Arg(1)); 1325 BDat t; 1326 if(Arg(2)) { t = Dat(Arg(2)); } 1327 contens_ = IsStationary(p,t); 1326 1328 } 1327 1329 … … 1339 1341 //-------------------------------------------------------------------- 1340 1342 { 1341 contens_ = Pol(Arg(1)).Period(); 1343 BPol& p = Pol(Arg(1)); 1344 contens_ = p.Period(); 1342 1345 } 1343 1346 1344 1347 //-------------------------------------------------------------------- 1345 1348 DeclareContensClass(BDat, BDatTemporary, BDatStationaryValue); 1346 DefExtOpr(1, BDatStationaryValue, "StationaryValue", 1, 1, "Polyn",1347 "(Polyn pol )",1349 DefExtOpr(1, BDatStationaryValue, "StationaryValue", 1, 2, "Polyn Real", 1350 "(Polyn pol [, Real tolerance=MachineEpsilon])", 1348 1351 I2("Returns a measure of the distence to the unit circle of the " 1349 1352 "polynomial roots .", … … 1354 1357 //-------------------------------------------------------------------- 1355 1358 { 1356 contens_ = Pol(Arg(1)).StationaryValue(BFALSE); 1359 BPol& p = Pol(Arg(1)); 1360 BDat toleranceBase; 1361 BDat tolerance; 1362 if(Arg(2)) { toleranceBase = Dat(Arg(2)); } 1363 bool isStationary; 1364 contens_ = StationaryValue(p,toleranceBase,tolerance,isStationary); 1357 1365 } 1358 1366 … … 1413 1421 } 1414 1422 pk.Aggregate(); 1415 BInt ok = pk.IsStationary();1423 BInt ok = IsStationary(pk); 1416 1424 // Std(BText("\n")+(ok?" OK ":" FAIL ")+pk.Name()); 1417 1425 sumOk += ok;
Note: See TracChangeset
for help on using the changeset viewer.
