Exemple #1
0
 def generate_realizations(self, p=99, marks=None):
     neighbor_perms = []
     for i in range(p):
         neighbor_perms.append(
             analytics.average_nearest_neighbor_distance(
                 self.generate_random_points(100)))
     return neighbor_perms
 def test_crit_tations(self):
     observed_avg = analytics.average_nearest_neighbor_distance(self.points)
     permutations = utils.permutations(99)
     lower, upper = utils.crit_tations(permutations)
     self.assertTrue(lower > 0.03)
     self.assertTrue(upper < 0.07)
     self.assertTrue(observed_avg < lower or observed_avg > upper)
Exemple #3
0
 def generate_realizations(self, p = 99, marks = None):
     neighbor_perms = []
     for i in range(p):
         neighbor_perms.append(
                 analytics.average_nearest_neighbor_distance(
                     self.generate_random_points(100)))
     return neighbor_perms
    def test_point_pattern(self):
        """
        This test checks that the code can compute an observed mean
         nearest neighbor distance and then use Monte Carlo simulation to
         generate some number of permutations.  A permutation is the mean
         nearest neighbor distance computed using a random realization of
         the point process.
        """
        random.seed(3673673)  # Reset the random number generator using system time
        # I do not know where you have moved avarege_nearest_neighbor_distance, so update the point_pattern module
        observed_avg = analytics.average_nearest_neighbor_distance(self.points)
        self.assertAlmostEqual(0.037507819095864134, observed_avg, 3)

        # Again, update the point_pattern module name for where you have placed the point_pattern module
        # Also update the create_random function name for whatever you named the function to generate
        #  random points
        rand_points = utils.create_n_rand_pts(100)
        self.assertEqual(100, len(rand_points))

        # As above, update the module and function name.
        permutations = analytics.p_perms(99)
        self.assertEqual(len(permutations), 99)
        self.assertNotEqual(permutations[0], permutations[1])

        # As above, update the module and function name.
        lower, upper = utils.critical_pts(permutations)
        self.assertTrue(lower > 0.03)
        self.assertTrue(upper < 0.07)
        self.assertTrue(observed_avg < lower or observed_avg > upper)

        # As above, update the module and function name.
        significant = analytics.monte_carlo_critical_bound_check(lower, upper, 0)
        self.assertTrue(significant)

        self.assertTrue(True)
 def test_crit_tations(self):
     observed_avg = analytics.average_nearest_neighbor_distance(self.points)
     permutations = utils.permutations(99)
     lower, upper = utils.crit_tations(permutations)
     self.assertTrue(lower > 0.03)
     self.assertTrue(upper < 0.07)
     self.assertTrue(observed_avg < lower or observed_avg > upper)
    def test_marks(self):
        random.seed(942323)  # Reset the random number generator using system time
        # I do not know where you have moved avarege_nearest_neighbor_distance, so update the point_pattern module
        observed_avg = analytics.average_nearest_neighbor_distance(self.points)
        self.assertAlmostEqual(0.037507819095864134, observed_avg, 3)

        # Again, update the point_pattern module name for where you have placed the point_pattern module
        # Also update the create_random function name for whatever you named the function to generate
        #  random points
        rand_points = utils.create_marked_rand_pts(100,self.marks)
        self.assertEqual(100, len(rand_points))

        # As above, update the module and function name.
        permutations = analytics.p_perms_marks(99,self.marks)
        self.assertEqual(len(permutations), 99)
        #print(permutations)
        self.assertNotEqual(permutations[0], permutations[1])

        # As above, update the module and function name.
        lower, upper = utils.critical_pts(permutations)
        self.assertTrue(lower > 0.03)
        self.assertTrue(upper < 0.07)
        self.assertTrue(observed_avg < lower or observed_avg > upper)

        # As above, update the module and function name.
        significant = analytics.monte_carlo_critical_bound_check(lower, upper, 0)
        self.assertTrue(significant)

        self.assertTrue(True)
        
Exemple #7
0
def permutations(number_of_permutations, number_of_points):


    result = []
    for i in range(number_of_permutations):
        points = create_random(number_of_points)
        observed_avg = analytics.average_nearest_neighbor_distance(points)
        result.append(observed_avg)

    return result
Exemple #8
0
def permutations(p=99, n=100, marks = None):
    """
    Calculate p number of average_nearest_neighbor_distances from n number
    of randomly generated points. Return list of size p with distance values.

    Parameter(s): integer p, integer n

    Return(s): list perm
    """
    perm = []
    for x in range(p):
        points = create_random_marked_points(n, marks)
        avg_nnd = average_nearest_neighbor_distance(points)
        perm.append(avg_nnd)

    return perm
Exemple #9
0
def permutations(p=99, n=100, marks = None):
    """
    Calculate p number of average_nearest_neighbor_distances from n number
    of randomly generated points. Return list of size p with distance values.

    Parameter(s): integer p, integer n

    Return(s): list perm
    """
    perm = []
    for x in range(p):
        points = create_random_marked_points(n, marks)
        avg_nnd = average_nearest_neighbor_distance(points)
        perm.append(avg_nnd)

    return perm
Exemple #10
0
def  permutation(p=99, n=100):
    """
    Return the mean nearest neighbor distance of p permutations.

    Parameters
    ----------
    p : integer
    n : integer

    Returns
    -------
    permutations : list
            the mean nearest neighbor distance list.

    """
    permutation_list=[]
    for i in range(p):
        permutation_list.append(average_nearest_neighbor_distance(generate_random_points(n)))
    return permutation_list
Exemple #11
0
 def nearestNeighborTweets(self):
     """ In this function, I will normalize it to the unit mile
     by multiplying the result by the distance in miles traveling
     about 1 unit longitudinally at roughly the same latitude.
     first coord = (33.471798, -112.445462)
     second coord = (33.451355, -111.442852)
     Distance (Miles / Spherical Earth) = 57.68 miles
     """
     root = Tk()
     root.withdraw()
     if self.sentiment == None:
         mb.showerror("Error", 'Please Open or Visualize tweets first.')
     else:
         if self.sentiment == 'All':
             mark = None
         else:
             mark = self.sentiment
         nnd = NORMALIZED_PHX_DISTANCE * average_nearest_neighbor_distance(self.tweetObjArr, mark)
         mb.showinfo("Info", 'The average nearest neighbor of\n{0} tweets is {1}'.format(self.sentiment, nnd))
Exemple #12
0
def  permutation_mark(p=99, n=100 ,marks=None,mark=None):
    """
    Return the mean nearest neighbor distance of p permutations.

    Parameters
    ----------
    p : integer
    n : integer
    marks : list

    Returns
    -------
    permutations : list
            the mean nearest neighbor distance list.

    """
    permutation_list=[]
    for i in range(p):
        permutation_list.append(average_nearest_neighbor_distance(create_random_marked_points(n,marks),mark))
    return permutation_list
Exemple #13
0
def permutation(p=99, n=100):
    """
    Return the mean nearest neighbor distance of p permutations.

    Parameters
    ----------
    p : integer
    n : integer

    Returns
    -------
    permutations : list
            the mean nearest neighbor distance list.

    """
    permutation_list = []
    for i in range(p):
        permutation_list.append(
            average_nearest_neighbor_distance(generate_random_points(n)))
    return permutation_list
Exemple #14
0
def permutation_mark(p=99, n=100, marks=None, mark=None):
    """
    Return the mean nearest neighbor distance of p permutations.

    Parameters
    ----------
    p : integer
    n : integer
    marks : list

    Returns
    -------
    permutations : list
            the mean nearest neighbor distance list.

    """
    permutation_list = []
    for i in range(p):
        permutation_list.append(
            average_nearest_neighbor_distance(
                create_random_marked_points(n, marks), mark))
    return permutation_list
Exemple #15
0
def permutations(p=99, n=100):
    solution = []
    for tations in range(p):
        solution.append(analytics.average_nearest_neighbor_distance(generate_random_points(n)))
    return solution
 def test_average_nearest_neighbor_distance(self):
     mean_d = analytics.average_nearest_neighbor_distance(self.points)
     self.assertAlmostEqual(mean_d, 7.629178, 5)
Exemple #17
0
 def average_nearest_neighbor(self, mark=None):
     return analytics.average_nearest_neighbor_distance(self.points, mark)
 def average_nearest_neighbor_distance(self, marks=None):
     return analytics.average_nearest_neighbor_distance(self.points,marks)
 def test_check_yer_sig(self):
     permutations = utils.permutations(99)
     lower, upper = utils.crit_tations(permutations)
     significant = utils.check_yer_sig(lower, upper, analytics.average_nearest_neighbor_distance(self.points))
     self.assertTrue(significant)
Exemple #20
0
def permutations(p=99, n=100):
    solution = []
    for tations in range(p):
        solution.append(analytics.average_nearest_neighbor_distance(generate_random_points(n)))
    return solution