コード例 #1
0
ファイル: linre29.py プロジェクト: vrepina/linre
def inc(fn,title,do_plot=0,eyl=1):
    l = AttrDict(load(fn+"pred.npz"))
    Ym, Ypred, expa = l.Ym, l.Ypred, l.expa
    print title
    print 'RMSEP',RMSEP(Ym, Ypred), 'BIAS',BIAS(Ym, Ypred), 'SE',SE(Ym, Ypred)
    #print len(Ym),len(Ypred),len(expa)
    if not do_plot: return
    persons = Persons(expa)
    
    ax = fig_pred.subplot(do_plot)
    Ymm = [0,max(Ym)]
    ax.plot(Ymm,Ymm,'g-')
    persons.plot( ax, Ym, Ypred )
    ax.set_title(title)
    ax.set_xlabel('IS, measured, mg/L')
    if eyl: ax.set_ylabel('IS, predicted, mg/L')
    
    ax = fig_ba.subplot(do_plot)
    mean_mp = (Ym+Ypred)/2.
    diff_mp = Ym-Ypred
    mm_mean_mp = [min(mean_mp),max(mean_mp)]
    md,s2 = mean(diff_mp), 2*diff_mp.std()
    #print mm_mean_mp,md,s2 #ax.clabel(contour,'AAA')#ax.set_xticklabels(['EE'],minor=True)
    def hline(l,txt):
        ax.axhline(y=l,ls=':',c='g')
        if txt: ax.annotate(txt,(mm_mean_mp[0],l),color='g')
    hline(md-s2,'Mean-2*SD')
    hline(md,'')
    hline(md+s2,'Mean+2*SD')
    persons.plot( ax, mean_mp, diff_mp )
    ax.set_title(title+', Bland-Altman')
    ax.set_xlabel('IS, (measured+predicted)/2, mg/L')
    if eyl: ax.set_ylabel('IS, (measured-predicted), mg/L')
コード例 #2
0
 def __init__(self, length, breadth):
     """Make an enemy."""
     Persons.__init__(self, length, breadth)
     self.nextX = None
     self.nextY = None
     self.direction = None
     self.matrix = [['{', '*', '*', '}'], [' ', ']', '[', ' ']]
コード例 #3
0
    def __init__(self):
        rospy.loginfo("Connecting to person detection service ...")
        self.pd = PersonDetection(service_name='what_am_i_looking_at')

        rospy.loginfo("Connecting to pose estimation service ...")
        self.pe = PoseEstimation()

        rospy.loginfo("Connecting to camera ...")
        self.camera = CameraStreamer(image_topic="/usb_cam/image_raw",
                                     scale=1.0)

        self.persons = Persons()
コード例 #4
0
def build_model():
    print("Initialisation...")
    face_recognizator = FaceRecognizator()
    face_recognizator.init()
    persons = Persons(face_recognizator)
    print("\n\nDémarrage...")
    face_detector = FaceDetector(persons)

    return face_detector
コード例 #5
0
    def build(self):

        self.theme_cls.primary_palette = "Gray"
        builder = Builder.load_file('main.kv')
        self.persons = Persons()

        #při startu vytvoří testovací data, kvůli testování aplikace je momentálně zaneprázdněna znaménky #,
        # ať se mi do toho nemotá
        ####self.persons.create_test_data()###

        builder.ids.navigation.ids.tab_manager.screens[0].add_widget(
            self.persons)
        return builder
コード例 #6
0
ファイル: linre21.py プロジェクト: vrepina/linre
X4fit,  Y4fit,  expa4fit  = X[a4fit ,:], Y[a4fit ,:], expa[a4fit ]
X4test, Y4test, expa4test = X[a4test,:], Y[a4test,:], expa[a4test]

pls = PLSRegression(n_components=n_components,algorithm='svd',scale=False)
pls.fit(X=X4fit,Y=Y4fit)

print "predict..."

Y_pred = pls.predict(X4test.copy())

dis4test = Y4test[:,0]
dis_pred = Y_pred[:,0]
dis_max = max(disa)
#dis_pred = where(dis_pred<dis_max+1,where(dis_pred<-1,-1,dis_pred),dis_max+1)

persons = Persons(expa4test)

#print ia4test, ia4fit, logical_not(a4fit & good_std)
#print expa4test.shape, dis4test.shape, dis_pred.shape, Y.shape, Y4test.shape, Y_pred.shape

plt.plot([0,dis_max],[0,dis_max],'g-')
persons.plot(plt,dis4test,dis_pred)
plt.savefig(out_pre+"pred.png")
plt.cla()

print "fit..."

pls = PLSRegression(n_components=n_components,algorithm='svd',scale=False)
pls.fit(X=X,Y=Y)

print "save..."
コード例 #7
0
 def __init__(self, length, breadth):
     Persons.__init__(self, length, breadth)
     self.matrix = [['[', '^', '^', ']'], [' ', ']', '[', ' ']]
コード例 #8
0
class WaveDetector:
    def __init__(self):
        rospy.loginfo("Connecting to person detection service ...")
        self.pd = PersonDetection(service_name='what_am_i_looking_at')

        rospy.loginfo("Connecting to pose estimation service ...")
        self.pe = PoseEstimation()

        rospy.loginfo("Connecting to camera ...")
        self.camera = CameraStreamer(image_topic="/usb_cam/image_raw",
                                     scale=1.0)

        self.persons = Persons()

    def process(self):
        cv2.namedWindow("image", cv2.WINDOW_NORMAL)

        while True:
            start_time = time.time()

            ret, image = self.camera.read()
            if not ret:
                rospy.logwarn("Frame skipped !")
                continue

            bodies = self.filter_human_bodies(self.pd.detect(image),
                                              self.pe.detect(image))
            for body in bodies:
                person = body["person"]
                if person[1] < 0.6:
                    continue

                points = body["points"]
                if '5' not in points:
                    continue
                points = limit_points(points)

                selected_person, exists = self.persons.find_nearest(
                    points['1'])
                cv2.circle(image, (selected_person.x, selected_person.y), 4,
                           BLUE_COLOR, -1)

                selected_person.add_point(points)

                if not exists:
                    self.persons.add(selected_person)
                else:
                    self.persons.update(selected_person.person_id, points['1'])

                visualize_points(image, points)

                x1, y1, x2, y2 = person[0]
                text = "{:.2f}, {}, {}".format(
                    person[1], selected_person.person_id,
                    selected_person.get_wave_label())
                text_size = cv2.getTextSize(text, cv2.FONT_HERSHEY_PLAIN, 1.0,
                                            1)
                cv2.rectangle(
                    image, (x1 - 1, y1),
                    (x1 + text_size[0][0], y1 - text_size[0][1] - 15),
                    RED_COLOR, -1)
                cv2.putText(image, text, (x1, y1 - 10), cv2.FONT_HERSHEY_PLAIN,
                            1.0, WHITE_COLOR)
                cv2.rectangle(image, (x1, y1), (x2, y2), RED_COLOR, 2)

            process_time = time.time() - start_time
            cv2.putText(image, "Process time : {:.2f}".format(process_time),
                        (10, 20), cv2.FONT_HERSHEY_PLAIN, 1.0, RED_COLOR)
            cv2.imshow("image", image)
            key = cv2.waitKey(1) & 0xFF
            if key == ord('q'):
                rospy.logwarn("The q key has been pressed !")
                break

    @staticmethod
    def filter_human_bodies(persons_list, humans_list):
        output = []
        for person in persons_list:
            x1, y1, x2, y2 = person[0]

            for body_parts in humans_list:
                for part in body_parts:
                    x, y = body_parts[part]
                    if x1 < x < x2 and y1 < y < y2:
                        output.append({"person": person, "points": body_parts})
                        break
        return output
コード例 #9
0
ファイル: linre25.py プロジェクト: vrepina/linre
n_components = 14

from numpy import load, array, where
from numpy.linalg import norm
from linre_tools import AttrDict
from persons import Persons
import matplotlib.pyplot as plt

l = AttrDict(load('linre_big'+'2'+'.npz'))

mds = AttrDict(load("out23/pred.npz"))
X, Y = mds.X, mds.Y
Ypred4n = mds.Ypred4n_components
Ym, Ypred = Y[:,0], Ypred4n[:,n_components-1]

eee = l.ema==l.exa
Xeee = X[:,eee]
#efm = Xeee.mean(axis=1)
#efm = [norm(s) for s in Xeee]
#efm = [len(where(s)[0]) for s in X_err]



#print Ym.shape, efm.shape
persons = Persons(mds.expa)
persons.plot( plt, efm, Ypred - Ym)
plt.show()
コード例 #10
0
ファイル: linre26.py プロジェクト: vrepina/linre
var_count = X.shape[1]
ma = empty((var_count,))
disa_pred4var = empty_like(X)
for varn in range(var_count):
    Xc = X[:,varn]
    loo = KFold( n=len(disa), k=group_count, indices=False )
    for fit, test in loo:
        slope, intercept, r_value, p_value, stderr = linregress(Xc[fit],disa[fit])
        disa_pred4var[test,varn] = Xc[test] * slope + intercept
    ma[varn] = RMSEP(disa,disa_pred4var[:,varn])

ia = argmin(ma)
print ma[ia]
l = AttrDict(load('linre_big2.npz'))
print l.exa[ia], l.ema[ia]

persons = Persons(expa)
Ymm = [0,max(disa)]
plt.plot(Ymm,Ymm,'g-')
persons.plot(plt,disa,disa_pred4var[:,ia])
plt.title('Univariate, K-Fold, '+str(len(disa))+' samples')
plt.xlabel('IS, measured, mg/L')
plt.ylabel('IS, predicted, mg/L')
plt.savefig("out26/pred.png")


Ym, Ypred = disa, disa_pred4var[:,ia]
print 'RMSEP',  RMSEP(Ym, Ypred)
print 'BIAS', BIAS(Ym, Ypred)
print 'SE', SE(Ym, Ypred)
savez('out26/pred.npz',Ym=Ym,Ypred=Ypred,expa=expa)
コード例 #11
0
import os
import os.path
import re
from persons import Persons
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

#engine = create_engine('postgresql://*****:*****@localhost:5432/enron_emails', echo = True)

# create database session
Session = sessionmaker()
Session.configure(bind=engine)
session = Session()

for directory in os.listdir(
        'C:\\Users\\MGOW\\Documents\\PythonProject\\maildir'):
    name_row = Persons(name=directory)
    session.add(name_row)
    session.commit()
コード例 #12
0
ファイル: linre17.py プロジェクト: vrepina/linre
X_orig = flum.T
X_err, X_orig = find_peaks(X_orig,exa)

## exclude outliers
PC = PCA(n_components=2).fit_transform(X_orig.copy()) #mean inside
PC1 = PC[:,0]
good_std = PC1 < PC1.std()

a4fit = arange(len(X_orig)) >= samples_in_testing_set
ia4fit, = where( a4fit & good_std )
X4fit = X_orig[ia4fit,:]
disa4fit = disa[ia4fit]
pca = PCA(n_components=n_components)
PC = pca.fit_transform(X4fit.copy())
dis_mean = disa4fit.mean()
#print PC.shape,(disa4fit-dis_mean).shape
(a,residues,rank,s) = lstsq(PC,disa4fit-dis_mean)

PC = pca.transform(X_orig.copy())
mdis = PC.dot(a[:,None])[:,0] + dis_mean

from persons import Persons
persons = Persons(expa)

import matplotlib.pyplot as plt
plt.figure()
dis_max = max(disa)
plt.plot([0,dis_max],[0,dis_max],'g-')
persons.plot(plt,disa,where(mdis<dis_max+1,where(mdis<-1,-1,mdis),dis_max+1))
plt.show()
コード例 #13
0
parser.add_argument("--enactments", help="argument for sync enactments", action='store_const', const='True', default=False)
parser.add_argument("--threads", help="argument for amount of threads for sync enactments", type=int, default=4)
args = parser.parse_args()

chrome_options = Options()
#chrome_options.add_argument("--headless")
chrome_options.add_argument("--no-sandbox")
driver = webdriver.Chrome(chrome_options=chrome_options)
deputats = None
date_from = datetime.datetime.strptime(args.fromd, "%d.%m.%Y")
date_to = datetime.datetime.strptime(args.tod, "%d.%m.%Y")


if args.deputats:
    print('--deputats = True: sync deputats')
    persons = Persons()
    deputats = persons.sync(driver)
    persons.save()
else:
    print('--deputats = False: load deputats')
    persons = Persons()
    deputats = persons.load()

if args.enactments:
    print('--enactment not None: sync enactments')
    enactment = Enactment(driver)
    enactment.sync(date_from, date_to)
    enactment.save()

threads_amount = args.threads
list_deps = devide_array(deputats, threads_amount)