-
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.
modify context distribution and add summaries
- Loading branch information
Showing
8 changed files
with
134 additions
and
50 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,35 @@ | ||
from typing import List | ||
from typing import List, Dict | ||
from scipy.stats import randint, bernoulli, uniform, norm | ||
|
||
import numpy as np | ||
|
||
|
||
class ContextAllocateData: | ||
values: List[float] | ||
allocations: List[float] | ||
min_val: float | ||
max_val: float | ||
type: str | ||
normalize: bool | ||
distribution: Dict | ||
|
||
def __init__(self, values: List, allocations: List) -> None: | ||
if len(values) == 0: | ||
print("no context values!") | ||
return None | ||
def __init__(self, min_val: float, max_val: float, type: str, normalize: bool, distribution: Dict) -> None: | ||
self.min_val = min_val | ||
self.max_val = max_val | ||
self.type = type | ||
self.normalize = normalize | ||
self.distribution = distribution | ||
|
||
if len(values) != len(allocations): | ||
print("can't allocate context values!") | ||
return None | ||
|
||
if sum(allocations) != 1: | ||
print("allocation invalid!") | ||
return None | ||
def get_rvs(self) -> float: | ||
distribution_copy = self.distribution.copy() | ||
dis_type = distribution_copy.pop('type', None) | ||
|
||
self.values = values | ||
self.allocations = allocations | ||
if dis_type is not None: | ||
random_val = eval(dis_type).rvs(**distribution_copy) | ||
if self.type != "CONT": | ||
random_val = np.floor(random_val) | ||
random_val = np.clip(random_val, self.min_val, self.max_val) | ||
|
||
if self.normalize: | ||
random_val = (random_val - self.min_val) / (self.max_val - self.min_val) | ||
|
||
return round(random_val, 2) | ||
return None |
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,8 @@ | ||
import pandas as pd | ||
import numpy as np | ||
|
||
|
||
def arm_summary(simulation_df: pd.DataFrame, reward_name: str) -> pd.DataFrame: | ||
arm_group = simulation_df.groupby(by=["arm"]).agg({reward_name: ['min', 'max', 'mean', 'std', 'sem', 'count'], 'arm' : ['count']}) | ||
|
||
return arm_group.unstack(level=0).unstack() |
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,8 @@ | ||
import pandas as pd | ||
import numpy as np | ||
|
||
|
||
def context_summary(simulation_df: pd.DataFrame, reward_name: str, context: str) -> pd.DataFrame: | ||
context_group = simulation_df.groupby(by=[context, "arm"]).agg({reward_name: ['min', 'max', 'mean', 'std', 'sem', 'count'], 'arm' : ['count']}) | ||
|
||
return context_group.stack(level=[0, 1]).unstack(level=[1, 0]) |
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 |
---|---|---|
|
@@ -7,3 +7,4 @@ scipy==1.8.0 | |
six==1.16.0 | ||
termcolor==1.1.0 | ||
tqdm==4.64.0 | ||
xlsxwriter |