In [7]:
%pylab inline
import json
import os
os.environ['XPA_METHOD'] = 'local'
from bubbly.viewer import BubblyViewer
from bubbly.extractors import RGBExtractor
from bubbly.cluster import merge, xmatch
import matplotlib
matplotlib.rcParams['axes.grid'] = False
In [3]:
bv = BubblyViewer()
bv.load_longitude(35)
In [4]:
data = json.load(open('../models/l035_scores.json'))
stamps = np.array(data['stamps'])
scores = np.array(data['scores'])
rank = np.argsort(scores)[::-1]
lohi = np.argsort(scores)
In [8]:
hist(scores, histtype='step')
yscale('log')
xlabel("Scores")
ylabel("N")
Out[8]:
In [9]:
ex = RGBExtractor()
ex.shp = (100, 100)
ss = np.linspace(1, -1, 20)
ss += np.random.random(ss.size) * .01
inds = lohi[np.minimum(np.searchsorted(scores[lohi], ss), lohi.size-1)]
ims = [ex.extract(*stamps[i]) for i in inds]
nx = 5
ny = int(np.ceil(inds.size / 5))
im = np.vstack(np.hstack(ims[i:i+nx]) for i in range(0, inds.size, nx))
figure(figsize=(15, 15))
imshow(im, origin='upper')
opts = dict(color = '#0000ff', ha='center', va='center', fontsize=18)
for i in range(inds.size):
x = (i % nx + 0.5) * ex.shp[0]
y = (i / nx + 0.5) * ex.shp[0]
annotate("%0.2f" % scores[inds[i]], xy = (x, y), **opts)
In [13]:
from bubbly.field import get_field
from bubbly.util import scale
from bubbly.dr1 import bubble_params
f = get_field(35)
g = scale(f.i4[::7, ::7])
r = scale(f.mips[::7, ::7])
b = r * 0
im = np.dstack((r, g, b))
def plot_stamps(stamps, **kwargs):
kwargs.setdefault('facecolor', 'none')
kwargs.setdefault('edgecolor', 'b')
kwargs.setdefault('alpha', .1)
ax = gca()
for s in stamps:
r = Rectangle((s[1] - s[-1], s[2] - s[-1]), width = 2 * s[-1], height = 2 * s[-1], **kwargs)
ax.add_patch(r)
mwp = [b for b in bubble_params() if b[0] == 35]
unmerged = stamps[scores > .2]
merged, scores = merge(unmerged, scores[scores > 0.2])
In [ ]:
from sklearn.cluster import DBSCAN
In [14]:
figure(figsize=(10, 10), dpi=100)
imshow(im, extent=[36, 34, -1, 1])
plot_stamps(unmerged)
plot_stamps(merged, edgecolor='r', alpha=1)
xlim(35.5, 34.5)
ylim(-1, 0)
gca().set_aspect('equal')
In [17]:
match = xmatch(merged, mwp)
print 'Bubbly -> mwp: (%i)' % ((match >= 0).sum())
for i, j in enumerate(match):
if j < 0:
continue
print '%i -> %i' % (i, j)
print 'Unmatched Bubbly (%i / %i)' % ((match == -1).sum(), merged.shape[0])
print np.where(match == -1)[0].tolist()
print 'Unmatched mwp (%i / %i)' % (len(mwp) - (match >= 0).sum(), len(mwp))
z = np.zeros(len(mwp))
z[match] = 1
print np.where(z == 0)[0].tolist()
In [18]:
len(merged), len(mwp)
Out[18]:
In [15]:
#bubbly in blue, MWP in red
bv.clear()
bv.outline(merged, color='red')
bv.outline(mwp)
In [46]:
6/32.
Out[46]:
Bubbly finds 20 stamps, MWP finds 32 (or 26 in Bubbly's search strategy). Of the 20 bubblys:
In addition, ignoring confusion examples, there are 17 bubbles in the MWP with no bubbly counterpart:
Overall, bubbly recovers 16 / 21 bubbles it is sensitive to (76%), at a false positive rate of 4 / 25 (16%)
The MWP, on the other hand, recovers 20/21 bubbles (95%), at a false positive rate of 18%.
In [10]:
from bubbly.model import ModelGroup
model = ModelGroup.load('../models/full_classifier.dat')
In [22]:
ind = 14
cat = merged
bv.look_at(cat[ind])
imshow(ex.extract(cat[ind][0], cat[ind][1], cat[ind][2], cat[ind][3] * 2))
show()
imshow(ex.extract(*cat[ind]))
show()
model.decision_function([cat[ind]])
Out[22]:
In [49]:
len(merged), len(mwp)
Out[49]:
In [47]:
merged.tolist()
Out[47]:
In [48]:
mwp
Out[48]:
In [ ]: