-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrandom_variable_uncertainty.py
73 lines (47 loc) · 1.89 KB
/
random_variable_uncertainty.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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