Skip to content

Implementation of BALD and BatchBALD query strategy. - #284

Merged
mherde merged 8 commits into
developmentfrom
275-BALD
Mar 14, 2023
Merged

mherde merged 8 commits into
developmentfrom
275-BALD

Conversation

@Pascal112

Copy link
Copy Markdown
Collaborator

No description provided.

Comment thread skactiveml/pool/_query_by_committee.py Outdated

if hasattr(ensemble, "estimators_"):
if hasattr(ensemble, "estimators_") and \
not len(ensemble.estimators_) == 0:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
not len(ensemble.estimators_) == 0:
len(ensemble.estimators_) > 0:

Comment thread skactiveml/pool/_bald.py Outdated
from ..utils import rand_argmax, MISSING_LABEL, check_type


class BALD(QueryByCommittee):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
class BALD(QueryByCommittee):
class BatchBALD(QueryByCommittee):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

class

Suggested change
class BALD(QueryByCommittee):
class BayesianALDisagreement(QueryByCommittee):

Comment thread skactiveml/pool/_bald.py Outdated


class BALD(QueryByCommittee):
"""Bayesian Active Learning by Disagreement

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Batch Bayesian Active Learning by Disagreement (BatchBALD)

Comment thread skactiveml/pool/_bald.py Outdated

References
----------
[1] HOULSBY, Neil, et al. Bayesian active learning for classification and

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lower cases for the names Houlsby and Kirsch and Van Amersfoort

Comment thread skactiveml/pool/_bald.py Outdated
return uncertainty - confident


def _batchbald(probas, batch_size=1):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def _batchbald(probas, batch_size=1):
def batch_bald(probas, batch_size=1):

Add check for probas and batch_size

Comment thread skactiveml/pool/_bald.py Outdated
return best_indices


def _bald(probas):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move to test file to check batch_bald

@Pascal112
Pascal112 requested a review from mherde March 2, 2023 08:41
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

Patch coverage: 100.00% and no project coverage change

Comparison is base (7da59b0) 100.00% compared to head (dd25386) 100.00%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Additional details and impacted files
@@            Coverage Diff             @@
##            master      #284    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files           51        52     +1     
  Lines         4115      4268   +153     
==========================================
+ Hits          4115      4268   +153     
Impacted Files Coverage Δ
skactiveml/visualization/_feature_space.py 100.00% <ø> (ø)
skactiveml/pool/__init__.py 100.00% <100.00%> (ø)
skactiveml/pool/_bald.py 100.00% <100.00%> (ø)
skactiveml/pool/_query_by_committee.py 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Comment thread docs/examples/pool/_bald.json Outdated
{
"class" : "BatchBALD",
"package" : "pool",
"method" : "Bayesian Active Learning by Disagreement",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"method" : "Bayesian Active Learning by Disagreement",
"method" : "Bayesian Active Learning by Disagreement (BALD)",

Comment thread docs/examples/pool/_four_ds.json Outdated
{
"class" : "FourDs",
"package" : "pool",
"method" : "Batch Density-Diversity-Distribution-Distance Sampling (4DS)",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"method" : "Batch Density-Diversity-Distribution-Distance Sampling (4DS)",
"method" : "Batch Density-Diversity-Distribution-Distance Sampling (Batch4DS)",

Comment thread docs/refs.bib Outdated
@article{kirsch2019batchbald,
title={Batchbald: Efficient and diverse batch acquisition for deep bayesian active learning},
author={Kirsch, Andreas and Van Amersfoort, Joost and Gal, Yarin},
journal={Advances in neural information processing systems},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
journal={Advances in neural information processing systems},
journal={Advances in Neural Information Processing Systems},

Comment thread skactiveml/pool/_bald.py Outdated
def empty(K):
return _ExactJointEntropy(np.ones((1, K)))

# def compute(self):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete outcommented code

Comment thread skactiveml/pool/_bald.py Outdated
The Bayesian-Active-Learning-by-Disagreement (BatchBALD) [1] strategy reduces the
number of possible hypotheses maximally fast to minimize the uncertainty
about the parameters using Shannon’s entropy. It seeks the data point that
maximises the decrease in expected posterior entropy. For the batch case

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
maximises the decrease in expected posterior entropy. For the batch case
maximises the decrease in expected posterior entropy. For the batch case,

Comment thread skactiveml/pool/_bald.py Outdated
n_MC_samples, batch_size - 1, K, C, random_state
)

# We always keep these on the CPU.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete this comment.

Comment thread skactiveml/pool/_query_by_committee.py Outdated
# Fit the ensemble.
if fit_ensemble:
ensemble = clone(ensemble).fit(X, y, sample_weight)
ensemble = copy.deepcopy(ensemble).fit(X, y, sample_weight)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check this cange

Comment thread skactiveml/pool/_query_by_committee.py Outdated

if hasattr(ensemble, "estimators_"):
if hasattr(ensemble, "estimators_") and \
len(ensemble.estimators_) > 0:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check this change

Comment thread skactiveml/pool/tests/test_bald.py Outdated
from skactiveml.utils import MISSING_LABEL, check_random_state


class TestBALD(TemplateSingleAnnotatorPoolQueryStrategy, unittest.TestCase):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TestBatchBALD

@@ -0,0 +1,295 @@
import unittest

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename file: test_batch_bald.py

Comment thread docs/examples/pool/_batch_bald.json Outdated
{
"class" : "BatchBALD",
"package" : "pool",
"method" : "Bayesian Active Learning by Disagreement (BALD",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"method" : "Bayesian Active Learning by Disagreement (BALD",
"method" : "Bayesian Active Learning by Disagreement (BALD)",

@mherde
mherde changed the base branch from master to development March 14, 2023 11:47
@mherde
mherde merged commit 37b1d9e into development Mar 14, 2023
@mherde
mherde deleted the 275-BALD branch March 14, 2023 11:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants