This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| 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 |