Skip to content

AttributeError: 'Sampler' object has no attribute 'sample', for DensityBasedSampling #8

@desmond-molloy-mcl

Description

@desmond-molloy-mcl

Currently, it is not possible to use DensityBasedSampling in this package. The code below, taken from the README, would be expected to successfully create a sampled dataset.

from sampling.Sampler import *
from sampling.SamplingMethods import *
import numpy as np
data = np.array([[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]])
labels = np.array([0, 1, 0, 1, 0])
sampler = Sampler() # Initialize the Sampler object
sampler.set_data(data, labels)
# data: an (n*2) numpy array indicating the point coordinates
# labels: an (n*1) numpy array indicating the class labels with integers 0, 1, 2, ...
# or None if you use single-class sampling methods
sampler.set_sampling_method(DensityBiasedSampling, sampling_rate=0.5)
indices = sampler.sample()
# indices: an (m*1) numpy array indicating the indices of the sampling result
sampled_data, sampled_labels = sampler.get_samples()
# sampled_data: an (m*2) numpy array indicating the sampled point coordinates
# sampled_labels: an (m*2) numpy array indicating the class labels of the sampled points

However, it throws the following error:

, line 14, in <module>
    indices = sampler.sample()
AttributeError: 'Sampler' object has no attribute 'sample'

This error does not occur when sampling method RandomSampling is used.

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