Пример #1
0
def test_get_previous_times_marked():
    th.random.manual_seed(0)
    events, query = get_test_events_query(batch_size=1,
                                          max_seq_len=12,
                                          queries=7)
    result = get_prev_times_marked(query=query, events=events)

    a = 0
Пример #2
0
def test_to_flat_idxs():
    events, query = get_test_events_query()

    times_marked = events.get_times(marked=True)
    times = events.get_times()
    masks = events.get_mask(marked=True)
    to_flat_idxs = events.to_flat_idxs

    for time_marked, time, mask, to_flat_idx in zip(
            times_marked, times, masks, to_flat_idxs):
        for tm, m, idx in zip(time_marked, mask, to_flat_idx):
            assert th.all(tm * m == th.take(time, idx) * m)
Пример #3
0
def get_times(batch_size=1, marks=1, seq_len=16, n_queries=16, n_iters=100):
    events, _ = get_test_events_query(marks=marks,
                                      batch_size=batch_size,
                                      max_seq_len=seq_len,
                                      queries=n_queries)
    beta = th.rand([marks, marks], dtype=th.float32).to(th.device("cpu"))

    # t1 = time.time()
    # for _ in range(n_iters):
    #     naive(events=events, beta=beta)
    # t1 = time.time() - t1
    # t1 = t1 / n_iters

    t2 = time.time()
    for _ in range(n_iters):
        recursive(events=events, beta=beta)
    t2 = time.time() - t2
    t2 = t2 / n_iters

    t3 = time.time()
    for _ in range(n_iters):
        recursive_v(events=events, beta=beta)
    t3 = time.time() - t3
    t3 = t3 / n_iters

    if th.cuda.is_available():
        events, query = get_test_events_query(marks=marks,
                                              batch_size=batch_size,
                                              max_seq_len=seq_len,
                                              queries=n_queries,
                                              device=th.device("cuda"))
        beta = beta.to(th.device("cuda"))
        t4 = time.time()
        for _ in range(n_iters):
            recursive_v(events=events, beta=beta)
        t4 = time.time() - t4
        t4 = t4 / n_iters
    else:
        t4 = None
    return None, t2, t3, t4
Пример #4
0
def test_r_terms(device=th.device("cpu")):
    th.manual_seed(3)
    marks, batch_size = 12, 23
    max_seq_len = 138
    queries = 13
    events, _ = get_test_events_query(marks=marks,
                                      batch_size=batch_size,
                                      max_seq_len=max_seq_len,
                                      queries=queries,
                                      device=device)
    beta = th.rand([marks, marks], dtype=th.float32).to(device)

    r_terms_naive = get_r_terms_n(events=events, beta=beta)
    r_terms_recursive = get_r_terms_r(events=events, beta=beta)
    r_terms_recursive_v = get_r_terms_v(events=events, beta=beta)

    assert th.allclose(r_terms_naive, r_terms_recursive), (
        "The r term computational approaches do not match.")

    assert th.allclose(r_terms_naive, r_terms_recursive_v), (
        "The r term vector computational approaches do not match.")
Пример #5
0
def get_fast_slow_results(queries=1,
                          marks=2,
                          max_seq_len=10,
                          batch_size=1,
                          dtype=th.float32):
    events, query = get_test_events_query(marks=marks,
                                          batch_size=batch_size,
                                          max_seq_len=max_seq_len,
                                          queries=queries,
                                          dtype=dtype)
    alpha = th.rand([marks, marks], dtype=dtype)
    beta = th.rand([marks, marks], dtype=dtype)
    mu = th.rand([marks], dtype=dtype)

    (prev_times, _), is_event, _ = get_prev_times(query=query,
                                                  events=events,
                                                  allow_window=True)

    results_fast = decoder_fast(events=events,
                                query=query,
                                prev_times=prev_times,
                                is_event=is_event,
                                alpha=alpha,
                                beta=beta,
                                mu=mu,
                                marks=marks)

    results_slow = decoder_slow(events=events,
                                query=query,
                                prev_times=prev_times,
                                is_event=is_event,
                                alpha=alpha,
                                beta=beta,
                                mu=mu,
                                marks=marks)

    return results_fast, results_slow
Пример #6
0
def run_test():
    marks = 3
    events, query = get_test_events_query(marks=marks)
    beta = th.rand([marks, marks])

    get_r_terms(events=events, beta=beta)