trendpy2 package

It is recommended to use the Trend object from the trendpy2.models, the methods from trendpy2.methods are contained as attributes of that objects. However, you can also use the methods from trendpy2.methods in a standalone way ;)

trendpy2.models module

class trendpy2.models.Trend(x, y, ansatz, deg=None, freeRegAnsatz=None)[source]

Bases: object

Trends Class. Initialization of Trend with training input, training output, ansatz (string) and deg (if polynomial ansatz). The following ansatz are supported ‘linReg’, ‘polReg’, ‘expReg’, ‘trigReg’, ‘freeReg’.

>>> from trendpy2 import models as tpm
>>> x = np.array([1, 2, 3])
>>> y = np.array([1, 1.5, 3.5])
>>> lin = tpm.Trend(x, y, 'linReg')
coef()[source]

Computes coefficients of corresponding ansatz-

>>> lin.coef
>>> [1.25, -0.5]
pred(x)[source]

Computes the predction for input x and the computed corresponding coefficients.

>>> lin.pred(3)
>>> 3.25        
predict(x)[source]

The same as pred.

r2()[source]

Computes the coefficient of determination for the training input.

>>> lin.r2
>>> 0.893          

trendpy2.methods module

trendpy2.methods.expReg(x_in, y)[source]

Time series exponential regression.

>>> from trendpy2 import methods as tm
>>> import numpy as np    
>>> x = np.array([0, 1, 2])
>>> y = 2*np.exp(x)
>>> tm.expReg(x, y)
>>> array([2., 1.])     
trendpy2.methods.freeReg(x_in, y_out, ansatz)[source]

Regression with user ansatz. The ansatz is expected to depend on three parameters, a, b, and c. The ansatz is expected to be a string with a symbolic formulation. for instance: ‘a*arctan(b*x_in+c)’.

>>> from trendpy2 import methods as tm
>>> import numpy as np    
>>> x = np.array([0, 1, 2, 3])
>>> y = 2*(1-3*np.exp(-x))
>>> tm.freeReg(x, y, ansatz='a*(1-b*exp(-c*x))')
>>> array([2., 3., 1.])     
trendpy2.methods.linReg(x_in, y)[source]

Time series linear regression. Returns coefs in polynomial descending order. Coefs computed analytically.

>>> from trendpy2 import methods as tm
>>> import numpy as np    
>>> x = np.array([1, 2, 3])
>>> y = np.array([1, 1.5, 3.5])
>>> tm.linReg(x, y)    
>>> [1.25, -0.5]
trendpy2.methods.polReg(x_in, y, deg)[source]

Time series polynomial regression. Returns coefs in polynomial descending order. Coefs computed numerically.

>>> from trendpy2 import methods as tm
>>> import numpy as np    
>>> x = np.array([0, 1, 2])
>>> y = np.array([0, 2, 4])
>>> tm.polReg(x, y, 2)  
>>> array([ 8.96585976e-17,  2.00000000e+00, -9.55246329e-17])
trendpy2.methods.pred(ansatz, coef, x_in, freeRegAnsatz=None)[source]

Computes the predction for input x_in and the computed corresponding coefficients.

trendpy2.methods.r2(y, y_pred)[source]

Coefficient of determination.

trendpy2.methods.trigReg(x_in, y)[source]

Time series sine regression. Returns amplitude, frequency and phase.

>>> from trendpy2 import methods as tm
>>> import numpy as np    
>>> x = np.linspace(0, 2, 50)
>>> y = 2*np.cos(x*2*np.pi*3+2)
>>> tm.trigReg(x, y)
>>> array([1.93690845, 2.94      , 2.38548967])