Skip to content

Commit

Permalink
Update pytorch plots (#177)
Browse files Browse the repository at this point in the history
+ update afr plots for power example
  • Loading branch information
simplymathematics authored Mar 28, 2024
1 parent 9b1de2f commit 104f954
Show file tree
Hide file tree
Showing 18 changed files with 3,080 additions and 2,837 deletions.
563 changes: 358 additions & 205 deletions deckard/layers/afr.py

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions deckard/layers/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ def parse_folder(folder, files=["params.yaml", "score_dict.json"]) -> pd.DataFra
path_gen.sort()
path_gen = list(set(path_gen))
path_gen.sort()
path_gen = list(set(path_gen))
path_gen.sort()
folder_gen = map(lambda x: x.parent, path_gen)
folder_gen = set(folder_gen)
results = {}
Expand All @@ -59,6 +61,8 @@ def parse_folder(folder, files=["params.yaml", "score_dict.json"]) -> pd.DataFra
df = pd.DataFrame(results).T
df = df.applymap(lambda x: x.strip() if isinstance(x, str) else x)
df.columns = df.columns.str.strip()
df = df.applymap(lambda x: x.strip() if isinstance(x, str) else x)
df.columns = df.columns.str.strip()
return df


Expand Down
14 changes: 14 additions & 0 deletions deckard/layers/plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ def cat_plot(
file,
folder,
legend_title=None,
x_lim=None,
y_lim=None,
hue_order=None,
rotation=0,
set={},
Expand Down Expand Up @@ -122,6 +124,10 @@ def cat_plot(
pass
graph.set_xticklabels(graph.axes.flat[-1].get_xticklabels(), rotation=rotation)
graph.set(**set)
if x_lim is not None:
graph.set(xlim=x_lim)
if y_lim is not None:
graph.set(ylim=y_lim)
graph.tight_layout()
graph.savefig(folder / file)
plt.gcf().clear()
Expand Down Expand Up @@ -229,6 +235,8 @@ def scatter_plot(
folder,
y_scale=None,
x_scale=None,
x_lim=None,
y_lim=None,
legend={},
hue_order=None,
filetype=".eps",
Expand Down Expand Up @@ -296,6 +304,10 @@ def scatter_plot(
graph.set_yscale(y_scale)
if x_scale is not None:
graph.set_xscale(x_scale)
if x_lim is not None:
graph.set_xlim(x_lim)
if y_lim is not None:
graph.set_ylim(y_lim)
graph.set_xlabel(xlabel)
graph.set_ylabel(ylabel)
graph.legend(**legend)
Expand Down Expand Up @@ -363,6 +375,7 @@ def main(args):
logger.info(f"Creating folder {FOLDER}")
FOLDER.mkdir(parents=True, exist_ok=True)
logger.info(f"Saving data to {FOLDER }")
logger.info(f"Saving data to {FOLDER }")
IMAGE_FILETYPE = (
args.plotfiletype
if args.plotfiletype.startswith(".")
Expand All @@ -382,6 +395,7 @@ def main(args):
for dict_ in line_plot_list:
line_plot(data, **dict_, folder=FOLDER, filetype=IMAGE_FILETYPE)

scatter_plot_list = big_dict.get("scatter_plot", [])
scatter_plot_list = big_dict.get("scatter_plot", [])
for dict_ in scatter_plot_list:
scatter_plot(data, **dict_, folder=FOLDER, filetype=IMAGE_FILETYPE)
Expand Down
16 changes: 10 additions & 6 deletions examples/gzip/.gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
output
*.db
kdd_nsl
truthseeker
ddos
sms_spam
/raw_data
.dvc/config
2-22/
2-28/
/params.yaml
.dvc/*
2-22/*
2-28/*
3-7/*
gzip/*
ddos/*
kdd_nsl/*
sms_spam/*
truthseeker/*
conf/*/best_*.yaml
Empty file removed examples/power/.dvc/config
Empty file.
122 changes: 62 additions & 60 deletions examples/power/conf/afr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,22 @@ weibull:
plot:
file : weibull_aft.pdf
title : Weibull AFR Model
labels:
"Intercept: rho_": "$\\rho$"
"Intercept: lambda_": "$\\lambda$"
"data.sample.random_state: lambda_": "Random State"
"atk_value: lambda_": "Attack Strength"
"train_time: lambda_": "$t_{train}$"
"predict_proba_time: lambda_": "$t_{predict}$"
"adv_accuracy: lambda_": "Adv. Accuracy"
"accuracy: lambda_": "Ben. Accuracy"
"adv_fit_time: lambda_": "$t_{attack}$"
"adv_failure_rate: lambda_": "$h_{adv.}(t;\\theta)$"
"failure_rate: lambda_": "$h_{ben.}(t;\\theta)$"
"model.trainer.nb_epoch: lambda_": "No. of Epochs"
"model.trainer.batch_size: lambda_": "Batch Size"
"def_gen": "Defence"
labels:
"Intercept: rho_": "$\\rho$"
"Intercept: lambda_": "$\\lambda$"
"data.sample.random_state: lambda_": "Random State"
"atk_value: lambda_": "Attack Strength"
"train_time: lambda_": "$t_{train}$"
"predict_proba_time: lambda_": "$t_{predict}$"
"adv_accuracy: lambda_": "Adv. Accuracy"
"accuracy: lambda_": "Ben. Accuracy"
"adv_fit_time: lambda_": "$t_{attack}$"
"adv_failure_rate: lambda_": "$h_{adv.}(t;\\theta)$"
"failure_rate: lambda_": "$h_{ben.}(t;\\theta)$"
"model.trainer.nb_epoch: lambda_": "No. of Epochs"
"model.trainer.batch_size: lambda_": "Batch Size"
"def_gen": "Defence"
"attack.init.eps: lambda_": "$\\varepsilon$"
partial_effect:
- "file": "weibull_epochs_partial_effect.pdf"
"covariate_array": "model.trainer.nb_epoch"
Expand All @@ -46,21 +47,20 @@ cox:
plot:
file : cox_aft.pdf
title : Cox AFR Model
labels:
"Intercept: rho_": "$\\rho$"
"Intercept: lambda_": "$\\lambda$"
"data.sample.random_state: lambda_": "Random State"
"atk_value: lambda_": "Attack Strength"
"train_time: lambda_": "$t_{train}$"
"predict_proba_time: lambda_": "$t_{predict}$"
"adv_accuracy: lambda_": "Adv. Accuracy"
"accuracy: lambda_": "Ben. Accuracy"
"adv_fit_time: lambda_": "$t_{attack}$"
"adv_failure_rate: lambda_": "$h_{adv.}(t;\\theta)$"
"failure_rate: lambda_": "$h_{ben.}(t;\\theta)$"
"model.trainer.nb_epoch: lambda_": "No. of Epochs"
"model.trainer.batch_size: lambda_": "Batch Size"
"def_gen": "Defence"
labels:
"data.sample.random_state": "Random State"
"atk_value": "Attack Strength"
"train_time": "$t_{train}$"
"predict_proba_time": "$t_{predict}$"
"adv_accuracy": "Adv. Accuracy"
"accuracy": "Ben. Accuracy"
"adv_fit_time": "$t_{attack}$"
"adv_failure_rate": "$h_{adv.}(t;\\theta)$"
"failure_rate": "$h_{ben.}(t;\\theta)$"
"model.trainer.nb_epoch": "No. of Epochs"
"model.trainer.batch_size": "Batch Size"
"def_gen": "Defence"
"attack.init.eps": "$\\varepsilon$"
partial_effect:
- "file": "cox_epochs_partial_effect.pdf"
"covariate_array": "model.trainer.nb_epoch"
Expand All @@ -76,21 +76,22 @@ log_logistic:
plot:
file : log_logistic_aft.pdf
title : Log logistic AFR Model
labels:
"Intercept: rho_": "$\\rho$"
"Intercept: lambda_": "$\\lambda$"
"data.sample.random_state: lambda_": "Random State"
"atk_value: lambda_": "Attack Strength"
"train_time: lambda_": "$t_{train}$"
"predict_proba_time: lambda_": "$t_{predict}$"
"adv_accuracy: lambda_": "Adv. Accuracy"
"accuracy: lambda_": "Ben. Accuracy"
"adv_fit_time: lambda_": "$t_{attack}$"
"adv_failure_rate: lambda_": "$h_{adv.}(t;\\theta)$"
"failure_rate: lambda_": "$h_{ben.}(t;\\theta)$"
"model.trainer.nb_epoch: lambda_": "No. of Epochs"
"model.trainer.batch_size: lambda_": "Batch Size"
"def_gen": "Defence"
labels:
"Intercept: beta_": "$\\beta$"
"Intercept: alpha_": "$\\alpha$"
"data.sample.random_state: alpha_": "Random State"
"atk_value: alpha_": "Attack Strength"
"train_time: alpha_": "$t_{train}$"
"predict_proba_time: alpha_": "$t_{predict}$"
"adv_accuracy: alpha_": "Adv. Accuracy"
"accuracy: alpha_": "Ben. Accuracy"
"adv_fit_time: alpha_": "$t_{attack}$"
"adv_failure_rate: alpha_": "$h_{adv.}(t;\\theta)$"
"failure_rate: alpha_": "$h_{ben.}(t;\\theta)$"
"model.trainer.nb_epoch: alpha_": "No. of Epochs"
"model.trainer.batch_size: alpha_": "Batch Size"
"def_gen": "Defence"
"attack.init.eps: alpha_": "$\\varepsilon$"
partial_effect:
- "file": "log_logistic_epochs_partial_effect.pdf"
"covariate_array": "model.trainer.nb_epoch"
Expand All @@ -106,21 +107,22 @@ log_normal:
plot:
file : log_normal_aft.pdf
title : Log Normal AFR Model
labels:
"Intercept: rho_": "$\\rho$"
"Intercept: lambda_": "$\\lambda$"
"data.sample.random_state: lambda_": "Random State"
"atk_value: lambda_": "Attack Strength"
"train_time: lambda_": "$t_{train}$"
"predict_proba_time: lambda_": "$t_{predict}$"
"adv_accuracy: lambda_": "Adv. Accuracy"
"accuracy: lambda_": "Ben. Accuracy"
"adv_fit_time: lambda_": "$t_{attack}$"
"adv_failure_rate: lambda_": "$h_{adv.}(t;\\theta)$"
"failure_rate: lambda_": "$h_{ben.}(t;\\theta)$"
"model.trainer.nb_epoch: lambda_": "No. of Epochs"
"model.trainer.batch_size: lambda_": "Batch Size"
"def_gen": "Defence"
labels:
"Intercept: sigma_": "$\\sigma$"
"Intercept: mu_": "$\\mu$"
"atk_value: mu_": "Attack Strength"
"train_time: mu_": "$t_{train}$"
"predict_proba_time: mu_": "$t_{predict}$"
"adv_accuracy: mu_": "Adv. Accuracy"
"accuracy: mu_": "Ben. Accuracy"
"adv_fit_time: mu_": "$t_{attack}$"
"adv_failure_rate: mu_": "$h_{adv.}(t;\\theta)$"
"failure_rate: mu_": "$h_{ben.}(t;\\theta)$"
"model.trainer.nb_epoch: mu_": "No. of Epochs"
"model.trainer.batch_size: mu_": "Batch Size"
"def_gen": "Defence"
"attack.init.eps: mu_": "$\\varepsilon$"
"data.sample.random_state: mu_": "Random State"
partial_effect:
- "file": "log_normal_epochs_partial_effect.pdf"
"covariate_array": "model.trainer.nb_epoch"
Expand Down
Loading

0 comments on commit 104f954

Please sign in to comment.