Skip to content

Instantly share code, notes, and snippets.

View abhishek-Kumar009's full-sized avatar
🎯
Focusing

Abhishek abhishek-Kumar009

🎯
Focusing
View GitHub Profile
@abhishek-Kumar009
abhishek-Kumar009 / UncleJohny
Created May 31, 2018 21:57
Uncle Johny problem of codeChef
import java.util.Scanner;
public class uncleJohny {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int T = sc.nextInt(); // Number of test Cases
int i, j, l;
def multivariateGaussian(X, mu, sigma2):
n = np.size(sigma2, 1)
m = np.size(sigma2, 0)
#print(m,n)
if n == 1 or m == 1:
# print('Yes!')
sigma2 = np.diag(sigma2[0, :])
#print(sigma2)
X = X - mu
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import numpy as np
import matplotlib.pyplot as plt
import scipy.io as sio
import math
dataset = sio.loadmat('anomalyData.mat')
X = dataset['X']
Xval = dataset['Xval']
yval = dataset['yval']
plt.scatter(X[:, 0], X[:, 1], marker = "x")
plt.xlabel('Latency(ms)')
plt.ylabel('Throughput(mb/s)')
def estimateGaussian(X):
n = np.size(X, 1)
m = np.size(X, 0)
mu = np.zeros((n, 1))
sigma2 = np.zeros((n, 1))
mu = np.reshape((1/m)*np.sum(X, 0), (1, n))
sigma2 = np.reshape((1/m)*np.sum(np.power((X - mu),2), 0),(1, n))
return mu, sigma2
def multivariateGaussian(X, mu, sigma2):
n = np.size(sigma2, 1)
m = np.size(sigma2, 0)
#print(m,n)
if n == 1 or m == 1:
# print('Yes!')
sigma2 = np.diag(sigma2[0, :])
#print(sigma2)
X = X - mu
def selectThreshHold(yval, pval):
F1 = 0
bestF1 = 0
bestEpsilon = 0
stepsize = (np.max(pval) - np.min(pval))/1000
epsVec = np.arange(np.min(pval), np.max(pval), stepsize)
noe = len(epsVec)
def findIndices(binVec):
l = []
for i in range(len(binVec)):
if binVec[i] == 1:
l.append(i)
return l