예제 #1
0
def test_example_features():
    vw_ex = Workspace(quiet=True)
    ex = vw_ex.example("1 |a two features |b more features here")
    ns = vowpalwabbit.NamespaceId(ex, 1)
    assert ex.get_feature_id(ns, "a") == 127530
    ex.push_hashed_feature(ns, 1122)
    ex.push_features("x", [("c", 1.0), "d"])
    ex.push_feature(ns, 11000)
    assert ex.num_features_in("x") == 2
    assert ex.sum_feat_sq(ns) == 5.0
    ns2 = vowpalwabbit.NamespaceId(ex, 2)
    ex.push_namespace(ns2)
    assert ex.pop_namespace()
예제 #2
0
def test_namespace_id():
    vw_ex = Workspace(quiet=True)
    ex = vw_ex.example("1 |a two features |b more features here")
    nm1 = vowpalwabbit.NamespaceId(ex, 0)
    nm2 = vowpalwabbit.NamespaceId(ex, 1)
    nm3 = vowpalwabbit.NamespaceId(ex, 2)
    assert nm1.id == 0
    assert nm1.ord_ns == 97
    assert nm1.ns == "a"
    assert nm2.id == 1
    assert nm2.ord_ns == 98
    assert nm2.ns == "b"
    assert nm3.id == 2
    assert nm3.ord_ns == 128
    assert nm3.ns == "\x80"  # Represents string of ord_ns
예제 #3
0
def test_example_namespace_id():
    vw_ex = Workspace(quiet=True)
    ex = vw_ex.example("1 |a two features |b more features here")
    ns = vowpalwabbit.NamespaceId(ex, 1)
    assert isinstance(ex.get_ns(1), vowpalwabbit.NamespaceId)
    assert isinstance(ex[2], vowpalwabbit.ExampleNamespace)
    assert ex.setup_done is True
    assert ex.num_features_in(ns) == 3
예제 #4
0
def test_example_namespace():
    vw_ex = Workspace(quiet=True)
    ex = vw_ex.example("1 |a two features |b more features here")
    ns_id = vowpalwabbit.NamespaceId(ex, 1)
    ex_nm = vowpalwabbit.ExampleNamespace(ex,
                                          ns_id,
                                          ns_hash=vw_ex.hash_space(ns_id.ns))
    assert isinstance(ex_nm.ex, vowpalwabbit.Example)
    assert isinstance(ex_nm.ns, vowpalwabbit.NamespaceId)
    assert ex_nm.ns_hash == 2514386435
    assert ex_nm.num_features_in() == 3
    assert ex_nm[2] == (11617, 1.0)  # represents (feature, value)
    iter_obj = ex_nm.iter_features()
    for i in range(ex_nm.num_features_in()):
        assert ex_nm[i] == next(iter_obj)
    assert ex_nm.pop_feature()
    ex_nm.push_features(ns_id, ["c", "d"])
    assert ex_nm.num_features_in() == 4