Skip to content

Instantly share code, notes, and snippets.

View BenBausch's full-sized avatar
🧩
Focusing

Ben Bausch BenBausch

🧩
Focusing
View GitHub Profile
@BenBausch
BenBausch / Kmeans.py
Created December 21, 2020 13:10
Gist for Kmeans
import numpy as np
def k_means(data, n_clusters):
# choose n_clusters data points randomly for the initialization
centroids_ids = np.random.choice(len(data), 3, replace=False)
centroids = [data[i] for i in centroids_ids]
asignment = [-1 for i in range(len(data))]
# convergence: no more data point changes class
no_change = False
@BenBausch
BenBausch / linear_classification.py
Last active December 20, 2020 22:31
Gist for linear classification
# disclaimer: example code not recommended for usage
def covariance_estimation(X):
mean_features = np.sum(X, axis=0) / X.shape[0]
X = X - mean_features
cov = np.dot(X.transpose(), X) / (X.shape[0] - 1)
return cov
def train_linear_model(X, y):
y_1 = np.where(y == 1, y, 0)
@BenBausch
BenBausch / robocup.py
Created April 16, 2019 12:52
Gist for Robocup
"""
Author: Ben Bausch
"""
import numpy as np
def generateRadnomLayout(bs_num=1, rs_num=2, cs_num=2, ds_num=1, width=30, length=30, agentNum=3):
"""
inputs:
:param bs_num: number of base stations