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 @@

Source code for aepsych.config

                     # 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
+
+
+
[docs]class ParameterConfigError(Exception): + pass
diff --git a/api/_modules/aepsych/config/index.html b/api/_modules/aepsych/config/index.html index c6f99946c..ba568c868 100644 --- a/api/_modules/aepsych/config/index.html +++ b/api/_modules/aepsych/config/index.html @@ -200,8 +200,8 @@

Source code for aepsych.config

                     # 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
+
+
+
[docs]class ParameterConfigError(Exception): + pass
diff --git a/api/_modules/aepsych/generators/manual_generator.html b/api/_modules/aepsych/generators/manual_generator.html index 5cffef88c..9268be4f9 100644 --- a/api/_modules/aepsych/generators/manual_generator.html +++ b/api/_modules/aepsych/generators/manual_generator.html @@ -24,9 +24,8 @@

Source code for aepsych.generators.manual_generator

# LICENSE file in the root directory of this source tree. import warnings -from typing import Dict, Optional, Union +from typing import Dict, Optional -import numpy as np import torch from aepsych.config import Config from aepsych.generators.base import AEPsychGenerator @@ -44,7 +43,7 @@

Source code for aepsych.generators.manual_generator

self, lb: torch.Tensor, ub: torch.Tensor, - points: Union[np.ndarray, torch.Tensor], + points: torch.Tensor, dim: Optional[int] = None, shuffle: bool = True, seed: Optional[int] = None, @@ -53,16 +52,18 @@

Source code for aepsych.generators.manual_generator

Args: lb torch.Tensor: Lower bounds of each parameter. ub torch.Tensor: Upper bounds of each parameter. - points (Union[np.ndarray, torch.Tensor]): The points that will be generated. + points torch.Tensor: The points that will be generated. 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. """ self.seed = seed self.lb, self.ub, self.dim = _process_bounds(lb, ub, dim) + self.points = points if shuffle: - np.random.seed(self.seed) - np.random.shuffle(points) - self.points = torch.tensor(points) + if seed is not None: + torch.manual_seed(seed) + self.points = points[torch.randperm(len(points))] + self.max_asks = len(self.points) self._idx = 0 @@ -100,10 +101,14 @@

Source code for aepsych.generators.manual_generator

lb = config.gettensor(name, "lb") ub = config.gettensor(name, "ub") dim = config.getint(name, "dim", fallback=None) - points = config.getarray(name, "points") + points = config.gettensor(name, "points") shuffle = config.getboolean(name, "shuffle", fallback=True) seed = config.getint(name, "seed", fallback=None) + if len(points.shape) == 3: + # Configs have a reasonable natural input method that produces incorrect tensors + points = points.swapaxes(-1, -2) + options = { "lb": lb, "ub": ub, @@ -125,10 +130,10 @@

Source code for aepsych.generators.manual_generator

def __init__( self, - lb: Union[np.ndarray, torch.Tensor], - ub: Union[np.ndarray, torch.Tensor], - window: Union[np.ndarray, torch.Tensor], - points: Union[np.ndarray, torch.Tensor], + lb: torch.Tensor, + ub: torch.Tensor, + window: torch.Tensor, + points: torch.Tensor, samples_per_point: int, dim: Optional[int] = None, shuffle: bool = True, @@ -138,7 +143,10 @@

Source code for aepsych.generators.manual_generator

Args: lb (Union[np.ndarray, torch.Tensor]): Lower bounds of each parameter. ub (Union[np.ndarray, torch.Tensor]): Upper bounds of each parameter. - window (Union[np.ndarray, torch.Tensor]): How far away to sample from the reference point along each dimension. + window (Union[np.ndarray, torch.Tensor]): How far away to sample from the + reference point along each dimension. If the parameters are transformed, + the proportion of the range (based on ub/lb given) covered by the window + will be preserved (and not the absolute distance from the reference points). 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. @@ -146,16 +154,27 @@

Source code for aepsych.generators.manual_generator

seed (int, optional): Random seed. """ lb, ub, dim = _process_bounds(lb, ub, dim) - points = torch.Tensor(points) self.engine = SobolEngine(dimension=dim, scramble=True, seed=seed) - generated = [] + gen_points = [] + if len(points.shape) > 2: + # We need to determine how many stimuli there are per trial to maintain the proper tensor shape + n_draws = points.shape[-1] + else: + n_draws = 1 for point in points: + if len(points.shape) > 2: + point = point.T p_lb = torch.max(point - window, lb) p_ub = torch.min(point + window, ub) - grid = self.engine.draw(samples_per_point) - grid = p_lb + (p_ub - p_lb) * grid - generated.append(grid) - generated = torch.Tensor(np.vstack(generated)) # type: ignore + for _ in range(samples_per_point): + grid = self.engine.draw(n_draws) + grid = p_lb + (p_ub - p_lb) * grid + gen_points.append(grid) + if len(points.shape) > 2: + generated = torch.stack(gen_points) + generated = generated.swapaxes(-2, -1) + else: + generated = torch.vstack(gen_points) super().__init__(lb, ub, generated, dim, shuffle, seed) # type: ignore diff --git a/api/_modules/aepsych/generators/manual_generator/index.html b/api/_modules/aepsych/generators/manual_generator/index.html index 5cffef88c..9268be4f9 100644 --- a/api/_modules/aepsych/generators/manual_generator/index.html +++ b/api/_modules/aepsych/generators/manual_generator/index.html @@ -24,9 +24,8 @@

Source code for aepsych.generators.manual_generator

# LICENSE file in the root directory of this source tree. import warnings -from typing import Dict, Optional, Union +from typing import Dict, Optional -import numpy as np import torch from aepsych.config import Config from aepsych.generators.base import AEPsychGenerator @@ -44,7 +43,7 @@

Source code for aepsych.generators.manual_generator

self, lb: torch.Tensor, ub: torch.Tensor, - points: Union[np.ndarray, torch.Tensor], + points: torch.Tensor, dim: Optional[int] = None, shuffle: bool = True, seed: Optional[int] = None, @@ -53,16 +52,18 @@

Source code for aepsych.generators.manual_generator

Args: lb torch.Tensor: Lower bounds of each parameter. ub torch.Tensor: Upper bounds of each parameter. - points (Union[np.ndarray, torch.Tensor]): The points that will be generated. + points torch.Tensor: The points that will be generated. 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. """ self.seed = seed self.lb, self.ub, self.dim = _process_bounds(lb, ub, dim) + self.points = points if shuffle: - np.random.seed(self.seed) - np.random.shuffle(points) - self.points = torch.tensor(points) + if seed is not None: + torch.manual_seed(seed) + self.points = points[torch.randperm(len(points))] + self.max_asks = len(self.points) self._idx = 0 @@ -100,10 +101,14 @@

Source code for aepsych.generators.manual_generator

lb = config.gettensor(name, "lb") ub = config.gettensor(name, "ub") dim = config.getint(name, "dim", fallback=None) - points = config.getarray(name, "points") + points = config.gettensor(name, "points") shuffle = config.getboolean(name, "shuffle", fallback=True) seed = config.getint(name, "seed", fallback=None) + if len(points.shape) == 3: + # Configs have a reasonable natural input method that produces incorrect tensors + points = points.swapaxes(-1, -2) + options = { "lb": lb, "ub": ub, @@ -125,10 +130,10 @@

Source code for aepsych.generators.manual_generator

def __init__( self, - lb: Union[np.ndarray, torch.Tensor], - ub: Union[np.ndarray, torch.Tensor], - window: Union[np.ndarray, torch.Tensor], - points: Union[np.ndarray, torch.Tensor], + lb: torch.Tensor, + ub: torch.Tensor, + window: torch.Tensor, + points: torch.Tensor, samples_per_point: int, dim: Optional[int] = None, shuffle: bool = True, @@ -138,7 +143,10 @@

Source code for aepsych.generators.manual_generator

Args: lb (Union[np.ndarray, torch.Tensor]): Lower bounds of each parameter. ub (Union[np.ndarray, torch.Tensor]): Upper bounds of each parameter. - window (Union[np.ndarray, torch.Tensor]): How far away to sample from the reference point along each dimension. + window (Union[np.ndarray, torch.Tensor]): How far away to sample from the + reference point along each dimension. If the parameters are transformed, + the proportion of the range (based on ub/lb given) covered by the window + will be preserved (and not the absolute distance from the reference points). 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. @@ -146,16 +154,27 @@

Source code for aepsych.generators.manual_generator

seed (int, optional): Random seed. """ lb, ub, dim = _process_bounds(lb, ub, dim) - points = torch.Tensor(points) self.engine = SobolEngine(dimension=dim, scramble=True, seed=seed) - generated = [] + gen_points = [] + if len(points.shape) > 2: + # We need to determine how many stimuli there are per trial to maintain the proper tensor shape + n_draws = points.shape[-1] + else: + n_draws = 1 for point in points: + if len(points.shape) > 2: + point = point.T p_lb = torch.max(point - window, lb) p_ub = torch.min(point + window, ub) - grid = self.engine.draw(samples_per_point) - grid = p_lb + (p_ub - p_lb) * grid - generated.append(grid) - generated = torch.Tensor(np.vstack(generated)) # type: ignore + for _ in range(samples_per_point): + grid = self.engine.draw(n_draws) + grid = p_lb + (p_ub - p_lb) * grid + gen_points.append(grid) + if len(points.shape) > 2: + generated = torch.stack(gen_points) + generated = generated.swapaxes(-2, -1) + else: + generated = torch.vstack(gen_points) super().__init__(lb, ub, generated, dim, shuffle, seed) # type: ignore diff --git a/api/_modules/aepsych/strategy.html b/api/_modules/aepsych/strategy.html index c4e2d297a..7192f15ca 100644 --- a/api/_modules/aepsych/strategy.html +++ b/api/_modules/aepsych/strategy.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/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 @@ -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