Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: replace input arguments to be compatible with state and work on… #12

Merged
merged 1 commit into from
Sep 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions src/autora/experimentalist/uncertainty/__init__.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
from typing import Iterable
from typing import Union

import numpy as np
import pandas as pd
from scipy.stats import entropy

from autora.utils.deprecation import deprecated_alias


def sample(X, model, num_samples, measure="least_confident"):
def sample(
conditions: Union[pd.DataFrame, np.ndarray],
model,
num_samples,
measure="least_confident",
):
"""

Args:
X: pool of IV conditions to evaluate uncertainty
conditions: pool of IV conditions to evaluate uncertainty
model: Scikit-learn model, must have `predict_proba` method.
num_samples: number of samples to select
measure: method to evaluate uncertainty. Options:
Expand All @@ -25,12 +31,10 @@ class labels under the model, respectively.
$x* = \\operatorname{argmax} \\left( - \\sum P(y_i|x)
\\operatorname{log} P(y_i|x) \\right)$

Returns: Sampled pool
Returns: Sampled conditions

"""

if isinstance(X, Iterable):
X = np.array(list(X))
X = np.array(conditions)

a_prob = model.predict_proba(X)

Expand Down Expand Up @@ -60,7 +64,11 @@ class labels under the model, respectively.
f"Only 'least_confident', 'margin', or 'entropy' is supported."
)

return X[idx]
new_conditions = X[idx]
if isinstance(conditions, pd.DataFrame):
new_conditions = pd.DataFrame(X[idx], columns=conditions.columns)

return new_conditions


uncertainty_sample = sample
Expand Down