Skip to content

Commit

Permalink
Fixed issue with a_vector.py that was affecting class method pm.summa…
Browse files Browse the repository at this point in the history
…ry mentioned in #11. Other minor cleanup removing Bayesian artifacts from master branch metalog.py file. Going to rebuild and publish to pypi
  • Loading branch information
tjefferies committed Sep 20, 2020
1 parent 7fed219 commit 0cd332b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 25 deletions.
6 changes: 4 additions & 2 deletions pymetalog/a_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,9 @@ def a_vector_OLS_and_LP(m_dict,
try:
temp = np.dot(np.dot(np.linalg.inv(np.dot(Y.T, Y) + alpha*eye), Y.T), z)
except:
temp = a_vector_LP(m_dict, term_limit=i, term_lower_bound=i, diff_error=diff_error, diff_step=diff_step)
# use LP solver if OLS breaks
temp = a_vector_LP(m_dict, term_limit=i, term_lower_bound=i, diff_error=diff_error, diff_step=diff_step)

This comment has been minimized.

Copy link
@tadamcz

tadamcz Sep 28, 2020

The except block here never even runs in my test.

methodFit = 'Linear Program'
if fit_method == 'OLS':
try:
temp = np.dot(np.dot(np.linalg.inv(np.dot(Y.T, Y) + alpha*eye), Y.T), z)
Expand All @@ -164,10 +165,11 @@ def a_vector_OLS_and_LP(m_dict,
temp = a_vector_LP(m_dict, term_limit=i, term_lower_bound=i, diff_error=diff_error, diff_step=diff_step)
methodFit = 'Linear Program'

temp = np.append(temp, np.zeros(term_limit-i))
if fit_method == 'MLE':
temp = a_vector_MLE(temp, y, i, m_dict, bounds, boundedness)

temp = np.append(temp, np.zeros(term_limit-i))

# build a y vector for smaller data sets
if len(z) < 100:
y2 = np.linspace(step_len, 1 - step_len, int((1 - step_len) / step_len))
Expand Down
24 changes: 1 addition & 23 deletions pymetalog/metalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class metalog():
fit_method (:obj: `str`): String type of metalog fit method ('any' | 'OLS' | 'LP' | 'MLE').
penalty (:obj:`str`): Used to specify the norm used in the regularization.
alpha (:obj:`float`): Regularization term to add to OLS fit.
save_data (:obj:`bool`, optional): T/F to save copy of input data `x` with metalog object.
output_dict (:obj:`dict` with keys ['params', 'dataValues', 'Y', 'A', 'M', 'Validation']).
- output_dict['params'] (:obj:`dict`):
Expand Down Expand Up @@ -92,7 +91,7 @@ class metalog():
append_zvector(`bounds`, `boundedness`) -> df_x: (:obj:`pandas.DataFrame` with columns ['x','probs','z'] of type numeric)
"""
def __init__(self, x, bounds=[0,1], boundedness='u', term_limit=13, term_lower_bound=2, step_len=.01, probs=None, fit_method='any', penalty=None, alpha=0., save_data = False):
def __init__(self, x, bounds=[0,1], boundedness='u', term_limit=13, term_lower_bound=2, step_len=.01, probs=None, fit_method='any', penalty=None, alpha=0.):
"""Fits a metalog distribution using the input array `x`.
Args:
Expand Down Expand Up @@ -150,12 +149,6 @@ def __init__(self, x, bounds=[0,1], boundedness='u', term_limit=13, term_lower_b
- should be set in conjunction with `penalty` parameter
- Default: 0. (no regularization, OLS)
save_data (:obj:`bool`, optional): Saves copy of input data `x` with metalog object.
- strictly boolean (True, False)
- saves a copy of data used to fit metalog object
* Used for Bayesian updating
- Default: False
Raises:
TypeError: 'Input x must be an array or pandas Series'
TypeError: 'Input x must be an array of allowable types: int, float, numpy.int64, or numpy.float64'
Expand Down Expand Up @@ -185,7 +178,6 @@ def __init__(self, x, bounds=[0,1], boundedness='u', term_limit=13, term_lower_b
ValueError: 'fit_method can only be values OLS, LP, any, or MLE'
ValueError: 'penalty can only be values l2 or None'
ValueError: 'alpha must only be a float >= 0.'
ValueError: 'save_data must only be boolean.'
Example:
Expand Down Expand Up @@ -215,7 +207,6 @@ def __init__(self, x, bounds=[0,1], boundedness='u', term_limit=13, term_lower_b
self.fit_method = fit_method
self.penalty = penalty
self.nobs = len(x)
self.save_data = save_data

if penalty == None:
alpha = 0.
Expand Down Expand Up @@ -436,18 +427,6 @@ def alpha(self, a):
raise ValueError('alpha must only be a float >= 0.')
self._alpha = a

@property
def save_data(self):
"""save_data (:obj:`bool`, optional): Saves copy of input data `x` with metalog object."""

return self._save_data

@save_data.setter
def save_data(self, sd):
if not type(sd) is bool:
raise ValueError('save_data must only be boolean.')
self._save_data = sd

def get_params(self):
"""Sets the `params` key (dict) of `output_dict` object prior to input to `a_vector_OLS_and_LP` method.
- Uses metalog attributes to set keys
Expand All @@ -465,7 +444,6 @@ def get_params(self):
params['step_len'] = self.step_len
params['fit_method'] = self.fit_method
params['nobs'] = self.nobs
params['save_data'] = self.save_data

return params

Expand Down

0 comments on commit 0cd332b

Please sign in to comment.