double Interval::delta(const Interval& x) const { if (is_empty()) return 0; if (x.is_empty()) return diam(); // ** warning ** // checking if *this or x is infinite by // testing if the lower/upper bounds are -oo/+oo // is not enough because diam() may return +oo even // with finite bounds (e.g, very large intervals like [-DBL_MAX,DBL_MAX]). // ("almost-unboundedness") volatile double d=diam(); volatile double dx=x.diam(); // furthermore, if these variables are not declared volatile // conditions like d==POS_INFINITY are evaluated // to FALSE for intervals like [-DBL_MAX,DBL_MAX] (with -O3 option) // while the returned expression (d-dx) evaluates to +oo (instead of 0). if (d==POS_INFINITY) { //cout << "d=" << d << " dx=" << dx << endl; if (dx==POS_INFINITY) { double left=(x.lb()==NEG_INFINITY? 0 : x.lb()-lb()); double right=(x.ub()==POS_INFINITY? 0 : ub()-x.ub()); //cout << "left=" << left << " right=" << right << endl; return left+right; } else return POS_INFINITY; } else return d-dx; }
void SignalLogger::log(const int level, const string& description, const interval& value) { stringstream textStream; textStream << description << ": " << value << " (d = " << diam(value) << ")" << endl; emitLogSignal(level, textStream); }
bool operator() (const SPnode * const lhs, const SPnode * const rhs) const { //std::cout << "----doing comparisons" << endl; //std::cout << lhs->getNodeName() << "\t" << lhs->getBox() << "\t"; ivector lbox = lhs->getBox(); interval lRange = fobj(lbox); interval lArea = (lhs->nodeVolume()) * (lRange); //riemann sum //cout << "left area: " << lArea << endl; //std::cout << rhs->getNodeName() << "\t" << rhs->getBox() << "\t"; ivector rbox = rhs->getBox(); interval rRange = fobj(rbox); interval rArea = (rhs->nodeVolume()) * (rRange); //cout << "right area: " << rArea << endl; //cout << (diam(lArea)) << "\t" << (diam(rArea)) << endl; //the diameters are the uncertainty in the approximate to the integral error return (diam(lArea) < diam(rArea)); }
typename IObject::ScalarType maxDiam(const IObject& v) { typedef typename IObject::ScalarType ScalarType; ScalarType result(0.); typename IObject::const_iterator b=v.begin(), e=v.end(); while(b!=e) { result = capd::max(result,diam(*b)); ++b; } return ScalarType(rightBound(result)); }
typename IntervalObject::ScalarType size(const IntervalObject& v) { typedef typename IntervalObject::ScalarType ScalarType; ScalarType result(0.); typename IntervalObject::const_iterator b=v.begin(), e=v.end(); while(b!=e) { result = chomp::max(result,diam(*b)); ++b; } return ScalarType(result.rightBound()); }
void diameter(const IntervalObject &v, ResultContainer &result) { if(v.dimension()!=result.dimension()) throw std::range_error("Unequal dimensions in function capd::vectalg::diameter"); typename ResultContainer::iterator i = result.begin(); typename IntervalObject::const_iterator b = v.begin(), e=v.end(); while(b!=e) { *i = diam(*b); ++i; ++b; } }
std::pair<Interval,Interval> Interval::bisect(double ratio) const { assert(is_bisectable()); assert(ratio>0 && ratio<1); Interval left,right; if (lb()==NEG_INFINITY) { if (ub()==POS_INFINITY) { left = Interval(NEG_INFINITY,0); right = Interval(0,POS_INFINITY); } else { left = Interval(NEG_INFINITY,-DBL_MAX); right = Interval(-DBL_MAX,ub()); } } else if (ub()==POS_INFINITY) { left = Interval(lb(),DBL_MAX); right = Interval(DBL_MAX,POS_INFINITY); } else { double point; if (ratio==0.5) point = mid(); else { point = lb()+ratio*diam(); // watch dog. note that since *this is // bisectable, we have next_float(left.lb()) < ub() if (point >= ub()) point=next_float(lb()); assert(point<ub()); } left = Interval(lb(), point); right = Interval(point, ub()); } return std::pair<Interval,Interval>(left,right); }
Tmatrix<Interval> EllipsoidalIntegrator::integrate( double t0, double tf, int M, const Tmatrix<Interval> &x, const Tmatrix<Interval> &p, const Tmatrix<Interval> &w ){ typedef TaylorVariable<Interval> T; Tmatrix< TaylorVariable<Interval> > xx(x.getDim()); Tmatrix<T> *pp = 0; Tmatrix<T> *ww = 0; if( p.getDim() > 0 ) pp = new Tmatrix<T>(p.getDim()); if( w.getDim() > 0 ) ww = new Tmatrix<T>(w.getDim()); int nn = 0; for( int i=0; i<(int) x.getDim(); i++ ) if( diam(x(i)) > EQUALITY_EPS ) nn++; for( int i=0; i<(int) p.getDim(); i++ ) if( diam(p(i)) > EQUALITY_EPS ) nn++; for( int i=0; i<(int) w.getDim(); i++ ) if( diam(w(i)) > EQUALITY_EPS ) nn++; TaylorModel<Interval> Mod( nn, M ); nn = 0; for( int i=0; i<(int) x.getDim(); i++ ){ if( diam(x(i)) > EQUALITY_EPS ){ xx(i) = T( &Mod, nn, x(i) ); nn++; } else xx(i) = x(i); } for( int i=0; i<(int) p.getDim(); i++ ){ if( diam(p(i)) > EQUALITY_EPS ){ pp->operator()(i) = T( &Mod, nn, p(i) ); nn++; } else pp->operator()(i) = p(i); } for( int i=0; i<(int) w.getDim(); i++ ){ if( diam(w(i)) > EQUALITY_EPS ){ ww->operator()(i) = T( &Mod, nn, w(i) ); nn++; } else ww->operator()(i) = w(i); } integrate( t0, tf, &xx, pp, ww ); return getStateBound( xx ); }
double Interval::ratiodelta(const Interval& x) const { double d=delta(x); if (d==POS_INFINITY) return 1; double D=diam(); return (D==0 || D==POS_INFINITY) ? 0.0 : (d/D); // if this.diam()=infinity here, necessarily d=0 }
void OdeNum<MatrixType>::diagBadEnlcosure(const VectorType &x) const { std::ofstream raport("raport.ecl",std::ios::app); raport << "-------------------------\n"; raport << "x=" << x << "\n"; raport << "step=" << step << "\n"; raport << "f(x)=" << ode.f(x) << "\n"; int dim = x.dimension(); ScalarType trial_step = ScalarType(-0.2,1.2) * step; int diag=0; VectorType max_r = trial_step*ode.f(x); VectorType Ye = x+max_r; raport << "Ye=" << Ye << "\n"; raport << "diam Ye=" ; for(int i=0; i<dim; i++) raport << rightBound(capd::abs(diam(Ye[i]))) << " " ; raport << "\n"; MatrixType dv = ode.df(x+max_r); capd::vectalg::MaxNorm<VectorType,MatrixType> maxN; ScalarType L = maxN(dv); if (!(step*L < 1)) { diag=1; raport << "hL > 1 \n"; } raport << "hL=" << step*L << "\n"; Real *diamvect = new Real[dim]; Real *dfabs = new Real[dim*dim]; if (!diag) { int i; for(i=0;i<dim; i++) diamvect[i] = rightBound(capd::abs(diam(Ye[i]))); for(i=0;i<dim; i++) for(int j=0; j<dim; j++) dfabs[i*dim+j]= rightBound(capd::abs(dv[i][j])); for(i=0;i<dim;i++) { Real t=0; for(int j=0;j<dim;j++) t += dfabs[i*dim+j]*diamvect[j]; t *= 2.5* rightBound(capd::abs(step)); if(t > diamvect[i]) { diag=2; raport << "5/2 h Dfi/Dxj diam(Ye_j)=t" << t << " > diam(Ye_i)= " << diamvect[i] << " ; i=" << i << "\n"; } }// i-loop } // if(!diag) if(!diag) { diag=3; raport << "unknown reason \n" ; } delete [] diamvect; delete [] dfabs; }