Skip to content

Commit

Permalink
Added option to show/not show the hessian in the summary. (#1134)
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulJonasJost authored Oct 13, 2023
1 parent e18de76 commit a52ae70
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
12 changes: 9 additions & 3 deletions pypesto/result/optimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,16 @@ def __getattr__(self, key):
__setattr__ = dict.__setitem__
__delattr__ = dict.__delitem__

def summary(self, full: bool = False) -> str:
def summary(self, full: bool = False, show_hess: bool = True) -> str:
"""
Get summary of the object.
Parameters
----------
full:
If True, print full vectors including fixed parameters.
show_hess:
If True, display the Hessian of the result.
Returns
-------
Expand Down Expand Up @@ -164,7 +166,7 @@ def summary(self, full: bool = False) -> str:
f"* final gradient value: "
f"{self.grad if full else self.grad[self.free_indices]}\n"
)
if self.hess is not None:
if self.hess is not None and show_hess:
hess = self.hess
if not full:
hess = self.hess[np.ix_(self.free_indices, self.free_indices)]
Expand Down Expand Up @@ -239,6 +241,7 @@ def summary(
disp_best: bool = True,
disp_worst: bool = False,
full: bool = False,
show_hess: bool = True,
) -> str:
"""
Get summary of the object.
Expand All @@ -251,6 +254,8 @@ def summary(
Whether to display a detailed summary of the worst run.
full:
If True, print full vectors including fixed parameters.
show_hess:
If True, display the Hessian of the OptimizerResult.
"""
if len(self) == 0:
return "## Optimization Result \n\n*empty*\n"
Expand Down Expand Up @@ -295,7 +300,8 @@ def summary(
)
if disp_best:
summary += (
f"\nA summary of the best run:\n\n{self[0].summary(full)}"
f"\nA summary of the best run:\n\n"
f"{self[0].summary(full, show_hess=show_hess)}"
)
if disp_worst:
summary += (
Expand Down
6 changes: 4 additions & 2 deletions pypesto/result/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@ def __init__(
self.profile_result = profile_result or ProfileResult()
self.sample_result = sample_result or SampleResult()

def summary(self, full: bool = False) -> str:
def summary(self, full: bool = False, show_hess: bool = True) -> str:
"""
Get summary of the object.
Parameters
----------
full:
If True, print full vectors including fixed parameters.
show_hess:
If True, display the Hessian of the OptimizeResult.
"""
return self.optimize_result.summary(full=full)
return self.optimize_result.summary(full=full, show_hess=show_hess)

0 comments on commit a52ae70

Please sign in to comment.