mindscience.data.HyperCube

class mindscience.data.HyperCube(name, dim, coord_min, coord_max, dtype=numpy.float32, sampling_config=None)[源代码]

超立方体(多维长方体)几何对象的定义。

参数:
  • name (str) - 超立方体名称。

  • dim (int) - 维度数量。

  • coord_min (Union[int, float, tuple, list, numpy.ndarray]) - 超立方体的最小坐标。若类型为 tuple/list,其元素可为 tuple[int, int]tuple[float, float]list[int, int]list[float, float] 等形式。

  • coord_max (Union[int, float, tuple, list, numpy.ndarray]) - 超立方体的最大坐标。若类型为 tuple/list,其元素可为 tuple[int, int]tuple[float, float]list[int, int]list[float, float] 等形式。

  • dtype (numpy.dtype) - 采样点数据类型,默认 numpy.float32

  • sampling_config (SamplingConfig) - 采样配置,默认 None

异常:
  • TypeError - 当 sampling_config 不是 SamplingConfig 类实例时抛出。

样例:

>>> from mindscience.data import generate_sampling_config, HyperCube
>>> hypercube_random = dict({
...      'domain': dict({
...          'random_sampling': True,
...          'size': 1000,
...          'sampler': 'uniform'
...         }),
...      'BC': dict({
...          'random_sampling': True,
...          'size': 200,
...          'sampler': 'uniform',
...          'with_normal': False,
...      }),
...  })
>>> sampling_config = generate_sampling_config(hypercube_random)
>>> hypercube = HyperCube("HyperCube", 3, [-1, 2, 1], [0, 3, 2], sampling_config=sampling_config)
>>> domain = hypercube.sampling(geom_type="domain")
>>> bc = hypercube.sampling(geom_type="BC")
>>> print(domain.shape)
(1000, 3)
sampling(geom_type='domain')[源代码]

采样点。

参数:
  • geom_type (str) - 几何类型:可为 'domain''BC',默认 'domain'

    • 'domain':问题的可行域(feasible domain of the problem)。

    • 'BC':问题的边界(boundary of the problem)。

返回:

Numpy.ndarray。若边界配置 with_normal 为 True,则返回带边界法线向量的二维数组;否则返回不带法线向量的二维数组。

异常:
  • KeyError - 当 geom_type'domain'self.sampling_config.domainNone 时抛出。

  • KeyError - 当 geom_type'BC'self.sampling_config.bcNone 时抛出。

  • ValueError - 当 geom_type 既不是 'BC' 也不是 'domain' 时抛出。