-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add extra type for performance indicators
Instead of using strings to describe performance indicators, use a class that stores if the indicator needs to be minimized or maximized. Also add machinery to only register indicators once so that you can still pass in strings for convenience.
- Loading branch information
1 parent
feab715
commit 9961765
Showing
5 changed files
with
165 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
from ._version import __version__ # noqa: F401 | ||
from .rtp import rtpplot, runtime_profiles | ||
from .result import ProblemDescription, Result, ResultSet | ||
from .indicator import Indicator | ||
|
||
__all__ = ["ProblemDescription", "Result", "ResultSet", "rtpplot", "runtime_profiles"] | ||
__all__ = ["ProblemDescription", "Result", "ResultSet", "Indicator", "rtpplot", "runtime_profiles"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
"""Functions and data structures for dealing with performance indicators""" | ||
|
||
import dataclasses | ||
|
||
from typing import Union | ||
|
||
|
||
KNOWN_INDICATORS = dict() | ||
|
||
|
||
@dataclasses.dataclass(eq=True, frozen=True) | ||
class Indicator: | ||
"""Description of a performance indicator | ||
Attributes | ||
---------- | ||
name : str | ||
Name of the quality indicator. Must match the column name | ||
in the Results object. | ||
larger_is_better : bool, default = True | ||
True if larger values of the indicator are better, False | ||
otherwise. | ||
""" | ||
name: str | ||
larger_is_better: bool = True | ||
|
||
|
||
def register(ind: Indicator): | ||
"""Register a new performance indicator | ||
cocoviz has a global list of know performance indicators with their | ||
associated metadata. Using this function, you can add additional indicators | ||
so that you do not have to specify their properties every time. | ||
Parameters | ||
---------- | ||
ind : Indicator | ||
Indicator to add to list of known indicators | ||
""" | ||
KNOWN_INDICATORS[ind.name] = ind | ||
|
||
|
||
def deregister(ind: Union[Indicator, str]): | ||
"""_summary_ | ||
Parameters | ||
---------- | ||
ind : Indicator or str | ||
Indicator to remove from list of known indicators | ||
Raises | ||
------ | ||
NotImplementedError | ||
when `ind` is neither a string nor an instance of Indicator | ||
""" | ||
if isinstance(ind, str): | ||
del KNOWN_INDICATORS[ind] | ||
elif isinstance(ind, Indicator): | ||
del KNOWN_INDICATORS[ind.name] | ||
else: | ||
raise NotImplementedError() | ||
|
||
|
||
## Register some common and not so common quality indicators | ||
register(Indicator("hypervolume", larger_is_better=True)) | ||
register(Indicator("hv", larger_is_better=True)) | ||
register(Indicator("r2", larger_is_better=True)) | ||
register(Indicator("time", larger_is_better=False)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters