for tb, sb in itertools.product([30, 50, 70, 90], [3, 4, 5, 6, 7]):
        weight = open_cp.prohotspot.ClassicWeight(time_bandwidth=tb,
                                                  space_bandwidth=sb)
        distance = open_cp.prohotspot.DistanceCircle()
        state.add_prediction(scripted.ProHotspotProvider(weight, distance),
                             time_range)

    for tb, sb in itertools.product([30, 50, 70, 90], [0.5, 1, 1.5]):
        weight = open_cp.prohotspot.ClassicWeight(time_bandwidth=tb,
                                                  space_bandwidth=sb)
        state.add_prediction(scripted.ProHotspotCtsProvider(weight, 150),
                             time_range)

    for max_s in [100, 200, 500, 1000]:
        for max_t in [7, 14, 21, 8 * 7]:
            provider = scripted.STScanProvider(max_s,
                                               datetime.timedelta(days=max_t),
                                               False)
            state.add_prediction(provider, time_range)
            state.add_prediction(provider.with_new_max_cluster(True),
                                 time_range)

    for tw in [12, 16, 20]:
        for bw in [50, 75, 100]:
            tk = open_cp.kde.ExponentialTimeKernel(tw * 7)
            sk = open_cp.kde.GaussianFixedBandwidthProvider(bw)
            state.add_prediction(scripted.KDEProvider(tk, sk), time_range)

    state.score(scripted.HitCountEvaluator)
    state.process(scripted.HitCountSave("hotspots2.csv"))
예제 #2
0
                                                  state.timed_points,
                                                  tk,
                                                  sk,
                                                  bk,
                                                  cutoff=time_range.first)
            state.add_prediction_range(provider, time_range)

    for omega in [0.1, 0.5, 1]:
        for sigma in [20, 50, 100]:
            tk = sepp.sepp_fixed.ExpTimeKernel(omega)
            sk = sepp.sepp_fixed.GaussianSpaceKernel(sigma)
            provider = predictors.GridFixedTriggerProvider(
                state.grid,
                state.timed_points,
                tk,
                sk,
                cutoff=time_range.first)
            state.add_prediction_range(provider, time_range)

    for omega in [0.1, 0.5, 1]:
        for sigma in [20, 50, 100]:
            tk = sepp.sepp_fixed.ExpTimeKernel(omega)
            sk = sepp.sepp_fixed.GaussianSpaceKernel(sigma)
            bk = sepp.kernels.FixedBandwidthKernelProvider(50)
            provider = predictors.KDEFixedTriggerProvider(
                state.timed_points, tk, sk, bk, cutoff=time_range.first)
            state.add_prediction_range(provider, time_range)

    state.score(scripted.HitCountEvaluator)
    state.process(scripted.HitCountSave("{}_all.csv".format(side)))
예제 #3
0
        return open_cp.sources.chicago.load(f, "BURGLARY", type="all")


def load_geometry():
    """Load the geometry for Chicago; we'll use Southside, as ever..."""
    open_cp.sources.chicago.set_data_directory(datadir)
    return open_cp.sources.chicago.get_side("South")


## Run

import datetime

with scripted.Data(load_points,
                   load_geometry,
                   start=datetime.datetime(2016, 1, 1)) as state:

    time_range = scripted.TimeRange(datetime.datetime(2016, 10, 1),
                                    datetime.datetime(2017, 1, 1),
                                    datetime.timedelta(days=1))

    provider = scripted.STScanProvider(500, datetime.timedelta(days=21), False)
    state.add_prediction(provider, time_range)
    state.add_prediction(provider.with_new_max_cluster(True), time_range)

    state.score(scripted.HitCountEvaluator)

    state.save_predictions("stscan_preds.pic.xz")

    state.process(scripted.HitCountSave("stscan_counts.csv"))
예제 #4
0
        return open_cp.sources.chicago.load(f, "BURGLARY", type="all")


def load_geometry():
    """Load the geometry for Chicago; we'll use Southside, as ever..."""
    open_cp.sources.chicago.set_data_directory(datadir)
    return open_cp.sources.chicago.get_side("South")


## Run

import datetime

with scripted.Data(load_points,
                   load_geometry,
                   start=datetime.datetime(2016, 1, 1)) as state:

    time_range = scripted.TimeRange(datetime.datetime(2016, 10, 1),
                                    datetime.datetime(2017, 1, 1),
                                    datetime.timedelta(days=1))
    state.add_prediction(scripted.NaiveProvider, time_range)
    state.add_prediction(scripted.ScipyKDEProvider, time_range)

    state.score(scripted.HitRateEvaluator)
    state.score(scripted.HitCountEvaluator)

    state.save_predictions("naive_preds.pic.xz")

    state.process(scripted.HitRateSave("naive.csv"))
    state.process(scripted.HitCountSave("naive_counts.csv"))
예제 #5
0
    time_range = scripted.TimeRange(datetime.datetime(2016, 10, 1),
                                    datetime.datetime(2017, 1, 1),
                                    datetime.timedelta(days=1))

    state.add_prediction(scripted.NaiveProvider, time_range)

    for omegai in [1, 2, 5, 10, 20, 100]:
        for sigma in [10, 20, 50, 100]:
            tk = sepp.sepp_fixed.ExpTimeKernel(1 / omegai)
            sk = sepp.sepp_fixed.GaussianSpaceKernel(sigma)
            provider = predictors.GridFixedTriggerProvider(
                state.grid,
                state.timed_points,
                tk,
                sk,
                cutoff=time_range.first)
            state.add_prediction_range(provider, time_range)

    for omegai in [1, 2, 5, 10, 20, 100]:
        for sigma in [10, 20, 50, 100]:
            for bkb in [20, 50, 100, 200]:
                tk = sepp.sepp_fixed.ExpTimeKernel(1 / omegai)
                sk = sepp.sepp_fixed.GaussianSpaceKernel(sigma)
                bk = sepp.kernels.FixedBandwidthKernelProvider(bkb)
                provider = predictors.KDEFixedTriggerProvider(
                    state.timed_points, tk, sk, bk, cutoff=time_range.first)
                state.add_prediction_range(provider, time_range)

    state.score(scripted.HitCountEvaluator)
    state.process(scripted.HitCountSave("{}_mod_fixed.csv".format(side)))
예제 #6
0
def load_geometry():
    frame = gpd.read_file("SouthSide")
    return frame.geometry[0]


def stringToDatetime(s):
    return datetime.datetime(*(s.split("-")))


earliest_time = "2016-01-01"
start_time = "2016-10-01"
end_time = "2017-01-01"

# Perform the predictions; see `scripted_intro.md`

with scripted.Data(load_points,
                   load_geometry,
                   start=stringToDatetime(earliest_time)) as state:

    time_range = scripted.TimeRange(stringToDatetime(start_time),
                                    stringToDatetime(end_time),
                                    datetime.timedelta(days=1))

    state.add_prediction(scripted.NaiveProvider, time_range)

    state.score(scripted.HitRateEvaluator)
    state.score(scripted.HitCountEvaluator)

    state.process(scripted.HitRateSave("ratesTest.csv"))
    state.process(scripted.HitCountSave("countsTest.csv"))