Skip to content

poor

Poor

Bases: Designs

Super class for poorly projected (collinear) designs.

Attributes:

Name Type Description
k int

The number of factors.

seed int

The seed for the random number generator.

Source code in spotpython/design/poor.py
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
class Poor(Designs):
    """
    Super class for poorly projected (collinear) designs.

    Attributes:
        k (int): The number of factors.
        seed (int): The seed for the random number generator.
    """

    def __init__(self, k: int = 2, seed: int = 123) -> None:
        """
        Initializes a Poor design object.

        Args:
            k (int): The number of factors. Defaults to 2.
            seed (int): The seed for the random number generator. Defaults to 123.
        """
        super().__init__(k, seed)
        self.k = k
        self.seed = seed

    def generate_collinear_design(self, n_points: int) -> np.ndarray:
        """Generates a collinear design (poorly projected).

        Args:
            n_points (int): The number of points to generate.

        Returns:
            numpy.ndarray: A 2D array of shape (n_points, n_dim) with collinear points.

        Examples:
            >>> from spotpython.design.poor import Poor
            >>> poor_design = Poor(k=2)
            >>> collinear_points = poor_design.generate_collinear_design(n_points=10)
            >>> print(collinear_points)
            [[0.1  0.5 ]
             [0.2  0.5 ]
             [0.3  0.5 ]
             ...
             [0.9  0.5 ]]

        """
        if self.k != 2:
            raise ValueError("Collinear design currently implemented for 2D only.")
        x_coords = np.linspace(0.1, 0.9, n_points)
        y_coords = np.full_like(x_coords, 0.5)  # All points on y=0.5 line
        # y_coords = 0.2 * x_coords + 0.3  # Or a sloped line
        return np.vstack([x_coords, y_coords]).T

__init__(k=2, seed=123)

Initializes a Poor design object.

Parameters:

Name Type Description Default
k int

The number of factors. Defaults to 2.

2
seed int

The seed for the random number generator. Defaults to 123.

123
Source code in spotpython/design/poor.py
14
15
16
17
18
19
20
21
22
23
24
def __init__(self, k: int = 2, seed: int = 123) -> None:
    """
    Initializes a Poor design object.

    Args:
        k (int): The number of factors. Defaults to 2.
        seed (int): The seed for the random number generator. Defaults to 123.
    """
    super().__init__(k, seed)
    self.k = k
    self.seed = seed

generate_collinear_design(n_points)

Generates a collinear design (poorly projected).

Parameters:

Name Type Description Default
n_points int

The number of points to generate.

required

Returns:

Type Description
ndarray

numpy.ndarray: A 2D array of shape (n_points, n_dim) with collinear points.

Examples:

>>> from spotpython.design.poor import Poor
>>> poor_design = Poor(k=2)
>>> collinear_points = poor_design.generate_collinear_design(n_points=10)
>>> print(collinear_points)
[[0.1  0.5 ]
 [0.2  0.5 ]
 [0.3  0.5 ]
 ...
 [0.9  0.5 ]]
Source code in spotpython/design/poor.py
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
def generate_collinear_design(self, n_points: int) -> np.ndarray:
    """Generates a collinear design (poorly projected).

    Args:
        n_points (int): The number of points to generate.

    Returns:
        numpy.ndarray: A 2D array of shape (n_points, n_dim) with collinear points.

    Examples:
        >>> from spotpython.design.poor import Poor
        >>> poor_design = Poor(k=2)
        >>> collinear_points = poor_design.generate_collinear_design(n_points=10)
        >>> print(collinear_points)
        [[0.1  0.5 ]
         [0.2  0.5 ]
         [0.3  0.5 ]
         ...
         [0.9  0.5 ]]

    """
    if self.k != 2:
        raise ValueError("Collinear design currently implemented for 2D only.")
    x_coords = np.linspace(0.1, 0.9, n_points)
    y_coords = np.full_like(x_coords, 0.5)  # All points on y=0.5 line
    # y_coords = 0.2 * x_coords + 0.3  # Or a sloped line
    return np.vstack([x_coords, y_coords]).T