Skip to content

Commit

Permalink
Cleanup x type in documentation (SMTorg#451)
Browse files Browse the repository at this point in the history
* Remove x type mentions

* Fix example format in doc

* Fix design space doc string about legacy xlimits
  • Loading branch information
relf authored Jun 26, 2023
1 parent a6cf760 commit 8c503d3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
14 changes: 7 additions & 7 deletions doc/_src_docs/applications/Mixed_Hier_usage.rst

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions doc/_src_docs/applications/Mixed_Hier_usage.rstx
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,21 @@ Design space and variable class references
The ``DesignSpace`` class and design variable classes implement the relevant functionality.

.. autoclass:: smt.utils.design_space.FloatVariable
:exclude-members: get_type, get_limits
:exclude-members: get_limits

.. autoclass:: smt.utils.design_space.IntegerVariable
:exclude-members: get_type, get_limits
:exclude-members: get_limits

.. autoclass:: smt.utils.design_space.OrdinalVariable
:exclude-members: get_type, get_limits
:exclude-members: get_limits

.. autoclass:: smt.utils.design_space.CategoricalVariable
:exclude-members: get_type, get_limits
:exclude-members: get_limits

.. autoclass:: smt.utils.design_space.DesignSpace
:members:
:inherited-members:
:exclude-members: get_unfolded_num_bounds, fold_x, unfold_x, get_num_bounds, get_x_limits, get_x_types
:exclude-members: get_unfolded_num_bounds, fold_x, unfold_x, get_num_bounds, get_x_limits

Example of sampling a mixed-discrete design space
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
13 changes: 10 additions & 3 deletions smt/utils/design_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ def sample_valid_x(self, n: int, unfolded=False) -> Tuple[np.ndarray, np.ndarray
return x, is_acting

def get_x_limits(self) -> list:
"""Returns the variable limit definitions in SMT style"""
"""Returns the variable limit definitions in SMT < 2.0 style"""
return [dv.get_limits() for dv in self.design_variables]

def get_num_bounds(self):
Expand Down Expand Up @@ -572,8 +572,8 @@ class DesignSpace(BaseDesignSpace):
Class for defining a (hierarchical) design space by defining design variables, and defining decreed variables
(optional).
If needed, it is possible to get the legacy design space definition format using `get_x_limits()` and
`get_x_types()`. Numerical bounds can be requested
Numerical bounds can be requested using `get_num_bounds()`.
If needed, it is possible to get the legacy SMT < 2.0 `xlimits` format using `get_x_limits()`.
Parameters
----------
Expand All @@ -583,6 +583,8 @@ class DesignSpace(BaseDesignSpace):
Examples
--------
Instantiate the design space with all its design variables:
>>> print("toto")
>>> from smt.utils.design_space import DesignSpace, FloatVariable, IntegerVariable, OrdinalVariable, CategoricalVariable
>>> ds = DesignSpace([
>>> CategoricalVariable(['A', 'B']), # x0 categorical: A or B; order is not relevant
Expand All @@ -593,10 +595,12 @@ class DesignSpace(BaseDesignSpace):
>>> assert len(ds.design_variables) == 4
You can define decreed variables (conditional activation):
>>> ds.declare_decreed_var(decreed_var=1, meta_var=0, meta_value='A') # Activate x1 if x0 == A
After defining everything correctly, you can then use the design space object to correct design vectors and get
information about which design variables are acting:
>>> x_corr, is_acting = ds.correct_get_acting(np.array([
>>> [0, 0, 2, .25],
>>> [1, 2, 1, .75],
Expand All @@ -611,13 +615,16 @@ class DesignSpace(BaseDesignSpace):
>>> ]))
It is also possible to randomly sample design vectors conforming to the constraints:
>>> x_sampled, is_acting_sampled = ds.sample_valid_x(100)
You can also instantiate a purely-continuous design space from bounds directly:
>>> continuous_design_space = DesignSpace([(0, 1), (0, 2), (.5, 5.5)])
>>> assert continuous_design_space.n_dv == 3
If needed, it is possible to get the legacy design space definition format:
>>> xlimits = ds.get_x_limits()
>>> cont_bounds = ds.get_num_bounds()
>>> unfolded_cont_bounds = ds.get_unfolded_num_bounds()
Expand Down

0 comments on commit 8c503d3

Please sign in to comment.