|
QDpy
|
Nearest-neighbour distances, novelty, and local competition. More...
Go to the source code of this file.
Namespaces | |
| namespace | qdpy |
Functions | |
| Sequence | qdpy.metrics.features_distances (IndividualLike individual, Sequence container, Union[str, Callable] dist="euclidean", *, Optional[Callable] get_features=None) |
| METRICS ########### {{{1. | |
| float | qdpy.metrics.novelty (IndividualLike individual, Sequence container, int k=1, Union[str, Callable] dist="euclidean", bool ignore_first=False, float default_novelty=0.1) |
| Tuple[float, Sequence] | qdpy.metrics.novelty_nn (IndividualLike individual, Sequence container, int k=1, int nn_size=1, Union[str, Callable] dist="euclidean", bool ignore_first=False, float default_novelty=np.inf, *, Optional[Callable] get_features=None) |
| Tuple[float, float] | qdpy.metrics.novelty_local_competition (IndividualLike individual, Sequence container, int k=1, Union[str, Callable] dist="euclidean", bool ignore_first=False, float default_novelty=0.1, float default_local_competition=1.0) |
| tuple[float,...] | qdpy.metrics.archive_originality (archives, *, key=tuple) |
| Fraction of each archive's distinct solutions exclusive to it. | |
| np.ndarray | qdpy.metrics.archive_overlap (archives, *, key=tuple) |
| Compare archive membership using the Jaccard index. | |
| float | qdpy.metrics.pairwise_kl_coverage (reference, compared, *, coordinate_pairs=None, int bins=10, ranges=None, float pseudocount=1e-12) |
| Sum reference-to-compared KL divergences over descriptor pairs. | |
Nearest-neighbour distances, novelty, and local competition.
Definition in file metrics.py.
| tuple[float, ...] qdpy.metrics.archive_originality | ( | archives, | |
| * | , | ||
| key = tuple ) |
Fraction of each archive's distinct solutions exclusive to it.
| archives | Iterable of archives in output order. |
| key | Callable mapping a candidate to a hashable identity. |
Return each archive's fraction of distinct solutions exclusive to it. The default identity is the genome tuple. Provide a hashable key for candidates with nested or otherwise unhashable genes. Multiple copies inside one archive count once. An empty archive contributes zero.
Definition at line 173 of file metrics.py.
| np.ndarray qdpy.metrics.archive_overlap | ( | archives, | |
| * | , | ||
| key = tuple ) |
Compare archive membership using the Jaccard index.
| archives | Iterable of archives in row and column order. |
| key | Callable mapping a candidate to a hashable identity. |
Return pairwise Jaccard overlap in archive order. Two empty archives have overlap one. A pair with one empty and one populated archive has overlap zero. By default, compare genome tuples.
Definition at line 190 of file metrics.py.
| Sequence qdpy.metrics.features_distances | ( | IndividualLike | individual, |
| Sequence | container, | ||
| Union[str, Callable] | dist = "euclidean", | ||
| * | , | ||
| Optional[Callable] | get_features = None ) |
METRICS ########### {{{1.
Check descriptor dimensions before computing each distance.
| individual | Query candidate. |
| container | Reference sequence. |
| dist | Euclidean metric name or descriptor-to-descriptor callable. |
| get_features | Optional accessor used on both sides of the comparison. |
| ValueError | If dimensions differ or the metric name is unknown. |
Measure distance from a candidate to each reference entry.
:param individual: Candidate to compare.
:param container: Reference entries in the order to report.
:param dist: The string ``"euclidean"`` or a callable taking two
descriptor vectors.
:param get_features: Descriptor accessor. Defaults to the
candidate's ``features`` attribute.
:returns: A one-dimensional NumPy array in reference order.
:raises ValueError: If a metric name is unsupported or descriptor
dimensions differ.
Definition at line 43 of file metrics.py.
| float qdpy.metrics.novelty | ( | IndividualLike | individual, |
| Sequence | container, | ||
| int | k = 1, | ||
| Union[str, Callable] | dist = "euclidean", | ||
| bool | ignore_first = False, | ||
| float | default_novelty = 0.1 ) |
Return the mean distance to the nearest scored neighbours.
:param individual: Candidate whose descriptors define the query.
:param container: Reference entries.
:param k: Maximum number of neighbours in the mean.
:param dist: Metric accepted by :func:`features_distances`.
:param ignore_first: Skip the closest entry before selecting
neighbours. Use it when the reference includes the query.
:param default_novelty: Result when no neighbours are scored.
:returns: The mean over the neighbours that are available.
Definition at line 83 of file metrics.py.
| Tuple[float, float] qdpy.metrics.novelty_local_competition | ( | IndividualLike | individual, |
| Sequence | container, | ||
| int | k = 1, | ||
| Union[str, Callable] | dist = "euclidean", | ||
| bool | ignore_first = False, | ||
| float | default_novelty = 0.1, | ||
| float | default_local_competition = 1.0 ) |
Return novelty and the fraction of requested neighbours outperformed. Compare the query's fitness to each nearest neighbour using dominance. Divide the number outperformed by ``k`` even when fewer neighbours are available. The novelty mean uses the actual number of neighbours available. ``ignore_first`` skips the closest entry. Return ``(default_novelty, default_local_competition)`` when no neighbours are scored.
Definition at line 147 of file metrics.py.
| Tuple[float, Sequence] qdpy.metrics.novelty_nn | ( | IndividualLike | individual, |
| Sequence | container, | ||
| int | k = 1, | ||
| int | nn_size = 1, | ||
| Union[str, Callable] | dist = "euclidean", | ||
| bool | ignore_first = False, | ||
| float | default_novelty = np.inf, | ||
| * | , | ||
| Optional[Callable] | get_features = None ) |
Return novelty and the indexes of the nearest entries.
The novelty calculation uses up to ``k`` neighbours independently
of the requested number of returned indexes. Ties in distance
keep reference order. When ``ignore_first`` is true, both operations
skip the closest entry.
:param nn_size: Maximum number of neighbour indexes to return.
:param default_novelty: Fallback score when the mean has no entries.
:param get_features: Optional accessor for the query and reference
descriptors. Archives use this to compare named descriptors.
:returns: A novelty score and indexes into the reference sequence.
Definition at line 117 of file metrics.py.
| float qdpy.metrics.pairwise_kl_coverage | ( | reference, | |
| compared, | |||
| * | , | ||
| coordinate_pairs = None, | |||
| int | bins = 10, | ||
| ranges = None, | |||
| float | pseudocount = 1e-12 ) |
Sum reference-to-compared KL divergences over descriptor pairs.
| reference | Nonempty matrix of reference descriptors. |
| compared | Nonempty matrix in the same descriptor space. |
| coordinate_pairs | Pairs of column indices, or consecutive pairs by default. |
| bins | Number of bins for each coordinate. |
| ranges | Optional finite (lower, upper) limits per coordinate. |
| pseudocount | Positive amount to add to each histogram bin. |
Compare descriptor distributions on explicit two-dimensional projections. Use common histogram edges for both inputs. With no explicit ranges, derive the edges from both samples together. Explicit ranges must contain every observation. Smooth the counts before normalising each histogram. Smaller values indicate more similar distributions.
Definition at line 214 of file metrics.py.