def validate_known_curve(self): plt.figure() N = 100 x = numpy.linspace(-1, 1, N) y = numpy.sin(4 * x) smoother.DEFAULT_BASIC_SMOOTHER = smoother.BasicFixedSpanSmootherSlowUpdate smooth = smoother.perform_smooth(x, y, smoother_cls=supersmoother.SuperSmoother) plt.plot(x, smooth.smooth_result, label='Slow') smoother.DEFAULT_BASIC_SMOOTHER = smoother.BasicFixedSpanSmoother smooth = smoother.perform_smooth(x, y, smoother_cls=supersmoother.SuperSmoother) plt.plot(x, smooth.smooth_result, label='Fast') plt.plot(x, y, '.', label='data') plt.legend() plt.show()
def validate_basic_smoother_resid(): """ compare residuals """ x, y = sort_data(*sample_problems.sample_smoother_problem_brieman82()) plt.figure() for span in smoother.DEFAULT_SPANS: my_smoother = smoother.perform_smooth(x, y, span) friedman_smooth, resids = run_friedman_smooth(x, y, span) plt.plot(x, my_smoother.cross_validated_residual, '.-', label='pyace span = {0}'.format(span)) plt.plot(x, resids, '.-', label='Friedman span = {0}'.format(span)) finish_plot()
def validate_supersmoother(): x, y = ace.samples.smoother_friedman82.build_sample_smoother_problem_friedman82() x, y = sort_data(x, y) my_smoother = smoother.perform_smooth(x, y, smoother_cls=supersmoother.SuperSmootherWithPlots) # smoother.DEFAULT_BASIC_SMOOTHER = BasicFixedSpanSmootherBreiman supsmu_result = run_freidman_supsmu(x, y, bass_enhancement=0.0) mace_result = run_mace_smothr(x, y, bass_enhancement=0.0) plt.plot(x, y, '.', label='Data') plt.plot(x, my_smoother.smooth_result, '-', label='pyace') plt.plot(x, supsmu_result, '-', label='SUPSMU') plt.plot(x, mace_result, '-', label='SMOOTH') plt.legend() plt.savefig('supersmoother_validation.png')
def validate_basic_smoother(): """ Runs Friedman's test from Figure 2b. """ x, y = sort_data(*ace.samples.smoother_friedman82.build_sample_smoother_problem_friedman82()) plt.figure() # plt.plot(x, y, '.', label='Data') for span in smoother.DEFAULT_SPANS: my_smoother = smoother.perform_smooth(x, y, span) friedman_smooth, resids = run_friedman_smooth(x, y, span) plt.plot(x, my_smoother.smooth_result, '.-', label='pyace span = {0}'.format(span)) plt.plot(x, friedman_smooth, '.-', label='Friedman span = {0}'.format(span)) finish_plot()
def validate_basic_smoother_resid(): """Compare residuals.""" x, y = sort_data( *smoother_friedman82.build_sample_smoother_problem_friedman82()) plt.figure() for span in smoother.DEFAULT_SPANS: my_smoother = smoother.perform_smooth(x, y, span) _friedman_smooth, resids = run_friedman_smooth(x, y, span) # pylint: disable=unused-variable plt.plot(x, my_smoother.cross_validated_residual, '.-', label='pyace span = {0}'.format(span)) plt.plot(x, resids, '.-', label='Friedman span = {0}'.format(span)) finish_plot()
def validate_supersmoother(): x, y = smoother_friedman82.build_sample_smoother_problem_friedman82() x, y = sort_data(x, y) my_smoother = smoother.perform_smooth( x, y, smoother_cls=supersmoother.SuperSmootherWithPlots) # smoother.DEFAULT_BASIC_SMOOTHER = BasicFixedSpanSmootherBreiman supsmu_result = run_freidman_supsmu(x, y, bass_enhancement=0.0) mace_result = run_mace_smothr(x, y, bass_enhancement=0.0) plt.plot(x, y, '.', label='Data') plt.plot(x, my_smoother.smooth_result, '-', label='pyace') plt.plot(x, supsmu_result, '--', label='SUPSMU') plt.plot(x, mace_result, ':', label='SMOOTH') plt.legend() plt.savefig('supersmoother_validation.png')
def validate_average_best_span(): """Figure 2d? from Friedman.""" N = 200 num_trials = 400 avg = numpy.zeros(N) for i in range(num_trials): x, y = smoother_friedman82.build_sample_smoother_problem_friedman82( N=N) my_smoother = smoother.perform_smooth( x, y, smoother_cls=supersmoother.SuperSmoother) avg += my_smoother._smoothed_best_spans.smooth_result if not (i + 1) % 20: print(i + 1) avg /= num_trials plt.plot(my_smoother.x, avg, '.', label='Average JCV') finish_plot()
def validate_basic_smoother(): """Run Friedman's test from Figure 2b.""" x, y = sort_data( *smoother_friedman82.build_sample_smoother_problem_friedman82()) plt.figure() # plt.plot(x, y, '.', label='Data') for span in smoother.DEFAULT_SPANS: my_smoother = smoother.perform_smooth(x, y, span) friedman_smooth, _resids = run_friedman_smooth(x, y, span) plt.plot(x, my_smoother.smooth_result, '.-', label='pyace span = {0}'.format(span)) plt.plot(x, friedman_smooth, '.-', label='Friedman span = {0}'.format(span)) finish_plot()
def validate_average_best_span(self): """ Figure 2d? from Friedman """ N = 200 num_trials = 400 avg = numpy.zeros(N) for i in range(num_trials): x, y = sample_problems.sample_smoother_problem_brieman82(N=N) my_smoother = smoother.perform_smooth( x, y, smoother_cls=supersmoother.SuperSmoother) avg += my_smoother._smoothed_best_spans.smooth_result if not (i + 1) % 20: print(i + 1) avg /= num_trials plt.plot(my_smoother.x, avg, '.', label='Average JCV') finish_plot()