Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid np.log of zero in ECM #203

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
8 changes: 5 additions & 3 deletions recordlinkage/algorithms/nb_sklearn.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@

_ALPHA_MIN = 1e-10

def log(x):
return np.log(x + np.finfo(float).eps)

def check_is_fitted(estimator, attributes, msg=None, all_or_any=all):
"""Perform is_fitted validation for estimator.
Expand Down Expand Up @@ -595,10 +597,10 @@ def fit(self, X):
g_freq_sum = g_freq.sum(axis=0)

# maximisation step
class_log_prior_ = np.log(g_freq_sum) - np.log(X.shape[0]) # p
class_log_prior_ = log(g_freq_sum) - log(X.shape[0]) # p
feature_prob_ = safe_sparse_dot(g_freq.T, X_unique_bin)
feature_log_prob_ = np.log(feature_prob_)
feature_log_prob_ -= np.log(np.atleast_2d(g_freq_sum).T)
feature_log_prob_ = log(feature_prob_)
feature_log_prob_ -= log(np.atleast_2d(g_freq_sum).T)

# Stop iterating when the class prior and feature probs are close
# to the values in the to previous iteration (parameters starting
Expand Down