Skip to content

Commit

Permalink
Create class fixed_uncertainty.py.
Browse files Browse the repository at this point in the history
  • Loading branch information
albertfrancajosuacosta committed Sep 10, 2023
1 parent 3f33ea9 commit 8e270be
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 1 deletion.
7 changes: 6 additions & 1 deletion __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,9 @@
@email: [email protected]
"""

from .import base
from .import base
from .fixed_uncertainty import FixedUncertainty
from .random_variable_uncertainty import RandomVariableUncertainty
from .variable_uncertainty import VariableUncertainty

__all__ = ["base", "FixedUncertainty", "RandomVariableUncertainty", "VariableUncertainty"]
2 changes: 2 additions & 0 deletions base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

import abc

__all__ = ["ActiveLearningBase"]

class ActiveLearningBase():

""" Base classe for Active Learning Library """
Expand Down
67 changes: 67 additions & 0 deletions fixed_uncertainty.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
"""
Active Learning 18
@author: Albert França Josuá Costa
@email: [email protected]
"""


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

0 comments on commit 8e270be

Please sign in to comment.