1
- from typing import Literal , Union
1
+ from typing import Literal , Optional , Union
2
2
3
3
import numpy as np
4
4
import pandas as pd
@@ -37,18 +37,63 @@ class MaximizeSigmoidObjective(SigmoidObjective):
37
37
38
38
type : Literal ["MaximizeSigmoidObjective" ] = "MaximizeSigmoidObjective"
39
39
40
- def __call__ (self , x : Union [pd .Series , np .ndarray ]) -> Union [pd .Series , np .ndarray ]:
40
+ def __call__ (
41
+ self ,
42
+ x : Union [pd .Series , np .ndarray ],
43
+ x_adapt : Optional [Union [pd .Series , np .ndarray ]] = None ,
44
+ ) -> Union [pd .Series , np .ndarray ]:
41
45
"""The call function returning a sigmoid shaped reward for passed x values.
42
46
43
47
Args:
44
48
x (np.ndarray): An array of x values
49
+ x_adapt (np.ndarray): An array of x values which are used to update the objective parameters on the fly.
45
50
46
51
Returns:
47
52
np.ndarray: A reward calculated with a sigmoid function. The stepness and the tipping point can be modified via passed arguments.
48
53
"""
49
54
return 1 / (1 + np .exp (- 1 * self .steepness * (x - self .tp )))
50
55
51
56
57
+ class MovingMaximizeSigmoidObjective (SigmoidObjective ):
58
+ """Class for a maximizing sigmoid objective with a moving turning point that depends on so far observed x values.
59
+
60
+ Attributes:
61
+ w (float): float between zero and one for weighting the objective when used in a weighting based strategy.
62
+ steepness (float): Steepness of the sigmoid function. Has to be greater than zero.
63
+ tp (float): Relative turning point of the sigmoid function. The actual turning point is calculated by adding
64
+ the maximum of the observed x values to the relative turning point.
65
+ """
66
+
67
+ type : Literal ["MovingMaximizeSigmoidObjective" ] = "MovingMaximizeSigmoidObjective"
68
+
69
+ def get_adjusted_tp (self , x : Union [pd .Series , np .ndarray ]) -> float :
70
+ """Get the adjusted turning point for the sigmoid function.
71
+
72
+ Args:
73
+ x (np.ndarray): An array of x values
74
+
75
+ Returns:
76
+ float: The adjusted turning point for the sigmoid function.
77
+ """
78
+ return x .max () + self .tp
79
+
80
+ def __call__ (
81
+ self , x : Union [pd .Series , np .ndarray ], x_adapt : Union [pd .Series , np .ndarray ]
82
+ ) -> Union [pd .Series , np .ndarray ]:
83
+ """The call function returning a sigmoid shaped reward for passed x values.
84
+
85
+ Args:
86
+ x (np.ndarray): An array of x values
87
+ x_adapt (np.ndarray): An array of x values which are used to update the objective parameters on the fly.
88
+
89
+ Returns:
90
+ np.ndarray: A reward calculated with a sigmoid function. The stepness and the tipping point can be modified via passed arguments.
91
+ """
92
+ return 1 / (
93
+ 1 + np .exp (- 1 * self .steepness * (x - self .get_adjusted_tp (x_adapt )))
94
+ )
95
+
96
+
52
97
class MinimizeSigmoidObjective (SigmoidObjective ):
53
98
"""Class for a minimizing a sigmoid objective
54
99
@@ -60,11 +105,16 @@ class MinimizeSigmoidObjective(SigmoidObjective):
60
105
61
106
type : Literal ["MinimizeSigmoidObjective" ] = "MinimizeSigmoidObjective"
62
107
63
- def __call__ (self , x : Union [pd .Series , np .ndarray ]) -> Union [pd .Series , np .ndarray ]:
108
+ def __call__ (
109
+ self ,
110
+ x : Union [pd .Series , np .ndarray ],
111
+ x_adapt : Optional [Union [pd .Series , np .ndarray ]] = None ,
112
+ ) -> Union [pd .Series , np .ndarray ]:
64
113
"""The call function returning a sigmoid shaped reward for passed x values.
65
114
66
115
Args:
67
116
x (np.ndarray): An array of x values
117
+ x_adapt (np.ndarray): An array of x values which are used to update the objective parameters on the fly.
68
118
69
119
Returns:
70
120
np.ndarray: A reward calculated with a sigmoid function. The stepness and the tipping point can be modified via passed arguments.
0 commit comments