use horners method in DISC instead of calculating so many powers and polynomials
See original GitHub issueDescribe the bug
the disc method has a lot of power and polynomials. IMO whenever possible, polynomials should use Horner’s method which is already implemented in np.polyval
but is easy to reimplement if needed.
To Reproduce https://github.com/pvlib/pvlib-python/blob/8b98768818ee5ad85d9479877533651a2e9dc2cd/pvlib/irradiance.py#L1405-L1422
0.512 - 1.56*kt + 2.286*kt2 - 2.222*kt3
becomes
0.512 - kt * (1.56 + kt * (2.286 - 2.222 * kt))
or
np.polyval([-2.222, 2.286, -1.56, 0.512], kt)
Expected behavior a few math tricks like this (atan2, log1p, Horner’s method, etc.) are musts for efficiency and numerical stability.
Versions:
pvlib.__version__
: 0.8.1
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
Horner's Method for Polynomial Evaluation - GeeksforGeeks
A naive way to evaluate a polynomial is to one by one evaluate all terms. First calculate x n, multiply the value with...
Read more >Horner's method - Wikipedia
In mathematics and computer science, Horner's method (or Horner's scheme) is an algorithm for polynomial evaluation. Although named after William George ...
Read more >Methods for evaluating polynomials quickly
Methods for evaluating polynomials quickly · 3. Horner's method. · 1. If it you happen to know that the powers are large compared...
Read more >Horner's Method - YouTube
Horner's Method (Ruffini-Horner Scheme) for evaluating polynomials including a brief history, examples, Ruffini's Rule with derivatives, ...
Read more >Horner's Method 2: Why it works for computing function values
This video explains a quicker method of computing function values of a polynomial. This method, also known as synthetic substitution, ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Miscellaneous observations:
bools
tois_cloudy
.I counted and surprisingly, there are the same flops in the existing
kt, kt2, kt3
code than in Horner’s, in fact, there are exactly 3 more, because it’s unnecessary to pre-calculatekt, kt2, kt3
when using Horner’sBy the numbers:
Surprise! Horners is about 10% faster for this part of the DISC too!