-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create classes random_variable_uncertainty.py and variable_uncertaint…
…y.py.
- Loading branch information
1 parent
8e270be
commit 3837d42
Showing
4 changed files
with
146 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
""" | ||
Active Learning 18 | ||
@author: Albert França Josuá Costa | ||
@email: [email protected] | ||
""" | ||
|
||
import numpy as np | ||
|
||
from .base import ActiveLearningBase | ||
|
||
|
||
|
||
class RandomVariableUncertainty (ActiveLearningBase): | ||
|
||
r"""Strategy of Active Learning to select instances more significative based on uncertainty. | ||
The random variable 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 random variable 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, s=0.5, delta=1.0): | ||
super().__init__() | ||
|
||
self.theta = theta | ||
self.s = s | ||
self.delta = delta | ||
|
||
|
||
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 | ||
|
||
thetaRand = self.theta * np.random.normal(1,self.delta) | ||
|
||
if maximum_posteriori < thetaRand: | ||
self.theta = self.theta*(1-self.s) | ||
selected = True | ||
else: | ||
self.theta = self.theta*(1+self.s) | ||
selected = False | ||
|
||
return selected |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
""" | ||
Active Learning 18 | ||
@author: Albert França Josuá Costa | ||
@email: [email protected] | ||
""" | ||
|
||
|
||
from .base import ActiveLearningBase | ||
|
||
|
||
|
||
class VariableUncertainty (ActiveLearningBase): | ||
|
||
r"""Strategy of Active Learning to select instances more significative based on uncertainty. | ||
The variable 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 random variable 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, s=0.5): | ||
super().__init__() | ||
|
||
self.theta = theta | ||
self.s = s | ||
|
||
|
||
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: | ||
self.theta = self.theta*(1-self.s) | ||
selected = True | ||
else: | ||
self.theta = self.theta*(1+self.s) | ||
selected = False | ||
|
||
return selected |