Skip to content

Changed ActiveLearner to be generic in Data #13

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
12 changes: 6 additions & 6 deletions enn/active_learning/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
import typing as tp

import chex
from enn import base as enn_base
from enn import networks
from enn.datasets import base as ds_base
import haiku as hk
import typing_extensions


class ActiveLearner(abc.ABC):
class ActiveLearner(abc.ABC, tp.Generic[enn_base.Data]):
"""Samples a batch from a pool of data for learning.

An active learner selects an "acquisition batch" with acquisition_size
Expand All @@ -38,9 +38,9 @@ def sample_batch(
self,
params: hk.Params,
state: hk.State,
batch: ds_base.ArrayBatch,
batch: enn_base.Data,
key: chex.PRNGKey,
) -> ds_base.ArrayBatch:
) -> enn_base.Data:
"""Samples a batch from a pool of data for learning."""

@property
Expand All @@ -57,13 +57,13 @@ def acquisition_size(self, size: int) -> None:
PriorityOutput = tp.Tuple[chex.Array, tp.Dict[str, chex.Array]]


class PriorityFn(typing_extensions.Protocol):
class PriorityFn(typing_extensions.Protocol[enn_base.Data]):

def __call__(
self,
params: hk.Params,
state: hk.State,
batch: ds_base.ArrayBatch,
batch: enn_base.Data,
key: chex.PRNGKey,
) -> PriorityOutput:
"""Assigns a priority score to a batch."""
Expand Down
2 changes: 1 addition & 1 deletion enn/active_learning/prioritized.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import jax.numpy as jnp


class PrioritizedBatcher(base.ActiveLearner):
class PrioritizedBatcher(base.ActiveLearner[datasets.ArrayBatch]):
"""Prioritizes bathces based on a priority fn."""

def __init__(
Expand Down