def test___init__(self):
     import numpy as np
     f = pysal.open(pysal.examples.get_path('usjoin.csv'))
     pci = np.array([f.by_col[str(y)]
                     for y in range(1929, 2010)]).transpose()
     w = pysal.open(pysal.examples.get_path("states48.gal")).read()
     lm = pysal.LISA_Markov(pci, w)
     obs = np.array([1, 2, 3, 4])
     np.testing.assert_array_almost_equal(obs, lm.classes)
     ss = np.matrix([[0.28561505], [0.14190226], [0.40493672],
                     [0.16754598]])
     np.testing.assert_array_almost_equal(lm.steady_state, ss)
     transitions = np.array(
         [[1.08700000e+03, 4.40000000e+01, 4.00000000e+00, 3.40000000e+01],
          [4.10000000e+01, 4.70000000e+02, 3.60000000e+01, 1.00000000e+00],
          [5.00000000e+00, 3.40000000e+01, 1.42200000e+03, 3.90000000e+01],
          [3.00000000e+01, 1.00000000e+00, 4.00000000e+01, 5.52000000e+02]])
     np.testing.assert_array_almost_equal(lm.transitions, transitions)
     p = np.matrix([[0.92985458, 0.03763901, 0.00342173, 0.02908469],
                    [0.07481752, 0.85766423, 0.06569343, 0.00182482],
                    [0.00333333, 0.02266667, 0.948, 0.026],
                    [0.04815409, 0.00160514, 0.06420546, 0.88603531]])
     np.testing.assert_array_almost_equal(lm.p, p)
     np.random.seed(10)
     lm_random = pysal.LISA_Markov(pci, w, permutations=99)
     expected = np.array(
         [[1.12328098e+03, 1.15377356e+01, 3.47522158e-01, 3.38337644e+01],
          [3.50272664e+00, 5.28473882e+02, 1.59178880e+01, 1.05503814e-01],
          [1.53878082e-01, 2.32163556e+01, 1.46690710e+03, 9.72266513e+00],
          [9.60775143e+00, 9.86856346e-02, 6.23537392e+00, 6.07058189e+02]])
     np.testing.assert_allclose(lm_random.expected_t, expected, RTOL)
     c = np.array([1058.207904, 0., 9.])
     np.testing.assert_allclose(lm_random.chi_2, c, RTOL)
Beispiel #2
0
 def computeMarkovLISA(self):
     """
     precomputing LISA maps
     """
     try:
         self.id_groups = []
         # computer the markov lisa and lisa maps
         progress_dlg = wx.ProgressDialog(
             "Progress",
             "Pre-computing Markov LISA...               ",
             maximum=2,
             parent=self,
             style=wx.PD_APP_MODAL | wx.PD_AUTO_HIDE)
         progress_dlg.CenterOnScreen()
         progress_dlg.Update(1)
         self.lisa_markov = pysal.LISA_Markov(
             np.array(self.data_sel_values).transpose(), self.weight)
         self.lisa_markov_mt = self.lisa_markov.move_types
         self.lisa_markov_p = np.array(self.lisa_markov.p)
         progress_dlg.Update(2)
         progress_dlg.Destroy()
         # precompute LISAs
         self.moran_locals = self.precomputeLISA()
         # filter out non-sig: all LISA p-values should be
         # significant for one shape object
         for i in range(self.t):
             ml_p_sim = np.array(self.moran_locals[i][1])  # 1~p values
             for j in range(self.n):
                 if ml_p_sim[j] > 0.05:
                     # then object j is not significant
                     self.lisa_markov_mt[j][-1] = 0
     except:
         raise Exception("compute Markov LISA error! ")
Beispiel #3
0
 def test___init__(self):
     import numpy as np
     f = pysal.open(pysal.examples.get_path('usjoin.csv'))
     pci = np.array([f.by_col[str(y)]
                     for y in range(1929, 2010)]).transpose()
     w = pysal.open(pysal.examples.get_path("states48.gal")).read()
     lm = pysal.LISA_Markov(pci, w)
     obs = np.array([1, 2, 3, 4])
     np.testing.assert_array_almost_equal(obs, lm.classes)
     """
Beispiel #4
0
def markov(observations, w=None, numQuints=5, method="regular"):
    result = None
    s = None
    if method == "regular":  # non spatial analysis
        quintiles = np.array([pysal.Quantiles(y, k=numQuints).yb for y in observations]).transpose()
        result = pysal.Markov(quintiles)
        #s = result.steady_state

    else:
        observations = observations.transpose()

        if method == "spatial":
            # standardize observations for smoother calculations:
            observations = observations / (observations.mean(axis=0))
            result = pysal.Spatial_Markov(observations, w, fixed=True, k=numQuints)
            #s = result.S

        else:  # method == lisa
            result = pysal.LISA_Markov(observations, w)
            #s = result.steady_state

    return result.transitions, result.p, s, pysal.ergodic.fmpt(result.p)
print(m5.transitions)

print(m5.p)

print(m5.steady_state)

print(pysal.ergodic.fmpt(m5.p))
################################################################# Spatial Markov
fpci = pci.transpose() / (pci.transpose().mean(axis=0))
print(fpci)

w = pysal.open(
    r'C:\Anaconda\Lib\site-packages\pysal\examples\us_income\states48.gal'
).read()
w.transform = 'r'
sm = pysal.Spatial_Markov(fpci, w, fixed=True, k=5)
for p in sm.p:
    print(p)

for f in sm.F:
    print(f)
################################################################# LISA Markov
lm = pysal.LISA_Markov(pci.transpose(), w)
print(lm.classes)

# the estimated transition probability matrix
print(lm.transitions)
print(lm.p)
print(lm.steady_state)
print(pysal.ergodic.fmpt(lm.p))