Penalties¶
Penalty matrix generators
-
pygam.penalties.
circular
(n, coef)¶ Builds a penalty matrix for P-Splines with continuous features. Penalizes violation of a circular feature function.
Parameters: - n (int) – number of splines
- coef (unused) – for compatibility with constraints
Returns: penalty matrix
Return type: sparse csc matrix of shape (n,n)
-
pygam.penalties.
concave
(n, coef)¶ Builds a penalty matrix for P-Splines with continuous features. Penalizes violation of a concave feature function.
Parameters: - n (int) – number of splines
- coef (array-like) – coefficients of the feature function
Returns: penalty matrix
Return type: sparse csc matrix of shape (n,n)
-
pygam.penalties.
convex
(n, coef)¶ Builds a penalty matrix for P-Splines with continuous features. Penalizes violation of a convex feature function.
Parameters: - n (int) – number of splines
- coef (array-like) – coefficients of the feature function
Returns: penalty matrix
Return type: sparse csc matrix of shape (n,n)
-
pygam.penalties.
convexity_
(n, coef, convex=True)¶ Builds a penalty matrix for P-Splines with continuous features. Penalizes violation of convexity in the feature function.
Parameters: Returns: penalty matrix
Return type: sparse csc matrix of shape (n,n)
-
pygam.penalties.
derivative
(n, coef, derivative=2)¶ Builds a penalty matrix for P-Splines with continuous features. Penalizes the squared differences between basis coefficients.
Parameters: Returns: penalty matrix
Return type: sparse csc matrix of shape (n,n)
-
pygam.penalties.
l2
(n, coef)¶ Builds a penalty matrix for P-Splines with categorical features. Penalizes the squared value of each basis coefficient.
Parameters: - n (int) – number of splines
- coef (unused) – for compatibility with constraints
Returns: penalty matrix
Return type: sparse csc matrix of shape (n,n)
-
pygam.penalties.
monotonic_dec
(n, coef)¶ Builds a penalty matrix for P-Splines with continuous features. Penalizes violation of a monotonic decreasing feature function.
Parameters: - n (int) – number of splines
- coef (array-like) – coefficients of the feature function
Returns: penalty matrix
Return type: sparse csc matrix of shape (n,n)
-
pygam.penalties.
monotonic_inc
(n, coef)¶ Builds a penalty matrix for P-Splines with continuous features. Penalizes violation of a monotonic increasing feature function.
Parameters: - n (int) – number of splines
- coef (array-like, coefficients of the feature function) –
Returns: penalty matrix
Return type: sparse csc matrix of shape (n,n)
-
pygam.penalties.
monotonicity_
(n, coef, increasing=True)¶ Builds a penalty matrix for P-Splines with continuous features. Penalizes violation of monotonicity in the feature function.
Parameters: Returns: penalty matrix
Return type: sparse csc matrix of shape (n,n)
-
pygam.penalties.
none
(n, coef)¶ Build a matrix of zeros for features that should go unpenalized
Parameters: - n (int) – number of splines
- coef (unused) – for compatibility with constraints
Returns: penalty matrix
Return type: sparse csc matrix of shape (n,n)
-
pygam.penalties.
sparse_diff
(array, n=1, axis=-1)¶ A ported sparse version of np.diff. Uses recursion to compute higher order differences
Parameters: Returns: diff_array – same shape as input array, but ‘axis’ dimension is smaller by ‘n’.
Return type: sparse array
-
pygam.penalties.
wrap_penalty
(p, fit_linear, linear_penalty=0.0)¶ tool to account for unity penalty on the linear term of any feature.
Parameters: - p (callable.) – penalty-matrix-generating function.
- fit_linear (boolean.) – whether the current feature has a linear term or not.
- linear_penalty (float, default: 0.) – penalty on the linear term
Returns: wrapped_p – modified penalty-matrix-generating function
Return type: callable