Пример #1
0
 def test_multiple_parameter(self):
     model = grav.DoublyConstrained(self.dt, 'Origin', 'Destination', 'flows', 'Dij', 'exp')
     ss = {'obs_mean_trip_len': 1250.9555521611339,
           'pred_mean_trip_len': 1250.9555521684863,
           'OD_pairs': 72, 'predicted_flows': 12314322.0,
           'avg_dist_trav': 1251.0, 'num_destinations': 9,
           'observed_flows': 12314322, 'avg_dist': 1414.0,
           'num_origins': 9}
     ps = {'beta': {'LL_zero_val': -4.1172103581711941,
                    'relative_likelihood_stat': 2053596.3814015209,
                    'standard_error': 4.9177433418433932e-07},
                     'all_params': {'zero_vals_LL': -4.1172102183395936,
                     'mle_vals_LL': -4.0338279201692675}}
     fs = {'r_squared': 0.89682406680906979,
           'srmse': 0.24804939821988789}
     es = {'pred_obs_deviance': 0.0314,
           'entropy_ratio': 0.8855,
           'maximum_entropy': 4.2767,
           'max_pred_deviance': 0.2429,
           'variance_obs_entropy': 3.667e-08,
           'predicted_entropy': 4.0338,
           't_stat_entropy': 117.1593,
           'max_obs_deviance': 0.2743,
           'observed_entropy': 4.0024,
           'variance_pred_entropy': 3.516e-08}
     sys_stats = stats.sys_stats(model)
     self.assertAlmostEqual(model.system_stats['obs_mean_trip_len'], ss['obs_mean_trip_len'], 4)
     self.assertAlmostEqual(model.system_stats['pred_mean_trip_len'], ss['pred_mean_trip_len'], 4)
     self.assertAlmostEqual(model.system_stats['OD_pairs'], ss['OD_pairs'])
     self.assertAlmostEqual(model.system_stats['predicted_flows'], ss['predicted_flows'])
     self.assertAlmostEqual(model.system_stats['avg_dist_trav'], ss['avg_dist_trav'])
     self.assertAlmostEqual(model.system_stats['num_destinations'], ss['num_destinations'])
     self.assertAlmostEqual(model.system_stats['observed_flows'], ss['observed_flows'])
     self.assertAlmostEqual(model.system_stats['avg_dist'], ss['avg_dist'], 4)
     self.assertAlmostEqual(model.system_stats['num_origins'], ss['num_origins'])
     param_stats = stats.param_stats(model)
     self.assertAlmostEqual(model.parameter_stats['beta']['LL_zero_val'], ps['beta']['LL_zero_val'], 4)
     self.assertAlmostEqual(model.parameter_stats['beta']['relative_likelihood_stat'],
                                               ps['beta']['relative_likelihood_stat'], 4)
     self.assertAlmostEqual(model.parameter_stats['beta']['standard_error'], ps['beta']['standard_error'], 4)
     self.assertAlmostEqual(model.parameter_stats['all_params']['zero_vals_LL'], ps['all_params']['zero_vals_LL'], 4)
     self.assertAlmostEqual(model.parameter_stats['all_params']['mle_vals_LL'], ps['all_params']['mle_vals_LL'], 4)
     fit_stats = stats.fit_stats(model)
     self.assertAlmostEqual(model.fit_stats['r_squared'], fs['r_squared'], 4)
     self.assertAlmostEqual(model.fit_stats['srmse'], fs['srmse'], 4)
     ent_stats = stats.ent_stats(model)
     self.assertAlmostEqual(model.entropy_stats['pred_obs_deviance'], es['pred_obs_deviance'], 4)
     self.assertAlmostEqual(model.entropy_stats['entropy_ratio'], es['entropy_ratio'], 4)
     self.assertAlmostEqual(model.entropy_stats['maximum_entropy'], es['maximum_entropy'], 4)
     self.assertAlmostEqual(model.entropy_stats['max_pred_deviance'], es['max_pred_deviance'], 4)
     self.assertAlmostEqual(model.entropy_stats['variance_obs_entropy'], es['variance_obs_entropy'], 4)
     self.assertAlmostEqual(model.entropy_stats['predicted_entropy'], es['predicted_entropy'], 4)
     self.assertAlmostEqual(model.entropy_stats['t_stat_entropy'], es['t_stat_entropy'], 4)
     self.assertAlmostEqual(model.entropy_stats['max_obs_deviance'], es['max_obs_deviance'], 4)
     self.assertAlmostEqual(model.entropy_stats['observed_entropy'], es['observed_entropy'], 4)
     self.assertAlmostEqual(model.entropy_stats['variance_pred_entropy'], es['variance_pred_entropy'], 4)
Пример #2
0
 def test_single_parameter(self):
     model = grav.ProductionConstrained(self.dt, 'origins', 'destinations', 'flows',
         ['pop'], 'Dij', 'pow')
     ss = {'obs_mean_trip_len': 736.52834197296534,
           'pred_mean_trip_len': 734.40974204773784,
           'OD_pairs': 24,
           'predicted_flows': 242873.00000000003,
           'avg_dist_trav': 737.0,
           'num_destinations': 24,
           'observed_flows': 242873,
           'avg_dist': 851.0,
           'num_origins': 1}
     ps = {'beta': {'LL_zero_val': -3.057415839736517,
                    'relative_likelihood_stat': 24833.721614296166,
                    'standard_error': 0.0052734418614330883},
           'all_params': {'zero_vals_LL': -3.1780538303479453,
                          'mle_vals_LL': -3.0062909275101761},
           'pop': {'LL_zero_val': -3.1773474269437778,
                   'relative_likelihood_stat': 83090.010373874276,
                   'standard_error': 0.0027673052892085684}}
     fs = {'r_squared': 0.60516003720997413,
           'srmse': 0.57873206718148507}
     es = {'pred_obs_deviance': 0.1327,
           'entropy_ratio': 0.5642,
           'maximum_entropy': 3.1781,
           'max_pred_deviance': 0.1718,
           'variance_obs_entropy': 2.55421e-06,
           'predicted_entropy': 3.0063,
           't_stat_entropy': 66.7614,
           'max_obs_deviance': 0.3045,
           'observed_entropy': 2.8736,
           'variance_pred_entropy': 1.39664e-06}
     sys_stats = stats.sys_stats(model)
     self.assertAlmostEqual(model.system_stats['obs_mean_trip_len'], ss['obs_mean_trip_len'], 4)
     self.assertAlmostEqual(model.system_stats['pred_mean_trip_len'], ss['pred_mean_trip_len'], 4)
     self.assertAlmostEqual(model.system_stats['OD_pairs'], ss['OD_pairs'])
     self.assertAlmostEqual(model.system_stats['predicted_flows'], ss['predicted_flows'])
     self.assertAlmostEqual(model.system_stats['avg_dist_trav'], ss['avg_dist_trav'])
     self.assertAlmostEqual(model.system_stats['num_destinations'], ss['num_destinations'])
     self.assertAlmostEqual(model.system_stats['observed_flows'], ss['observed_flows'])
     self.assertAlmostEqual(model.system_stats['avg_dist'], ss['avg_dist'], 4)
     self.assertAlmostEqual(model.system_stats['num_origins'], ss['num_origins'])
     param_stats = stats.param_stats(model)
     self.assertAlmostEqual(model.parameter_stats['beta']['LL_zero_val'], ps['beta']['LL_zero_val'], 4)
     self.assertAlmostEqual(model.parameter_stats['beta']['relative_likelihood_stat'],
                                               ps['beta']['relative_likelihood_stat'], 4)
     self.assertAlmostEqual(model.parameter_stats['beta']['standard_error'], ps['beta']['standard_error'], 4)
     self.assertAlmostEqual(model.parameter_stats['pop']['LL_zero_val'], ps['pop']['LL_zero_val'], 4)
     self.assertAlmostEqual(model.parameter_stats['pop']['relative_likelihood_stat'],
                                               ps['pop']['relative_likelihood_stat'], 4)
     self.assertAlmostEqual(model.parameter_stats['pop']['standard_error'], ps['pop']['standard_error'], 4)
     self.assertAlmostEqual(model.parameter_stats['all_params']['zero_vals_LL'], ps['all_params']['zero_vals_LL'], 4)
     self.assertAlmostEqual(model.parameter_stats['all_params']['mle_vals_LL'], ps['all_params']['mle_vals_LL'], 4)
     fit_stats = stats.fit_stats(model)
     self.assertAlmostEqual(model.fit_stats['r_squared'], fs['r_squared'], 4)
     self.assertAlmostEqual(model.fit_stats['srmse'], fs['srmse'], 4)
     ent_stats = stats.ent_stats(model)
     self.assertAlmostEqual(model.entropy_stats['pred_obs_deviance'], es['pred_obs_deviance'], 4)
     self.assertAlmostEqual(model.entropy_stats['entropy_ratio'], es['entropy_ratio'], 4)
     self.assertAlmostEqual(model.entropy_stats['maximum_entropy'], es['maximum_entropy'], 4)
     self.assertAlmostEqual(model.entropy_stats['max_pred_deviance'], es['max_pred_deviance'], 4)
     self.assertAlmostEqual(model.entropy_stats['variance_obs_entropy'], es['variance_obs_entropy'], 4)
     self.assertAlmostEqual(model.entropy_stats['predicted_entropy'], es['predicted_entropy'], 4)
     self.assertAlmostEqual(model.entropy_stats['t_stat_entropy'], es['t_stat_entropy'], 4)
     self.assertAlmostEqual(model.entropy_stats['max_obs_deviance'], es['max_obs_deviance'], 4)
     self.assertAlmostEqual(model.entropy_stats['observed_entropy'], es['observed_entropy'], 4)
     self.assertAlmostEqual(model.entropy_stats['variance_pred_entropy'], es['variance_pred_entropy'], 4)
Пример #3
0
 def test_single_parameter(self):
     model = grav.ProductionConstrained(self.dt, 'origins', 'destinations',
                                        'flows', ['pop'], 'Dij', 'pow')
     ss = {
         'obs_mean_trip_len': 736.52834197296534,
         'pred_mean_trip_len': 734.40974204773784,
         'OD_pairs': 24,
         'predicted_flows': 242873.00000000003,
         'avg_dist_trav': 737.0,
         'num_destinations': 24,
         'observed_flows': 242873,
         'avg_dist': 851.0,
         'num_origins': 1
     }
     ps = {
         'beta': {
             'LL_zero_val': -3.057415839736517,
             'relative_likelihood_stat': 24833.721614296166,
             'standard_error': 0.0052734418614330883
         },
         'all_params': {
             'zero_vals_LL': -3.1780538303479453,
             'mle_vals_LL': -3.0062909275101761
         },
         'pop': {
             'LL_zero_val': -3.1773474269437778,
             'relative_likelihood_stat': 83090.010373874276,
             'standard_error': 0.0027673052892085684
         }
     }
     fs = {'r_squared': 0.60516003720997413, 'srmse': 0.57873206718148507}
     es = {
         'pred_obs_deviance': 0.1327,
         'entropy_ratio': 0.5642,
         'maximum_entropy': 3.1781,
         'max_pred_deviance': 0.1718,
         'variance_obs_entropy': 2.55421e-06,
         'predicted_entropy': 3.0063,
         't_stat_entropy': 66.7614,
         'max_obs_deviance': 0.3045,
         'observed_entropy': 2.8736,
         'variance_pred_entropy': 1.39664e-06
     }
     sys_stats = stats.sys_stats(model)
     self.assertAlmostEqual(model.system_stats['obs_mean_trip_len'],
                            ss['obs_mean_trip_len'], 4)
     self.assertAlmostEqual(model.system_stats['pred_mean_trip_len'],
                            ss['pred_mean_trip_len'], 4)
     self.assertAlmostEqual(model.system_stats['OD_pairs'], ss['OD_pairs'])
     self.assertAlmostEqual(model.system_stats['predicted_flows'],
                            ss['predicted_flows'])
     self.assertAlmostEqual(model.system_stats['avg_dist_trav'],
                            ss['avg_dist_trav'])
     self.assertAlmostEqual(model.system_stats['num_destinations'],
                            ss['num_destinations'])
     self.assertAlmostEqual(model.system_stats['observed_flows'],
                            ss['observed_flows'])
     self.assertAlmostEqual(model.system_stats['avg_dist'], ss['avg_dist'],
                            4)
     self.assertAlmostEqual(model.system_stats['num_origins'],
                            ss['num_origins'])
     param_stats = stats.param_stats(model)
     self.assertAlmostEqual(model.parameter_stats['beta']['LL_zero_val'],
                            ps['beta']['LL_zero_val'], 4)
     self.assertAlmostEqual(
         model.parameter_stats['beta']['relative_likelihood_stat'],
         ps['beta']['relative_likelihood_stat'], 4)
     self.assertAlmostEqual(model.parameter_stats['beta']['standard_error'],
                            ps['beta']['standard_error'], 4)
     self.assertAlmostEqual(model.parameter_stats['pop']['LL_zero_val'],
                            ps['pop']['LL_zero_val'], 4)
     self.assertAlmostEqual(
         model.parameter_stats['pop']['relative_likelihood_stat'],
         ps['pop']['relative_likelihood_stat'], 4)
     self.assertAlmostEqual(model.parameter_stats['pop']['standard_error'],
                            ps['pop']['standard_error'], 4)
     self.assertAlmostEqual(
         model.parameter_stats['all_params']['zero_vals_LL'],
         ps['all_params']['zero_vals_LL'], 4)
     self.assertAlmostEqual(
         model.parameter_stats['all_params']['mle_vals_LL'],
         ps['all_params']['mle_vals_LL'], 4)
     fit_stats = stats.fit_stats(model)
     self.assertAlmostEqual(model.fit_stats['r_squared'], fs['r_squared'],
                            4)
     self.assertAlmostEqual(model.fit_stats['srmse'], fs['srmse'], 4)
     ent_stats = stats.ent_stats(model)
     self.assertAlmostEqual(model.entropy_stats['pred_obs_deviance'],
                            es['pred_obs_deviance'], 4)
     self.assertAlmostEqual(model.entropy_stats['entropy_ratio'],
                            es['entropy_ratio'], 4)
     self.assertAlmostEqual(model.entropy_stats['maximum_entropy'],
                            es['maximum_entropy'], 4)
     self.assertAlmostEqual(model.entropy_stats['max_pred_deviance'],
                            es['max_pred_deviance'], 4)
     self.assertAlmostEqual(model.entropy_stats['variance_obs_entropy'],
                            es['variance_obs_entropy'], 4)
     self.assertAlmostEqual(model.entropy_stats['predicted_entropy'],
                            es['predicted_entropy'], 4)
     self.assertAlmostEqual(model.entropy_stats['t_stat_entropy'],
                            es['t_stat_entropy'], 4)
     self.assertAlmostEqual(model.entropy_stats['max_obs_deviance'],
                            es['max_obs_deviance'], 4)
     self.assertAlmostEqual(model.entropy_stats['observed_entropy'],
                            es['observed_entropy'], 4)
     self.assertAlmostEqual(model.entropy_stats['variance_pred_entropy'],
                            es['variance_pred_entropy'], 4)
Пример #4
0
 def test_multiple_parameter(self):
     model = grav.DoublyConstrained(self.dt, 'Origin', 'Destination',
                                    'flows', 'Dij', 'exp')
     ss = {
         'obs_mean_trip_len': 1250.9555521611339,
         'pred_mean_trip_len': 1250.9555521684863,
         'OD_pairs': 72,
         'predicted_flows': 12314322.0,
         'avg_dist_trav': 1251.0,
         'num_destinations': 9,
         'observed_flows': 12314322,
         'avg_dist': 1414.0,
         'num_origins': 9
     }
     ps = {
         'beta': {
             'LL_zero_val': -4.1172103581711941,
             'relative_likelihood_stat': 2053596.3814015209,
             'standard_error': 4.9177433418433932e-07
         },
         'all_params': {
             'zero_vals_LL': -4.1172102183395936,
             'mle_vals_LL': -4.0338279201692675
         }
     }
     fs = {'r_squared': 0.89682406680906979, 'srmse': 0.24804939821988789}
     es = {
         'pred_obs_deviance': 0.0314,
         'entropy_ratio': 0.8855,
         'maximum_entropy': 4.2767,
         'max_pred_deviance': 0.2429,
         'variance_obs_entropy': 3.667e-08,
         'predicted_entropy': 4.0338,
         't_stat_entropy': 117.1593,
         'max_obs_deviance': 0.2743,
         'observed_entropy': 4.0024,
         'variance_pred_entropy': 3.516e-08
     }
     sys_stats = stats.sys_stats(model)
     self.assertAlmostEqual(model.system_stats['obs_mean_trip_len'],
                            ss['obs_mean_trip_len'], 4)
     self.assertAlmostEqual(model.system_stats['pred_mean_trip_len'],
                            ss['pred_mean_trip_len'], 4)
     self.assertAlmostEqual(model.system_stats['OD_pairs'], ss['OD_pairs'])
     self.assertAlmostEqual(model.system_stats['predicted_flows'],
                            ss['predicted_flows'])
     self.assertAlmostEqual(model.system_stats['avg_dist_trav'],
                            ss['avg_dist_trav'])
     self.assertAlmostEqual(model.system_stats['num_destinations'],
                            ss['num_destinations'])
     self.assertAlmostEqual(model.system_stats['observed_flows'],
                            ss['observed_flows'])
     self.assertAlmostEqual(model.system_stats['avg_dist'], ss['avg_dist'],
                            4)
     self.assertAlmostEqual(model.system_stats['num_origins'],
                            ss['num_origins'])
     param_stats = stats.param_stats(model)
     self.assertAlmostEqual(model.parameter_stats['beta']['LL_zero_val'],
                            ps['beta']['LL_zero_val'], 4)
     self.assertAlmostEqual(
         model.parameter_stats['beta']['relative_likelihood_stat'],
         ps['beta']['relative_likelihood_stat'], 4)
     self.assertAlmostEqual(model.parameter_stats['beta']['standard_error'],
                            ps['beta']['standard_error'], 4)
     self.assertAlmostEqual(
         model.parameter_stats['all_params']['zero_vals_LL'],
         ps['all_params']['zero_vals_LL'], 4)
     self.assertAlmostEqual(
         model.parameter_stats['all_params']['mle_vals_LL'],
         ps['all_params']['mle_vals_LL'], 4)
     fit_stats = stats.fit_stats(model)
     self.assertAlmostEqual(model.fit_stats['r_squared'], fs['r_squared'],
                            4)
     self.assertAlmostEqual(model.fit_stats['srmse'], fs['srmse'], 4)
     ent_stats = stats.ent_stats(model)
     self.assertAlmostEqual(model.entropy_stats['pred_obs_deviance'],
                            es['pred_obs_deviance'], 4)
     self.assertAlmostEqual(model.entropy_stats['entropy_ratio'],
                            es['entropy_ratio'], 4)
     self.assertAlmostEqual(model.entropy_stats['maximum_entropy'],
                            es['maximum_entropy'], 4)
     self.assertAlmostEqual(model.entropy_stats['max_pred_deviance'],
                            es['max_pred_deviance'], 4)
     self.assertAlmostEqual(model.entropy_stats['variance_obs_entropy'],
                            es['variance_obs_entropy'], 4)
     self.assertAlmostEqual(model.entropy_stats['predicted_entropy'],
                            es['predicted_entropy'], 4)
     self.assertAlmostEqual(model.entropy_stats['t_stat_entropy'],
                            es['t_stat_entropy'], 4)
     self.assertAlmostEqual(model.entropy_stats['max_obs_deviance'],
                            es['max_obs_deviance'], 4)
     self.assertAlmostEqual(model.entropy_stats['observed_entropy'],
                            es['observed_entropy'], 4)
     self.assertAlmostEqual(model.entropy_stats['variance_pred_entropy'],
                            es['variance_pred_entropy'], 4)