1
+ from hyperopt import hp
1
2
from lenskit .als import BiasedMFScorer , ImplicitMFScorer
2
3
from ConfigSpace import ConfigurationSpace , UniformIntegerHyperparameter , UniformFloatHyperparameter , CategoricalHyperparameter
3
4
@@ -8,16 +9,26 @@ def __init__(self, features, feedback="implicit", **kwargs):
8
9
self .features = features # store the features as an instance variable for testing
9
10
10
11
@staticmethod
11
- def get_default_configspace (** kwargs ):
12
+ def get_default_configspace (hyperopt = False , ** kwargs ):
12
13
"""
13
- return default configurationspace
14
+ return default (hyperopt) configurationspace
14
15
"""
15
- features = UniformIntegerHyperparameter ('features' , lower = 5 , upper = 10000 , default_value = 1000 , log = True )
16
- ureg = UniformFloatHyperparameter ('ureg' , lower = 0.01 , upper = 0.1 , default_value = 0.1 , log = True )
17
- ireg = UniformFloatHyperparameter ('ireg' , lower = 0.01 , upper = 0.1 , default_value = 0.1 , log = True )
16
+ if hyperopt :
17
+ cs = {
18
+ "algo" : "ImplicitMF" ,
19
+ "features" : hp .uniformint ("features" , 5 , 10000 ),
20
+ "ureq" : hp .uniform ("ureq" , 0.01 , 0.1 ),
21
+ "ireq" : hp .uniform ("ireq" , 0.01 , 0.1 ),
22
+ }
23
+
24
+ else :
25
+ features = UniformIntegerHyperparameter ('features' , lower = 5 , upper = 10000 , default_value = 1000 , log = True )
26
+ ureg = UniformFloatHyperparameter ('ureg' , lower = 0.01 , upper = 0.1 , default_value = 0.1 , log = True )
27
+ ireg = UniformFloatHyperparameter ('ireg' , lower = 0.01 , upper = 0.1 , default_value = 0.1 , log = True )
28
+
29
+ cs = ConfigurationSpace ()
30
+ cs .add ([features , ureg , ireg ])
18
31
19
- cs = ConfigurationSpace ()
20
- cs .add ([features , ureg , ireg ])
21
32
return cs
22
33
23
34
@@ -28,39 +39,51 @@ def __init__(self, features, feedback="explicit", **kwargs):
28
39
self .features = features # store the features as an instance variable for testing
29
40
30
41
@staticmethod
31
- def get_default_configspace (** kwargs ):
42
+ def get_default_configspace (hyperopt = False , ** kwargs ):
32
43
"""
33
44
return default configuration spaces for hyperparameter
34
45
"""
35
46
36
- """
37
- The authors of the original ALS paper (https://link.springer.com/chapter/10.1007/978-3-540-68880-8_32) stated:
38
- The most important discovery we made is that ALS-WR never overfits the data if we either increase
39
- the number of iterations or the number of hidden features.
40
- The paper stated that the improvement of the performance maximized around 1000 features.
41
- Therefore, we will set the upper bound and the default value of features to 10000.
42
- Since the authors just evaluated on one larger dataset, we still allow smaller and larger feature numbers
43
- but set the default value to 1000.
44
- """
45
- # features = Integer('features', bounds=(2, 10000), default=1000, log=True) # No default value given
46
- # no default value given but we set the default value to 1000???
47
- features = UniformIntegerHyperparameter ('features' , lower = 2 , upper = 10000 , default_value = 1000 , log = True )
48
- """
49
- The authors of the original ALS paper set the range of the regularization hyperparameter to from 0.03 - 0.065.
50
- https://link.springer.com/chapter/10.1007/978-3-540-68880-8_32
51
- Therefore we set the lower bound of the two regularization parameters (ureg and ireg) to 0.065.
52
- LensKit sets the default regularization hyperparameter to 0.1 Therefore we set the upper bound of the two
53
- regularization parameters (ureg and ireg) to 0.1.
54
- """
55
- ureg = UniformFloatHyperparameter ('ureg' , lower = 0.01 , upper = 0.1 , default_value = 0.1 , log = True )
56
- ireg = UniformFloatHyperparameter ('ireg' , lower = 0.01 , upper = 0.1 , default_value = 0.1 , log = True )
47
+ if hyperopt :
48
+ cs = {
49
+ "algo" : "ALSBiasedMF" ,
50
+ "features" : hp .uniformint ("features" , 2 , 10000 ),
51
+ "ureq" : hp .uniform ("ureq" , 0.01 , 0.1 ),
52
+ "ireq" : hp .uniform ("ireq" , 0.01 , 0.1 ),
53
+ "bias" : hp .choice ("bias" , [True , False ]),
54
+ }
57
55
58
- """
59
- The damping hyperparameter en- or disables a damping factor.
60
- In the future we may want to tune the damping values as well.
61
- """
62
- bias = CategoricalHyperparameter ('bias' , choices = [True , False ], default_value = True )
56
+ else :
57
+
58
+ """
59
+ The authors of the original ALS paper (https://link.springer.com/chapter/10.1007/978-3-540-68880-8_32) stated:
60
+ The most important discovery we made is that ALS-WR never overfits the data if we either increase
61
+ the number of iterations or the number of hidden features.
62
+ The paper stated that the improvement of the performance maximized around 1000 features.
63
+ Therefore, we will set the upper bound and the default value of features to 10000.
64
+ Since the authors just evaluated on one larger dataset, we still allow smaller and larger feature numbers
65
+ but set the default value to 1000.
66
+ """
67
+ # features = Integer('features', bounds=(2, 10000), default=1000, log=True) # No default value given
68
+ # no default value given but we set the default value to 1000???
69
+ features = UniformIntegerHyperparameter ('features' , lower = 2 , upper = 10000 , default_value = 1000 , log = True )
70
+ """
71
+ The authors of the original ALS paper set the range of the regularization hyperparameter to from 0.03 - 0.065.
72
+ https://link.springer.com/chapter/10.1007/978-3-540-68880-8_32
73
+ Therefore we set the lower bound of the two regularization parameters (ureg and ireg) to 0.065.
74
+ LensKit sets the default regularization hyperparameter to 0.1 Therefore we set the upper bound of the two
75
+ regularization parameters (ureg and ireg) to 0.1.
76
+ """
77
+ ureg = UniformFloatHyperparameter ('ureg' , lower = 0.01 , upper = 0.1 , default_value = 0.1 , log = True )
78
+ ireg = UniformFloatHyperparameter ('ireg' , lower = 0.01 , upper = 0.1 , default_value = 0.1 , log = True )
79
+
80
+ """
81
+ The damping hyperparameter en- or disables a damping factor.
82
+ In the future we may want to tune the damping values as well.
83
+ """
84
+ bias = CategoricalHyperparameter ('bias' , choices = [True , False ], default_value = True )
85
+
86
+ cs = ConfigurationSpace ()
87
+ cs .add ([features , ureg , ireg , bias ])
63
88
64
- cs = ConfigurationSpace ()
65
- cs .add ([features , ureg , ireg , bias ])
66
89
return cs
0 commit comments