Skip to content

polykin.math.optimization¤

VectorOptimumResult 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

ngeval

Number of user-supplied gradient evaluations.

TYPE: int | None

nheval

Number of user-supplied Hessian evaluations.

TYPE: int | None

niter

Number of iterations.

TYPE: int

x

Optimum value.

TYPE: FloatVector

f

Function value at the optimum.

TYPE: float

g

Gradient at the optimum.

TYPE: FloatVector | None

H

Last evaluated or estimated Hessian matrix.

TYPE: FloatMatrix | None

Hinv

Last evaluated or estimated inverse Hessian (\(H^{-1}\)) matrix.

TYPE: FloatMatrix | None

L

Last evaluated or estimated Cholesky factor \(L\) (where \(H = LL^T\)) of the Hessian matrix.

TYPE: FloatMatrix | None

Source code in src/polykin/math/optimization/results.py
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
@dataclass(frozen=True, slots=True)
class VectorOptimumResult:
    """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.
    ngeval: int | None
        Number of user-supplied gradient evaluations.
    nheval: int | None
        Number of user-supplied Hessian evaluations.
    niter: int
        Number of iterations.
    x: FloatVector
        Optimum value.
    f: float
        Function value at the optimum.
    g: FloatVector | None
        Gradient at the optimum.
    H: FloatMatrix | None
        Last evaluated or estimated Hessian matrix.
    Hinv: FloatMatrix | None
        Last evaluated or estimated inverse Hessian ($H^{-1}$) matrix.
    L: FloatMatrix | None
        Last evaluated or estimated Cholesky factor $L$ (where $H = LL^T$) of the
        Hessian matrix.
    """

    method: str
    success: bool
    message: str
    nfeval: int
    ngeval: int | None
    nheval: int | None
    niter: int
    x: FloatVector
    f: float
    g: FloatVector | None = None
    H: FloatMatrix | None = None
    Hinv: FloatMatrix | None = None
    L: FloatMatrix | None = None

    def __repr__(self) -> str:
        """Return a string representation of the optimum result."""
        rows = [
            ("method", self.method),
            ("success", colored_bool(self.success)),
            ("message", self.message),
            ("nfeval", self.nfeval),
            ("ngeval", self.ngeval),
            ("nheval", self.nheval),
            ("niter", self.niter),
            ("x", self.x),
            ("f", self.f),
            ("g", self.g),
            ("H", self.H),
            ("Hinv", self.Hinv),
            ("L", self.L),
        ]

        return "\n".join(
            f"{name:>7}: {value}"
            for name, value in rows
            if value is not None and not (hasattr(value, "size") and value.size == 0)
        )

__repr__ ¤

__repr__() -> str

Return a string representation of the optimum result.

Source code in src/polykin/math/optimization/results.py
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
def __repr__(self) -> str:
    """Return a string representation of the optimum result."""
    rows = [
        ("method", self.method),
        ("success", colored_bool(self.success)),
        ("message", self.message),
        ("nfeval", self.nfeval),
        ("ngeval", self.ngeval),
        ("nheval", self.nheval),
        ("niter", self.niter),
        ("x", self.x),
        ("f", self.f),
        ("g", self.g),
        ("H", self.H),
        ("Hinv", self.Hinv),
        ("L", self.L),
    ]

    return "\n".join(
        f"{name:>7}: {value}"
        for name, value in rows
        if value is not None and not (hasattr(value, "size") and value.size == 0)
    )