Beispiel #1
0
    def __rand_vecs_A(self, focus):
        if focus.lower() == 'origin':
            newOs = [
                np.random.permutation(self.o) for i in range(self.permutations)
            ]
            sims = [
                np.hstack([
                    np.arange(self.n).reshape((-1, 1)), newO,
                    self._newD(self.o, self.d, newO)
                ]) for newO in newOs
            ]
            Ws = [
                DistanceBand(newO,
                             threshold=self.threshold,
                             alpha=self.alpha,
                             binary=self.binary,
                             build_sp=self.build_sp,
                             silence_warnings=self.silence_warnings)
                for newO in newOs
            ]
        elif focus.lower() == 'destination':
            newDs = [
                np.random.permutation(self.d) for i in range(self.permutations)
            ]
            sims = [
                np.hstack([
                    np.arange(self.n).reshape((-1, 1)),
                    self._newO(self.o, self.d, newD), newD
                ]) for newD in newDs
            ]
            Ws = [
                DistanceBand(newD,
                             threshold=self.threshold,
                             alpha=self.alpha,
                             binary=self.binary,
                             build_sp=self.build_sp,
                             silence_warnings=self.silence_warnings)
                for newD in newDs
            ]
        else:
            raise ValueError(
                "Parameter 'focus' must take value of either 'origin' or 'destination.'"
            )

        VMs = [
            VecMoran(y, Ws[i], permutations=None) for i, y in enumerate(sims)
        ]
        sim = [VM.__calc(VM.z) for VM in VMs]
        return sim
Beispiel #2
0
 def test_origin_focused_B(self):
     wo = DistanceBand(self.origins,
                       threshold=9999,
                       alpha=-1.5,
                       binary=False)
     vmo = VecMoran(self.vecs, wo, focus='origin', rand='B')
     self.assertAlmostEquals(vmo.I, 0.645944594367)
     self.assertAlmostEquals(vmo.p_z_sim, 0.071427063787951814)
Beispiel #3
0
 def test_origin_focused_B(self):
     wo = DistanceBand(self.origins,
                       threshold=9999,
                       alpha=-1.5,
                       binary=False)
     np.random.seed(1)
     vmo = VecMoran(self.vecs, wo, focus='origin', rand='B')
     self.assertAlmostEquals(vmo.I, 0.645944594367)
     self.assertAlmostEquals(vmo.p_z_sim, 0.02944612633233532)
Beispiel #4
0
import unittest
import numpy as np

from .. import getisord
from libpysal.weights.distance import DistanceBand
from libpysal.common import pandas, RTOL, ATOL

POINTS = np.array([(10, 10), (20, 10), (40, 10), (15, 20), (30, 20), (30, 30)])
W = DistanceBand(POINTS, threshold=15)
Y = np.array([2, 3, 3.2, 5, 8, 7])

PANDAS_EXTINCT = pandas is None


class G_Tester(unittest.TestCase):
    def setUp(self):
        self.w = W
        self.y = Y
        np.random.seed(10)

    def test_G(self):
        g = getisord.G(self.y, self.w)
        np.testing.assert_allclose(g.G, 0.55709779, rtol=RTOL, atol=ATOL)
        np.testing.assert_allclose(g.p_norm, 0.172936, rtol=RTOL, atol=ATOL)

    @unittest.skipIf(PANDAS_EXTINCT, "missing pandas")
    def test_by_col(self):
        import pandas as pd

        df = pd.DataFrame(self.y, columns=["y"])
        np.random.seed(12345)
Beispiel #5
0
 def test_dest_focused_B(self):
     wd = DistanceBand(self.dests, threshold=9999, alpha=-1.5, binary=False)
     np.random.seed(1)
     vmd = VecMoran(self.vecs, wd, focus='destination', rand='B')
     self.assertAlmostEquals(vmd.I, -0.764603695022)
     self.assertAlmostEquals(vmd.p_z_sim, 0.12411761124197379)
Beispiel #6
0
 def test_dest_focused_B(self):
     wd = DistanceBand(self.dests, threshold=9999, alpha=-1.5, binary=False)
     vmd = VecMoran(self.vecs, wd, focus='destination', rand='B')
     self.assertAlmostEquals(vmd.I, -0.764603695022)
     self.assertAlmostEquals(vmd.p_z_sim, 0.086894261015806051)
Beispiel #7
0
 def test_dest_focused_A(self):
     wd = DistanceBand(self.dests, threshold=9999, alpha=-1.5, binary=False)
     vmd = VecMoran(self.vecs, wd, focus='destination', rand='A')
     self.assertAlmostEquals(vmd.I, -0.764603695022)
     self.assertAlmostEquals(vmd.p_z_sim, 0.149472673677)