From f5049beae15e22d2a9e3c82f862c2104fe9a90c3 Mon Sep 17 00:00:00 2001 From: Leona Odole Date: Thu, 13 Mar 2025 12:49:04 +0100 Subject: [PATCH 1/5] added examples to standardize transformation documentation --- bayesflow/adapters/transforms/standardize.py | 29 ++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/bayesflow/adapters/transforms/standardize.py b/bayesflow/adapters/transforms/standardize.py index de5cdcfa7..aa5b1c0d9 100644 --- a/bayesflow/adapters/transforms/standardize.py +++ b/bayesflow/adapters/transforms/standardize.py @@ -16,6 +16,8 @@ class Standardize(ElementwiseTransform): z = (x - mean(x))/std(x) + Important to note that when specifying a mean and sd user should be careful to specify which variables should be standardized. Please see examples. + Parameters: mean: integer or float used to specify a mean if known but will be estimated from data when not provided std: integer or float used to specify a standard devation if known but will be estimated from data when not provided @@ -23,6 +25,33 @@ class Standardize(ElementwiseTransform): standardization happens individually for each dimension momentum: float in (0,1) specifying the momentum during training + Examples: + + 1) Standardize all variables using estimated mean and standard deviation + + adapter = ( + bf.adapters.Adapter() + .standardize() + ) + + + 2) Standardize all with same known mean and standard deviation. In this example all data is drawn from a standard normal + + adapter = ( + bf.adapters.Adapter() + .standardize(mean = 1, sd = 0) + ) + + + 3) Mix of specified and auto-computed means/sds. Suppose we have priors for "beta" and "sigma" where we know the mean and standard deviations. However for our simulated data "x" and "y" the mean and standard deviations are unknown. Then standardize should be used in several stages specifying which variables to include or exclude. + + adapter = ( + bf.adapters.Adapter() + .standardize(include = "beta", mean = 1) # specify only mean/sd + .standardize(include = "sigma", mean = 0.6, sd = 1) # specify both mean and sd + .standardize(exclude = ["beta", "sigma"]) # specify neither mean nor sd + ) + """ def __init__( From 47f72abbca04f8d9d32c073dd473162cd44d40a1 Mon Sep 17 00:00:00 2001 From: Leona Odole Date: Thu, 13 Mar 2025 12:53:46 +0100 Subject: [PATCH 2/5] ran linter --- bayesflow/adapters/transforms/standardize.py | 27 ++++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/bayesflow/adapters/transforms/standardize.py b/bayesflow/adapters/transforms/standardize.py index aa5b1c0d9..de52b4e6a 100644 --- a/bayesflow/adapters/transforms/standardize.py +++ b/bayesflow/adapters/transforms/standardize.py @@ -16,7 +16,8 @@ class Standardize(ElementwiseTransform): z = (x - mean(x))/std(x) - Important to note that when specifying a mean and sd user should be careful to specify which variables should be standardized. Please see examples. + Important to note that when specifying a mean and sd user should be careful to specify which variables should + be standardized. Please see examples. Parameters: mean: integer or float used to specify a mean if known but will be estimated from data when not provided @@ -25,31 +26,35 @@ class Standardize(ElementwiseTransform): standardization happens individually for each dimension momentum: float in (0,1) specifying the momentum during training - Examples: + Examples: + + 1) Standardize all variables using estimated mean and standard deviation - 1) Standardize all variables using estimated mean and standard deviation - adapter = ( bf.adapters.Adapter() .standardize() ) - - 2) Standardize all with same known mean and standard deviation. In this example all data is drawn from a standard normal + + 2) Standardize all with same known mean and standard deviation. In this example all data is drawn from a + standard normal adapter = ( bf.adapters.Adapter() .standardize(mean = 1, sd = 0) ) - - 3) Mix of specified and auto-computed means/sds. Suppose we have priors for "beta" and "sigma" where we know the mean and standard deviations. However for our simulated data "x" and "y" the mean and standard deviations are unknown. Then standardize should be used in several stages specifying which variables to include or exclude. - + + 3) Mix of specified and auto-computed means/sds. Suppose we have priors for "beta" and "sigma" where we + know the mean and standard deviations. However for our simulated data "x" and "y" the mean and standard + deviations are unknown. Then standardize should be used in several stages specifying which variables to + include or exclude. + adapter = ( bf.adapters.Adapter() .standardize(include = "beta", mean = 1) # specify only mean/sd - .standardize(include = "sigma", mean = 0.6, sd = 1) # specify both mean and sd - .standardize(exclude = ["beta", "sigma"]) # specify neither mean nor sd + .standardize(include = "sigma", mean = 0.6, sd = 1) # specify both mean and sd + .standardize(exclude = ["beta", "sigma"]) # specify neither mean nor sd ) """ From e0161785b044eb9fe50a0e979008784ea52241ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul-Christian=20B=C3=BCrkner?= Date: Fri, 14 Mar 2025 09:16:30 +0100 Subject: [PATCH 3/5] improve standardize doc further --- bayesflow/adapters/transforms/standardize.py | 30 +++++++++----------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/bayesflow/adapters/transforms/standardize.py b/bayesflow/adapters/transforms/standardize.py index de52b4e6a..bf629477d 100644 --- a/bayesflow/adapters/transforms/standardize.py +++ b/bayesflow/adapters/transforms/standardize.py @@ -12,12 +12,9 @@ class Standardize(ElementwiseTransform): """ Transform that when applied standardizes data using typical z-score standardization i.e. for some unstandardized - data x the standardized version z would be + data x the standardized version z would be - z = (x - mean(x))/std(x) - - Important to note that when specifying a mean and sd user should be careful to specify which variables should - be standardized. Please see examples. + z = (x - mean(x)) / std(x) Parameters: mean: integer or float used to specify a mean if known but will be estimated from data when not provided @@ -28,7 +25,7 @@ class Standardize(ElementwiseTransform): Examples: - 1) Standardize all variables using estimated mean and standard deviation + 1) Standardize all variables using their individually estimated mean and stds. adapter = ( bf.adapters.Adapter() @@ -36,25 +33,26 @@ class Standardize(ElementwiseTransform): ) - 2) Standardize all with same known mean and standard deviation. In this example all data is drawn from a - standard normal + 2) Standardize all with same known mean and std. adapter = ( bf.adapters.Adapter() - .standardize(mean = 1, sd = 0) + .standardize(mean = 5, sd = 10) ) - 3) Mix of specified and auto-computed means/sds. Suppose we have priors for "beta" and "sigma" where we - know the mean and standard deviations. However for our simulated data "x" and "y" the mean and standard - deviations are unknown. Then standardize should be used in several stages specifying which variables to - include or exclude. + 3) Mix of fixed and estimated means/stds. Suppose we have priors for "beta" and "sigma" where we + know the means and stds. However for all other variables, the means and stds are unknown. + Then standardize should be used in several stages specifying which variables to include or exclude. adapter = ( bf.adapters.Adapter() - .standardize(include = "beta", mean = 1) # specify only mean/sd - .standardize(include = "sigma", mean = 0.6, sd = 1) # specify both mean and sd - .standardize(exclude = ["beta", "sigma"]) # specify neither mean nor sd + # mean fixed, std estimated + .standardize(include = "beta", mean = 1) + # both mean and SD fixed + .standardize(include = "sigma", mean = 0.6, sd = 3) + # both means and stds estimated for all other variables + .standardize(exclude = ["beta", "sigma"]) ) """ From f9f7b90640622a2738b5a8c82af03a85d7f05380 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul-Christian=20B=C3=BCrkner?= Date: Fri, 14 Mar 2025 09:18:25 +0100 Subject: [PATCH 4/5] rerun linter --- bayesflow/adapters/transforms/standardize.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/bayesflow/adapters/transforms/standardize.py b/bayesflow/adapters/transforms/standardize.py index bf629477d..275a750e4 100644 --- a/bayesflow/adapters/transforms/standardize.py +++ b/bayesflow/adapters/transforms/standardize.py @@ -33,7 +33,7 @@ class Standardize(ElementwiseTransform): ) - 2) Standardize all with same known mean and std. + 2) Standardize all with same known mean and std. adapter = ( bf.adapters.Adapter() @@ -42,17 +42,17 @@ class Standardize(ElementwiseTransform): 3) Mix of fixed and estimated means/stds. Suppose we have priors for "beta" and "sigma" where we - know the means and stds. However for all other variables, the means and stds are unknown. + know the means and stds. However for all other variables, the means and stds are unknown. Then standardize should be used in several stages specifying which variables to include or exclude. adapter = ( bf.adapters.Adapter() # mean fixed, std estimated - .standardize(include = "beta", mean = 1) + .standardize(include = "beta", mean = 1) # both mean and SD fixed - .standardize(include = "sigma", mean = 0.6, sd = 3) + .standardize(include = "sigma", mean = 0.6, sd = 3) # both means and stds estimated for all other variables - .standardize(exclude = ["beta", "sigma"]) + .standardize(exclude = ["beta", "sigma"]) ) """ From 6ff52d3804114426988484fd0307251e2a789704 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul-Christian=20B=C3=BCrkner?= Date: Fri, 14 Mar 2025 09:32:10 +0100 Subject: [PATCH 5/5] minor cleaning --- bayesflow/adapters/transforms/standardize.py | 36 ++++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/bayesflow/adapters/transforms/standardize.py b/bayesflow/adapters/transforms/standardize.py index aaf3e5c87..740f21ee0 100644 --- a/bayesflow/adapters/transforms/standardize.py +++ b/bayesflow/adapters/transforms/standardize.py @@ -14,7 +14,7 @@ class Standardize(ElementwiseTransform): Transform that when applied standardizes data using typical z-score standardization i.e. for some unstandardized data x the standardized version z would be - z = (x - mean(x)) / std(x) + >>> z = (x - mean(x)) / std(x) Parameters ---------- @@ -32,33 +32,33 @@ class Standardize(ElementwiseTransform): -------- 1) Standardize all variables using their individually estimated mean and stds. - adapter = ( - bf.adapters.Adapter() - .standardize() - ) + >>> adapter = ( + bf.adapters.Adapter() + .standardize() + ) 2) Standardize all with same known mean and std. - adapter = ( - bf.adapters.Adapter() - .standardize(mean = 5, sd = 10) - ) + >>> adapter = ( + bf.adapters.Adapter() + .standardize(mean = 5, sd = 10) + ) 3) Mix of fixed and estimated means/stds. Suppose we have priors for "beta" and "sigma" where we know the means and stds. However for all other variables, the means and stds are unknown. Then standardize should be used in several stages specifying which variables to include or exclude. - adapter = ( - bf.adapters.Adapter() - # mean fixed, std estimated - .standardize(include = "beta", mean = 1) - # both mean and SD fixed - .standardize(include = "sigma", mean = 0.6, sd = 3) - # both means and stds estimated for all other variables - .standardize(exclude = ["beta", "sigma"]) - ) + >>> adapter = ( + bf.adapters.Adapter() + # mean fixed, std estimated + .standardize(include = "beta", mean = 1) + # both mean and SD fixed + .standardize(include = "sigma", mean = 0.6, sd = 3) + # both means and stds estimated for all other variables + .standardize(exclude = ["beta", "sigma"]) + ) """ def __init__(