import regreg.api as rr
import regreg.affine as ra
[docs]def restricted_estimator(loss, active, solve_args={'min_its':50, 'tol':1.e-10}):
"""
Fit a restricted model using only columns `active`.
Parameters
----------
Mest_loss : objective function
A GLM loss.
active : ndarray
Which columns to use.
solve_args : dict
Passed to `solve`.
Returns
-------
soln : ndarray
Solution to restricted problem.
"""
X, Y = loss.data
if not loss._is_transform and hasattr(loss, 'saturated_loss'): # M_est is a glm
X_restricted = X[:,active]
loss_restricted = rr.affine_smooth(loss.saturated_loss, X_restricted)
else:
I_restricted = ra.selector(active, ra.astransform(X).input_shape[0], ra.identity((active.sum(),)))
loss_restricted = rr.affine_smooth(loss, I_restricted.T)
beta_E = loss_restricted.solve(**solve_args)
return beta_E