JamesSaxon / access-old

Python module to calculate spatial access scores.
http://access.readthedocs.io
BSD 3-Clause "New" or "Revised" License
4 stars 0 forks source link

Create additional weight functions #21

Open JamesSaxon opened 5 years ago

JamesSaxon commented 5 years ago
JamesSaxon commented 5 years ago

It looks like for the gaussian, you can just get the function from scipy directly.

from scipy.stats import norm
n1 = norm(scale = 1).pdf
n2(0)

https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.norm.html

For the step functions you could create something to generate the functions, like this:

d = {10 : 0.962, 20 : 0.704, 30 : 0.377, 60 : 0.042}
def step_fn(d):

    step_limits = d

    def F(v):

        for lim in sorted(list(step_limits)):
            if v <= lim: 
                return step_limits[lim]

        return 0

    return F

step_dict = step_fn(d)
step_dict(12)
20bryan commented 5 years ago

Are the dictionaries for the step functions user-inputted? Or should there be some pre-defined dictionaries in place?

BTW, to clarify the general process for the way a weighting function is called.

  1. Explicitly call a helper function to generate a desired weighting function
  2. Pass in the generated weighting function as a parameter to an FCA call

For example,

stepwise_weight = HelperClass.step_fn(UserInputtedDictionary)

demand_df[NewColumn] = two_stage_fca(..., weight_fn = stepwise_weight)

JamesSaxon commented 5 years ago

Yes, they will be user-specified.