This file contains 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
from numpy import exp, array, random, dot, reshape | |
from autograd import grad | |
class NeuronLayer(): | |
def __init__(self, neuron_n, inputs_n): | |
self.weights = 2 * random.random((inputs_n, neuron_n)) - 1 | |
class NeuralNetwork(): | |
def __init__(self, layer1, layer2): | |
self.layer1 = layer1 |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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
c=['#415952', '#f35134', '#243AB5'] | |
def dataset_ (n=200, idx_outlier=0, ydistance=5): | |
rng = np.random.RandomState(4) | |
data = np.dot(rng.rand(2, 2), rng.randn(2, n)).T | |
data[idx_outlier:idx_outlier+1,1] = ydistance | |
return data | |
N=200 | |
inx=10 | |
i = dataset_(N, inx) |
This file contains 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 | |
x=np.array([1,4,7,2,5,7,7,8,4,6,8,30]) | |
z=(x-x.mean(axis=0))/x.std() | |
# | |
for l in (z < z.mean() - 3*z.std(), | |
z > z.mean() + 3*z.std()): | |
if np.any(z[l]): | |
print(z[l]) |
This file contains 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 | |
import matplotlib | |
import matplotlib.pyplot as plt | |
plt.style.use('ggplot') | |
fig, (ax1, ax2) = plt.subplots(ncols=2,figsize=(16,6)) | |
plt.xlim((0, 10)) | |
plt.ylim((0, 7)) | |
plt.tight_layout(w_pad=1.5) | |
#red line |
This file contains 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
N=60 | |
mu=0 | |
sd=2 | |
np.random.seed(0) | |
ran = np.random.normal(size=N) | |
error1 = sd**2 * ran + mu | |
error2 = sd*.5 * ran + mu | |
lin = np.linspace(-15., 15., num=N) |
This file contains 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 scipy.odr as odr | |
def odr_line(B, x): | |
y = B[0]*x + B[1]*x**2 | |
return y | |
def perform_odr(x, y, xerr, yerr): | |
quadr = odr.Model(odr_line) | |
mydata = odr.Data(x, y, wd=1./xerr, we=1./yerr) | |
#mydata = odr.Data(x, y) |
This file contains 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.linalg as la | |
def tls(X,y): | |
if X.ndim is 1: | |
n = 1 # the number of variable of X | |
X = X.reshape(len(X),1) | |
else: | |
n = np.array(X).shape[1] | |
Z = np.vstack((X.T,y)).T |