Least Square Approximation and Logarithm evaluation #639
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Numerical Analysis Algorithms
Description
Current pull request adds 2 new algorithms.
Least Square Approximation
This algorithm is a response to the problem risen by analysis of some data, projected in grafing the data to points (in 2 dimension)
and figuring out a pattern that the data follow or fiding a median for those data.
Least Square Approximation creates a polynomial of any degree with the given set of points, starting from the following idea:
--> Fiding something in common for those points means, mathematically, to evaluate a distance; since we want to observe, relative to a polynomial, the behaviour of the data, we define a function ( called E ) that describes this idea:
E(a0, a1, ... , aD) =$\sum_{i=0..n}$ (yi - P(xi))2, where:
P(..) -> polynomial we want to find; D -> degree of polynomial
n -> number of points (data)
yi -> ordinate of some data
xi -> abscissa of some data
a0, a1, ... , aD -> coefficients of terms of the polynomial
Now, for the idea to really produce a result, the function E shall be as small as possible, fact supported by smaller the sum, closer the values added, meaning yi and P(xi) are very close to each other. This now becomes a Calculus 2 problem, more specifically minimising the function E. This is possible by taking the partial derivative of the function "E" with respect to each coefficient ai and evaluate it to zero, as follows:
Choosing a degree for P and replacing it's form into the formula for E above, we will have a system of equations, generated by the derivatives above, looking something like:
Decomposing the bigger sum from the left side and exposing all the D + 1 equations, we can observe that the left side can be rewritten as follows:
$\to$ A matrix A which holds, as elements, $\sum_{j=1..n}$ xj j+k ( For each line, the elements will be the sums for the respective derivative (k representing it's index) )
$\to$ A column vector x which holds the coefficients $a_0, a_1, ..., a_D$ , in this order
Also, the right side can be expressed as a column vector b, which holds the sums$\sum_{i=0..n}$ yi* xi k
Finally, the whole algorithm is based on solving the equation: A * x = b for the column vector x; in this implementation, the method used is QR decomposition and ultimately solving it.
Logarithm evaluation
This function calculates the logbasex, for any base > 0, x > 0
For the case base = e and x between 0 and 1, the function uses the MacLaurin Series for ln: ln(x) =$\sum_{n>=1} {(-1)^n * \frac{x^n}{n}}$