Python numpy.polynomial.polynomial.polyroots() Examples
The following are 16
code examples of numpy.polynomial.polynomial.polyroots().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
numpy.polynomial.polynomial
, or try the search function
.
Example #1
Source File: test_polynomial.py From recruit with Apache License 2.0 | 5 votes |
def test_polyroots(self): assert_almost_equal(poly.polyroots([1]), []) assert_almost_equal(poly.polyroots([1, 2]), [-.5]) for i in range(2, 5): tgt = np.linspace(-1, 1, i) res = poly.polyroots(poly.polyfromroots(tgt)) assert_almost_equal(trim(res), trim(tgt))
Example #2
Source File: test_polynomial.py From auto-alt-text-lambda-api with MIT License | 5 votes |
def test_polyroots(self): assert_almost_equal(poly.polyroots([1]), []) assert_almost_equal(poly.polyroots([1, 2]), [-.5]) for i in range(2, 5): tgt = np.linspace(-1, 1, i) res = poly.polyroots(poly.polyfromroots(tgt)) assert_almost_equal(trim(res), trim(tgt))
Example #3
Source File: test_polynomial.py From vnpy_crypto with MIT License | 5 votes |
def test_polyroots(self): assert_almost_equal(poly.polyroots([1]), []) assert_almost_equal(poly.polyroots([1, 2]), [-.5]) for i in range(2, 5): tgt = np.linspace(-1, 1, i) res = poly.polyroots(poly.polyfromroots(tgt)) assert_almost_equal(trim(res), trim(tgt))
Example #4
Source File: test_polynomial.py From Computable with MIT License | 5 votes |
def test_polyroots(self) : assert_almost_equal(poly.polyroots([1]), []) assert_almost_equal(poly.polyroots([1, 2]), [-.5]) for i in range(2, 5) : tgt = np.linspace(-1, 1, i) res = poly.polyroots(poly.polyfromroots(tgt)) assert_almost_equal(trim(res), trim(tgt))
Example #5
Source File: test_polynomial.py From Mastering-Elasticsearch-7.0 with MIT License | 5 votes |
def test_polyroots(self): assert_almost_equal(poly.polyroots([1]), []) assert_almost_equal(poly.polyroots([1, 2]), [-.5]) for i in range(2, 5): tgt = np.linspace(-1, 1, i) res = poly.polyroots(poly.polyfromroots(tgt)) assert_almost_equal(trim(res), trim(tgt))
Example #6
Source File: test_polynomial.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def test_polyroots(self): assert_almost_equal(poly.polyroots([1]), []) assert_almost_equal(poly.polyroots([1, 2]), [-.5]) for i in range(2, 5): tgt = np.linspace(-1, 1, i) res = poly.polyroots(poly.polyfromroots(tgt)) assert_almost_equal(trim(res), trim(tgt))
Example #7
Source File: test_polynomial.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def test_polyroots(self): assert_almost_equal(poly.polyroots([1]), []) assert_almost_equal(poly.polyroots([1, 2]), [-.5]) for i in range(2, 5): tgt = np.linspace(-1, 1, i) res = poly.polyroots(poly.polyfromroots(tgt)) assert_almost_equal(trim(res), trim(tgt))
Example #8
Source File: test_polynomial.py From pySINDy with MIT License | 5 votes |
def test_polyroots(self): assert_almost_equal(poly.polyroots([1]), []) assert_almost_equal(poly.polyroots([1, 2]), [-.5]) for i in range(2, 5): tgt = np.linspace(-1, 1, i) res = poly.polyroots(poly.polyfromroots(tgt)) assert_almost_equal(trim(res), trim(tgt))
Example #9
Source File: test_polynomial.py From mxnet-lambda with Apache License 2.0 | 5 votes |
def test_polyroots(self): assert_almost_equal(poly.polyroots([1]), []) assert_almost_equal(poly.polyroots([1, 2]), [-.5]) for i in range(2, 5): tgt = np.linspace(-1, 1, i) res = poly.polyroots(poly.polyfromroots(tgt)) assert_almost_equal(trim(res), trim(tgt))
Example #10
Source File: test_polynomial.py From ImageFusion with MIT License | 5 votes |
def test_polyroots(self): assert_almost_equal(poly.polyroots([1]), []) assert_almost_equal(poly.polyroots([1, 2]), [-.5]) for i in range(2, 5): tgt = np.linspace(-1, 1, i) res = poly.polyroots(poly.polyfromroots(tgt)) assert_almost_equal(trim(res), trim(tgt))
Example #11
Source File: test_polynomial.py From elasticintel with GNU General Public License v3.0 | 5 votes |
def test_polyroots(self): assert_almost_equal(poly.polyroots([1]), []) assert_almost_equal(poly.polyroots([1, 2]), [-.5]) for i in range(2, 5): tgt = np.linspace(-1, 1, i) res = poly.polyroots(poly.polyfromroots(tgt)) assert_almost_equal(trim(res), trim(tgt))
Example #12
Source File: test_polynomial.py From coffeegrindsize with MIT License | 5 votes |
def test_polyroots(self): assert_almost_equal(poly.polyroots([1]), []) assert_almost_equal(poly.polyroots([1, 2]), [-.5]) for i in range(2, 5): tgt = np.linspace(-1, 1, i) res = poly.polyroots(poly.polyfromroots(tgt)) assert_almost_equal(trim(res), trim(tgt))
Example #13
Source File: test_polynomial.py From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License | 5 votes |
def test_polyroots(self): assert_almost_equal(poly.polyroots([1]), []) assert_almost_equal(poly.polyroots([1, 2]), [-.5]) for i in range(2, 5): tgt = np.linspace(-1, 1, i) res = poly.polyroots(poly.polyfromroots(tgt)) assert_almost_equal(trim(res), trim(tgt))
Example #14
Source File: test_polynomial.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_polyroots(self): assert_almost_equal(poly.polyroots([1]), []) assert_almost_equal(poly.polyroots([1, 2]), [-.5]) for i in range(2, 5): tgt = np.linspace(-1, 1, i) res = poly.polyroots(poly.polyfromroots(tgt)) assert_almost_equal(trim(res), trim(tgt))
Example #15
Source File: test_polynomial.py From keras-lambda with MIT License | 5 votes |
def test_polyroots(self): assert_almost_equal(poly.polyroots([1]), []) assert_almost_equal(poly.polyroots([1, 2]), [-.5]) for i in range(2, 5): tgt = np.linspace(-1, 1, i) res = poly.polyroots(poly.polyfromroots(tgt)) assert_almost_equal(trim(res), trim(tgt))
Example #16
Source File: prony_decomposition.py From capytaine with GNU General Public License v3.0 | 4 votes |
def exponential_decomposition(X, F, m): """Use Prony's method to approximate the sampled real function F=f(X) as a sum of m exponential functions x → Σ a_i exp(lamda_i x). Parameters ---------- X: 1D array sampling points. F: 1D array (same size as X) values of the function to approximate at the points of x. m: integer number of exponential functions Return ------ a: 1D array (size m) coefficients of the exponentials lamda: 1D array (size m) growth rate of the exponentials """ assert X.shape == F.shape # Compute the coefficients of the polynomials of Prony's method A = toeplitz(c=F[m-1:-1], r=F[:m][::-1]) P, *_ = np.linalg.lstsq(A, F[m:], rcond=None) # Build and solve polynomial function coeffs = np.ones(m+1) # coeffs[:m] = -P[::-1] for i in range(m): coeffs[m-i-1] = -P[i] roots = polynomial.polyroots(coeffs) # Discard values where log is undefined roots = roots[np.logical_or(np.imag(roots) != 0.0, np.real(roots) >= 0.0)] # Deduce lamda and keep only interesting values lamda = np.real(np.log(roots)/(X[1] - X[0])) lamda = np.unique(lamda) lamda = lamda[np.logical_and(-20.0 < lamda, lamda < 0.0)] # Fit the values of 'a' on the curve def f(x, *ar): ar = np.asarray(ar)[:, np.newaxis] la = lamda[:, np.newaxis] return np.sum(ar * np.exp(la * x), axis=0) a, *_ = curve_fit(f, X, F, p0=np.zeros(lamda.shape)) return a, lamda