Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 2 additions & 53 deletions pytorch_ipynb/autoencoder/ae-basic-with-rf.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -151,58 +151,7 @@
"metadata": {},
"outputs": [],
"source": [
"##########################\n",
"### MODEL\n",
"##########################\n",
"\n",
"class Autoencoder(torch.nn.Module):\n",
"\n",
" def __init__(self, num_features):\n",
" super(Autoencoder, self).__init__()\n",
" \n",
" ### ENCODER\n",
" \n",
" self.linear_1 = torch.nn.Linear(num_features, num_hidden_1)\n",
" # The following to lones are not necessary, \n",
" # but used here to demonstrate how to access the weights\n",
" # and use a different weight initialization.\n",
" # By default, PyTorch uses Xavier/Glorot initialization, which\n",
" # should usually be preferred.\n",
" self.linear_1.weight.detach().normal_(0.0, 0.1)\n",
" self.linear_1.bias.detach().zero_()\n",
" \n",
" ### DECODER\n",
" self.linear_2 = torch.nn.Linear(num_hidden_1, num_features)\n",
" self.linear_1.weight.detach().normal_(0.0, 0.1)\n",
" self.linear_1.bias.detach().zero_()\n",
" \n",
" def encoder(self, x):\n",
" encoded = self.linear_1(x)\n",
" encoded = F.leaky_relu(encoded)\n",
" return encoded\n",
" \n",
" def decoder(self, encoded_x):\n",
" logits = self.linear_2(encoded_x)\n",
" decoded = torch.sigmoid(logits)\n",
" return decoded\n",
" \n",
"\n",
" def forward(self, x):\n",
" \n",
" ### ENCODER\n",
" encoded = self.encoder(x)\n",
" \n",
" ### DECODER\n",
" decoded = self.decoder(encoded)\n",
" \n",
" return decoded\n",
"\n",
" \n",
"torch.manual_seed(random_seed)\n",
"model = Autoencoder(num_features=num_features)\n",
"model = model.to(device)\n",
"\n",
"optimizer = torch.optim.Adam(model.parameters(), lr=learning_rate) "
"##########################\n### MODEL\n##########################\n\nclass Autoencoder(torch.nn.Module):\n\n def __init__(self, num_features):\n super(Autoencoder, self).__init__()\n \n ### ENCODER\n \n self.linear_1 = torch.nn.Linear(num_features, num_hidden_1)\n # The following to lones are not necessary, \n # but used here to demonstrate how to access the weights\n # and use a different weight initialization.\n # By default, PyTorch uses Xavier/Glorot initialization, which\n # should usually be preferred.\n self.linear_1.weight.detach().normal_(0.0, 0.1)\n self.linear_1.bias.detach().zero_()\n \n ### DECODER\n self.linear_2 = torch.nn.Linear(num_hidden_1, num_features)\n self.linear_2.weight.detach().normal_(0.0, 0.1)\n self.linear_2.bias.detach().zero_()\n \n def encoder(self, x):\n encoded = self.linear_1(x)\n encoded = F.leaky_relu(encoded)\n return encoded\n \n def decoder(self, encoded_x):\n logits = self.linear_2(encoded_x)\n decoded = torch.sigmoid(logits)\n return decoded\n \n\n def forward(self, x):\n \n ### ENCODER\n encoded = self.encoder(x)\n \n ### DECODER\n decoded = self.decoder(encoded)\n \n return decoded\n\n \ntorch.manual_seed(random_seed)\nmodel = Autoencoder(num_features=num_features)\nmodel = model.to(device)\n\noptimizer = torch.optim.Adam(model.parameters(), lr=learning_rate) "
]
},
{
Expand Down Expand Up @@ -684,4 +633,4 @@
},
"nbformat": 4,
"nbformat_minor": 4
}
}
46 changes: 2 additions & 44 deletions pytorch_ipynb/autoencoder/ae-basic.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -151,49 +151,7 @@
"metadata": {},
"outputs": [],
"source": [
"##########################\n",
"### MODEL\n",
"##########################\n",
"\n",
"class Autoencoder(torch.nn.Module):\n",
"\n",
" def __init__(self, num_features):\n",
" super(Autoencoder, self).__init__()\n",
" \n",
" ### ENCODER\n",
" self.linear_1 = torch.nn.Linear(num_features, num_hidden_1)\n",
" # The following to lones are not necessary, \n",
" # but used here to demonstrate how to access the weights\n",
" # and use a different weight initialization.\n",
" # By default, PyTorch uses Xavier/Glorot initialization, which\n",
" # should usually be preferred.\n",
" self.linear_1.weight.detach().normal_(0.0, 0.1)\n",
" self.linear_1.bias.detach().zero_()\n",
" \n",
" ### DECODER\n",
" self.linear_2 = torch.nn.Linear(num_hidden_1, num_features)\n",
" self.linear_1.weight.detach().normal_(0.0, 0.1)\n",
" self.linear_1.bias.detach().zero_()\n",
" \n",
"\n",
" def forward(self, x):\n",
" \n",
" ### ENCODER\n",
" encoded = self.linear_1(x)\n",
" encoded = F.leaky_relu(encoded)\n",
" \n",
" ### DECODER\n",
" logits = self.linear_2(encoded)\n",
" decoded = torch.sigmoid(logits)\n",
" \n",
" return decoded\n",
"\n",
" \n",
"torch.manual_seed(random_seed)\n",
"model = Autoencoder(num_features=num_features)\n",
"model = model.to(device)\n",
"\n",
"optimizer = torch.optim.Adam(model.parameters(), lr=learning_rate) "
"##########################\n### MODEL\n##########################\n\nclass Autoencoder(torch.nn.Module):\n\n def __init__(self, num_features):\n super(Autoencoder, self).__init__()\n \n ### ENCODER\n self.linear_1 = torch.nn.Linear(num_features, num_hidden_1)\n # The following to lones are not necessary, \n # but used here to demonstrate how to access the weights\n # and use a different weight initialization.\n # By default, PyTorch uses Xavier/Glorot initialization, which\n # should usually be preferred.\n self.linear_1.weight.detach().normal_(0.0, 0.1)\n self.linear_1.bias.detach().zero_()\n \n ### DECODER\n self.linear_2 = torch.nn.Linear(num_hidden_1, num_features)\n self.linear_2.weight.detach().normal_(0.0, 0.1)\n self.linear_2.bias.detach().zero_()\n \n\n def forward(self, x):\n \n ### ENCODER\n encoded = self.linear_1(x)\n encoded = F.leaky_relu(encoded)\n \n ### DECODER\n logits = self.linear_2(encoded)\n decoded = torch.sigmoid(logits)\n \n return decoded\n\n \ntorch.manual_seed(random_seed)\nmodel = Autoencoder(num_features=num_features)\nmodel = model.to(device)\n\noptimizer = torch.optim.Adam(model.parameters(), lr=learning_rate) "
]
},
{
Expand Down Expand Up @@ -377,4 +335,4 @@
},
"nbformat": 4,
"nbformat_minor": 2
}
}