forked from wbpowell328/stochastic-optimization
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAdaptiveMarketPlanningPolicy.py
51 lines (34 loc) · 1.37 KB
/
AdaptiveMarketPlanningPolicy.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
"""
Adaptive Market Planning Policy class
"""
from collections import namedtuple
import numpy as np
from copy import copy
from AdaptiveMarketPlanningModel import AdaptiveMarketPlanningModel
class AdaptiveMarketPlanningPolicy():
"""
Base class for policy
"""
def __init__(self, AdaptiveMarketPlanningModel, theta_step):
"""
Initializes the model
:param AdaptiveMarketPlanningModel: AdaptiveMarketPlanningModel - model to construct decision for
:param theta_step: float - theta step variable
"""
self.M = AdaptiveMarketPlanningModel
self.theta_step = theta_step
# returns decision based on harmonic step size policy
def harmonic_rule(self):
return self.M.build_decision({'step_size': self.theta_step / (self.theta_step + self.M.t - 1)})
# returns decision based on Kesten's rule policy
def kesten_rule(self):
return self.M.build_decision({'step_size': self.theta_step / (self.theta_step + self.M.state.counter - 1)})
# returns decision based on a constant rule policy
def constant_rule(self):
return self.M.build_decision({'step_size': self.theta_step})
# returns decision based on a constant rule policy
def run_policy(self):
model_copy = copy(self.M)
for t in range(model_copy.T):
model_copy.step(AdaptiveMarketPlanningPolicy(model_copy, self.theta_step).kesten_rule())
return (model_copy.obj,model_copy.learning_list.copy())