Skip to content

Commit

Permalink
Merge pull request #181 from jGaboardi/update_vars
Browse files Browse the repository at this point in the history
Updating/standardizing network/graph element naming
  • Loading branch information
jGaboardi committed Dec 3, 2018
2 parents 59f0bd6 + d509c85 commit 1c91b9f
Show file tree
Hide file tree
Showing 5 changed files with 702 additions and 573 deletions.
18 changes: 16 additions & 2 deletions spaghetti/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@ class NetworkBase(object):
observed y-axis of values
"""

def __init__(self, ntw, pointpattern, nsteps=10, permutations=99,
threshold=0.5, distribution='poisson',
lowerbound=None, upperbound=None):

self.ntw = ntw
self.pointpattern = pointpattern
self.nsteps = nsteps
Expand All @@ -82,6 +84,7 @@ def __init__(self, ntw, pointpattern, nsteps=10, permutations=99,
def validatedistribution(self):
"""enusure statistical distribution is supported
"""

valid_distributions = ['uniform', 'poisson']
assert(self.distribution in valid_distributions),\
"Distribution not in {}".format(valid_distributions)
Expand All @@ -90,6 +93,7 @@ def validatedistribution(self):
def computeenvelope(self):
"""compute upper and lower bounds of envelope
"""

upper = 1.0 - self.threshold / 2.0
lower = self.threshold / 2.0

Expand All @@ -100,6 +104,7 @@ def computeenvelope(self):
def setbounds(self, nearest):
"""set upper and lower bounds
"""

if self.lowerbound is None:
self.lowerbound = 0
if self.upperbound is None:
Expand All @@ -111,9 +116,11 @@ class NetworkG(NetworkBase):
capability to compute a distance matrix between two point patterns.
In this case one will be observed and one will be simulated.
"""

def computeobserved(self):
"""compute the observed nearest
"""

nearest = np.nanmin(self.ntw.allneighbordistances(self.pointpattern),
axis=1)
self.setbounds(nearest)
Expand All @@ -126,6 +133,7 @@ def computeobserved(self):
def computepermutations(self):
"""compute permutations of the nearest
"""

for p in range(self.permutations):
sim = self.ntw.simulate_observations(self.npts,
distribution=self.distribution)
Expand Down Expand Up @@ -155,13 +163,15 @@ class NetworkK(NetworkBase):
Based on :cite:`Okabe2001`.
"""

def computeobserved(self):
"""compute the observed nearest
"""

nearest = self.ntw.allneighbordistances(self.pointpattern)
self.setbounds(nearest)

self.lam = self.npts / sum(self.ntw.edge_lengths.values())
self.lam = self.npts / sum(self.ntw.arc_lengths.values())
observedx, observedy = kfunction(nearest,
self.upperbound,
self.lam,
Expand All @@ -173,6 +183,7 @@ def computeobserved(self):
def computepermutations(self):
"""compute permutations of the nearest
"""

for p in range(self.permutations):
sim = self.ntw.simulate_observations(self.npts,
distribution=self.distribution)
Expand All @@ -198,10 +209,10 @@ class NetworkF(NetworkBase):
"""


def computeobserved(self):
"""compute the observed nearest and simulated nearest
"""

self.fsim = self.ntw.simulate_observations(self.npts)
# Compute nearest neighbor distances from the simulated to the
# observed.
Expand All @@ -220,6 +231,7 @@ def computeobserved(self):
def computepermutations(self):
"""compute permutations of the nearest
"""

for p in range(self.permutations):
sim = self.ntw.simulate_observations(self.npts,
distribution=self.distribution)
Expand Down Expand Up @@ -259,6 +271,7 @@ def gfunction(nearest, lowerbound, upperbound, nsteps=10):
y-axis of values
"""

nobs = len(nearest)
x = np.linspace(lowerbound, upperbound, nsteps)
nearest = np.sort(nearest)
Expand Down Expand Up @@ -303,6 +316,7 @@ def kfunction(nearest, upperbound, intensity, nsteps=10):
y-axis of values
"""

nobs = len(nearest)
x = np.linspace(0, upperbound, nsteps)
y = np.empty(len(x))
Expand Down

0 comments on commit 1c91b9f

Please sign in to comment.