Skip to content

BUG: Incorrect shape handling for annotators parameter in query function in SingleAnnotatorWrapper #404

Closed

Description

@Cheng-JY

Describe the issue:

The annotators parameter, expected to be of shape (n_candidates, n_annotators), does not work correctly in the query function of class SingleAnnotatorWrapper.

Reproduce the bug via a code example:

import numpy as np
from sklearn.datasets import make_blobs
from skactiveml.pool import RandomSampling
from skactiveml.pool.multiannotator import SingleAnnotatorWrapper
from skactiveml.utils import majority_vote, is_labeled, is_unlabeled

if __name__ == '__main__':
    X, y_true = make_blobs(n_samples=200, random_state=0)
    X = X.astype(np.float32)
    y = np.array([y_true, y_true], dtype=float).T
    y[:100, 0] = -1
    y[100:, 1] = -1

    candidate_indicies = np.arange(50, 150)

    sa_qs = RandomSampling(random_state=0, missing_label=-1)
    ma_qs = SingleAnnotatorWrapper(sa_qs, random_state=0, missing_label=-1)

    label_available = is_labeled(y, missing_label=-1)
    A_perf = np.ones_like(y)

    query_indices = ma_qs.query(
        X=X,
        y=y,
        candidates=candidate_indicies,
        A_perf=A_perf[candidate_indicies],
        batch_size=50,
        annotators=label_available[candidate_indicies],
        n_annotators_per_sample=1,
    )

Error message:

Traceback (most recent call last):
  File "/Users/chengjiaying/BachelorProjekt/Crowd_Layer/11_test.py", line 22, in <module>
    query_indices = ma_qs.query(
  File "/opt/anaconda3/envs/BachelorProjekt/lib/python3.10/site-packages/skactiveml/pool/multiannotator/_wrapper.py", line 187, in query
    ) = super()._validate_data(
  File "/opt/anaconda3/envs/BachelorProjekt/lib/python3.10/site-packages/skactiveml/base.py", line 599, in _validate_data
    check_consistent_length(X, annotators)
  File "/opt/anaconda3/envs/BachelorProjekt/lib/python3.10/site-packages/sklearn/utils/validation.py", line 397, in check_consistent_length
    raise ValueError(
ValueError: Found input variables with inconsistent numbers of samples: [200, 100]

Context for the issue:

No response

Activity

  1. changed the title [-]BUG: Incorrect shape handling for 'annotators' parameter in query function in SingleAnnotatorWrapper[/-] [+]BUG: Incorrect shape handling for `annotators` parameter in query function in SingleAnnotatorWrapper[/+] on Jun 13, 2024
  2. Cheng-JY commented on Jun 18, 2024

    @Cheng-JY
    ContributorAuthor

    Hello,

    I resolved this problem by modifying the code in skactiveml/base.py at line 596 to:

    elif annotators.ndim == 2:
        annotators = check_array(annotators, dtype=bool)
        if candidates is None:
            check_consistent_length(X, annotators)
        else:
            check_consistent_length(candidates, annotators)
        check_consistent_length(y.T, annotators.T)
    

    This change ensures that the annotators parameter is handled correctly when its shape is `(n_candidates, n_annotators)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions