Ejemplo n.º 1
0
def plotLevel0VsLevel1Stats(data, prop0, prop1, label0, label1):
    d0 = getLevel0Prop(data, prop0)
    m, std, sm = level1Stats(data, prop1)
    for (v, p) in [(m, "mean"), (std, "standard deviation"), (sm, "sum")]:
        pl.newFigure()
        pl.plot(d0, v, style='ko-', xLog=False, yLog=False)
        pl.labels(label0, label1 + " " + p)
Ejemplo n.º 2
0
def wordSimScatterPlot(set1, set2, label1, label2):
    pl.newFigure()
    sims1, sims2 = intersectionSimilarities(set1, set2)
    pl.plot(sims1, sims2, style='ko', markerSize=4)
    pl.labels(label1, label2)
    print "Spearman correlation between", label1, "and", label2, ":", spearmanCorrelation(
        sims1, sims2)
Ejemplo n.º 3
0
def plotVsMaxInDegree(data, prop, label):
    pl.newFigure()
    pl.plot(getLevel0Prop(data, "max in-degree"),
            getLevel0Prop(data, prop),
            style='k-o',
            markerSize=4)
    pl.labels("In-degree threshold", label)
Ejemplo n.º 4
0
 def on_plot_clicked(self, widget):
     self.set_status(Status.PLOTTING)
     self.maybe_set_ready()
     try:
         plotlib.plot(self.plotter_port, self.plotter_baud_rate, self.file)
     except Exception as e:
         self.set_status(Status.ERROR)
         print(e)
     else:
         self.set_status(Status.DONE)
     self.maybe_set_ready()
Ejemplo n.º 5
0
def similarityDistribution(data):
    pl.newFigure()
    for d in data["results"]:
        hist = d["relative l1 norm"]["histogram"]
        bins = [1.0 - b for [b, c] in hist]
        counts = [float(c) for [t, c] in hist]
        tot = sum(counts)
        pl.plot(bins, [c / tot for c in counts],
                style='-',
                xLog=True,
                yLog=True)
    pl.labels("$1 - \mathrm{L_{1}}$", "Density")
    pl.legend(getLevel0Prop(data, "max in-degree"))
Ejemplo n.º 6
0
def histograms(data, prop, label):
    pl.newFigure()
    for d in data["results"]:
        hist = d[prop]["histogram"]
        bins = [b for [b, c] in hist]
        counts = [float(c) for [b, c] in hist]
        deltaTot = sum(counts) * (bins[1] - bins[0])
        pl.plot(bins, [c / deltaTot for c in counts],
                style='-',
                xLog=False,
                yLog=False)
    pl.labels(label, "Density")
    pl.legend(getLevel0Prop(data, "max in-degree"))
Ejemplo n.º 7
0
def correlationsVsLevel0Prop(data, prop0, label0, benchmarks, benchLabels):
    pl.newFigure()
    l0Prop = getLevel0Prop(data, prop0)
    l1Sims = selectedSimilarities(data)

    for b in benchmarks:

        def spearman(s1, s2):
            sims1, sims2 = intersectionSimilarities(s1, s2)
            return spearmanCorrelation(sims1, sims2)

        correlations = [spearman(b, s1) for s1 in l1Sims]
        pl.plot(l0Prop, correlations, style='o-', markerSize=4)

    pl.labels(label0, "Spearman rank correlation coefficient")
    pl.legend(benchLabels)
Ejemplo n.º 8
0
import cv2
import dlib
import imutils
from matplotlib import pyplot as plt
from plotlib import fig, plot

detector = dlib.get_frontal_face_detector()

img = load_image_url(
    'http://sensestudy-server/api/resource/public/accountstorage-objs/18ff97da-ead9-439d-82b5-deebcc29502a/zy1.jpeg'
)

img = img[:, :, ::-1]
print(img.shape)
plt.imshow(img)
plt.axis('off')
plt.show()  # Download as SVG format

img = imutils.resize(img, width=400)
fig() + plot(img)  # Download as PNG format
Ejemplo n.º 9
0
    return r[0]


df = pd.read_csv('https://sololearn.com/uploads/files/titanic.csv')
df['male'] = df['Sex'] == 'male'
X = df[[
    'Pclass', 'male', 'Age', 'Siblings/Spouses', 'Parents/Children', 'Fare'
]].values
y = df['Survived'].values

X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=5)

model = LogisticRegression()
model.fit(X_train, y_train)

# Adjusting the threshhold
# y_pred = model.predict_proba(X_test)[:, 1] > 0.75
y_pred_proba = model.predict_proba(X_test)
fpr, tpr, thresholds = roc_curve(y_test, y_pred_proba[:, 1])

plt.plot(fpr, tpr)
plt.plot([0, 1], [0, 1], linestyle='--')
plt.xlim([0.0, 1.0])
plt.ylim([0.0, 1.0])
plt.xlabel('1 - specificity')
plt.ylabel('sensitivity')
plt.show()

# print("sensitivity:", sensitivity_score(y_test, y_pred))
# print("specificity:", specificity_score(y_test, y_pred))
Ejemplo n.º 10
0
    return [r[prop] for r in data["results"]]


def plotVsMaxInDegree(data, prop, label):
    pl.newFigure()
    pl.plot(getLevel0Prop(data, "max in-degree"),
            getLevel0Prop(data, prop),
            style='k-o',
            markerSize=4)
    pl.labels("In-degree threshold", label)


def level0Plot(data, (prop1, label1), (prop2, label2)):
    fig = pl.newFigure()
    pl.plot(getLevel0Prop(data, prop1),
            getLevel0Prop(data, prop2),
            style='k-o',
            markerSize=4)
    pl.labels(label1, label2)
    return fig


def histograms(data, prop, label):
    pl.newFigure()
    for d in data["results"]:
        hist = d[prop]["histogram"]
        bins = [b for [b, c] in hist]
        counts = [float(c) for [b, c] in hist]
        deltaTot = sum(counts) * (bins[1] - bins[0])
        pl.plot(bins, [c / deltaTot for c in counts],
                style='-',
                xLog=False,
Ejemplo n.º 11
0
im = Image.open(file_path)
im = im.convert('RGB')
pixel = im.load()
output_path = os.path.join(os.path.dirname(__file__), "output/")

size_x = int(im.size[0])
size_y = int(im.size[1])
totalPx = size_x * size_y

print "Pixel: %spx X %spx " % (size_x, size_y)
print "Size: %.2fmm X %.2fmm " % (size_x * pxScale, size_y * pxScale)

target = open(output_path + filename + '.nc', 'w')
target.seek(0)

plotter = plotlib.plot(int(size_x/renderScale), int(size_y/renderScale))  # just for visualization and debugging
plotter.setBackground(0, 0, 0)

precalc = math.sqrt(math.pow(255, 2) + math.pow(255, 2) + math.pow(255, 2))
# precalculation of the length of an 3 dimensional RGB-color vector (255,255,255) - white

if (threshold >= 255):
    threshold = 255
elif (threshold <= 0):
    threshold = 0

# Header of Gcode
target.write('/#############################################################/ \n')
target.write('/###########Gcode generated with PathImg.py V0.4##############/ \n')
target.write('/######written by Nick Sidney Lemberger aka Holysocks#########/ \n')
target.write('/#############################################################/ \n\n')
Ejemplo n.º 12
0
import cv2
import numpy as np
import os
import plotlib

plotter = plotlib.plot()
plotter.setBackground(0,0,0)
dim = plotter.getDim()

video_capture = cv2.VideoCapture(0)

t_minus = cv2.cvtColor(video_capture.read()[1], cv2.COLOR_RGB2GRAY)
t = cv2.cvtColor(video_capture.read()[1], cv2.COLOR_RGB2GRAY)
t_plus = cv2.cvtColor(video_capture.read()[1], cv2.COLOR_RGB2GRAY)

def diffImg(t0, t1, t2):
	d1 = cv2.absdiff(t2, t1)
	d2 = cv2.absdiff(t1, t0)
	return cv2.bitwise_and(d1, d2)

def show(img):
	for x in xrange(dim[0]):
		for y in xrange(dim[1]):
			plotter.setColor(img.item(y,x,3),img.item(y,x,2),img.item(y,x,1))

while True:
	img = ("Motion",diffImg(t_minus, t, t_plus))
	show(img)

	t_minus = t
	t = t_plus
Ejemplo n.º 13
0
from plotlib import fig, plot
img_list = []
label_list = []
feat_list = []

trainset, testset = load_list()
img_list, label_list = trainset
print(len(img_list))
for i in range(5):
    img = load_img(img_list[i])
    fig() + plot(img)
    print(label_list[i])

HF = hogfeature()


def extract_hog(path):
    img = load_img(path)
    img_gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
    img_resize = cv2.resize(img_gray, (100, 100))
    return HF.getHog(img_resize, 0)


for img in img_list:
    feat = extract_hog(img)
    feat_list.append(feat)

model = linear_classifier()
model.train(feat_list, label_list)
pred = model.predict(feat_list)
print(accuracy(pred, label_list))
Ejemplo n.º 14
0
		if i > yi + 1:
			y = float(line[yi + 1:i])
		else:
			continue

		if xmin < 0 or x < xmin:
			xmin = x
		if ymin < 0 or y < ymin:
			ymin = y
		if xmax < 0 or x > xmax:
			xmax = x
		if ymax < 0 or y > ymax:
			ymax = y
print xmin,xmax,ymin,ymax

plotter = plotlib.plot(int((xmax-xmin)*pixelpermm), int((ymax-ymin)*pixelpermm))  # just for visualization and debugging
plotter.setBackground(0, 0, 0)
#plotter = plotlib.plot(int(size_x/renderScale), int(size_y/renderScale))  # just for visualization and debugging
#plotter.setBackground(0, 0, 0)
		
def step(x, y, dirx, diry):
	global color
	if x:
		global pos_x
		pos_x = pos_x + 1 if dirx else pos_x - 1
	if y:
		global pos_y
		pos_y = pos_y + 1 if diry else pos_y - 1
	plotter.setColor(color[0], color[1], color[2])
	plotter.plotdot(pos_x-xmin*pixelpermm, pos_y-ymin*pixelpermm)
	if not skipAnimation: plotter.show()