Sliding Window Algorithm Implementation Using Python3
Mon, May 21, 2018
One-minute read
In this article shows how to implement sliding window algorithm using python3 and 5000 sample (x,y) points.
First of all create our class for putting points to it.
class Nokta:
def __init__(self,x,y): #nokta sınıfı tanımladım
self.x = x
self.y = y
Then read csv file for all points by filtering using(,) filter and by using these x,y variables created new Nokta class and append these objects to a List.
file = open("s5000.txt","r") #dışarıdan 5000 nokta için dosyayı açtım
threshold = 80 #threshold değerini seçtim
noktalar=[] #noktalar adında boş liste oluşturdum
for a in range (5000) : #5000 satırı okumak için for döngüsü
tmp = file.readline()
x,y = tmp.split(",") #her bir satırı virgül ile ayırıp x ve y değişkenine atadım
x_int = int(x)
y_int = int(y)
tmp = Nokta(x_int,y_int) #nokta nesnesi oluşturdum
noktalar.append(tmp) #bu nesneyi noktalar listesine ekledim
And using euclid hypot equation detect anomalies and add these to a dictionary.
With finishing the searching anomalies i had write dictionary to new .csv file and printed how many anomalies has been found.
All codes can be accessible on github.