def grenoble_estimation(main_data_dir): with open(main_data_dir+'grenoble.yml') as model_file,\ open(main_data_dir+'grenoble.csv') as data_file: model = choice_model.MultinomialLogit.from_yaml(model_file) model.load_data(data_file) interface = choice_model.AlogitInterface(model, alogit_path=r'D:\Alo45.exe') interface.estimate() return interface
def grenoble_estimation_example(main_data_dir, data_dir): with open(main_data_dir+'grenoble.yml') as model_file,\ open(main_data_dir+'grenoble.csv') as data_file: model = choice_model.MultinomialLogit.from_yaml(model_file) model.load_data(data_file) interface = choice_model.AlogitInterface(model, alogit_path='./dummy') interface._parse_output_file(data_dir + 'Grenoble.LOG') interface._estimated = True return interface
def test_data_file(self, simple_multinomial_model_with_data, tmp_path): temp = tmp_path data_file = temp / 'simple.csv' alo_file = temp / 'simple.alo' interface = choice_model.AlogitInterface( simple_multinomial_model_with_data, alogit_path='./dummy', data_file=str(data_file.absolute()), alo_file=str(alo_file.absolute())) interface._write_data_file() assert data_file.read_text() == '1,2,3,4,1,1,1.0\n5,6,7,8,1,1,2.0\n'
def test_alo_file(self, simple_multinomial_model_with_data, tmp_path): temp = tmp_path data_file = temp / 'simple.csv' alo_file = temp / 'simple.alo' interface = choice_model.AlogitInterface( simple_multinomial_model_with_data, alogit_path='./dummy', data_file=str(data_file.absolute()), alo_file=str(alo_file.absolute())) interface._write_alo_file() file_text = alo_file.read_text() # Skip checking file name as this will be different between runs start_string = ( '$title Simple model\n$estimate\n$coeff prm1 prm2 prm3 c1\n$nest ' 'root() ch1 ch2\n') assert file_text[:len(start_string)] == start_string end_string = ( 'Avail(ch1) = av1\nAvail(ch2) = av2\nchoice=recode(alt ch1, ch2)\n' '$array v3(alts)\nv3(ch1) = cv1\nv3(ch2) = cv2\nUtil(ch1) = c1 + ' 'prm1*v1 + prm3*v3(ch1)\nUtil(ch2) = prm2*v2 + prm3*v3(ch2)\n') assert file_text[-(len(end_string)):] == end_string
def test_multinomial_logit(self, simple_multinomial_model_with_data): model = simple_multinomial_model_with_data choice_model.AlogitInterface(model, alogit_path='./dummy')
def simple_multinomial_alogit_interface(simple_multinomial_model_with_data): return choice_model.AlogitInterface(simple_multinomial_model_with_data, alogit_path='./dummy')
def test_no_data(self, simple_multinomial_model): with pytest.raises(choice_model.interface.interface.NoDataLoaded): choice_model.AlogitInterface(simple_multinomial_model, alogit_path='./dummy')
def test_simple_model(self, simple_model): with pytest.raises(TypeError): choice_model.AlogitInterface(simple_model, alogit_path='./dummy')
def simple_multinomial_alogit_estimation(simple_multinomial_model_with_data): interface = choice_model.AlogitInterface( simple_multinomial_model_with_data, alogit_path=r'D:\Alo45.exe') interface.estimate() return interface
def test_alogit_path(self, simple_multinomial_model_with_data): model = simple_multinomial_model_with_data interface = choice_model.AlogitInterface(model, alogit_path='alo.exe') assert interface.alogit_path == os.path.abspath('alo.exe')