Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions ipca/ipca.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ def __init__(self, n_factors=1, intercept=False, max_iter=10000,


def fit(self, X, y, indices=None, PSF=None, Gamma=None,
Factors=None, data_type="portfolio", label_ind=False, **kwargs):
Factors=None, data_type="portfolio", label_ind=False,
quiet=False, **kwargs):
"""
Fits the regressor to the data using an alternating least squares
scheme.
Expand Down Expand Up @@ -141,6 +142,10 @@ def fit(self, X, y, indices=None, PSF=None, Gamma=None,
Currently, the bootstrap procedure is only implemented in terms
of the portfolio data_type.

quiet : bool, default=False
If True, suppresses informational printing during fitting
(panel dimensions, progress bar, and ALS iteration output).

Returns
-------
self
Expand Down Expand Up @@ -213,15 +218,16 @@ def fit(self, X, y, indices=None, PSF=None, Gamma=None,

# store data
self.X, self.y, self.indices, self.PSF = X, y, indices, PSF
Q, W, val_obs = _build_portfolio(X, y, indices, metad)
Q, W, val_obs = _build_portfolio(X, y, indices, metad, quiet=quiet)
self.Q, self.W, self.val_obs = Q, W, val_obs
self.metad = metad

# Run IPCA
Gamma, Factors = self._fit_ipca(X=X, y=y, indices=indices, Q=Q,
W=W, val_obs=val_obs, PSF=PSF,
Gamma=Gamma, Factors=Factors,
data_type=data_type, **kwargs)
data_type=data_type, quiet=quiet,
**kwargs)

# Store estimates
if self.PSFcase:
Expand Down Expand Up @@ -1354,7 +1360,7 @@ def _prep_input(X, y=None, indices=None):
return X, y, indices, metad


def _build_portfolio(X, y, indices, metad):
def _build_portfolio(X, y, indices, metad, quiet=False):
""" Converts a stacked panel of data where each row corresponds to an
observation (i, t) into a tensor of dimensions (N, L, T) where N is the
number of unique entities, L is the number of characteristics and T is
Expand Down Expand Up @@ -1402,8 +1408,9 @@ def _build_portfolio(X, y, indices, metad):

N, L, T = metad["N"], metad["L"], metad["T"]

print('The panel dimensions are:')
print('n_samples:', N, ', L:', L, ', T:', T)
if not quiet:
print('The panel dimensions are:')
print('n_samples:', N, ', L:', L, ', T:', T)

bar = progressbar.ProgressBar(maxval=T,
widgets=[progressbar.Bar('=', '[', ']'),
Expand Down