def skip_test_bma(self): storage = StorageFactory().get_storage('dict_storage') storage.write_table(table_name='dataset', table_data={ "id": arange(100) + 1, "attr1": concatenate((random.randint(0, 10, 50), random.randint(20, 40, 50))), "attr2": random.ranf(100), "outcome": array(50 * [0] + 50 * [1]) }) ds = Dataset(in_storage=storage, in_table_name='dataset', id_name="id") specification = EquationSpecification( variables=array(["constant", "attr2", "attr1"]), coefficients=array(["constant", "ba2", "ba1"])) filename = 'bma_output.pdf' model = RegressionModel( estimate_config={'bma_imageplot_filename': filename}) model.estimate(specification, ds, "outcome", procedure="opus_core.bma_for_linear_regression_r")
#"residential_units", # "avg_income", #"commercial_sqft", #"t_max", # "demand_lag1" # "sum_demand_times_2", "waterdemand.consumption_re.something_like_sum_demand", ) ) print "Create a model object" years = range(2001, 2003) # single model = RegressionModel() print "Estimate coefficients - single" coefficients, other_est_results = model.estimate(specification, consumption, outcome_attribute="waterdemand.%s.sum_demand" % consumption_type, # if outcome_attribute is opus_core.func.ln(), the simulation results need to take exp() index=index_est, procedure="opus_core.estimate_linear_regression", data_objects=dataset_pool.datasets_in_pool()) """Simulate over the set of years.""" for year in years: print "\nSimulate water demand %s" % year SimulationState().set_current_time(year) dataset_pool = SessionConfiguration().get_dataset_pool() dataset_pool.remove_all_datasets() gridcells = dataset_pool.get_dataset("gridcell")
compute_capacity_flag=True, capacity_string=vacant_capacity, number_of_agents_string=number_of_agents, number_of_units_string="capacity", run_config={"lottery_max_iterations":10}) seed(1) result = hlcm2.run(specification, coefficients, households) #coef, results = hlcm2.estimate(specification, agent_set=households, debuglevel=1) #hlcm2.plot_choice_histograms(capacity=locations.get_attribute("capacity")) households.get_attribute("location") # Regression model locations.add_primary_attribute(name="distance_to_cbd", data=[5,10,5,1,20,0,7,7,3]) from opus_core.regression_model import RegressionModel rm = RegressionModel(regression_procedure="opus_core.linear_regression") specification = EquationSpecification( variables=array(["constant", "gridcell.distance_to_cbd"]), coefficients=array(["constant", "dcbd_coef"])) coef, other_results = rm.estimate(specification, dataset=locations, outcome_attribute="gridcell.cost", procedure="opus_core.estimate_linear_regression") coef.summary() dstorage = StorageFactory().get_storage('dict_storage') dstorage.write_table( table_name = 'gridcells', table_data = {'id':array([1,2,3,4]), 'distance_to_cbd':array([2,4,6,8]) })