In [1]:
import os, sys
sys.path.insert(0, os.path.abspath(os.path.join("..", "..")))

Prospective hotspotting


In [2]:
%matplotlib inline
import matplotlib.pyplot as plt
import open_cp.scripted
import open_cp.scripted.analysis as analysis

In [3]:
betas = analysis.hit_counts_to_beta("pro_grid_opt.csv")

In [4]:
import re
def label(key):
    m = re.search("Classic\((.*?)\)", key)
    return m.group(1)
label(list(betas)[0])


Out[4]:
'sb=2, tb=6'

In [5]:
fig, ax = plt.subplots(ncols=2, figsize=(16,7))
analysis.plot_betas(betas, ax[0])
ax[0].legend([])
analysis.plot_betas(betas, ax[1], plot_sds=False)
ax[1].legend([label(k) for k in betas])


Out[5]:
<matplotlib.legend.Legend at 0x7f4f5e4d52e8>

In [6]:
fig, ax = plt.subplots(ncols=2, figsize=(16,7))
analysis.plot_betas(betas, ax[0], range(1, 21))
ax[0].legend([])
analysis.plot_betas(betas, ax[1], range(1, 21), plot_sds=False)
ax[1].legend([label(k) for k in betas])


Out[6]:
<matplotlib.legend.Legend at 0x7f4f5e3726a0>

In [7]:
fig, ax = plt.subplots(figsize=(12,6))
r = analysis.plot_betas_means_against_max(betas, ax, range(1,21))



In [8]:
{k : all(x>0.85 for x in r[k]) for k in r}


Out[8]:
{'ProHotspotProvider(Weight=Classic(sb=2, tb=6), Distance=DiagsCircle, TimeUnit=24.0h)': False,
 'ProHotspotProvider(Weight=Classic(sb=2, tb=7), Distance=DiagsCircle, TimeUnit=24.0h)': False,
 'ProHotspotProvider(Weight=Classic(sb=2, tb=8), Distance=DiagsCircle, TimeUnit=24.0h)': False,
 'ProHotspotProvider(Weight=Classic(sb=2, tb=9), Distance=DiagsCircle, TimeUnit=24.0h)': True,
 'ProHotspotProvider(Weight=Classic(sb=3, tb=6), Distance=DiagsCircle, TimeUnit=24.0h)': False,
 'ProHotspotProvider(Weight=Classic(sb=3, tb=7), Distance=DiagsCircle, TimeUnit=24.0h)': False,
 'ProHotspotProvider(Weight=Classic(sb=3, tb=8), Distance=DiagsCircle, TimeUnit=24.0h)': False,
 'ProHotspotProvider(Weight=Classic(sb=3, tb=9), Distance=DiagsCircle, TimeUnit=24.0h)': False,
 'ProHotspotProvider(Weight=Classic(sb=4, tb=6), Distance=DiagsCircle, TimeUnit=24.0h)': False,
 'ProHotspotProvider(Weight=Classic(sb=4, tb=7), Distance=DiagsCircle, TimeUnit=24.0h)': False,
 'ProHotspotProvider(Weight=Classic(sb=4, tb=8), Distance=DiagsCircle, TimeUnit=24.0h)': False,
 'ProHotspotProvider(Weight=Classic(sb=4, tb=9), Distance=DiagsCircle, TimeUnit=24.0h)': False}

In [9]:
{k : sum(x>0.95 for x in r[k]) >= 16 for k in r}


Out[9]:
{'ProHotspotProvider(Weight=Classic(sb=2, tb=6), Distance=DiagsCircle, TimeUnit=24.0h)': False,
 'ProHotspotProvider(Weight=Classic(sb=2, tb=7), Distance=DiagsCircle, TimeUnit=24.0h)': False,
 'ProHotspotProvider(Weight=Classic(sb=2, tb=8), Distance=DiagsCircle, TimeUnit=24.0h)': False,
 'ProHotspotProvider(Weight=Classic(sb=2, tb=9), Distance=DiagsCircle, TimeUnit=24.0h)': False,
 'ProHotspotProvider(Weight=Classic(sb=3, tb=6), Distance=DiagsCircle, TimeUnit=24.0h)': False,
 'ProHotspotProvider(Weight=Classic(sb=3, tb=7), Distance=DiagsCircle, TimeUnit=24.0h)': False,
 'ProHotspotProvider(Weight=Classic(sb=3, tb=8), Distance=DiagsCircle, TimeUnit=24.0h)': False,
 'ProHotspotProvider(Weight=Classic(sb=3, tb=9), Distance=DiagsCircle, TimeUnit=24.0h)': False,
 'ProHotspotProvider(Weight=Classic(sb=4, tb=6), Distance=DiagsCircle, TimeUnit=24.0h)': False,
 'ProHotspotProvider(Weight=Classic(sb=4, tb=7), Distance=DiagsCircle, TimeUnit=24.0h)': False,
 'ProHotspotProvider(Weight=Classic(sb=4, tb=8), Distance=DiagsCircle, TimeUnit=24.0h)': False,
 'ProHotspotProvider(Weight=Classic(sb=4, tb=9), Distance=DiagsCircle, TimeUnit=24.0h)': True}

In [10]:
highlight = {"sb=2, tb=9", "sb=4, tb=9"}

fig, ax = plt.subplots(figsize=(10,6))
x = list(range(1, 21))
for k in r:
    if label(k) not in highlight:
        ax.plot(x, r[k], color="black", label="_")
    else:
        ax.plot(x, r[k], label=label(k))
ax.legend()
None


Continuous predictions


In [12]:
betas = analysis.hit_counts_to_beta("pro_opt.csv")

In [13]:
fig, ax = plt.subplots(ncols=2, figsize=(16,7))
analysis.plot_betas(betas, ax[0])
ax[0].legend([])
analysis.plot_betas(betas, ax[1], plot_sds=False)
ax[1].legend([label(k) for k in betas])


Out[13]:
<matplotlib.legend.Legend at 0x7f4f60f0eeb8>

In [14]:
fig, ax = plt.subplots(ncols=2, figsize=(16,7))
analysis.plot_betas(betas, ax[0], range(1, 21))
ax[0].legend([])
analysis.plot_betas(betas, ax[1], range(1, 21), plot_sds=False)
ax[1].legend([label(k) for k in betas])


Out[14]:
<matplotlib.legend.Legend at 0x7f4f61143c18>

In [15]:
fig, ax = plt.subplots(figsize=(12,6))
r = analysis.plot_betas_means_against_max(betas, ax, range(1,21))



In [19]:
{k : all(x>0.92 for x in r[k]) for k in r}


Out[19]:
{'ProHotspotCtsProvider(Weight=Classic(sb=2, tb=6), DistanceUnit=150)': False,
 'ProHotspotCtsProvider(Weight=Classic(sb=2, tb=7), DistanceUnit=150)': False,
 'ProHotspotCtsProvider(Weight=Classic(sb=2, tb=8), DistanceUnit=150)': False,
 'ProHotspotCtsProvider(Weight=Classic(sb=2, tb=9), DistanceUnit=150)': False,
 'ProHotspotCtsProvider(Weight=Classic(sb=3, tb=6), DistanceUnit=150)': False,
 'ProHotspotCtsProvider(Weight=Classic(sb=3, tb=7), DistanceUnit=150)': False,
 'ProHotspotCtsProvider(Weight=Classic(sb=3, tb=8), DistanceUnit=150)': False,
 'ProHotspotCtsProvider(Weight=Classic(sb=3, tb=9), DistanceUnit=150)': False,
 'ProHotspotCtsProvider(Weight=Classic(sb=4, tb=6), DistanceUnit=150)': False,
 'ProHotspotCtsProvider(Weight=Classic(sb=4, tb=7), DistanceUnit=150)': True,
 'ProHotspotCtsProvider(Weight=Classic(sb=4, tb=8), DistanceUnit=150)': False,
 'ProHotspotCtsProvider(Weight=Classic(sb=4, tb=9), DistanceUnit=150)': False}

In [22]:
{k : sum(x>0.96 for x in r[k]) >= 16 for k in r}


Out[22]:
{'ProHotspotCtsProvider(Weight=Classic(sb=2, tb=6), DistanceUnit=150)': False,
 'ProHotspotCtsProvider(Weight=Classic(sb=2, tb=7), DistanceUnit=150)': False,
 'ProHotspotCtsProvider(Weight=Classic(sb=2, tb=8), DistanceUnit=150)': True,
 'ProHotspotCtsProvider(Weight=Classic(sb=2, tb=9), DistanceUnit=150)': True,
 'ProHotspotCtsProvider(Weight=Classic(sb=3, tb=6), DistanceUnit=150)': False,
 'ProHotspotCtsProvider(Weight=Classic(sb=3, tb=7), DistanceUnit=150)': False,
 'ProHotspotCtsProvider(Weight=Classic(sb=3, tb=8), DistanceUnit=150)': False,
 'ProHotspotCtsProvider(Weight=Classic(sb=3, tb=9), DistanceUnit=150)': True,
 'ProHotspotCtsProvider(Weight=Classic(sb=4, tb=6), DistanceUnit=150)': False,
 'ProHotspotCtsProvider(Weight=Classic(sb=4, tb=7), DistanceUnit=150)': False,
 'ProHotspotCtsProvider(Weight=Classic(sb=4, tb=8), DistanceUnit=150)': False,
 'ProHotspotCtsProvider(Weight=Classic(sb=4, tb=9), DistanceUnit=150)': False}

In [25]:
highlight = {"sb=4, tb=7", "sb=3, tb=9"}

fig, ax = plt.subplots(figsize=(10,6))
x = list(range(1, 21))
for k in r:
    if label(k) not in highlight:
        ax.plot(x, r[k], color="black", label="_")
    else:
        ax.plot(x, r[k], label=label(k))
ax.legend()
None



In [ ]: