Skip to content

polykin.math.optimization¤

OptimumResult dataclass ¤

Dataclass with the results of the optimization.

ATTRIBUTE DESCRIPTION
method

Method used to find the optimum.

TYPE: str

success

If True, the optimum was found.

TYPE: bool

message

Description of the exit status.

TYPE: str

nfeval

Number of function evaluations.

TYPE: int

niter

Number of iterations.

TYPE: int

x

Optimum value.

TYPE: float

f

Function value at the optimum.

TYPE: float

df

Derivative at the optimum (if available).

TYPE: float | None

Source code in src/polykin/math/optimization/results.py
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
53
54
55
56
57
58
59
60
61
62
63
@dataclass(frozen=True, slots=True)
class OptimumResult:
    """Dataclass with the results of the optimization.

    Attributes
    ----------
    method: str
        Method used to find the optimum.
    success: bool
        If `True`, the optimum was found.
    message: str
        Description of the exit status.
    nfeval: int
        Number of function evaluations.
    niter: int
        Number of iterations.
    x: float
        Optimum value.
    f: float
        Function value at the optimum.
    df: float | None
        Derivative at the optimum (if available).
    """

    method: str
    success: bool
    message: str
    nfeval: int
    niter: int
    x: float
    f: float
    df: float | None = None

    def __repr__(self) -> str:
        """Return a string representation of the optimum result."""
        result = (
            f" method: {self.method}\n"
            f"success: {colored_bool(self.success)}\n"
            f"message: {self.message}\n"
            f" nfeval: {self.nfeval}\n"
            f"  niter: {self.niter}\n"
            f"      x: {self.x:.8e}\n"
            f"      f: {self.f:.8e}"
        )
        if self.df is not None:
            result += f"\n     df: {self.df:.8e}"

        return result

__repr__ ¤

__repr__() -> str

Return a string representation of the optimum result.

Source code in src/polykin/math/optimization/results.py
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
def __repr__(self) -> str:
    """Return a string representation of the optimum result."""
    result = (
        f" method: {self.method}\n"
        f"success: {colored_bool(self.success)}\n"
        f"message: {self.message}\n"
        f" nfeval: {self.nfeval}\n"
        f"  niter: {self.niter}\n"
        f"      x: {self.x:.8e}\n"
        f"      f: {self.f:.8e}"
    )
    if self.df is not None:
        result += f"\n     df: {self.df:.8e}"

    return result