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
[loadbalancer] | |
lb ansible_connection=local ansible_python_interpreter=/usr/bin/python2 s$ | |
[mainserver] | |
ms ansible_connection=local ansible_python_interpreter=/usr/bin/python2 | |
[executionnodes] | |
en1 port=8081 | |
en2 port=8082 | |
en3 port=8083 |
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
def predict(Xi,weights): | |
activation = 0 | |
for i in range(len(weights)): | |
activation += weights[i]*Xi[i] | |
return 1.0 if activation>=0 else 0.0 | |
#Training using a 0-1 Loss and Stochastic Gradient Descent | |
def train(data,labels,lr,epochs): | |
weights = np.random.randn(data.shape[1]) | |
for epoch in range(epochs): | |
error = 0.0 |
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
positive=[] | |
negative=[] | |
for i in range(len(y)): | |
if y[i]==0: | |
negative.append(X[i]) | |
else: | |
positive.append(X[i]) | |
negative = np.array(negative) | |
positive = np.array(positive) |
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
# Making an SVM | |
#Length to weight map | |
lwm={} | |
#Need these transforms for checking each combination of weights | |
transforms = [[1,1],[-1,1],[-1,-1],[1,-1]] | |
#Need to check for values of b in betwen. | |
b_step_size = 2 |
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
#Set values for | |
colors = {1:'r',-1:'b'} | |
fig = plt.figure() | |
fig.set_size_inches(10,8) | |
ax = fig.add_subplot(1,1,1) | |
plt.scatter(X1[:,1],X1[:,2],marker='o',c=y) | |
def hyperplane_value(x,w,b,v): | |
return (-w[0]*x-b+v) / w[1] |
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
class AE(nn.Module): | |
def __init__(self): | |
super(AE,self).__init__() | |
self.encoder = nn.Sequential(nn.Linear(784,50),nn.ReLU(),nn.Linear(50,50),nn.ReLU()) | |
self.decoder = nn.Sequential(nn.Linear(14,50),nn.ReLU(),nn.Linear(50,50),nn.ReLU(),nn.Linear(50,784),nn.ReLU()) | |
def forward(self,inp): | |
return self.decoder(self.encoder(inp)) |
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
ae = AE() | |
ae.to(device) | |
criterion = nn.MSELoss() | |
optimizer = optim.Adamax(ae.parameters(),lr = 1e-4) | |
l = None | |
for epoch in range(100): | |
for i, data in enumerate(loader,0): | |
inputs,classes = data | |
inputs,classes = Variable(inputs.resize_(batch_size,784)).to(device),Variable(classes).to(device) |
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
inp = torch.from_numpy(np.random.normal(0,1,size=(100,64))).to(device).float() | |
temp = ae.decoder(inp) | |
temp = temp.data.reshape(100,1,28,28) | |
grid = torchvision.utils.make_grid(temp,nrow=10) | |
print(grid.shape) | |
plt.imshow(grid.to('cpu').permute(1,2,0)) | |
plt.gcf().set_size_inches(20,10) | |
plt.show() |
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
class VAE(nn.Module): | |
def __init__(self): | |
super(VAE,self).__init__() | |
self.encoder = nn.Sequential(nn.Linear(784,128),nn.ReLU(),nn.Linear(128,64),nn.ReLU()) | |
self.decoder = nn.Sequential(nn.Linear(64,128),nn.ReLU(),nn.Linear(128,784)) | |
self._mu = nn.Linear(64,64) | |
self._log_sigma = nn.Linear(64,64) | |
def sampler(self,encoding): | |
mu = self._mu(encoding) |
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
vae = VAE() | |
vae.to(device) | |
criterion = nn.MSELoss() | |
optimizer = optim.Adamax(vae.parameters(),lr = 1e-4) | |
l = None | |
for epoch in range(100): | |
for i, data in enumerate(loader,0): | |
inputs,classes = data | |
inputs,classes = Variable(inputs.resize_(batch_size,784)).to(device),Variable(classes).to(device) |
OlderNewer