Example #1
0
 def test_list(self):
     # same length
     self.assertEqual(distanceMetric(self.list_a, self.list_b), 4.4)
     # different length
     self.assertEqual(distanceMetric(self.list_b, self.list_c), 1.0)
     # sanity check, same objects
     self.assertEqual(distanceMetric(self.list_b, self.list_b), 0.0)
Example #2
0
 def test_array(self):
     # same length
     self.assertEqual(
         distanceMetric(np.array(self.list_a), np.array(self.list_b)), 4.4)
     # different length
     self.assertEqual(
         distanceMetric(
             np.array(self.list_b).reshape(1, 3), np.array(self.list_c)),
         1.0,
     )
     # sanity check, same objects
     self.assertEqual(
         distanceMetric(np.array(self.list_b), np.array(self.list_b)), 0.0)
Example #3
0
    def test_hark_object_distance(self):
        self.obj_a.distance_criteria = ["var_1", "var_2", "var_3"]
        self.obj_b.distance_criteria = ["var_1", "var_2", "var_3"]
        self.obj_c.distance_criteria = ["var_5"]
        # if attributes don't exist or don't match
        self.assertEqual(distanceMetric(self.obj_a, self.obj_b), 1000.0)
        self.assertEqual(distanceMetric(self.obj_a, self.obj_c), 1000.0)
        # add single numbers to attributes
        self.obj_a.var_1, self.obj_a.var_2, self.obj_a.var_3 = 0.1, 1, 2.1
        self.obj_b.var_1, self.obj_b.var_2, self.obj_b.var_3 = 1.8, -1, 0.1
        self.assertEqual(distanceMetric(self.obj_a, self.obj_b), 2.0)

        # sanity check - same objects
        self.assertEqual(distanceMetric(self.obj_a, self.obj_a), 0.0)
Example #4
0
 def solveIfChanged(self):
     '''
     Re-solve the lifecycle model only if the attributes MrkvArray_pcvd and uPfac
     do not match those in MrkvArray_pcvd_prev and uPfac_prev.
     '''
     # Check whether MrkvArray_pcvd and uPfac have changed (and whether they exist at all!)
     try:
         same_MrkvArray = distanceMetric(self.MrkvArray_pcvd, self.MrkvArray_pcvd_prev) == 0.
         same_uPfac = distanceMetric(self.uPfac, self.uPfac_prev) == 0.
         if (same_MrkvArray and same_uPfac):
             return
     except:
         pass
     
     # Re-solve the model, then note the values in MrkvArray_pcvd and uPfac
     self.solve()
     self.MrkvArray_pcvd_prev = self.MrkvArray_pcvd
     self.uPfac_prev = self.uPfac
Example #5
0
 def makeShocksIfChanged(self):
     '''
     Re-draw the histories of Markov states and income shocks only if the attributes
     MrkvArray_sim and L_shared do not match those in MrkvArray_sim_prev and L_shared_prev.
     '''
     # Check whether MrkvArray_sim and L_shared have changed (and whether they exist at all!)
     try:
         same_MrkvArray = distanceMetric(self.MrkvArray_sim, self.MrkvArray_sim_prev) == 0.
         same_shared = self.L_shared == self.L_shared_prev
         if (same_MrkvArray and same_shared):
             return
     except:
         pass
     
     # Re-draw the shock histories, then note the values in MrkvArray_sim and L_shared
     self.makeAlternateShockHistories()