Skip to content

autora.experimentalist.novelty

Novelty Experimentalist

sample(conditions, reference_conditions, num_samples=None, metric='euclidean', integration='min')

This novelty experimentalist re-arranges the pool of experimental conditions according to their dissimilarity with respect to a reference pool. The default dissimilarity is calculated as the average of the pairwise distances between the conditions in the pool and the reference conditions. If no number of samples are specified, all samples will be ordered and returned from the pool.

Parameters:

Name Type Description Default
conditions Union[DataFrame, ndarray]

pool of experimental conditions to evaluate dissimilarity

required
reference_conditions Union[DataFrame, ndarray]

reference pool of experimental conditions

required
num_samples Optional[int]

number of samples to select from the pool of experimental conditions

None
metric str

dissimilarity measure. Options: 'euclidean', 'manhattan', 'chebyshev', 'minkowski', 'wminkowski', 'seuclidean', 'mahalanobis', 'haversine', 'hamming', 'canberra', 'braycurtis', 'matching', 'jaccard', 'dice', 'kulsinski', 'rogerstanimoto', 'russellrao', 'sokalmichener', 'sokalsneath', 'yule'. See sklearn.metrics.DistanceMetric for more details.

'euclidean'

Returns:

Type Description

Sampled pool of conditions

Source code in temp_dir/novelty/src/autora/experimentalist/novelty/__init__.py
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
64
65
66
67
68
69
70
71
72
73
74
75
76
def sample(
    conditions: Union[pd.DataFrame, np.ndarray],
    reference_conditions: Union[pd.DataFrame, np.ndarray],
    num_samples: Optional[int] = None,
    metric: AllowedMetrics = "euclidean",
    integration: str = "min",
):
    """
    This novelty experimentalist re-arranges the pool of experimental conditions according to their
    dissimilarity with respect to a reference pool. The default dissimilarity is calculated
    as the average of the pairwise distances between the conditions in the pool and the reference
    conditions.
    If no number of samples are specified, all samples will be ordered and returned from the pool.

    Args:
        conditions: pool of experimental conditions to evaluate dissimilarity
        reference_conditions: reference pool of experimental conditions
        num_samples: number of samples to select from the pool of experimental conditions
        (the default is to select all)
        metric (str): dissimilarity measure. Options: 'euclidean', 'manhattan', 'chebyshev',
            'minkowski', 'wminkowski', 'seuclidean', 'mahalanobis', 'haversine',
            'hamming', 'canberra', 'braycurtis', 'matching', 'jaccard', 'dice',
            'kulsinski', 'rogerstanimoto', 'russellrao', 'sokalmichener',
            'sokalsneath', 'yule'. See [sklearn.metrics.DistanceMetric][] for more details.

    Returns:
        Sampled pool of conditions
    """

    condition_pool_copy = conditions.copy()

    new_conditions = novelty_score_sample(
        conditions, reference_conditions, num_samples, metric, integration
    )
    new_conditions.drop("score", axis=1, inplace=True)

    if isinstance(condition_pool_copy, pd.DataFrame):
        new_conditions = pd.DataFrame(new_conditions, columns=condition_pool_copy.columns)

    return new_conditions

score_sample(conditions, reference_conditions, num_samples=None, metric='euclidean', integration='sum')

This dissimilarity samples re-arranges the pool of experimental conditions according to their dissimilarity with respect to a reference pool. The default dissimilarity is calculated as the average of the pairwise distances between the conditions in the pool and the reference conditions. If no number of samples are specified, all samples will be ordered and returned from the pool.

Parameters:

Name Type Description Default
conditions Union[DataFrame, ndarray]

pool of experimental conditions to evaluate dissimilarity

required
reference_conditions Union[DataFrame, ndarray]

reference pool of experimental conditions

required
num_samples Optional[int]

number of samples to select from the pool of experimental conditions

None
metric str

dissimilarity measure. Options: 'euclidean', 'manhattan', 'chebyshev', 'minkowski', 'wminkowski', 'seuclidean', 'mahalanobis', 'haversine', 'hamming', 'canberra', 'braycurtis', 'matching', 'jaccard', 'dice', 'kulsinski', 'rogerstanimoto', 'russellrao', 'sokalmichener', 'sokalsneath', 'yule'. See sklearn.metrics.DistanceMetric for more details.

'euclidean'
integration str

Distance integration method used to compute the overall dissimilarity score

'sum'
for a given data point. Options

'sum', 'prod', 'mean', 'min', 'max'.

required

Returns:

Type Description
DataFrame

Sampled pool of conditions and dissimilarity scores

Source code in temp_dir/novelty/src/autora/experimentalist/novelty/__init__.py
 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
138
139
def score_sample(
    conditions: Union[pd.DataFrame, np.ndarray],
    reference_conditions: Union[pd.DataFrame, np.ndarray],
    num_samples: Optional[int] = None,
    metric: AllowedMetrics = "euclidean",
    integration: str = "sum",
) -> pd.DataFrame:
    """
    This dissimilarity samples re-arranges the pool of experimental conditions according to their
    dissimilarity with respect to a reference pool. The default dissimilarity is calculated
    as the average of the pairwise distances between the conditions in the pool and the reference
    conditions.
    If no number of samples are specified, all samples will be ordered and returned from the pool.

    Args:
        conditions: pool of experimental conditions to evaluate dissimilarity
        reference_conditions: reference pool of experimental conditions
        num_samples: number of samples to select from the pool of experimental conditions
        (the default is to select all)
        metric (str): dissimilarity measure. Options: 'euclidean', 'manhattan', 'chebyshev',
            'minkowski', 'wminkowski', 'seuclidean', 'mahalanobis', 'haversine',
            'hamming', 'canberra', 'braycurtis', 'matching', 'jaccard', 'dice',
            'kulsinski', 'rogerstanimoto', 'russellrao', 'sokalmichener',
            'sokalsneath', 'yule'. See [sklearn.metrics.DistanceMetric][] for more details.
        integration: Distance integration method used to compute the overall dissimilarity score
        for a given data point. Options: 'sum', 'prod', 'mean', 'min', 'max'.

    Returns:
        Sampled pool of conditions and dissimilarity scores
    """
    conditions = pd.DataFrame(conditions)
    reference_conditions = pd.DataFrame(reference_conditions)

    dist = DistanceMetric.get_metric(metric)
    distances = dist.pairwise(reference_conditions, conditions)

    if integration == "sum":
        integrated_distance = np.sum(distances, axis=0)
    elif integration == "mean":
        integrated_distance = np.mean(distances, axis=0)
    elif integration == "max":
        integrated_distance = np.max(distances, axis=0)
    elif integration == "min":
        integrated_distance = np.min(distances, axis=0)
    elif integration == "prod":
        integrated_distance = np.prod(distances, axis=0)
    else:
        raise ValueError(f"Integration method {integration} not supported.")

    # normalize the distances
    scaler = StandardScaler()
    score = scaler.fit_transform(integrated_distance.reshape(-1, 1)).flatten()

    # order rows in Y from highest to lowest
    conditions["score"] = score
    conditions = conditions.sort_values(by="score", ascending=False)

    if num_samples is not None:
        return conditions[:num_samples]
    else:
        return conditions