Пример #1
0
 def test_one(A):
     selected = sample_to_2min(A)
     ratios = []
     for l0 in set(A):
         for l1 in set(A):
             ratios.append( (A[selected] == l0).sum() / (A[selected] == l1).sum() )
     assert np.max(ratios) <= 2.001
Пример #2
0
 def test_one(A):
     selected = sample_to_2min(A)
     ratios = []
     for l0 in set(A):
         for l1 in set(A):
             ratios.append(
                 (A[selected] == l0).sum() / (A[selected] == l1).sum())
     assert np.max(ratios) <= 2.001
Пример #3
0
def test_sample_to_2min_list():
    from collections import defaultdict
    def count(xs):
        counts = defaultdict(int)
        for x in xs:
            counts[x] += 1
        return counts
    labels = ["A"]*8 + ["B"]*12 + ["C"]*16 + ["D"] * 24 + ["E"] * 1000
    selected = sample_to_2min(labels)
    before = count(labels)
    after = count(np.array(labels)[selected])
    assert max(after.values()) == min(before.values())*2
Пример #4
0
def test_sample_to_2min_list():
    from collections import defaultdict

    def count(xs):
        counts = defaultdict(int)
        for x in xs:
            counts[x] += 1
        return counts

    labels = ["A"] * 8 + ["B"] * 12 + ["C"] * 16 + ["D"] * 24 + ["E"] * 1000
    selected = sample_to_2min(labels)
    before = count(labels)
    after = count(np.array(labels)[selected])
    assert max(after.values()) == min(before.values()) * 2