chaospy.fit_regression¶
- chaospy.fit_regression(polynomials, abscissas, evals, model=None, retall=0)[source]¶
Fit a polynomial chaos expansion using linear regression.
- Args:
- polynomials (numpoly.ndpoly):
Polynomial expansion with
polynomials.shape == (M,)
and polynomials.dim=D.- abscissas (numpy.ndarray):
Collocation nodes with
abscissas.shape == (D, K)
.- evals (numpy.ndarray):
Model evaluations with
len(evals) == K
.- model (Optional[sklearn.base.BaseEstimator]):
By default regression is done using the classical least-square method. However, if provided, and sklearn regression model can be used instead.
- retall (int):
What the function should return. 0: only return fitted polynomials, with shape evals.shape[1:]. 1: polynomials, and Fourier coefficients, 2: polynomials, coefficients and polynomial evaluations.
- Returns:
- (chaospy.ndpoly, numpy.ndarray, numpy.ndarray):
Returned value as determined by retval.
- Examples:
>>> x, y = chaospy.variable(2) >>> polynomials = chaospy.polynomial([1, x, y]) >>> abscissas = [[-1, -1, 1, 1], [-1, 1, -1, 1]] >>> evals = [0, 1, 1, 2] >>> chaospy.fit_regression(polynomials, abscissas, evals).round(14) polynomial(0.5*q1+0.5*q0+1.0) >>> model = sklearn.linear_model.LinearRegression(fit_intercept=False) >>> chaospy.fit_regression( ... polynomials, abscissas, evals, model=model).round(14) polynomial(0.5*q1+0.5*q0+1.0)