From 8e270be31ed76118b83ebfd335b0c34468f62fc4 Mon Sep 17 00:00:00 2001 From: albertfrancajosuacosta Date: Sat, 9 Sep 2023 23:00:06 -0300 Subject: [PATCH] Create class fixed_uncertainty.py. --- __init__.py | 7 ++++- base.py | 2 ++ fixed_uncertainty.py | 67 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 fixed_uncertainty.py diff --git a/__init__.py b/__init__.py index 93177a0..6f65cbb 100644 --- a/__init__.py +++ b/__init__.py @@ -5,4 +5,9 @@ @email: albertfrancajosuacosta@gmail.com """ -from .import base \ No newline at end of file +from .import base +from .fixed_uncertainty import FixedUncertainty +from .random_variable_uncertainty import RandomVariableUncertainty +from .variable_uncertainty import VariableUncertainty + +__all__ = ["base", "FixedUncertainty", "RandomVariableUncertainty", "VariableUncertainty"] \ No newline at end of file diff --git a/base.py b/base.py index cee99af..3f7d4d7 100644 --- a/base.py +++ b/base.py @@ -7,6 +7,8 @@ import abc +__all__ = ["ActiveLearningBase"] + class ActiveLearningBase(): """ Base classe for Active Learning Library """ diff --git a/fixed_uncertainty.py b/fixed_uncertainty.py new file mode 100644 index 0000000..3fea69c --- /dev/null +++ b/fixed_uncertainty.py @@ -0,0 +1,67 @@ +""" +Active Learning 18 + +@author: Albert França Josuá Costa +@email: albertfrancajosuacosta@gmail.com +""" + + +from .base import ActiveLearningBase + + + +class FixedUncertainty(ActiveLearningBase): + + """Strategy of Active Learning to select instances more significative based on uncertainty. + + The fixed uncertainty sampler selects samples for labeling based on the uncertainty of the prediction. + The higher the uncertainty, the more likely the sample will be selected for labeling. The uncertainty + measure is compared with a fixed uncertainty limit. + + + References + ---------- + [^1]: I. Zliobaite, A. Bifet, B.Pfahringer, G. Holmes. “Active Learning with Drifting Streaming Data”, IEEE Transactions on Neural Netowrks and Learning Systems, Vol.25 (1), pp.27-39, 2014. + +""" + + def __init__(self, theta: float = 0.95, seed=None): + super().__init__() + self.theta = theta + + + def describe(self): + print('Strategy of Active Learning to select instances more significative based on uncertainty.'+ + 'The fixed uncertainty sampler selects samples for labeling based on the uncertainty of the prediction.'+ + 'The higher the uncertainty, the more likely the sample will be selected for labeling. The uncertainty'+ + 'measure is compared with a fixed uncertainty limit.'+ + 'References [^1]: I. Zliobaite, A. Bifet, B.Pfahringer, G. Holmes. “Active Learning with Drifting Streaming Data”, IEEE Transactions on Neural Netowrks and Learning Systems, Vol.25 (1), pp.27-39, 2014.') + + def isSignificative(self, x, y_pred) -> bool: + """Ask for the label of a current instance. + + Based on the uncertainty of the base classifier, it checks whether the current instance should be labeled. + + Parameters + ---------- + x + Instance + + y_pred + + Arrays of predicted labels + + + Returns + ------- + selected + A boolean indicating whether a label is needed. + True for selected instance. + False for not selecte instance. + + """ + maximum_posteriori = max(y_pred.values()) + selected = False + if maximum_posteriori < self.theta: + selected = True + return selected \ No newline at end of file