Пример #1
0
def test_control_predition_for_feature():
    start_time = datetime.now()
    x, y = get_feedback1()
    hr = SpaceRepetitionReference(epoch=start_time)
    hf = SpaceRepetitionFeedback(x[0:4], y, epoch=start_time)
    hctrl = SpaceRepetitionController(epoch=start_time,
                                      reference=hr,
                                      feedback=hf)

    graph_handle, data_dict = hctrl.plot_graphs(stop=30)
    training_moments_1 = hctrl.range_for(stop=30, curve=1, day_step_size=0.1)
    results_1 = [
        hctrl.recollect_scalar(training_moment, curve=1)
        for training_moment in training_moments_1
    ]
    training_moments_2 = hctrl.range_for(stop=30, curve=2, day_step_size=0.1)
    results_2 = [
        hctrl.recollect_scalar(training_moment, curve=2)
        for training_moment in training_moments_2
    ]
    training_moments_3 = hr.range_for(stop=30, curve=3, day_step_size=0.1)
    results_3 = [
        hctrl.recollect_scalar(training_moment, curve=3)
        for training_moment in training_moments_3
    ]
    ctrl_plot = graph_handle.axarr[-1]
    ctrl_plot.plot(training_moments_1, results_1, color='xkcd:azure')
    ctrl_plot.plot(training_moments_2, results_2, color='xkcd:darkgreen')
    ctrl_plot.plot(training_moments_3, results_3, color='xkcd:maroon')
    hr.save_figure("results/space_ctrl_predictions.pdf")
    graph_handle.close()
Пример #2
0
def test_feedback_graph_too_short():
    x, y = get_feedback1()
    start_time = datetime.now()
    hr = SpaceRepetitionReference(epoch=start_time)
    hf = SpaceRepetitionFeedback(x, y, epoch=start_time)
    hdl, _ = hf.plot_graph(stop=4)
    hr.save_figure("results/space_feedback_too_short.pdf")
    hdl.close()
Пример #3
0
def test_feedback_graph_too_long():
    x, y = get_feedback1()
    start_time = datetime.now()
    hr = SpaceRepetitionReference(epoch=start_time)
    hf = SpaceRepetitionFeedback(x, y, epoch=start_time)
    hdl, _ = hf.plot_graph(stop=50)  # it should automatically fit the data
    hr.save_figure("results/space_feedback_too_long.pdf")
    hdl.close()
Пример #4
0
def test_learning_tracker_scheduled_offsets_from_generator():
    hr = SpaceRepetitionReference(epoch=datetime.now())

    targets = [
        0.0, 0.4589442709995035, 0.8952268306891566, 1.3571621263040674,
        1.881320415336438, 2.517823066268917, 3.3604547989757783,
        4.635636774985627, 7.118908457377074, 16.123000823500735
    ]

    for r, t in zip(hr.schedule_as_offset(stop=40), targets):
        assert abs(r - t) <= 0.001
Пример #5
0
def test_reference_scheduled_datetimes_from_generator():
    start_time = datetime.now()
    hr = SpaceRepetitionReference(epoch=datetime.now())

    targets = [
        0.0, 0.4589442709995035, 0.8952268306891566, 1.3571621263040674,
        1.881320415336438, 2.517823066268917, 3.3604547989757783,
        4.635636774985627, 7.118908457377074, 16.123000823500735
    ]

    datetime_targets = [start_time + timedelta(days=t) for t in targets]

    stop_date = start_time + timedelta(days=40)
    for r, t in zip(hr.schedule(stop=stop_date), datetime_targets):
        assert abs((r - t).total_seconds()) <= 0.001
Пример #6
0
def test_control_graph_too_short():
    start_time = datetime.now()
    x, y = get_feedback1()
    stop_date = 5
    hr = SpaceRepetitionReference(epoch=start_time)
    hf = SpaceRepetitionFeedback(x[0:2], y, epoch=start_time)
    hctrl = SpaceRepetitionController(reference=hr,
                                      feedback=hf,
                                      epoch=start_time)
    graph_handle, data_dict = hctrl.plot_graphs(stop=stop_date)
    hctrl.save_figure("results/spaced_control_too_short.pdf")
    graph_handle.close()
Пример #7
0
def test_generator_controller():
    start_time = datetime.now()
    x, y = get_feedback1()

    hr = SpaceRepetitionReference(epoch=start_time)
    hf = SpaceRepetitionFeedback(x[0:4], y, epoch=start_time)
    hctrl = SpaceRepetitionController(reference=hr,
                                      feedback=hf,
                                      epoch=start_time)

    hdl, _ = hctrl.plot_graphs(stop=43)
    hctrl.save_figure("results/space_control.pdf")
    hdl.close()
Пример #8
0
def test_control_predition_range_for_feature():
    start_time = datetime.now()
    x, y = get_feedback1()
    hr = SpaceRepetitionReference(epoch=start_time)
    hf = SpaceRepetitionFeedback(x[0:4], y, epoch=start_time)
    hctrl = SpaceRepetitionController(epoch=start_time,
                                      reference=hr,
                                      feedback=hf)
    training_moments = hctrl.range_for(stop=30, curve=1, day_step_size=0.1)
    assert training_moments[0] == hctrl.days_offset_from_epoch_to_datetime(
        hctrl.dates_as_day_offsets[0])

    training_moments = hctrl.range_for(stop=30, curve=2, day_step_size=0.1)
    assert training_moments[0] == hctrl.days_offset_from_epoch_to_datetime(
        hctrl.dates_as_day_offsets[1])
Пример #9
0
def test_reference_prediction_range_for_feature():
    start_time = datetime.now()
    hr = SpaceRepetitionReference(
        epoch=start_time,
        plasticity_root=0.03699,
        plasticity_denominator_offset=0.0054,
    )
    training_moments = hr.range_for(stop=30, curve=1, day_step_size=0.1)
    assert training_moments[0] == hr.days_offset_from_epoch_to_datetime(
        hr.dates_as_day_offsets[0])
    assert training_moments[-1] == \
      hr.days_offset_from_epoch_to_datetime(30) - timedelta(days=0.1)

    training_moments = hr.range_for(stop=30, curve=2, day_step_size=0.1)
    assert training_moments[0] == hr.days_offset_from_epoch_to_datetime(
        hr.dates_as_day_offsets[1])
Пример #10
0
def test_a_control_series():
    start_time = datetime.now()
    x, y = get_feedback1()
    stop_date = 2 * x[-1] * 0.5
    hr = SpaceRepetitionReference(epoch=start_time)
    hf = SpaceRepetitionFeedback(x[0:2], y, epoch=start_time)
    hctrl = SpaceRepetitionController(reference=hr,
                                      feedback=hf,
                                      epoch=start_time)
    graph_handle, data_dict = hctrl.plot_graphs(stop=stop_date)
    hctrl.save_figure("results/spaced_0.pdf")
    graph_handle.close()

    #hr = SpaceRepetitionReference(plot=False, range=range_, epoch=start_time)
    hf = SpaceRepetitionFeedback(x[0:3], y, epoch=start_time)
    hctrl.initialize_feedback(feedback=hf)
    graph_handle, _ = hctrl.plot_graphs(stop=stop_date)
    hctrl.save_figure("results/spaced_1.pdf")
    graph_handle.close()

    #hr = SpaceRepetitionReference(plot=False,range=range_,epoch=start_time)
    hf = SpaceRepetitionFeedback(x[0:4], y, epoch=start_time)
    hctrl.initialize_feedback(feedback=hf)
    graph_handle, _ = hctrl.plot_graphs(stop=stop_date)
    hctrl.save_figure("results/spaced_2.pdf")
    graph_handle.close()

    #hr = SpaceRepetitionReference(plot=False,range=range_,epoch=start_time)
    hf = SpaceRepetitionFeedback(x[0:5], y, epoch=start_time)
    hctrl.initialize_feedback(feedback=hf)
    graph_handle, _ = hctrl.plot_graphs(stop=stop_date)
    data_dict.clear()
    hctrl.save_figure("results/spaced_3.pdf")
    graph_handle.close()

    #hr = SpaceRepetitionReference(plot=False,range=range_,epoch=start_time)
    hf = SpaceRepetitionFeedback(x[0:6], y, epoch=start_time)
    hctrl.initialize_feedback(feedback=hf)
    graph_handle, _ = hctrl.plot_graphs(stop=stop_date)
    data_dict.clear()
    hctrl.save_figure("results/spaced_4.pdf")
    graph_handle.close()

    #hr = SpaceRepetitionReference(plot=False,range=range_,epoch=start_time)
    hf = SpaceRepetitionFeedback(x[0:7], y, epoch=start_time)
    hctrl.initialize_feedback(feedback=hf)
    graph_handle, _ = hctrl.plot_graphs(stop=stop_date)
    data_dict.clear()
    hctrl.save_figure("results/spaced_5.pdf")
    graph_handle.close()

    #hr = SpaceRepetitionReference(plot=False,range=range_,epoch=start_time)
    hf = SpaceRepetitionFeedback(x[0:8], y, epoch=start_time)
    hctrl.initialize_feedback(feedback=hf)
    graph_handle, _ = hctrl.plot_graphs(stop=stop_date)
    graph_handle.epoch  # the epoch
    graph_handle.axarr  # array of matplotlib axes mapping the subplots
    graph_handle.figure  # the matplotlib figure
    graph_handle.axarr[-1]  # the control plot

    data_dict.clear()
    hctrl.save_figure("results/spaced_6.pdf")
    graph_handle.close()
Пример #11
0
def test_reference_prediction_feature():
    start_time = datetime.now()
    hr = SpaceRepetitionReference(epoch=start_time, )

    graph_handle, data_dict = hr.plot_graph(stop=30)
    training_moments_1 = hr.range_for(stop=30, curve=1, day_step_size=0.1)
    results_1 = [
        hr.recollect_scalar(training_moment, curve=1)
        for training_moment in training_moments_1
    ]
    training_moments_2 = hr.range_for(stop=30, curve=2, day_step_size=0.1)
    results_2 = [
        hr.recollect_scalar(training_moment, curve=2)
        for training_moment in training_moments_2
    ]
    training_moments_3 = hr.range_for(stop=30, curve=3, day_step_size=0.1)
    results_3 = [
        hr.recollect_scalar(training_moment, curve=3)
        for training_moment in training_moments_3
    ]
    reference_plot = graph_handle.axarr
    reference_plot.plot(training_moments_1, results_1, color='xkcd:azure')
    reference_plot.plot(training_moments_2, results_2, color='xkcd:darkgreen')
    reference_plot.plot(training_moments_3, results_3, color='xkcd:maroon')
    hr.save_figure("results/space_reference_predictions.pdf")
    graph_handle.close()
Пример #12
0
def test_reference_plot_closing_features():
    start_time = datetime.now()
    hr = SpaceRepetitionReference(epoch=start_time)
    hdl, _ = hr.plot_graph(stop=42)
    hdl.close()
Пример #13
0
def test_reference_graph_too_long():
    hr = SpaceRepetitionReference(epoch=datetime.now())
    hdl, _ = hr.plot_graph(stop=60)
    hr.save_figure("results/space_reference_too_long_plot.pdf")
    hdl.close()
Пример #14
0
def test_reference_sizeof_growing_deques():
    hr = SpaceRepetitionReference(epoch=datetime.now())
    # the deques should grow at the same rate, otherwise
    # we will have ring buffer slippage
    assert len(hr.forgetting_enclosures) == len(hr.dates_as_day_offsets)
    assert len(hr.forgetting_enclosures) == len(hr.results_at_training_moments)
Пример #15
0
def test_reference_deque_maxlen():
    hr = SpaceRepetitionReference(epoch=datetime.now())
    assert hr.maxlen == SpaceRepetitionReference.Max_Length