diff --git a/api/_modules/aepsych/config.html b/api/_modules/aepsych/config.html index c6f99946c..ba568c868 100644 --- a/api/_modules/aepsych/config.html +++ b/api/_modules/aepsych/config.html @@ -200,8 +200,8 @@
# Validate the parameter-specific block
self._check_param_settings(par_name)
- lb[i] = self[par_name]["lower_bound"]
- ub[i] = self[par_name]["upper_bound"]
+ lb[i] = self[par_name].get("lower_bound", fallback="0")
+ ub[i] = self[par_name].get("upper_bound", fallback="1")
self["common"]["lb"] = f"[{', '.join(lb)}]"
self["common"]["ub"] = f"[{', '.join(ub)}]"
@@ -278,8 +278,45 @@ Source code for aepsych.config
raise ValueError(
f"Parameter {param_name} is missing the upper_bound setting."
)
+
+ elif param_block["par_type"] == "integer":
+ # Check if bounds exist and actaully integers
+ if "lower_bound" not in param_block:
+ raise ValueError(
+ f"Parameter {param_name} is missing the lower_bound setting."
+ )
+ if "upper_bound" not in param_block:
+ raise ValueError(
+ f"Parameter {param_name} is missing the upper_bound setting."
+ )
+
+ try:
+ if not (
+ self.getint(param_name, "lower_bound") % 1 == 0
+ and self.getint(param_name, "upper_bound") % 1 == 0
+ ):
+ raise ParameterConfigError(
+ f"Parameter {param_name} has non-integer bounds."
+ )
+ except ValueError:
+ raise ParameterConfigError(
+ f"Parameter {param_name} has non-discrete bounds."
+ )
+
+ elif param_block["par_type"] == "binary":
+ if "lower_bound" in param_block or "upper_bound" in param_block:
+ raise ParameterConfigError(
+ f"Parameter {param_name} is binary and shouldn't have bounds."
+ )
+
+ elif param_block["par_type"] == "fixed":
+ if "value" not in param_block:
+ raise ParameterConfigError(
+ f"Parameter {param_name} is fixed and needs to have value set."
+ )
+
else:
- raise ValueError(
+ raise ParameterConfigError(
f"Parameter {param_name} has an unsupported parameter type {param_block['par_type']}."
)
@@ -510,6 +547,10 @@ Source code for aepsych.config
Config.register_module(botorch.acquisition)
Config.register_module(botorch.acquisition.multi_objective)
Config.registered_names["None"] = None
+
+
+
# Validate the parameter-specific block
self._check_param_settings(par_name)
- lb[i] = self[par_name]["lower_bound"]
- ub[i] = self[par_name]["upper_bound"]
+ lb[i] = self[par_name].get("lower_bound", fallback="0")
+ ub[i] = self[par_name].get("upper_bound", fallback="1")
self["common"]["lb"] = f"[{', '.join(lb)}]"
self["common"]["ub"] = f"[{', '.join(ub)}]"
@@ -278,8 +278,45 @@ Source code for aepsych.config
raise ValueError(
f"Parameter {param_name} is missing the upper_bound setting."
)
+
+ elif param_block["par_type"] == "integer":
+ # Check if bounds exist and actaully integers
+ if "lower_bound" not in param_block:
+ raise ValueError(
+ f"Parameter {param_name} is missing the lower_bound setting."
+ )
+ if "upper_bound" not in param_block:
+ raise ValueError(
+ f"Parameter {param_name} is missing the upper_bound setting."
+ )
+
+ try:
+ if not (
+ self.getint(param_name, "lower_bound") % 1 == 0
+ and self.getint(param_name, "upper_bound") % 1 == 0
+ ):
+ raise ParameterConfigError(
+ f"Parameter {param_name} has non-integer bounds."
+ )
+ except ValueError:
+ raise ParameterConfigError(
+ f"Parameter {param_name} has non-discrete bounds."
+ )
+
+ elif param_block["par_type"] == "binary":
+ if "lower_bound" in param_block or "upper_bound" in param_block:
+ raise ParameterConfigError(
+ f"Parameter {param_name} is binary and shouldn't have bounds."
+ )
+
+ elif param_block["par_type"] == "fixed":
+ if "value" not in param_block:
+ raise ParameterConfigError(
+ f"Parameter {param_name} is fixed and needs to have value set."
+ )
+
else:
- raise ValueError(
+ raise ParameterConfigError(
f"Parameter {param_name} has an unsupported parameter type {param_block['par_type']}."
)
@@ -510,6 +547,10 @@ Source code for aepsych.config
Config.register_module(botorch.acquisition)
Config.register_module(botorch.acquisition.multi_objective)
Config.registered_names["None"] = None
+
+
+
if self.stimuli_per_trial == 1:
self.event_shape: Tuple[int, ...] = (self.dim,)
- if self.stimuli_per_trial == 2:
+ if self.stimuli_per_trial > 1:
self.event_shape = (self.dim, self.stimuli_per_trial)
self.model = model
diff --git a/api/_modules/aepsych/strategy/index.html b/api/_modules/aepsych/strategy/index.html
index c4e2d297a..7192f15ca 100644
--- a/api/_modules/aepsych/strategy/index.html
+++ b/api/_modules/aepsych/strategy/index.html
@@ -256,7 +256,7 @@ Source code for aepsych.strategy
if self.stimuli_per_trial == 1:
self.event_shape: Tuple[int, ...] = (self.dim,)
- if self.stimuli_per_trial == 2:
+ if self.stimuli_per_trial > 1:
self.event_shape = (self.dim, self.stimuli_per_trial)
self.model = model
diff --git a/api/_modules/aepsych/utils.html b/api/_modules/aepsych/utils.html
index 95f1d534c..403977237 100644
--- a/api/_modules/aepsych/utils.html
+++ b/api/_modules/aepsych/utils.html
@@ -25,7 +25,7 @@ Source code for aepsych.utils
from collections.abc import Iterable
from configparser import NoOptionError
-from typing import Any, Dict, List, Mapping, Optional, Tuple, Union
+from typing import Any, Dict, Mapping, Optional, Tuple, Union
import numpy as np
import torch
@@ -250,120 +250,35 @@ Source code for aepsych.utils
return result
-def _get_ax_parameters(
- config: Config,
-) -> Tuple[list[Dict[str, Any]], list[Dict[str, Any]], list[Dict[str, Any]]]:
- range_parnames = config.getlist("common", "parnames", element_type=str, fallback=[])
- lb = config.getlist("common", "lb", element_type=float, fallback=[])
- ub = config.getlist("common", "ub", element_type=float, fallback=[])
-
- assert (
- len(range_parnames) == len(lb) == len(ub)
- ), f"Length of parnames ({range_parnames}), lb ({lb}), and ub ({ub}) don't match!"
-
- range_params = [
- {
- "name": parname,
- "type": "range",
- "value_type": config.get(str(parname), "value_type", fallback="float"),
- "log_scale": config.getboolean(str(parname), "log_scale", fallback=False),
- "bounds": [l, u],
- }
- for parname, l, u in zip(range_parnames, lb, ub)
- ]
-
- choice_parnames = config.getlist(
- "common", "choice_parnames", element_type=str, fallback=[]
- )
- choices = [
- config.getlist(
- str(parname), "choices", element_type=str, fallback=["True", "False"]
+[docs]def get_bounds(config: Config) -> torch.Tensor:
+ r"""Return the bounds for all parameters in config.
+
+ Args:
+ config (Config): The config to find the bounds from.
+
+ Returns:
+ torch.Tensor: A `[2, d]` tensor with the lower and upper bounds for each
+ parameter.
+ """
+ parnames = config.getlist("common", "parnames", element_type=str)
+
+ # Try to build a full array of bounds based on parameter-specific bounds
+ try:
+ _lower_bounds = torch.tensor(
+ [config.getfloat(par, "lower_bound") for par in parnames]
+ )
+ _upper_bounds = torch.tensor(
+ [config.getfloat(par, "upper_bound") for par in parnames]
)
- for parname in choice_parnames
- ]
- choice_params = [
- {
- "name": parname,
- "type": "choice",
- "value_type": config.get(str(parname), "value_type", fallback="str"),
- "is_ordered": config.getboolean(str(parname), "is_ordered", fallback=False),
- "values": choice,
- }
- for parname, choice in zip(choice_parnames, choices)
- ]
-
- fixed_parnames = config.getlist(
- "common", "fixed_parnames", element_type=str, fallback=[]
- )
- values = []
- for parname in fixed_parnames:
- try:
- try:
- value: Union[float, str] = config.getfloat(str(parname), "value")
- except ValueError:
- value = config.get(str(parname), "value")
-
- values.append(value)
- except NoOptionError:
- raise RuntimeError(f"Missing value for fixed parameter {parname}!")
- fixed_params = [
- {
- "name": parname,
- "type": "fixed",
- "value": value,
- }
- for parname, value in zip(fixed_parnames, values)
- ]
-
- return range_params, choice_params, fixed_params
-
-
-[docs]def get_parameters(config: Config) -> List[Dict]:
- range_params, choice_params, fixed_params = _get_ax_parameters(config)
- return range_params + choice_params + fixed_params
+ bounds = torch.stack((_lower_bounds, _upper_bounds))
-[docs]def get_bounds(config: Config) -> torch.Tensor:
- range_params, choice_params, _ = _get_ax_parameters(config)
- # Need to sum dimensions added by both range and choice parameters
- bounds = [parm["bounds"] for parm in range_params]
- for par in choice_params:
- n_vals = len(par["values"])
- if par["is_ordered"]:
- bounds.append(
- [0, 1]
- ) # Ordered choice params are encoded like continuous parameters
- elif n_vals > 2:
- for _ in range(n_vals):
- bounds.append(
- [0, 1]
- ) # Choice parameter is one-hot encoded such that they add 1 dim for every choice
- else:
- for _ in range(n_vals - 1):
- bounds.append(
- [0, 1]
- ) # Choice parameters with n_choices <= 2 add n_choices - 1 dims
-
- return torch.tensor(bounds)
-
-
-[docs]def get_dim(config: Config) -> int:
- range_params, choice_params, _ = _get_ax_parameters(config)
- # Need to sum dimensions added by both range and choice parameters
- dim = len(range_params) # 1 dim per range parameter
- for par in choice_params:
- if par["is_ordered"]:
- dim += 1 # Ordered choice params are encoded like continuous parameters
- elif len(par["values"]) > 2:
- dim += len(
- par["values"]
- ) # Choice parameter is one-hot encoded such that they add 1 dim for every choice
- else:
- dim += (
- len(par["values"]) - 1
- ) # Choice parameters with n_choices < 3 add n_choices - 1 dims
+ except NoOptionError: # Look for general lb/ub array
+ _lb = config.gettensor("common", "lb")
+ _ub = config.gettensor("common", "ub")
+ bounds = torch.stack((_lb, _ub))
- return dim
+ return bounds
[docs]def get_optimizer_options(config: Config, name: str) -> Dict[str, Any]:
diff --git a/api/_modules/aepsych/utils/index.html b/api/_modules/aepsych/utils/index.html
index 95f1d534c..403977237 100644
--- a/api/_modules/aepsych/utils/index.html
+++ b/api/_modules/aepsych/utils/index.html
@@ -25,7 +25,7 @@ Source code for aepsych.utils
from collections.abc import Iterable
from configparser import NoOptionError
-from typing import Any, Dict, List, Mapping, Optional, Tuple, Union
+from typing import Any, Dict, Mapping, Optional, Tuple, Union
import numpy as np
import torch
@@ -250,120 +250,35 @@ Source code for aepsych.utils
return result
-def _get_ax_parameters(
- config: Config,
-) -> Tuple[list[Dict[str, Any]], list[Dict[str, Any]], list[Dict[str, Any]]]:
- range_parnames = config.getlist("common", "parnames", element_type=str, fallback=[])
- lb = config.getlist("common", "lb", element_type=float, fallback=[])
- ub = config.getlist("common", "ub", element_type=float, fallback=[])
-
- assert (
- len(range_parnames) == len(lb) == len(ub)
- ), f"Length of parnames ({range_parnames}), lb ({lb}), and ub ({ub}) don't match!"
-
- range_params = [
- {
- "name": parname,
- "type": "range",
- "value_type": config.get(str(parname), "value_type", fallback="float"),
- "log_scale": config.getboolean(str(parname), "log_scale", fallback=False),
- "bounds": [l, u],
- }
- for parname, l, u in zip(range_parnames, lb, ub)
- ]
-
- choice_parnames = config.getlist(
- "common", "choice_parnames", element_type=str, fallback=[]
- )
- choices = [
- config.getlist(
- str(parname), "choices", element_type=str, fallback=["True", "False"]
+[docs]def get_bounds(config: Config) -> torch.Tensor:
+ r"""Return the bounds for all parameters in config.
+
+ Args:
+ config (Config): The config to find the bounds from.
+
+ Returns:
+ torch.Tensor: A `[2, d]` tensor with the lower and upper bounds for each
+ parameter.
+ """
+ parnames = config.getlist("common", "parnames", element_type=str)
+
+ # Try to build a full array of bounds based on parameter-specific bounds
+ try:
+ _lower_bounds = torch.tensor(
+ [config.getfloat(par, "lower_bound") for par in parnames]
+ )
+ _upper_bounds = torch.tensor(
+ [config.getfloat(par, "upper_bound") for par in parnames]
)
- for parname in choice_parnames
- ]
- choice_params = [
- {
- "name": parname,
- "type": "choice",
- "value_type": config.get(str(parname), "value_type", fallback="str"),
- "is_ordered": config.getboolean(str(parname), "is_ordered", fallback=False),
- "values": choice,
- }
- for parname, choice in zip(choice_parnames, choices)
- ]
-
- fixed_parnames = config.getlist(
- "common", "fixed_parnames", element_type=str, fallback=[]
- )
- values = []
- for parname in fixed_parnames:
- try:
- try:
- value: Union[float, str] = config.getfloat(str(parname), "value")
- except ValueError:
- value = config.get(str(parname), "value")
-
- values.append(value)
- except NoOptionError:
- raise RuntimeError(f"Missing value for fixed parameter {parname}!")
- fixed_params = [
- {
- "name": parname,
- "type": "fixed",
- "value": value,
- }
- for parname, value in zip(fixed_parnames, values)
- ]
-
- return range_params, choice_params, fixed_params
-
-
-[docs]def get_parameters(config: Config) -> List[Dict]:
- range_params, choice_params, fixed_params = _get_ax_parameters(config)
- return range_params + choice_params + fixed_params
+ bounds = torch.stack((_lower_bounds, _upper_bounds))
-[docs]def get_bounds(config: Config) -> torch.Tensor:
- range_params, choice_params, _ = _get_ax_parameters(config)
- # Need to sum dimensions added by both range and choice parameters
- bounds = [parm["bounds"] for parm in range_params]
- for par in choice_params:
- n_vals = len(par["values"])
- if par["is_ordered"]:
- bounds.append(
- [0, 1]
- ) # Ordered choice params are encoded like continuous parameters
- elif n_vals > 2:
- for _ in range(n_vals):
- bounds.append(
- [0, 1]
- ) # Choice parameter is one-hot encoded such that they add 1 dim for every choice
- else:
- for _ in range(n_vals - 1):
- bounds.append(
- [0, 1]
- ) # Choice parameters with n_choices <= 2 add n_choices - 1 dims
-
- return torch.tensor(bounds)
-
-
-[docs]def get_dim(config: Config) -> int:
- range_params, choice_params, _ = _get_ax_parameters(config)
- # Need to sum dimensions added by both range and choice parameters
- dim = len(range_params) # 1 dim per range parameter
- for par in choice_params:
- if par["is_ordered"]:
- dim += 1 # Ordered choice params are encoded like continuous parameters
- elif len(par["values"]) > 2:
- dim += len(
- par["values"]
- ) # Choice parameter is one-hot encoded such that they add 1 dim for every choice
- else:
- dim += (
- len(par["values"]) - 1
- ) # Choice parameters with n_choices < 3 add n_choices - 1 dims
+ except NoOptionError: # Look for general lb/ub array
+ _lb = config.gettensor("common", "lb")
+ _ub = config.gettensor("common", "ub")
+ bounds = torch.stack((_lb, _ub))
- return dim
+ return bounds
[docs]def get_optimizer_options(config: Config, name: str) -> Dict[str, Any]:
diff --git a/api/config.html b/api/config.html
index 0af96f7d1..428ae44dd 100644
--- a/api/config.html
+++ b/api/config.html
@@ -204,6 +204,11 @@ aepsych.config
+
+exception aepsych.config.ParameterConfigError[source]¶
+Bases: Exception
+
diff --git a/api/config/index.html b/api/config/index.html
index 0af96f7d1..428ae44dd 100644
--- a/api/config/index.html
+++ b/api/config/index.html
@@ -204,6 +204,11 @@ aepsych.config
+
+exception aepsych.config.ParameterConfigError[source]¶
+Bases: Exception
+
diff --git a/api/generators.html b/api/generators.html
index 9ff7b53d5..470bb48be 100644
--- a/api/generators.html
+++ b/api/generators.html
@@ -148,8 +148,7 @@ Submodules
lb (Tensor) –
ub (Tensor) –
-points (Union[ndarray, Tensor]) –
+points (Tensor) –
dim (Optional[int]) –
shuffle (bool) –
seed (Optional[int]) –
@@ -232,29 +231,23 @@ Submodules
- Parameters:
-lb (Union[ndarray, Tensor]) –
-ub (Union[ndarray, Tensor]) –
-window (Union[ndarray, Tensor]) –
-points (Union[ndarray, Tensor]) –
-samples_per_point (int) –
-dim (Optional[int]) –
-shuffle (bool) –
-seed (Optional[int]) –
+points (Union[np.ndarray, torch.Tensor]) – The points that will be generated.
+samples_per_point (int) – How many samples around each point to take.
+dim (int, optional) – Dimensionality of the parameter space. If None, it is inferred from lb and ub.
+shuffle (bool) – Whether or not to shuffle the order of the points. True by default.
+seed (int, optional) – Random seed.
+lb (Tensor) –
+ub (Tensor) –
+window (Union[np.ndarray, torch.Tensor]) –
@@ -955,8 +948,7 @@ Submodules
lb (Tensor) –
ub (Tensor) –
-points (Union[ndarray, Tensor]) –
+points (Tensor) –
dim (Optional[int]) –
shuffle (bool) –
seed (Optional[int]) –
@@ -1039,29 +1031,23 @@ Submodules
- Parameters:
-lb (Union[ndarray, Tensor]) –
-ub (Union[ndarray, Tensor]) –
-window (Union[ndarray, Tensor]) –
-points (Union[ndarray, Tensor]) –
-samples_per_point (int) –
-dim (Optional[int]) –
-shuffle (bool) –
-seed (Optional[int]) –
+points (Union[np.ndarray, torch.Tensor]) – The points that will be generated.
+samples_per_point (int) – How many samples around each point to take.
+dim (int, optional) – Dimensionality of the parameter space. If None, it is inferred from lb and ub.
+shuffle (bool) – Whether or not to shuffle the order of the points. True by default.
+seed (int, optional) – Random seed.
+lb (Tensor) –
+ub (Tensor) –
+window (Union[np.ndarray, torch.Tensor]) –
diff --git a/api/generators/index.html b/api/generators/index.html
index 9ff7b53d5..470bb48be 100644
--- a/api/generators/index.html
+++ b/api/generators/index.html
@@ -148,8 +148,7 @@ Submodules
lb (Tensor) –
ub (Tensor) –
-points (Union[ndarray, Tensor]) –
+points (Tensor) –
dim (Optional[int]) –
shuffle (bool) –
seed (Optional[int]) –
@@ -232,29 +231,23 @@ Submodules
- Parameters:
-lb (Union[ndarray, Tensor]) –
-ub (Union[ndarray, Tensor]) –
-window (Union[ndarray, Tensor]) –
-points (Union[ndarray, Tensor]) –
-samples_per_point (int) –
-dim (Optional[int]) –
-shuffle (bool) –
-seed (Optional[int]) –
+points (Union[np.ndarray, torch.Tensor]) – The points that will be generated.
+samples_per_point (int) – How many samples around each point to take.
+dim (int, optional) – Dimensionality of the parameter space. If None, it is inferred from lb and ub.
+shuffle (bool) – Whether or not to shuffle the order of the points. True by default.
+seed (int, optional) – Random seed.
+lb (Tensor) –
+ub (Tensor) –
+window (Union[np.ndarray, torch.Tensor]) –
@@ -955,8 +948,7 @@ Submodules
lb (Tensor) –
ub (Tensor) –
-points (Union[ndarray, Tensor]) –
+points (Tensor) –
dim (Optional[int]) –
shuffle (bool) –
seed (Optional[int]) –
@@ -1039,29 +1031,23 @@ Submodules
- Parameters:
-lb (Union[ndarray, Tensor]) –
-ub (Union[ndarray, Tensor]) –
-window (Union[ndarray, Tensor]) –
-points (Union[ndarray, Tensor]) –
-samples_per_point (int) –
-dim (Optional[int]) –
-shuffle (bool) –
-seed (Optional[int]) –
+points (Union[np.ndarray, torch.Tensor]) – The points that will be generated.
+samples_per_point (int) – How many samples around each point to take.
+dim (int, optional) – Dimensionality of the parameter space. If None, it is inferred from lb and ub.
+shuffle (bool) – Whether or not to shuffle the order of the points. True by default.
+seed (int, optional) – Random seed.
+lb (Tensor) –
+ub (Tensor) –
+window (Union[np.ndarray, torch.Tensor]) –
diff --git a/api/genindex.html b/api/genindex.html
index ab43fd5e6..6ed1fcbb7 100644
--- a/api/genindex.html
+++ b/api/genindex.html
@@ -1019,8 +1019,6 @@ G
- (aepsych.server.server.AEPsychServer method)
-- get_dim() (in module aepsych.utils)
-
- get_engine() (aepsych.database.db.Database method)
@@ -1060,8 +1058,6 @@ G
- get_param_for() (aepsych.database.db.Database method)
-- get_parameters() (in module aepsych.utils)
-
- get_raw_for() (aepsych.database.db.Database method)
- get_replay_for() (aepsych.database.db.Database method)
@@ -1651,6 +1647,8 @@
P
- param_value (aepsych.database.tables.DbParamTable attribute)
+- ParameterConfigError
+
- parent (aepsych.database.tables.DbConfigTable attribute)
- (aepsych.database.tables.DbOutcomeTable attribute)
diff --git a/api/utils.html b/api/utils.html
index 9ed032e92..b315834d1 100644
--- a/api/utils.html
+++ b/api/utils.html
@@ -131,38 +131,22 @@
aepsych.utils
--
-aepsych.utils.get_parameters(config)[source]¶
-
-- Parameters:
-config (Config) –
-
-- Return type:
-List[Dict]
-
-
-
-
-
aepsych.utils.get_bounds(config)[source]¶
-
+Return the bounds for all parameters in config.
+
- Parameters:
-config (Config) –
+config (Config) – The config to find the bounds from.
-- Return type:
-Tensor
+- Returns:
+
+- A [2, d] tensor with the lower and upper bounds for each
parameter.
-
-
--
-aepsych.utils.get_dim(config)[source]¶
-
-- Parameters:
-config (Config) –
+
-- Return type:
-int
+- Return type:
+torch.Tensor
diff --git a/api/utils/index.html b/api/utils/index.html
index 9ed032e92..b315834d1 100644
--- a/api/utils/index.html
+++ b/api/utils/index.html
@@ -131,38 +131,22 @@ aepsych.utils
--
-aepsych.utils.get_parameters(config)[source]¶
-
-- Parameters:
-config (Config) –
-
-- Return type:
-List[Dict]
-
-
-
-
-
aepsych.utils.get_bounds(config)[source]¶
-
+Return the bounds for all parameters in config.
+
- Parameters:
-config (Config) –
+config (Config) – The config to find the bounds from.
-- Return type:
-Tensor
+- Returns:
+
+- A [2, d] tensor with the lower and upper bounds for each
parameter.
-
-
--
-aepsych.utils.get_dim(config)[source]¶
-
-- Parameters:
-config (Config) –
+
-- Return type:
-int
+- Return type:
+torch.Tensor
diff --git a/demos/ParticleEffectDemo.html b/demos/ParticleEffectDemo.html
index 0709c0c9a..65dfb3146 100644
--- a/demos/ParticleEffectDemo.html
+++ b/demos/ParticleEffectDemo.html
@@ -64,7 +64,7 @@
-
+
Particle Effect Demo¶