OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimPolynom.h
Go to the documentation of this file.
1 // ossimPolynom.h
3 // Author: Frederic Claudel Meraka/CSIR, 2005
5 //
6 //TODO : check if automatically removing small monoms is actually viable
7 //
8 //TBD : normalization for Least Mean Square fit
9 //TBD : copy constructor for different DIM
10 //TBD : LOW PRIORITY redo serialization so that doesn't have to use strings (streams only)
11 
12 #ifndef ossimPolynom_HEADER
13 #define ossimPolynom_HEADER
14 
15 #include <cmath>
16 #include <vector>
17 #include <map>
18 #include <set>
19 #include <iostream>
20 #include <iomanip>
21 
23 #include <ossim/base/ossimString.h>
24 #include <ossim/matrix/newmat.h>
25 #include <ossim/matrix/newmatap.h>
26 
37 template < class T, int DIM = 1 >
39 {
40 public:
44  typedef std::vector< int > EXP_TUPLE;
45  typedef std::vector< T > VAR_TUPLE;
46 
48  {
49  //warning both EXP_TUPLE should have same dimension (not necessarily DIM)
50  bool operator()(const EXP_TUPLE& o1, const EXP_TUPLE& o2)const
51  {
52  for(unsigned int i=0;i<o1.size();++i)
53  {
54  if (o1[i]<o2[i])
55  {
56  return true;
57  } else if (o1[i]>o2[i])
58  {
59  return false;
60  }
61  }
62  return false;
63  }
64  };
65 
66  typedef std::map< EXP_TUPLE, T , EXP_TUPLE_LESSTHAN > MONOM_MAP;
67 
68  typedef std::set< EXP_TUPLE, EXP_TUPLE_LESSTHAN > EXPT_SET;
69 
74  //TBD : by default, adapt epsilon to template type T
75  ossimPolynom(const T& epsilon = 0)
76  : theEpsilon(epsilon)
77  {}
78 
80  theMonoms(p.getMonoms()),
82  {}
83 
85  {}
86 
88  {
89  if (this != &pt)
90  {
91  theEpsilon = pt.getEpsilon();
92  theMonoms = pt.getMonoms();
93  }
94  return *this;
95  }
96 
97  void setMonom(const EXP_TUPLE& m, const T& v)
98  {
99  if (isNegligible(v))
100  {
101  theMonoms.erase(m); //TBC TBD: what happens if m is not in the map?
102  } else {
103  theMonoms[m] = v;
104  }
105  }
106 
107  void setMonom(const int mexp[DIM], const T& v)
108  {
109  EXP_TUPLE mexpV(mexp,mexp+DIM);
110  if (isNegligible(v))
111  {
112  theMonoms.erase(mexpV); //TBC TBD: what happens if m is not in the map?
113  } else {
114  theMonoms[mexpV] = v;
115  }
116  }
117 
118 
119  inline void delMonom(const EXP_TUPLE& m)
120  {
121  theMonoms.erase(m); //TBC TBD: what happens if m is not in the map?
122  }
123 
124  T getCoeff(const EXP_TUPLE& m)const
125  {
126  typename MONOM_MAP::const_iterator it = theMonoms.find(m);
127  if (it != theMonoms.end())
128  {
129  return it->second;
130  } else {
131  return 0;
132  }
133  }
134 
135  void nullify() //set to 0
136  {
137  theMonoms.clear();
138  }
139 
140  inline bool isNull()const
141  {
142  return (theMonoms.size() == 0);
143  }
144 
145  inline const MONOM_MAP& getMonoms()const
146  {
147  return theMonoms;
148  }
149 
150  inline const T& getEpsilon()const
151  {
152  return theEpsilon;
153  }
154 
160  bool operator==(const ossimPolynom& pt)const
161  {
162  if (getMonoms().size() != pt.getMonoms().size()) return false;
163 
164  // loop on my monoms
165  typename MONOM_MAP::const_iterator it;
166  for ( it = getMonoms().begin(); it != getMonoms().end() ; ++it )
167  {
168  if ( !isNegligible(it->second - pt.getCoeff(it->first)) ) return false;
169  }
170  return true; //same number of identical monoms
171  }
172 
173  bool operator!=(const ossimPolynom& pt)const
174  {
175  return !operator==(pt);
176  }
177 
178  inline bool isNegligible(const T& v)const
179  {
180  return ( fabs(v) <= theEpsilon );
181  }
182 
186  int getOrder(int d)const
187  {
188  if ((d>=DIM) || (d<0)) return -1; //error = no dimension
189 
190  // loop on monoms
191  int order = -1; //for null polynom
192  int corder;
193  typename MONOM_MAP::const_iterator it;
194  for ( it = getMonoms().begin(); it != getMonoms().end() ; ++it )
195  {
196  corder = (it->first)[d];
197  if ( corder > order ) order = corder;
198  }
199  return order;
200  }
201 
202  int getTotalOrder()const
203  {
204  int order = -1; //for null polynom
205  int sorder;
206  typename MONOM_MAP::const_iterator it;
207  for ( it = getMonoms().begin(); it != getMonoms().end() ; ++it )
208  {
209  sorder = 0;
210  for (int d=0;d<DIM;++d) sorder+=(it->first)[d];
211  if ( sorder > order ) order = sorder;
212  }
213  return order;
214  }
215 
219  T eval(const VAR_TUPLE& v)const
220  {
221  T ev = 0;
222  //loop on monoms. TBD optimize powers using map order
223  typename MONOM_MAP::const_iterator it;
224  int p;
225  for ( it = getMonoms().begin(); it != getMonoms().end() ; ++it )
226  {
227  //compute powers
228  T mv = it->second;
229  for(int d=0;d<DIM;++d)
230  {
231  p = (it->first)[d];
232  if (p != 0)
233  {
234  mv *= std::pow( v[d], p );
235  }
236  }
237  //add momom value
238  ev += mv;
239  }
240  return ev;
241  }
242 
246  void pdiff(int pdim, ossimPolynom& result)const
247  {
248  result.nullify();
249  int ord;
250  //loop on monoms
251  for ( typename MONOM_MAP::const_iterator it = getMonoms().begin(); it != getMonoms().end() ; ++it )
252  {
253  ord = it->first[pdim];
254  if (ord>=1)
255  {
256  EXP_TUPLE expDiff(it->first);
257  expDiff[pdim] -= 1;
258  result.setMonom(expDiff, it->second * ord);
259  }
260  }
261  }
262 
266  const ossimPolynom& operator*=(const T& k)
267  {
268  //loop on monoms
269  for ( typename MONOM_MAP::const_iterator it = getMonoms().begin(); it != getMonoms().end() ; ++it )
270  {
271  it->second *= k;
272  }
274  }
275 
280  {
281  ossimPolynom< T , DIM > sum(*this);
282  return (sum+=p);
283  }
285  {
286  ossimPolynom< T , DIM > diff(*this);
287  return (diff-=p);
288  }
289 
291  {
292  typename MONOM_MAP::const_iterator it;
293  //loop on p monoms
294  for ( it = p.getMonoms().begin(); it != p.getMonoms().end() ; ++it )
295  {
296  setMonom( it->first, getCoeff(it->first) + it->second );
297  }
298  return *this;
299  }
300 
302  {
303  typename MONOM_MAP::const_iterator it;
304  //loop on p monoms
305  for ( it = p.getMonoms().begin(); it != p.getMonoms().end() ; ++it )
306  {
307  setMonom( it->first, getCoeff(it->first) - it->second );
308  }
309  return *this;
310  }
311 
316  {
317  //do a stupid multiplication (sum all monom pairs)
319  T coeff;
320  //loop on p monoms
321  for ( typename MONOM_MAP::const_iterator it = getMonoms().begin(); it != getMonoms().end() ; ++it )
322  {
323  for ( typename MONOM_MAP::const_iterator pit = p.getMonoms().begin(); pit != p.getMonoms().end() ; ++pit )
324  {
325  coeff = it->second * pit->second;
326  if (coeff!=0)
327  {
328  EXP_TUPLE prodExp(it->first);
329  addExpTuple(prodExp, pit->first);
330  prod.addMonomQuick(prodExp, coeff);
331  }
332  }
333  }
334  //scan for null monoms and discard
335  prod.discardNullMonoms();
336  return prod;
337  }
338 
340  {
341  return operator=( this->operator*(p) );
342  }
343 
344  static void addExpTuple(EXP_TUPLE& m1, const EXP_TUPLE& m2)
345  {
346  for(int i=0;i<DIM;++i) {
347  m1[i] += m2[i];
348  }
349  }
350 
371  {
372  static const char* monom_sep = " ; ";
373  static const char* no_sep = "";
374 
375  const char* use_sep = no_sep;
376 
377  os<<"[";
378  os<<std::setprecision(16); //16 for double, TBD TBC: adapt to epsilon
379  os<<std::setiosflags(std::ios_base::scientific);
380  //output epsilon if not null
381  if (getEpsilon() > 0)
382  {
383  os<<use_sep<<"eps="<<getEpsilon();
384  use_sep=monom_sep;
385  }
386  //loop on monoms
387  for ( typename MONOM_MAP::const_iterator it = getMonoms().begin(); it != getMonoms().end() ; ++it )
388  {
389  os<<use_sep<<it->second<<"(";
390  for(int d=0 ; d<DIM ; ++d)
391  {
392  /* if (d>0) */
393  /* { */
394  /* os<<","; */
395  /* } */
396  os<<(it->first)[d];
397  }
398  os<<")";
399  use_sep=monom_sep;
400  }
401  os<<"]";
402  return os;
403  }
404 
405  std::ostream&
406  printNice(std::ostream& os, const char symbols[DIM])
407  {
408  if (getMonoms().size() == 0)
409  {
410  os<<"0"; //zero
411  } else {
412  os<<std::setiosflags(std::ios_base::fixed);
413  os<<std::setprecision(14); //14 for double, TBD TBC: adapt to epsilon
414  //loop on monoms (map order)
415  for ( typename MONOM_MAP::const_iterator it = getMonoms().begin(); it != getMonoms().end() ; ++it )
416  {
417  T coeff = it->second;
418  if (coeff>0)
419  {
420  os<<"+";
421  }
422  os<<coeff;
423  for(int d=0;d<DIM;++d)
424  {
425  int ord=(it->first)[d];
426  if (ord>0)
427  {
428  os<<""<<symbols[d];
429  if (ord != 1)
430  {
431  os<<ord;
432  }
433  }
434  }
435  }
436  }
437  return os;
438  }
439 
441  {
442  nullify();
443 
444  //extract data in brackets [ ]
445  //swallow bracket
446  ossimString tempString;
447  char tempChar;
448  is.get(tempChar);
449  if (!is)
450  {
451  std::cerr<<"ossimPolynom::import ERROR, cannot read left bracket ["<<std::endl;
452  return is;
453  }
454  if (tempChar != '[')
455  {
456  std::cerr<<"ossimPolynom::import ERROR, missing left bracket ["<<std::endl;
457  return is;
458  }
459  const int BUFSIZE=32768; //should be enough fro most apps (TBC TBD : allow loops if not enough)
460  char buffer[BUFSIZE];
461  is.getline(buffer, BUFSIZE, ']');
462  if (!is)
463  {
464  std::cerr<<"ossimPolynom::import ERROR, cannot read after left bracket ["<<std::endl;
465  return is;
466  }
467  if (is.gcount() >= BUFSIZE-1)
468  {
469  std::cerr<<"ossimPolynom::import ERROR, cannot find right bracket ] after "<<BUFSIZE-1<<"characters"<<std::endl;
470  return is;
471  }
472  tempString = buffer; //no more brackets
473 
474  //split string using semicolons
475  std::vector< ossimString > subparts = tempString.explode(";");
476  //loop on subparts
477  for (typename std::vector< ossimString >::const_iterator it=subparts.begin() ; it!=subparts.end() ; ++it )
478  {
479  ossimString sp = it->trim();
480  //check for epsilon
481  ossimString aft_eps=sp.after("eps=");
482  if (aft_eps.size()>0)
483  {
484  //get epsilon value
485  aft_eps.trim();
486  theEpsilon = static_cast< T >(aft_eps.toDouble());
487  } else {
488  //no epsilon : must be a monom
489  ossimString scalpart=sp.before("(");
490  if (scalpart.size() < sp.size())
491  {
492  T coeff = static_cast< T >(scalpart.toDouble());
493  ossimString expopart = ((sp.before(")")).after("(")).trim();
494  if (expopart.size() == 0)
495  {
496  std::cerr<<"ossimPolynom::import ERROR, cannot find ) in monom or empty monom"<<std::endl;
497  return is;
498  }
499  std::vector< ossimString > vexpo = expopart.explode(",");
500  if (vexpo.size() != DIM)
501  {
502  std::cerr<<"ossimPolynom::import ERROR, bad number of exponents in monom (need "<<DIM<<"): "<<vexpo.size()<<std::endl;
503  return is;
504  }
505  //store all exponents
506  EXP_TUPLE expt(DIM);
507  int d;
508  std::vector< ossimString >::const_iterator eit;
509  for (eit=vexpo.begin() , d=0 ; eit != vexpo.end() ; ++eit, ++d )
510  {
511  expt[d] = eit->toInt(); //TBD : could check that value is integer, but how?
512  }
513  //add new monom (if duplicate...error)
514  if (getMonoms().find(expt) != getMonoms().end())
515  {
516  std::cerr<<"ossimPolynom::import ERROR, duplicate exponent tuple in polynom"<<std::endl;
517  return is;
518  }
519  theMonoms[expt] = coeff;
520 
521  } else {
522  std::cerr<<"ossimPolynom::import ERROR, cannot find left parenthesis ( in monom "<<std::endl;
523  return is;
524  }
525  }
526  }
527 
528  return is;
529  }
534  EXPT_SET builExpSet(const EXP_TUPLE& orders)const
535  {
536  EXPT_SET eset;
537  if (orders.size() != DIM)
538  {
539  std::cerr<<"ossimPolynom::import ERROR bad dimension for parameter, need "<<DIM<<" elements"<<std::endl;
540  return eset;
541  }
542  //initialise variable exponent tuple
543  EXP_TUPLE et(DIM);
544  for(int d=0;d<DIM;++d) et[d]=0;
545  while (et[0] <= orders[0])
546  {
547  //add tuple to set
548  eset.insert(et);
549 
550  //increment tuple within bounds
551  et[DIM-1]++;
552  for(int d=DIM-1 ; d>=0 ; --d)
553  {
554  if ((et[d] > orders[d]) && (d>0))
555  {
556  et[d] = 0;
557  et[d-1]++;
558  }
559  }
560  }
561  return eset;
562  }
563 
569  void addExpTupleRight(int newdim, int totalOrder, EXPT_SET& eset )const
570  {
571  EXPT_SET newset;
572  // add a copy off eset for each order with the specific last dim
573  for(int o=0; o<=totalOrder ; ++o)
574  {
575  EXPT_SET extset; //extended set
576  if (eset.size()==0)
577  {
578  EXP_TUPLE tu(1);
579  tu[0]=o;
580  extset.insert(tu);
581  } else {
582  //we have to construct a new set from eset, extending dimension
583  // cause: stored tuples cannot be compared at different dimensions
584  for(typename EXPT_SET::iterator sit = eset.begin(); sit != eset.end(); ++sit)
585  {
586  EXP_TUPLE tu(*sit);
587  tu.push_back(o);
588  extset.insert(tu);
589  }
590  }
591  //recursively add remaining dimensions
592  if (newdim>1)
593  {
594  addExpTupleRight(newdim-1, totalOrder-o, extset); //only dimension decreases
595  }
596  //add full set for the specific order
597  newset.insert(extset.begin(), extset.end());
598  }
599  eset=newset; //overwrite
600  }
601 
610 bool
611 LMSfit(const EXPT_SET& expset,
612  const std::vector< VAR_TUPLE > obs_input,
613  const std::vector< T > obs_output,
614  T* prms = NULL)
615 {
616  //init
617  nullify();
618 
619  //check size
620  int nobs = (int)obs_input.size();
621  if (nobs != (int)obs_output.size())
622  {
623  std::cerr<<"ossimPolynom::LMSfit ERROR observation input/output must have the same size"<<std::endl;
624  return false;
625  }
626  if (nobs<=0)
627  {
628  std::cerr<<"ossimPolynom::LMSfit ERROR observation count is zero"<<std::endl;
629  return false;
630  }
631  int ncoeff = (int)expset.size();
632  if (ncoeff<=0)
633  {
634  std::cerr<<"ossimPolynom::LMSfit ERROR exponent count is zero"<<std::endl;
635  return false;
636  }
637 
638  //construct LMS linear system (using OSSIM matrices)
639  // M.k = v
640  // M : monom matrix
641  // k : polynbm coefficients
642  // v : output_obs
643  NEWMAT::Matrix M(nobs, ncoeff);
644  double elt;
645  int p;
646  typename EXPT_SET::const_iterator cit;
647  typename std::vector< VAR_TUPLE >::const_iterator oit;
648  int i,j;
649  for (cit=expset.begin(), j=1; cit != expset.end() ; ++cit, ++j) //loop on exponent tuples
650  {
651  for(oit=obs_input.begin(), i=1; oit!=obs_input.end();++oit, ++i) //loop on observations
652  {
653  //compute powers using observation position
654  elt=1.0;
655  for(int d=0;d<DIM;++d)
656  {
657  p = (*cit)[d];
658  if (p != 0)
659  {
660  elt *= std::pow( (*oit)[d], p );
661  }
662  }
663  //init M
664  M(i,j) = elt; //NEWMAT indices start at 1
665  }
666  }
667 
668  NEWMAT::ColumnVector v(nobs);
669  for(int o=0;o<nobs;++o)
670  {
671  v(o+1) = obs_output[o];
672  }
673 
674  //build LMS symmetric matrix tM.M
675  //build best fit
676  NEWMAT::ColumnVector bfit = invert(M.t()*M)*M.t()*v; //TBD : check inversion
677 
678  //compute RMS (optional, if rms non null)
679  if (prms!=NULL)
680  {
681  NEWMAT::ColumnVector delta = M*bfit - v;
682  *prms = std::sqrt( delta.SumSquare() / nobs);
683  }
684 
685  //init polynom
686  for (cit=expset.begin(), j=1; cit != expset.end() ; ++cit, ++j) //loop on exponent tuples
687  {
688  setMonom(*cit, bfit(j));
689  }
690  return true;
691 }
692 
693 
699 bool
700 SLSfit(const EXPT_SET& expset,
701  const std::vector< VAR_TUPLE > obs_input,
702  const std::vector< T > obs_output,
703  T* prms = NULL)
704 {
705  //init
706  nullify();
707 
708  //check size
709  int nobs = (int)obs_input.size();
710  if (nobs != (int)obs_output.size())
711  {
712  std::cerr<<"ossimPolynom::LMSfit ERROR observation input/output must have the same size"<<std::endl;
713  return false;
714  }
715  if (nobs<=0)
716  {
717  std::cerr<<"ossimPolynom::LMSfit ERROR observation count is zero"<<std::endl;
718  return false;
719  }
720  int ncoeff = (int)expset.size();
721  if (ncoeff<=0)
722  {
723  std::cerr<<"ossimPolynom::LMSfit ERROR exponent count is zero"<<std::endl;
724  return false;
725  }
726 
727  // M : monom matrix
728  // k : polynomial coefficients
729  // v : output_obs
730  NEWMAT::Matrix M(nobs, ncoeff);
731  double elt;
732  int p;
733  typename EXPT_SET::const_iterator cit;
734  typename std::vector< VAR_TUPLE >::const_iterator oit;
735  int i,j;
736  for (cit=expset.begin(), j=1; cit != expset.end() ; ++cit, ++j) //loop on exponent tuples
737  {
738  for(oit=obs_input.begin(), i=1; oit!=obs_input.end();++oit, ++i) //loop on observations
739  {
740  elt=1.0;
741  for(int d=0;d<DIM;++d)
742  {
743  p = (*cit)[d];
744  if (p != 0)
745  {
746  elt *= std::pow( (*oit)[d], p );
747  }
748  }
749  M(i,j) = elt;
750  }
751  }
752 
753  NEWMAT::ColumnVector v(nobs);
754  for(int o=0;o<nobs;++o)
755  {
756  v(o+1) = obs_output[o];
757  }
758 
759  //perform solution
760  NEWMAT::ColumnVector bfit = (M.t()*M).i()*M.t()*v;
761 
762  //compute RMS (optional, if rms non null)
763  if (prms!=NULL)
764  {
765  NEWMAT::ColumnVector delta = M*bfit - v;
766  *prms = std::sqrt( delta.SumSquare() / nobs);
767  }
768 
769  //init polynom
770  for (cit=expset.begin(), j=1; cit != expset.end() ; ++cit, ++j) //loop on exponent tuples
771  {
772  setMonom(*cit, bfit(j));
773  }
774  return true;
775 }
776 
777 protected:
782 
784 
788  void
790  {
791  std::vector< typename MONOM_MAP::iterator > erasev; //storage for iterators on elements to erase
792  for (typename MONOM_MAP::iterator it = theMonoms.begin(); it != theMonoms.end() ; ++it )
793  {
794  if (isNegligible(it->second)) erasev.push_back(it);
795  }
796  //erase all elements afterwards
797  for ( typename std::vector< typename MONOM_MAP::iterator >::const_iterator vit = erasev.begin(); vit != erasev.end() ; ++vit )
798  {
799  theMonoms.erase(*vit); //*vit is an iterator in theMonoms
800  }
801  }
802 
806  void
807  addMonomQuick(const EXP_TUPLE& m, const T& v)
808  {
809  typename MONOM_MAP::iterator it = theMonoms.find(m);
810  if (it != theMonoms.end())
811  {
812  it->second += v;
813  } else {
814  theMonoms.insert( MONOM_MAP::value_type(m,v));
815  }
816  }
817 
821  NEWMAT::Matrix
822  invert(const NEWMAT::Matrix& m)const
823  {
824  ossim_uint32 idx = 0;
825  NEWMAT::DiagonalMatrix d;
826  NEWMAT::Matrix u;
827  NEWMAT::Matrix v;
828 
829  // decompose m.t*m which is stored in Temp into the singular values and vectors.
830  //
831  NEWMAT::SVD(m, d, u, v, true, true);
832 
833  // invert the diagonal
834  // this is just doing the reciprical fo all diagonal components and store back int
835  // d. ths compute d inverse.
836  //
837  for(idx=0; idx < (ossim_uint32)d.Ncols(); ++idx)
838  {
839  if(d[idx] > getEpsilon()) //adpated here for epsilon
840  {
841  d[idx] = 1.0/d[idx];
842  }
843  else
844  {
845  d[idx] = 0.0;
846  }
847  }
848 
849  //compute inverse of decomposed m;
850  return v*d*u.t();
851  }
852 
853 }; //class ossimPolynom
854 
855 
856 
860 template < class T, int DIM > std::ostream&
861 operator<<(std::ostream& os, const ossimPolynom<T,DIM>& pt)
862 {
863  return pt.print(os);
864 }
865 
866 template < class T, int DIM > std::istream&
868 {
869  return pt.import(is);
870 }
871 
872 #endif
ossimPolynom(const ossimPolynom &p)
Definition: ossimPolynom.h:79
ossimString before(const ossimString &str, std::string::size_type pos=0) const
METHOD: before(str, pos) Returns string beginning at pos and ending one before the token str If strin...
EXPT_SET builExpSet(const EXP_TUPLE &orders) const
constructs simple exponent tuples set for using LMSfit need order for each dimension ...
Definition: ossimPolynom.h:534
const T & getEpsilon() const
no setEpsilon beacause might erase monoms
Definition: ossimPolynom.h:150
bool isNegligible(const T &v) const
can v be considered as zero?
Definition: ossimPolynom.h:178
int getOrder(int d) const
orders
Definition: ossimPolynom.h:186
T eval(const VAR_TUPLE &v) const
evaluation : needs DIM values as input
Definition: ossimPolynom.h:219
type to store multivariate input
Definition: ossimPolynom.h:47
template class for multivariate polynom algebra
Definition: ossimPolynom.h:38
bool SLSfit(const EXPT_SET &expset, const std::vector< VAR_TUPLE > obs_input, const std::vector< T > obs_output, T *prms=NULL)
Standard least squares Modified version of LMSfit that uses standard NEWMAT inverse as alternative to...
Definition: ossimPolynom.h:700
T theEpsilon
associate a scalar to each tuple of orders : monom
Definition: ossimPolynom.h:783
ossimPolynom operator*(const ossimPolynom &p) const
product operator : use epsilon from left side
Definition: ossimPolynom.h:315
std::istream & import(std::istream &is)
note that it can only import for the template type T and dimesnion DIM
Definition: ossimPolynom.h:440
yy_size_t size
std::string::size_type size() const
Definition: ossimString.h:405
void addExpTupleRight(int newdim, int totalOrder, EXPT_SET &eset) const
concatenate exponents (at the right) to existing tuple set, for a given maximum total order eg: with ...
Definition: ossimPolynom.h:569
unsigned int ossim_uint32
bool operator!=(const ossimPolynom &pt) const
Definition: ossimPolynom.h:173
ossimString trim(const ossimString &valueToTrim=ossimString(" \\)) const
this will strip lead and trailing character passed in.
double toDouble() const
void setMonom(const int mexp[DIM], const T &v)
Definition: ossimPolynom.h:107
std::map< EXP_TUPLE, T, EXP_TUPLE_LESSTHAN > MONOM_MAP
Definition: ossimPolynom.h:66
ossimPolynom(const T &epsilon=0)
for storing set of exponent tuples
Definition: ossimPolynom.h:75
void SVD(const Matrix &, DiagonalMatrix &, Matrix &, Matrix &, bool=true, bool=true)
Definition: svd.cpp:26
std::set< EXP_TUPLE, EXP_TUPLE_LESSTHAN > EXPT_SET
for storing polynom
Definition: ossimPolynom.h:68
std::vector< int > EXP_TUPLE
inner types
Definition: ossimPolynom.h:44
const ossimPolynom & operator*=(const T &k)
operations with scalar
Definition: ossimPolynom.h:266
MONOM_MAP theMonoms
protected data members
Definition: ossimPolynom.h:781
const MONOM_MAP & getMonoms() const
Definition: ossimPolynom.h:145
std::vector< ossimString > explode(const ossimString &delimeter) const
NEWMAT::Matrix invert(const NEWMAT::Matrix &m) const
invert stolen from ossimRpcSolver
Definition: ossimPolynom.h:822
const ossimPolynom & operator*=(const ossimPolynom &p)
Definition: ossimPolynom.h:339
bool operator==(const ossimPolynom &pt) const
comparison operators -don&#39;t compare theEpsilon values -use my own epsilon in comparisons (not the com...
Definition: ossimPolynom.h:160
ossimPolynom operator-(const ossimPolynom &p) const
Definition: ossimPolynom.h:284
std::ostream & printNice(std::ostream &os, const char symbols[DIM])
classic representation (bad accuracy, for display only)
Definition: ossimPolynom.h:406
std::basic_istream< char > istream
Base class for char input streams.
Definition: ossimIosFwd.h:20
ossimPolynom operator+(const ossimPolynom &p) const
arithmetic operators
Definition: ossimPolynom.h:279
void discardNullMonoms()
positive values below epsilon are considered 0
Definition: ossimPolynom.h:789
void delMonom(const EXP_TUPLE &m)
Definition: ossimPolynom.h:119
int getTotalOrder() const
returns maximum order of monoms
Definition: ossimPolynom.h:202
const ossimPolynom & operator=(const ossimPolynom< T, DIM > &pt)
Definition: ossimPolynom.h:87
void addMonomQuick(const EXP_TUPLE &m, const T &v)
add value without testing for negligible
Definition: ossimPolynom.h:807
bool LMSfit(const EXPT_SET &expset, const std::vector< VAR_TUPLE > obs_input, const std::vector< T > obs_output, T *prms=NULL)
fits the polynom to the observations using Least Mean Squares returns true on success (can fail if no...
Definition: ossimPolynom.h:611
std::ostream & print(std::ostream &os) const
I/O.
Definition: ossimPolynom.h:370
std::vector< T > VAR_TUPLE
type to store exponent tuples
Definition: ossimPolynom.h:45
bool operator()(const EXP_TUPLE &o1, const EXP_TUPLE &o2) const
Definition: ossimPolynom.h:50
const ossimPolynom & operator+=(const ossimPolynom &p)
Definition: ossimPolynom.h:290
void pdiff(int pdim, ossimPolynom &result) const
partial differentiation polynom
Definition: ossimPolynom.h:246
bool isNull() const
Definition: ossimPolynom.h:140
friend OSSIM_DLL std::istream & getline(std::istream &is, ossimString &str, char delim)
Reads a string from the input stream is, stopping when it reaches delim.
Definition: ossimString.h:916
static void addExpTuple(EXP_TUPLE &m1, const EXP_TUPLE &m2)
Definition: ossimPolynom.h:344
void setMonom(const EXP_TUPLE &m, const T &v)
Definition: ossimPolynom.h:97
ossimString after(const ossimString &str, std::string::size_type pos=0) const
METHOD: after(str, pos) Returns string immediately after the token str.
const ossimPolynom & operator-=(const ossimPolynom &p)
Definition: ossimPolynom.h:301
void nullify()
Definition: ossimPolynom.h:135
std::basic_ostream< char > ostream
Base class for char output streams.
Definition: ossimIosFwd.h:23
T getCoeff(const EXP_TUPLE &m) const
Definition: ossimPolynom.h:124
std::istream & operator>>(std::istream &is, ossimPolynom< T, DIM > &pt)
Definition: ossimPolynom.h:867