Skip to content

Commit

Permalink
Update esol results
Browse files Browse the repository at this point in the history
  • Loading branch information
ziatdinovmax committed Dec 10, 2024
1 parent ca65da3 commit ea2d23c
Show file tree
Hide file tree
Showing 57 changed files with 436 additions and 256 deletions.
Binary file modified active_learning_scripts/esol/.DS_Store
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
67 changes: 35 additions & 32 deletions active_learning_scripts/esol/dkl.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from typing import List, Dict, Tuple
import json
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
import pickle

# Configure logging
Expand Down Expand Up @@ -70,37 +71,37 @@ def __init__(self, input_dim: int, latent_dim: int, activation: str = "tanh"):
act_fn = activation_map[activation.lower()]

# Build network with specified activation function
self.add_module('linear1', torch.nn.Linear(input_dim, 32))
self.add_module('linear1', torch.nn.Linear(input_dim, 8))
self.add_module('act1', act_fn())
self.add_module('linear2', torch.nn.Linear(32, 16))
self.add_module('linear2', torch.nn.Linear(8, 8))
self.add_module('act2', act_fn())
self.add_module('linear3', torch.nn.Linear(16, 8))
self.add_module('linear3', torch.nn.Linear(8, 8))
self.add_module('act3', act_fn())
self.add_module('linear4', torch.nn.Linear(8, 8))
self.add_module('act4', act_fn())
self.add_module('linear_latent', torch.nn.Linear(8, latent_dim))


class GPModel(gpytorch.models.ExactGP):
"""Gaussian Process model using RBF kernel."""

def __init__(
self,
train_x: torch.Tensor,
train_y: torch.Tensor,
feature_extractor: torch.nn.Module,
likelihood: gpytorch.likelihoods.Likelihood
):
super().__init__(train_x, train_y, likelihood)
self.mean_module = gpytorch.means.ConstantMean()
self.covar_module = gpytorch.kernels.RBFKernel()
self.feature_extractor = feature_extractor

def forward(self, x: torch.Tensor) -> gpytorch.distributions.MultivariateNormal:
features = self.feature_extractor(x)
mean = self.mean_module(features)
covar = self.covar_module(features)
return gpytorch.distributions.MultivariateNormal(mean, covar)
def __init__(self, train_x, train_y, feature_extractor, latent_dim, likelihood):
super(GPModel, self).__init__(train_x, train_y, likelihood)
self.mean_module = gpytorch.means.ConstantMean()
self.covar_module = gpytorch.kernels.ScaleKernel(
gpytorch.kernels.RBFKernel(ard_num_dims=latent_dim))
self.feature_extractor = feature_extractor

# This module will scale the NN features so that they're nice values
self.scale_to_bounds = gpytorch.utils.grid.ScaleToBounds(-1., 1.)

def forward(self, x):
# We're first putting our data through a deep net (feature extractor)
projected_x = self.feature_extractor(x)
projected_x = self.scale_to_bounds(projected_x) # Make the NN values "nice"

mean_x = self.mean_module(projected_x)
covar_x = self.covar_module(projected_x)
return gpytorch.distributions.MultivariateNormal(mean_x, covar_x)


class DKLExplorer:
Expand All @@ -123,7 +124,7 @@ def init_model(
latent_dim,
activation=self.config.activation
)
model = GPModel(X_train, y_train, feature_extractor, likelihood)
model = GPModel(X_train, y_train, feature_extractor, latent_dim, likelihood)

return model.to(self.device), likelihood.to(self.device)

Expand Down Expand Up @@ -179,10 +180,9 @@ def calculate_metrics(
mae = torch.mean(torch.abs(y_true - y_pred)).item()

# Calculate NLPD
nlpd = 0.5 * torch.mean(
torch.log(2 * np.pi * variance) +
(y_true - y_pred) ** 2 / variance
).item()
const = -0.5 * torch.log(2 * np.pi * variance)
prob_density = -0.5 * (y_true - y_pred) ** 2 / variance
nlpd = -torch.mean(const + prob_density).item()

# Calculate 95% coverage
z_score = 1.96
Expand Down Expand Up @@ -283,7 +283,7 @@ def main():
"--latent-dims",
nargs="+",
type=int,
default=[2, 4],
default=[2,],
help="List of latent dimensions to test"
)
parser.add_argument(
Expand All @@ -302,7 +302,7 @@ def main():
parser.add_argument(
"--num-epochs",
type=int,
default=1000,
default=100,
help="Number of training epochs per step"
)
parser.add_argument(
Expand All @@ -315,13 +315,13 @@ def main():
"--activation",
type=str,
choices=["tanh", "relu", "silu"],
default="tanh",
default="silu",
help="Activation function to use"
)
parser.add_argument(
"--output-dir",
type=Path,
default=Path("results/dkl"),
default=Path("results/dkl8888"),
help="Directory to save results"
)
parser.add_argument(
Expand All @@ -333,7 +333,7 @@ def main():
parser.add_argument(
"--experiment-name",
type=str,
default="esol_dkl_comparison",
default="esol_dkl",
help="Name for this experiment"
)

Expand All @@ -346,6 +346,9 @@ def main():
# Load data
data = np.load(config.input_file)
X, y = data["features"], data["targets"]

x_scaler = StandardScaler()
X = x_scaler.fit_transform(X)

explorer = DKLExplorer(config)

Expand Down
Binary file not shown.
Binary file not shown.
6 changes: 5 additions & 1 deletion active_learning_scripts/esol/gp.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from typing import List, Dict, Any, Optional, Tuple
import json
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
import pickle
import datetime

Expand Down Expand Up @@ -291,7 +292,7 @@ def main():
parser.add_argument(
"--experiment-name",
type=str,
default="gp_comparison",
default="esol_gp_comparison",
help="Name for this experiment"
)

Expand All @@ -304,6 +305,9 @@ def main():
# Load data
data = np.load(config.input_file)
X, y = data["features"], data["targets"]

x_scaler = StandardScaler()
X = x_scaler.fit_transform(X)

explorer = GPExplorer(config)

Expand Down
10 changes: 5 additions & 5 deletions active_learning_scripts/esol/pbnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def parse_arguments() -> ExplorationConfig:
parser.add_argument(
"--exploration_steps",
type=int,
default=200,
default=1,
help="Number of exploration steps"
)
parser.add_argument(
Expand All @@ -247,27 +247,27 @@ def parse_arguments() -> ExplorationConfig:
"--probabilistic-layer-names",
nargs="+",
type=str,
default=['Dense1', 'Dense4'],
default=['Dense2', 'Dense4'],
help="Names of layers to make probabilistic (e.g., Dense0 Dense4)"
)
parser.add_argument(
"--hidden-dims",
nargs="+",
type=int,
default=[32, 16, 8, 8],
default=[8, 8, 8, 8],
help="Dimensions of hidden layers (e.g., 32 16 8 8)"
)
parser.add_argument(
"--activation",
type=str,
choices=['tanh', 'silu'],
default='tanh',
default='silu',
help="Activation function to use in the neural network"
)
parser.add_argument(
"--output-dir",
type=Path,
default=Path("results"),
default=Path("results/pbnn8888"),
help="Directory to save results"
)
parser.add_argument(
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"parameters": {
"latent_dims": [
2,
4
2
],
"seeds": [
1,
Expand All @@ -12,14 +11,14 @@
5
],
"exploration_steps": 200,
"num_epochs": 1000,
"num_epochs": 100,
"learning_rate": 0.01,
"output_dir": "results/dkl",
"input_file": "esol.npz",
"activation": "relu",
"experiment_name": "esol_dkl_comparison",
"latent_dim": 2
},
"timestamp": "2024-12-01T20:51:54.483971",
"results_file": "esol_dkl_comparison_latent2_relu_20241201_205154.pkl"
"timestamp": "2024-12-06T01:40:32.071421",
"results_file": "esol_dkl_comparison_latent2_relu_20241206_014032.pkl"
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"parameters": {
"latent_dims": [
2,
4
2
],
"seeds": [
1,
Expand All @@ -12,14 +11,14 @@
5
],
"exploration_steps": 200,
"num_epochs": 1000,
"num_epochs": 100,
"learning_rate": 0.01,
"output_dir": "results/dkl",
"input_file": "esol.npz",
"activation": "silu",
"experiment_name": "esol_dkl_comparison",
"latent_dim": 2
},
"timestamp": "2024-12-02T17:00:42.015468",
"results_file": "esol_dkl_comparison_latent2_silu_20241202_170042.pkl"
"timestamp": "2024-12-06T01:37:05.231457",
"results_file": "esol_dkl_comparison_latent2_silu_20241206_013705.pkl"
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"parameters": {
"latent_dims": [
2,
4
2
],
"seeds": [
1,
Expand All @@ -12,14 +11,14 @@
5
],
"exploration_steps": 200,
"num_epochs": 1000,
"num_epochs": 100,
"learning_rate": 0.01,
"output_dir": "results/dkl",
"input_file": "esol.npz",
"activation": "tanh",
"experiment_name": "esol_dkl_comparison",
"latent_dim": 2
},
"timestamp": "2024-12-02T19:13:21.681819",
"results_file": "esol_dkl_comparison_latent2_tanh_20241202_191321.pkl"
"timestamp": "2024-12-06T01:33:48.840444",
"results_file": "esol_dkl_comparison_latent2_tanh_20241206_013348.pkl"
}
Binary file not shown.
Loading

0 comments on commit ea2d23c

Please sign in to comment.