Exemple #1
0
 def num(self, x, y):
     if functions.dist(self, x) > functions.dist(self, y):
         return 1
     elif functions.dist(self, x) == functions.dist(self, y):
         return 0
     else:
         return -1
Exemple #2
0
 def get_in_SOF(self):
     self.planets_in_SOF = []
     for p in self.game.all_planets:
         if fn.dist(self.pos,p.pos) <= self.radius:
             self.planets_in_SOF.append(p)
             
             
Exemple #3
0
 def gsort(self, x):
     nGrid = []
     x.sort(self.num)
     for item in x:
         nGrid.append([item, functions.dist(self, item)])
     del x
     return nGrid
Exemple #4
0
async def getnearby(lat: float, lng: float, radius: float):
    res = session.query(schemas.Places).all()
    nearby = []
    for entry in res:
        d = dist(lat, lng, entry.latitude, entry.longitude)
        if (d < radius):
            nearby.append(entry)
    return nearby
Exemple #5
0
async def getnearbyf(lat: float, lng: float, radius: float):
    query = "select * from places where  (point({0},{1}) <@> (point(longitude,latitude))) < {2}".format(
        lng, lat, radius)
    query = text(query)
    res = conn.execute(query)
    nearby = []
    for entry in res:
        d = dist(lat, lng, entry.latitude, entry.longitude)
        if (d < radius):
            nearby.append(entry)
    return nearby
Exemple #6
0
# We understand from it that by erasing full rows we did not change the balance dramatically but we did loose
# information. Since We have less negative than positive patients, we don't want to loose patients from the negative
# group. We will complete the missing values by random sampling of each series values.

# Replace nan's with random samples of each series values:
from functions import nan2samp
T1D_clean = nan2samp(T1D_dataset)

# section 2
lbl = np.ravel(T1D_clean['Diagnosis'])
X_train, X_test, y_train, y_test = train_test_split(T1D_clean,
                                                    lbl,
                                                    test_size=0.2,
                                                    random_state=0,
                                                    stratify=lbl)

# Section 3.a - show that the distribution of the features is similar between test and train
# Using a function to create a table of positive rates for every feature in the train/test groups:
from functions import dist_table as dist
X_test_dummy = pd.get_dummies(X_test, dummy_na=False, drop_first=True)
X_train_dummy = pd.get_dummies(X_train, dummy_na=False, drop_first=True)
d_table = dist(X_train_dummy, X_test_dummy)
print(d_table.transpose())

# Section 3.b - show the relationship between feature and label:
from functions import feat_lab_cor as fl_cor
fl_cor(T1D_dataset)

# Section 3.c - additional plots
#
Exemple #7
0
from functions import converttime
from functions import toprint
from functions import date
from functions import observations
from functions import setdata
from functions import getdata
from functions import deletedata
from functions import createtable
from texts import menu_text
from texts import invalidoption_text

#Menu inicial
menu_text()
option = input()
if option == '1':
    total = dist()
    totaltime = timerun()
    adjusted = adjust(totaltime)
    finalpace = calcpace(adjusted, total)
    convertedpace = converttime(finalpace)
    impress = toprint(convertedpace)
elif option == '2':
    total = dist()
    totaltime = timerun()
    adjusted = adjust(totaltime)
    calctemp = predictrun(adjusted, total)
    convertedtemprun = converttime(calctemp)
    impress = toprint(convertedtemprun)
elif option == '3':
    createtable()
    thedate = date()
Exemple #8
0
C_x = np.random.randint(0, np.max(X) - 20, size=k)
# Y coordinates of random centroids
C_y = np.random.randint(0, np.max(X) - 20, size=k)
C = np.array(list(zip(C_x, C_y)), dtype=np.float32)
print(C)

plt.scatter(f1, f2, c='#050505', s=7)
plt.scatter(C_x, C_y, marker='*', s=200, c='g')
plt.show()

# To store the value of centroids when it updates
C_old = np.zeros(C.shape)
# Cluster labels (0, 1, 2)
clusters = np.zeros(len(X))
#error function - distance between new centroids and old centroids
error = func.dist(C, C_old, None)

# Loop will run until the error becomes 0
while error != 0:
    # Assigning each value to its closest cluster
    for i in range(len(X)):
        distances = func.dist(X[i], C)
        cluster = np.argmin(distances)
        clusters[i] = cluster
    # Storing the old centroid values
    C_old = deepcopy(C)
    # Finding the new centroids by taking the average value
    for i in range(k):
        points = [X[j] for j in range(len(X)) if clusters[j] == i]
        C[i] = np.mean(points, axis=0)
    error = func.dist(C, C_old, None)
Exemple #9
0
 def get_travel_info(self,planet,travel_bonus):
     self.travel_time = fn.travel_time(fn.dist(self.instance[0].pos,planet.pos),self.instance[0].game.space_travel_unit)/travel_bonus
     self.travel_cost = fn.travel_formula(self.travel_time)