Least-squares function approximation: Difference between revisions

Content deleted Content added
#property copyright "Copyright 2016, MetaQuotes Software Corp." #property link "http://www.mql5.com" #property version "1.00" #property strict #property indicator_separate_window #property indicator_buffers 1 input int iBarsTotal=300; string pair[]={"EURUSD","GBPUSD","AUDUSD","NZDUSD","USDCAD","USDCHF","USDJPY"}; bool bDirect[]={false,false,false,false,true,true,true}; int iCount=7; //+------------------------------------------------------------------+ //|
Tags: Reverted nowiki added Visual edit Mobile edit Mobile web edit
Citation bot (talk | contribs)
Alter: isbn. Add: publisher, chapter-url. Removed or converted URL. Upgrade ISBN10 to 13. | Use this bot. Report bugs. | Suggested by Abductive | Category:Approximation theory‎ | #UCB_Category 25/32
 
(3 intermediate revisions by 3 users not shown)
Line 1:
{{Short description|Mathematical method}}
In [[mathematics]], '''least squares function approximation''' applies the principle of [[least squares]] to [[function approximation]], by means of a weighted sum of other functions. The best approximation can be defined as that which minimisesminimizes the difference between the original function and the approximation; for a least-squares approach the quality of the approximation is measured in terms of the squared differences between the two.
 
<nowiki>#</nowiki>property copyright "Copyright 2016, MetaQuotes Software Corp."
#property link      "<nowiki>http://www.mql5.com</nowiki>"
#property version   "1.00"
#property strict
#property indicator_separate_window
#property indicator_buffers 1
input int     iBarsTotal=300;      
string pair[]={"EURUSD","GBPUSD","AUDUSD","NZDUSD","USDCAD","USDCHF","USDJPY"};
bool bDirect[]={false,false,false,false,true,true,true};
int iCount=7;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double GetValue(int shift)
  {
   double res=1.0,t;
   for(int i=0; i<iCount; i++)
     {
      t=iClose(pair[i],0,shift);
      if(!bDirect[i]) t=1/t;
      res*=t;
     }//end for (int i = 0; i < iCount; i++)
   return (NormalizeDouble(MathPow (res, (double)1/iCount), _Digits) );
  }
double upp[];
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnInit()
  {
   IndicatorShortName("testBasket");
   IndicatorDigits(_Digits);
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2,clrGreen);
   SetIndexBuffer(0,upp);
   SetIndexLabel(0,"testBasket");
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
   if(prev_calculated==0)
     {
      int total;
      if(iBarsTotal==0) total=rates_total;
      else total= MathMin(iBarsTotal,rates_total);
      for(int i = 0; i<total; i++) upp[i] = GetValue(i);
     }//end if (prev_calculated == 0)
   else
     {
      upp[0]=GetValue(0);
     }
   return(rates_total);
  }
 
==Functional analysis==
Line 84 ⟶ 14:
with the set of functions {<math>\ \phi _j (x) </math>} an [[Orthonormal_set#Real-valued_functions|orthonormal set]] over the interval of interest, {{nowrap|say [a, b]}}: see also [[Fejér's theorem]]. The coefficients {<math>\ a_j </math>} are selected to make the magnitude of the difference ||{{nowrap|''f'' − ''f''<sub>''n''</sub>}}||<sup>2</sup> as small as possible. For example, the magnitude, or norm, of a function {{nowrap|''g'' (''x'' )}} over the {{nowrap|interval [a, b]}} can be defined by:<ref name=Folland>
 
{{cite book |title=Fourier analysis and its application |page =69 |chapter=Equation 3.14 |author=Gerald B Folland |chapter-url=https://books.google.com/books?id=ix2iCQ-o9x4C&pg=PA69 |isbn=978-0-8218-4790-29 |publisher=American Mathematical Society Bookstore |year=2009 |edition=Reprint of Wadsworth and Brooks/Cole 1992}}
 
</ref>
Line 91 ⟶ 21:
 
where the ‘*’ denotes [[complex conjugate]] in the case of complex functions. The extension of Pythagoras' theorem in this manner leads to [[function space]]s and the notion of [[Lebesgue measure]], an idea of “space” more general than the original basis of Euclidean geometry. The {{nowrap|{ <math>\phi_j (x)\ </math> } }} satisfy [[Orthogonal#Orthogonal_functions|orthonormality relations]]:<ref name=Folland2>
{{cite book |title=Fourier Analysis and Its Applications|page =69 |first1=Gerald B | last1= Folland|url=https://books.google.com/books?id=ix2iCQ-o9x4C&pg=PA69 |isbn=978-0-8218-4790-29 |year=2009 |publisher=American Mathematical Society}}
</ref>
 
Line 99 ⟶ 29:
the ''n''-dimensional [[Pythagorean theorem]]:<ref name=Wood>
 
{{cite book |title=Statistical methods: the geometric approach |author= David J. Saville, Graham R. Wood |chapter=§2.5 Sum of squares |page=30 |chapter-url=https://books.google.com/books?id=8ummgMVRev0C&pg=PA30 |isbn=0-387-97517-9 |year=1991 |edition=3rd |publisher=Springer}}
</ref>
 
Line 110 ⟶ 40:
The generalization of the ''n''-dimensional Pythagorean theorem to ''infinite-dimensional&thinsp;'' [[real number|real]] inner product spaces is known as [[Parseval's identity]] or Parseval's equation.<ref name=Folland3>
 
{{cite book |title=cited work |page =77 |chapter=Equation 3.22 |author=Gerald B Folland |chapter-url=https://books.google.com/books?id=ix2iCQ-o9x4C&pg=PA77 |isbn=978-0-8218-4790-29 |date=2009-01-13 |publisher =American Mathematical Soc. }}
 
</ref> Particular examples of such a representation of a function are the [[Fourier series]] and the [[generalized Fourier series]].