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

Fix DiscriminatorReweightDensity and ReweightDensity #118

Merged
merged 2 commits into from
Mar 1, 2024
Merged
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
7 changes: 5 additions & 2 deletions skada/_reweight.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def adapt(self, X, y=None, sample_domain=None):
ws = self.weight_estimator_source_.score_samples(X[source_idx])
wt = self.weight_estimator_target_.score_samples(X[source_idx])
source_weights = np.exp(wt - ws)
source_weights /= source_weights.sum()
source_weights /= source_weights.mean()
weights = np.zeros(X.shape[0], dtype=source_weights.dtype)
weights[source_idx] = source_weights
else:
Expand Down Expand Up @@ -371,7 +371,10 @@ def adapt(self, X, y=None, sample_domain=None, **kwargs):
# xxx(okachaiev): move this to API
if source_idx.sum() > 0:
source_idx, = np.where(source_idx)
source_weights = self.domain_classifier_.predict_proba(X[source_idx])[:, 1]
probas = self.domain_classifier_.predict_proba(X[source_idx])[:, 1]
probas = np.clip(probas, EPS, 1.)
source_weights = (1 - probas) / probas
source_weights /= source_weights.mean()
weights = np.zeros(X.shape[0], dtype=source_weights.dtype)
weights[source_idx] = source_weights
else:
Expand Down
Loading