def find_best_annualized_usage_params(target_annualized_usage, model, start_params, params_to_change, weather_normal_source, n_guesses=100): best_params = start_params meter = AnnualizedUsageMeter(model=model, temperature_unit_str=TEMPERATURE_UNIT_STR) best_result = meter.evaluate_raw(model_params=best_params, weather_normal_source=weather_normal_source) best_ann_usage = best_result["annualized_usage"][0] for n in range(n_guesses): resolution = abs((target_annualized_usage - best_ann_usage) / target_annualized_usage) param_dict = best_params.to_dict() for param_name,scale_factor in params_to_change: current_value = param_dict[param_name] current_value = norm.rvs(param_dict[param_name], resolution * scale_factor) while current_value < 0: current_value = norm.rvs(param_dict[param_name], resolution * scale_factor) param_dict[param_name] = current_value model_params = model.param_type(param_dict) result = meter.evaluate_raw(model_params=model_params, weather_normal_source=weather_normal_source) ann_usage = result["annualized_usage"][0] if abs(target_annualized_usage - ann_usage) < abs(target_annualized_usage - best_ann_usage): diff = abs(target_annualized_usage - best_ann_usage) best_params = model_params best_ann_usage = ann_usage return best_params, best_ann_usage
def _generate_fuel_consumptions(self, weather_source, weather_normal_source, period, model, param_dists, param_delta_dists, noise, baseline_period, reporting_period, fuel_type, consumption_unit_name, temperature_unit_name): baseline_params = model.param_type([param.rvs() for param in param_dists.to_list()]) reporting_params = model.param_type([bl_param + param_delta.rvs() for bl_param, param_delta in zip(baseline_params.to_list(), param_delta_dists.to_list())]) annualized_usage_meter = AnnualizedUsageMeter(temperature_unit_name, model) baseline_annualized_usage = annualized_usage_meter.evaluate_raw( model_params=baseline_params, weather_normal_source=weather_normal_source)["annualized_usage"] reporting_annualized_usage = annualized_usage_meter.evaluate_raw( model_params=reporting_params, weather_normal_source=weather_normal_source)["annualized_usage"] estimated_annualized_savings = baseline_annualized_usage - \ reporting_annualized_usage baseline_generator = MonthlyBillingConsumptionGenerator(fuel_type, consumption_unit_name, temperature_unit_name, model, baseline_params) reporting_generator = MonthlyBillingConsumptionGenerator(fuel_type, consumption_unit_name, temperature_unit_name, model, reporting_params) datetimes = generate_monthly_billing_datetimes(period, dist=None) baseline_consumption_data = baseline_generator.generate( weather_source, datetimes, daily_noise_dist=noise) reporting_consumption_data = reporting_generator.generate( weather_source, datetimes, daily_noise_dist=noise) baseline_data = baseline_consumption_data.data reporting_data = reporting_consumption_data.data periods = baseline_consumption_data.periods() records = [] for bl_data, rp_data, period in zip(baseline_data, reporting_data, periods): if period in reporting_period: val = rp_data else: val = bl_data record = {"start": period.start, "end": period.end, "value": val} records.append(record) cd = ConsumptionData(records, fuel_type, consumption_unit_name, record_type="arbitrary") return cd, estimated_annualized_savings, baseline_params, \ reporting_params
def find_best_annualized_usage_params(target_annualized_usage, model, start_params, params_to_change, weather_normal_source, n_guesses=100): best_params = start_params meter = AnnualizedUsageMeter(model=model, temperature_unit_str=TEMPERATURE_UNIT_STR) best_result = meter.evaluate_raw( model_params=best_params, weather_normal_source=weather_normal_source) best_ann_usage = best_result["annualized_usage"][0] for n in range(n_guesses): resolution = abs((target_annualized_usage - best_ann_usage) / target_annualized_usage) param_dict = best_params.to_dict() for param_name, scale_factor in params_to_change: current_value = param_dict[param_name] current_value = norm.rvs(param_dict[param_name], resolution * scale_factor) while current_value < 0: current_value = norm.rvs(param_dict[param_name], resolution * scale_factor) param_dict[param_name] = current_value model_params = model.param_type(param_dict) result = meter.evaluate_raw( model_params=model_params, weather_normal_source=weather_normal_source) ann_usage = result["annualized_usage"][0] if abs(target_annualized_usage - ann_usage) < abs(target_annualized_usage - best_ann_usage): diff = abs(target_annualized_usage - best_ann_usage) best_params = model_params best_ann_usage = ann_usage return best_params, best_ann_usage