def test_learning_tracker_scheduled_should_output_dates_after_feedback(): lt = LearningTracker(epoch=datetime.now()) lt.learned(result=0.40, when=0.01) lt.learned(result=0.44, when=0.8) for offset in lt.schedule_as_offset(stop=10): assert offset > 0.8
def test_learning_tracker_broken_feedback_curve_reproduction(): lt = LearningTracker(epoch=datetime.now()) lt.learned(result=0.44, when=0.8) lt.learned(result=0.64, when=1.75) lt.learned(result=0.55, when=1.3) lt.learned(result=0.40, when=0.001) lt.learned(result=0.64, when=3.02) lt.plot_graphs(stop=30) lt.save_figure("results/lt_broken_feedback_curve.pdf")
def test_serialization_epoch(): lt = LearningTracker(epoch=datetime.now(), ) moments, results = get_feedback1() for index, (moment, result) in enumerate(zip(moments[0:4], results)): lt.learned(when=moment, result=result) byte_stream = pickle.dumps(lt) unpickled_learning_tracker = pickle.loads(byte_stream) hdl, _ = unpickled_learning_tracker.plot_graphs(stop=40) unpickled_learning_tracker.save_figure("results/post_pickle.pdf") hdl.close()
def test_learning_tracker_longterm_response(): start_time = datetime.now() moments, results = get_feedback1() lt = LearningTracker(epoch=start_time) for index, (moment, result) in enumerate(zip(moments[0:2], results)): lt.learned(when=moment, result=result) hd, _ = lt.plot_graphs(stop=300) lt.save_figure("results/space_learning_tracker_too_long.pdf") hd.close()
def test_learning_tracker_broken_two_handle_graph(): lt = LearningTracker(epoch=datetime.now()) # give our learning tracker some feedback for d, r in zip( [0, 0.8, 1.75, 3.02, 4.8, 7.33], [0.40, 0.44, 0.64, 0.76, 0.83, 0.89], ): lt.learned(result=r, when=d) with lt.graphs(stop=43, show=True, control_handle=True, reference_handle=True, filename='results/context_manager_two_handles.svg') as (rh, ch): r_m = lt.reference.range_for(curve=3, stop=43, day_step_size=0.5) r_p = [lt.reference.predict_result(moment, curve=3) for moment in r_m] rh.plot(r_m, r_p, color='xkcd:ruby') c_m = lt.range_for(curve=1, stop=43, day_step_size=0.5) c_p = [lt.predict_result(moment, curve=1) for moment in c_m] ch.plot(c_m, c_p, color='xkcd:azure')
def test_learning_tracker_next_offset_feature(): lt = LearningTracker(epoch=datetime.now()) lt.learned(result=0.40, when=0.001) lt.learned(result=0.44, when=0.8) lt.learned(result=0.55, when=1.3) lt.learned(result=0.64, when=1.75) lt.learned(result=0.76, when=3.02) results = [ [4.8, 7.33, 10.93, 16.00, 23.00, 29.00], [0.83, 0.89, 1.00, 0.99, 0.99, 1.00], ] for d, r in zip(*results): days_since_training_epoch, result = d, r lt.learned(result=result, when=days_since_training_epoch) sc = lt.next_offset() assert abs(sc - 122.4043) < 0.01