def report_time_spent(ga_engine): global _time_of_prev_gen now = time.time() gen = ga_engine.getCurrentGeneration() print "Time spent on generation %s, total %s." % \ (SimpleTimer.period_to_string(_time_of_prev_gen[1], now), SimpleTimer.period_to_string(_time_of_prev_gen[0], now)) _time_of_prev_gen[1] = now
def report_time_spent(ga_engine): global _time_of_prev_gen now = time.time() gen = ga_engine.getCurrentGeneration() print "Time spent on generation %s, total %s." % \ (SimpleTimer.period_to_string(_time_of_prev_gen[1], now), SimpleTimer.period_to_string(_time_of_prev_gen[0], now)) _time_of_prev_gen[1] = now
# Try smoothing/cleansing different time series lengths for hindsight_days in [1]: # Select data num_hours = 24 * hindsight_days data = dataset["Load"][-num_hours:].copy() # Some output and rough timing print "Cleansing %d hours of data with smoothness %.2f, z-score %.2f..." % (num_hours, smoothness, zscore) sys.stdout.flush() start_time = time.time() # This is the part that takes time smoother = _get_smoother()(data, smoothness) cleaner = cln.RegressionCleaner(smoother, zscore) cleaned, _ = cleaner.get_cleaned_data(method=cln.RegressionCleaner.replace_with_bound) # Wrap up and plot the result end_time = time.time() print "Done in %s." % SimpleTimer.period_to_string(start_time, end_time) print cleaned sys.stdout.flush() plt.figure() data.plot(style="r", label="Raw load") spline = pd.TimeSeries(data=smoother.splev(range(len(cleaned))), index=cleaned.index) spline.plot(style="g", label="Smoothing spline") # THE SAUSAGE! lower, upper = cleaner.get_confidence_interval() ax = plt.gca() ax.fill_between(cleaned.index, lower, upper, facecolor="g", alpha=0.1) cleaned.plot(style="b", label="Cleaned load")
# Select data num_hours = 24 * hindsight_days data = dataset["Load"][-num_hours:].copy() # Some output and rough timing print "Cleansing %d hours of data with smoothness %.2f, z-score %.2f..." % \ (num_hours, smoothness, zscore) sys.stdout.flush() start_time = time.time() # This is the part that takes time smoother = _get_smoother()(data, smoothness) cleaner = cln.RegressionCleaner(smoother, zscore) cleaned, _ = cleaner.get_cleaned_data( method=cln.RegressionCleaner.replace_with_bound) # Wrap up and plot the result end_time = time.time() print "Done in %s." % SimpleTimer.period_to_string(start_time, end_time) print cleaned sys.stdout.flush() plt.figure() data.plot(style='r', label='Raw load') spline = pd.TimeSeries(data=smoother.splev(range(len(cleaned))), index=cleaned.index) spline.plot(style='g', label='Smoothing spline') # THE SAUSAGE! lower, upper = cleaner.get_confidence_interval() ax = plt.gca() ax.fill_between(cleaned.index, lower, upper, facecolor='g', alpha=0.1)