model_skeletons/model_class_1.py ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ # Auto-extracted class source (static)
2
+
3
+ class LossWeights:
4
+ lambda_task: float = 1.0
5
+ lambda_res: float = 0.5
6
+ lambda_ent: float = 0.2
model_skeletons/model_class_10.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Auto-extracted class source (static)
2
+
3
+ class DiracGraphConv(nn.Module):
4
+ def __init__(self, in_dim: int, out_dim: int, alpha: float = 1.0, bias: bool = True):
5
+ super().__init__()
6
+ self.lin = nn.Linear(in_dim, out_dim, bias=bias)
7
+ self.alpha = nn.Parameter(torch.tensor(alpha, dtype=torch.float32))
8
+ self.bias_edge = nn.Parameter(torch.tensor(0.0, dtype=torch.float32))
9
+
10
+ @staticmethod
11
+ def cosine_corr(z_i: torch.Tensor, z_j: torch.Tensor, eps: float = 1e-9) -> torch.Tensor:
12
+ num = (z_i * z_j).sum(dim=-1)
13
+ den = torch.clamp(z_i.norm(dim=-1) * z_j.norm(dim=-1), min=eps)
14
+ return num / den
15
+
16
+ def forward(self, x: torch.Tensor, edge_index: torch.Tensor, z: torch.Tensor) -> torch.Tensor:
17
+ N = x.size(0)
18
+ row, col = edge_index
19
+ corr = self.cosine_corr(z[row], z[col])
20
+ logits = self.alpha * corr + self.bias_edge
21
+ device = x.device
22
+ E = row.size(0)
23
+ ones = torch.ones(E, device=device)
24
+ max_per_row = torch.full((N,), -1e9, device=device)
25
+ max_per_row = max_per_row.index_put((row,), logits, accumulate=False).scatter_reduce_(0, row, logits, reduce="amax")
26
+ logits_centered = logits - max_per_row[row]
27
+ exp_logits = torch.exp(logits_centered)
28
+ denom = torch.zeros(N, device=device).index_add_(0, row, exp_logits)
29
+ attn = exp_logits / (denom[row] + 1e-9)
30
+ deg = torch.zeros(N, device=device).index_add_(0, row, ones)
31
+ norm = 1.0 / torch.clamp(deg[row], min=1.0)
32
+ msgs = norm.unsqueeze(-1) * attn.unsqueeze(-1) * x[col]
33
+ out = torch.zeros_like(x).index_add_(0, row, msgs)
34
+ return self.lin(out)
model_skeletons/model_class_11.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Auto-extracted class source (static)
2
+
3
+ class GNNDiracRRF(nn.Module):
4
+ def __init__(self, in_dim: int, hidden_dim: int, out_dim: int, num_layers: int, z_dim: int,
5
+ alpha_attn: float = 1.0, dropout: float = 0.1):
6
+ super().__init__()
7
+ self.z_dim = z_dim
8
+ self.layers = nn.ModuleList()
9
+ self.layers.append(DiracGraphConv(in_dim, hidden_dim, alpha=alpha_attn))
10
+ for _ in range(num_layers - 2):
11
+ self.layers.append(DiracGraphConv(hidden_dim, hidden_dim, alpha=alpha_attn))
12
+ self.layers.append(DiracGraphConv(hidden_dim, out_dim, alpha=alpha_attn))
13
+ self.dropout = nn.Dropout(dropout)
14
+
15
+ def forward(self, x: torch.Tensor, edge_index: torch.Tensor, z: torch.Tensor) -> torch.Tensor:
16
+ h = x
17
+ for i, layer in enumerate(self.layers):
18
+ h = layer(h, edge_index, z)
19
+ if i < len(self.layers) - 1:
20
+ h = F.gelu(h)
21
+ h = self.dropout(h)
22
+ return h
model_skeletons/model_class_12.py ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ # Auto-extracted class source (static)
2
+
3
+ class LossWeights:
4
+ lambda_task: float = 1.0
5
+ lambda_res: float = 0.5
6
+ lambda_ent: float = 0.2
model_skeletons/model_class_13.py ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Auto-extracted class source (static)
2
+
3
+ class IcosahedralRRF(nn.Module):
4
+ def __init__(self, input_dim, hidden_dim, output_dim, gnn_num_layers=2, gnn_z_dim=16, gnn_alpha_attn=1.0, gnn_dropout=0.1):
5
+ super(IcosahedralRRF, self).__init__()
6
+ # 12 nodos gauge
7
+ self.nodes = nn.ModuleList([
8
+ SavantRRF_Gauge(input_dim, hidden_dim, output_dim) for _ in range(12)
9
+ ])
10
+ # Núcleo ético
11
+ # The input to ethical_core is the concatenation of the outputs of the 12 gauge nodes.
12
+ # Each gauge node outputs a tensor of shape [batch_size, output_dim].
13
+ # Concatenating these along dim=1 results in a shape [batch_size, 12 * output_dim].
14
+ self.ethical_core = nn.Linear(12 * output_dim, output_dim)
15
+
16
+ # Subconsciente (dodecaedro) using GNNDiracRRF
17
+ # The input dimension (in_dim) for the GNN should match the feature dimension of its input nodes.
18
+ # There's ambiguity in the original code about what the GNN's nodes and features are.
19
+ # Interpretation 1 (based on original code passing 'regulated'): GNN operates on 'batch_size' nodes, with 'output_dim' features. in_dim = output_dim.
20
+ # Interpretation 2 (more conventional for graph on icosahedron/dodecahedron): GNN operates on 12 or 20 nodes, with features derived from gauge outputs.
21
+ # Let's assume interpretation 2, where the GNN operates on the 12 gauge nodes.
22
+ # The features for each of these 12 nodes would be the output of the corresponding gauge node, shape [batch_size, output_dim].
23
+ # For a GNN layer expecting [num_nodes, in_channels], the input should be [12, output_dim] per batch item.
24
+ # This means the GNN's in_dim should be output_dim. This matches the current GNN init below.
25
+ # The GNN's out_dim should match the desired output feature dimension per node (e.g., output_dim).
26
+ # The number of nodes for the GNN is 12 (for icosahedral).
27
+
28
+ # Let's define the memory_map GNN assuming it operates on the 12 gauge nodes.
29
+ # The input features to the GNN will be the outputs of the 12 gauge nodes.
30
+ # Each gauge node outputs a tensor of shape [batch_size, output_dim].
31
+ # We will treat output_dim as the feature dimension for the GNN nodes (the 12 gauge nodes).
32
+ # So, in_dim for GNN = output_dim.
33
+ # The GNN will output features for each of the 12 nodes. Let's assume out_dim for GNN is also output_dim.
34
+ self.memory_map = GNNDiracRRF(in_dim=output_dim, # Feature dimension for GNN nodes (output_dim of gauge nodes)
35
+ hidden_dim=hidden_dim,
36
+ out_dim=output_dim, # Output feature dimension per GNN node
37
+ num_layers=gnn_num_layers,
38
+ z_dim=gnn_z_dim,
39
+ alpha_attn=gnn_alpha_attn,
40
+ dropout=gnn_dropout)
41
+
42
+
43
+ def forward(self, x, edge_index=None, z=None):
44
+ # x is the input to the gauge nodes, shape [batch_size, input_dim, sequence_length]
45
+ outputs = [node(x) for node in self.nodes]
46
+ # outputs is a list of 12 tensors, each [batch_size, output_dim]
47
+
48
+ # Concatenate outputs for the ethical core
49
+ concat = torch.cat(outputs, dim=1) # [batch_size, 12 * output_dim]
50
+ regulated = torch.sigmoid(self.ethical_core(concat)) # [batch_size, output_dim]
51
+
52
+ # GNN operation on the 12 gauge nodes
53
+ if edge_index is not None and z is not None:
54
+ # Prepare input for the GNN: Features for the 12 nodes (the gauge node outputs).
55
+ # Stack the outputs to get [batch_size, 12, output_dim]
56
+ stacked_outputs = torch.stack(outputs, dim=1) # [batch_size, 12, output_dim]
57
+
58
+ # Reshape for GNN input: [num_nodes, in_channels] = [12, output_dim] per batch item.
59
+ # Need to process batch items. Simplest is to iterate.
60
+ # A more efficient way is to use torch_geometric.data.Batch
61
+
62
+ gnn_outputs_list = []
63
+ for i in range(stacked_outputs.size(0)):
64
+ # GNN input features for this batch item: [12, output_dim]
65
+ gnn_input_features_i = stacked_outputs[i]
66
+
67
+ # Ensure edge_index and z are on the correct device
68
+ edge_index_i = edge_index.to(x.device)
69
+ z_i = z.to(x.device)
70
+
71
+ # GNN forward pass for one batch item
72
+ gnn_output_i = self.memory_map(gnn_input_features_i, edge_index_i, z_i) # [12, output_dim]
73
+ gnn_outputs_list.append(gnn_output_i)
74
+
75
+ # Stack GNN outputs back into a batch tensor: [batch_size, 12, output_dim]
76
+ gnn_outputs_stacked = torch.stack(gnn_outputs_list, dim=0)
77
+
78
+ # Now, how to combine the GNN output [batch_size, 12, output_dim] with the 'regulated' output [batch_size, output_dim]?
79
+ # The original model returned just 'regulated'.
80
+ # A simple approach is to maybe combine them, e.g., add, concatenate, or use the GNN output as a modulation.
81
+ # Let's stick to returning the aggregated GNN output as the final output when GNN is used.
82
+ # This changes the model's behavior compared to the original.
83
+
84
+ # Alternative: The GNN output modulates the 'regulated' output.
85
+ # E.g., regulated * sigmoid(aggregated_gnn_output) or similar.
86
+ # Let's stick to returning the aggregated GNN output when edge_index and z are provided,
87
+ # and the original 'regulated' output otherwise. This seems the most direct path based on the conditional in the original forward.
88
+
89
+ # Aggregate the 12 nodes' outputs from the GNN
90
+ aggregated_gnn_output = gnn_outputs_stacked.mean(dim=1) # [batch_size, output_dim]
91
+
92
+ return aggregated_gnn_output # [batch_size, output_dim]
93
+
94
+ else:
95
+ # If edge_index and z are not provided, return the output of the ethical core as before.
96
+ return regulated
model_skeletons/model_class_14.py ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ # Auto-extracted class source (static)
2
+
3
+ class LossWeights:
4
+ lambda_task: float = 1.0
5
+ lambda_res: float = 0.5
6
+ lambda_ent: float = 0.2
model_skeletons/model_class_15.py ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Auto-extracted class source (static)
2
+
3
+ class IcosahedralRRFDataset(InMemoryDataset):
4
+ def __init__(self, num_graphs: int = 64, k_modes: int = 16, feat_dim: int = 8,
5
+ task_type: str = 'classification', split: str = 'train', transform=None, pre_transform=None):
6
+ super().__init__('.', transform, pre_transform)
7
+ self.task_type = task_type
8
+ self.num_graphs = num_graphs
9
+ self.k_modes = k_modes
10
+ self.feat_dim = feat_dim
11
+
12
+ # Generate graphs and process them
13
+ data_list = []
14
+ rng = np.random.default_rng(42 if split == 'train' else (43 if split == 'val' else 44))
15
+
16
+ for i in range(num_graphs):
17
+ G = nx.icosahedral_graph()
18
+ n_nodes = G.number_of_nodes()
19
+
20
+ # Build Dirac operator and compute spectral modes
21
+ D = build_dirac_operator(G, normalize=True)
22
+ # Use the modified dirac_eigendecomp that uses np.linalg.eigh
23
+ vals, vecs = dirac_eigendecomp(D, k=k_modes)
24
+ Z = node_spectral_coords_from_dirac(vecs, n_nodes) # N x k
25
+
26
+ # Get edge index
27
+ edge_list = list(G.edges())
28
+ edge_index = torch.tensor(edge_list, dtype=torch.long).t().contiguous()
29
+ # Add reverse edges for undirected graph
30
+ row, col = edge_index
31
+ edge_index = torch.cat([edge_index, torch.stack([col, row], dim=0)], dim=1)
32
+
33
+ # Generate synthetic node features (x) and labels (y)
34
+ # Features: [n_nodes, feat_dim]
35
+ x = torch.randn(n_nodes, feat_dim, dtype=torch.float32)
36
+
37
+ # Labels: based on task_type
38
+ if task_type == 'classification':
39
+ # Example: Binary classification based on a simple rule, e.g., sum of features > threshold
40
+ threshold = 0.0 # Example threshold
41
+ y = (x.sum(dim=-1) > threshold).long() # [n_nodes]
42
+ elif task_type == 'regression':
43
+ # Example: Regression target based on sum of features
44
+ y = x.sum(dim=-1) # [n_nodes]
45
+ else:
46
+ raise ValueError("task_type must be 'classification' or 'regression'")
47
+
48
+
49
+ # Create Data object
50
+ # Note: The IcosahedralRRF model expects input 'x' as [batch_size, input_dim, sequence_length],
51
+ # edge_index [2, num_edges], and z [num_nodes, z_dim].
52
+ # The IcosahedralRRFDataset provides batch.x [num_nodes, feat_dim], batch.edge_index [2, num_edges], and batch.U [num_nodes, k_modes].
53
+ # There is a mismatch in the expected input format for the IcosahedralRRF model's forward pass when using the DataLoader.
54
+ # The IcosahedralRRF expects a single batch tensor `x` for the gauge nodes, and graph data (edge_index, z) for the GNN part which operates on gauge outputs.
55
+ # The IcosahedralRRFDataset provides node features `batch.x` that are intended as features *for the graph nodes themselves*, not as input to the gauge nodes.
56
+ # The current IcosahedralRRF forward pass processes a single input `x` [batch_size, input_dim, sequence_length] through all gauge nodes.
57
+ # The GNN then operates on the *outputs* of these gauge nodes, using the provided edge_index and z.
58
+
59
+ # To use the IcosahedralRRFDataset with the current IcosahedralRRF model structure,
60
+ # we need to map the dataset's structure to the model's expectations.
61
+ # The dataset provides graphs, each with nodes (typically 12 for icosahedral), node features (batch.x), edge_index, and spectral coords (batch.U).
62
+ # The IcosahedralRRF model has 12 gauge nodes, each designed to process a sequence [input_dim, sequence_length].
63
+ # It seems there is a conceptual mismatch in how the IcosahedralRRFDataset is structured (graph-centric with node features)
64
+ # and how the IcosahedralRRF model processes input (sequence-centric through gauge nodes first).
65
+
66
+ # Alternative Interpretation: The IcosahedralRRFDataset is meant to provide data where each *graph* is a sample in the batch.
67
+ # batch.x would be the concatenated node features for all graphs in the batch: [total_num_nodes_in_batch, feat_dim].
68
+ # batch.edge_index would be the block-diagonal edge indices for all graphs: [2, total_num_edges_in_batch].
69
+ # batch.U would be the concatenated spectral coordinates for all nodes: [total_num_nodes_in_batch, k_modes].
70
+ # In this case, the input to the IcosahedralRRF model's forward pass is still expected to be a single tensor `x` for the gauge nodes.
71
+ # The IcosahedralRRFDataset does *not* provide this `x` input directly in the expected format.
72
+
73
+ # There is a fundamental incompatibility in how the IcosahedralRRFDataset provides data (graph-batching)
74
+ # and how the IcosahedralRRF model expects input (single batch of sequences + graph data for GNN).
75
+
76
+ # To make this cell runnable, we need to either:
77
+ # 1. Modify the IcosahedralRRF model's forward pass to handle graph batches from DataLoader.
78
+ # 2. Modify the IcosahedralRRFDataset or create a custom Dataset/DataLoader that provides data in the format expected by the IcosahedralRRF model.
79
+ # 3. Use a simplified evaluation approach that aligns with the synthetic data generation method used in the training loop (single batch).
80
+
81
+ # Given the current structure, the simplest approach to get the cell running is to align the evaluation data generation
82
+ # with the training data generation (single synthetic batch) and evaluate on that.
83
+ # This bypasses the DataLoader incompatibility but doesn't fully test with graph batching.
84
+
85
+ # Let's revert to generating a single synthetic batch for evaluation, similar to training.
86
+ # This requires defining x_val and y_val outside the DataLoader loop.
87
+
88
+ # Reverting the evaluation loop to use the single synthetic batch approach:
89
+
90
+ # Check if x_val and y_val are defined (from previous code cell)
91
+ if 'x_val' not in locals() or 'y_val' not in locals():
92
+ # Generate synthetic validation data if not already defined
93
+ val_batch_size = 16 # Example validation batch size
94
+ x_val = torch.randn(val_batch_size, input_dim, sequence_length, dtype=torch.float32).to(device)
95
+ y_val = torch.randint(0, 2, (val_batch_size,), dtype=torch.long).to(device) # Binary labels
96
+ print("Generated synthetic validation data for evaluation.")
97
+
98
+ # Ensure z and edge_index are on the correct device
99
+ if 'z' in locals() and 'edge_index' in locals():
100
+ z = z.to(device)
101
+ edge_index = edge_index.to(device)
102
+ else:
103
+ print("⚠️ Warning: Graph data (z, edge_index) not found. Skipping evaluation.")
104
+ # Exit the evaluation block if graph data is missing
105
+ # break # This will exit the with torch.no_grad(): block - REMOVED/COMMENTED OUT DUE TO SyntaxError
106
+ pass # Use pass instead of break to avoid SyntaxError outside a loop
107
+
108
+ # Forward pass on validation data using the single batch
109
+ # Pass the validation input features (x_val), edge index, and spectral coordinates (z) through the model
110
+ val_outputs = hybrid_model(x_val, edge_index, z) # Shape: [val_batch_size, output_dim]
111
+
112
+ # Calculate the validation loss (using BCEWithLogitsLoss as corrected in training)
113
+ val_loss = F.binary_cross_entropy_with_logits(val_outputs.squeeze(-1), y_val.float())
114
+
115
+ # Calculate evaluation metrics (e.g., accuracy for binary classification)
116
+ # Convert logits to predicted class (0 or 1)
117
+ predicted_classes = (torch.sigmoid(val_outputs.squeeze(-1)) > 0.5).long()
118
+
119
+ # Calculate accuracy
120
+ correct_predictions = (predicted_classes == y_val).sum().item()
121
+ accuracy = correct_predictions / val_batch_size
122
+
123
+ print(f'Validation Loss: {val_loss.item():.4f}, Validation Accuracy: {accuracy:.4f}')
model_skeletons/model_class_16.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Auto-extracted class source (static)
2
+
3
+ class DiracGraphConv(nn.Module):
4
+ def __init__(self, in_dim: int, out_dim: int, alpha: float = 1.0, bias: bool = True):
5
+ super().__init__()
6
+ self.lin = nn.Linear(in_dim, out_dim, bias=bias)
7
+ self.alpha = nn.Parameter(torch.tensor(alpha, dtype=torch.float32))
8
+ self.bias_edge = nn.Parameter(torch.tensor(0.0, dtype=torch.float32))
9
+
10
+ @staticmethod
11
+ def cosine_corr(z_i: torch.Tensor, z_j: torch.Tensor, eps: float = 1e-9) -> torch.Tensor:
12
+ num = (z_i * z_j).sum(dim=-1)
13
+ den = torch.clamp(z_i.norm(dim=-1) * z_j.norm(dim=-1), min=eps)
14
+ return num / den
15
+
16
+ def forward(self, x: torch.Tensor, edge_index: torch.Tensor, z: torch.Tensor) -> torch.Tensor:
17
+ N = x.size(0)
18
+ row, col = edge_index
19
+ corr = self.cosine_corr(z[row], z[col])
20
+ logits = self.alpha * corr + self.bias_edge
21
+ device = x.device
22
+ E = row.size(0)
23
+ ones = torch.ones(E, device=device)
24
+ max_per_row = torch.full((N,), -1e9, device=device)
25
+ max_per_row = max_per_row.index_put((row,), logits, accumulate=False).scatter_reduce_(0, row, logits, reduce="amax")
26
+ logits_centered = logits - max_per_row[row]
27
+ exp_logits = torch.exp(logits_centered)
28
+ denom = torch.zeros(N, device=device).index_add_(0, row, exp_logits)
29
+ attn = exp_logits / (denom[row] + 1e-9)
30
+ deg = torch.zeros(N, device=device).index_add_(0, row, ones)
31
+ norm = 1.0 / torch.clamp(deg[row], min=1.0)
32
+ msgs = norm.unsqueeze(-1) * attn.unsqueeze(-1) * x[col]
33
+ out = torch.zeros_like(x).index_add_(0, row, msgs)
34
+ return self.lin(out)
model_skeletons/model_class_17.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Auto-extracted class source (static)
2
+
3
+ class GNNDiracRRF(nn.Module):
4
+ def __init__(self, in_dim: int, hidden_dim: int, out_dim: int, num_layers: int, z_dim: int,
5
+ alpha_attn: float = 1.0, dropout: float = 0.1):
6
+ super().__init__()
7
+ self.z_dim = z_dim
8
+ self.layers = nn.ModuleList()
9
+ self.layers.append(DiracGraphConv(in_dim, hidden_dim, alpha=alpha_attn))
10
+ for _ in range(num_layers - 2):
11
+ self.layers.append(DiracGraphConv(hidden_dim, hidden_dim, alpha=alpha_attn))
12
+ self.layers.append(DiracGraphConv(hidden_dim, out_dim, alpha=alpha_attn))
13
+ self.dropout = nn.Dropout(dropout)
14
+
15
+ def forward(self, x: torch.Tensor, edge_index: torch.Tensor, z: torch.Tensor) -> torch.Tensor:
16
+ h = x
17
+ for i, layer in enumerate(self.layers):
18
+ h = layer(h, edge_index, z)
19
+ if i < len(self.layers) - 1:
20
+ h = F.gelu(h)
21
+ h = self.dropout(h)
22
+ return h
model_skeletons/model_class_18.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Auto-extracted class source (static)
2
+
3
+ class DiracGraphConv(nn.Module):
4
+ def __init__(self, in_dim: int, out_dim: int, alpha: float = 1.0, bias: bool = True):
5
+ super().__init__()
6
+ self.lin = nn.Linear(in_dim, out_dim, bias=bias)
7
+ self.alpha = nn.Parameter(torch.tensor(alpha, dtype=torch.float32))
8
+ self.bias_edge = nn.Parameter(torch.tensor(0.0, dtype=torch.float32))
9
+
10
+ @staticmethod
11
+ def cosine_corr(z_i: torch.Tensor, z_j: torch.Tensor, eps: float = 1e-9) -> torch.Tensor:
12
+ num = (z_i * z_i).sum(dim=-1) # Corrected dot product: z_i * z_j
13
+ den = torch.clamp(z_i.norm(dim=-1) * z_j.norm(dim=-1), min=eps)
14
+ return num / den
15
+
16
+ def forward(self, x: torch.Tensor, edge_index: torch.Tensor, z: torch.Tensor) -> torch.Tensor:
17
+ N = x.size(0)
18
+ row, col = edge_index
19
+ corr = self.cosine_corr(z[row], z[col])
20
+ logits = self.alpha * corr + self.bias_edge
21
+ device = x.device
22
+ E = row.size(0)
23
+ ones = torch.ones(E, device=device)
24
+ max_per_row = torch.full((N,), -1e9, device=device)
25
+ max_per_row = max_per_row.index_put((row,), logits, accumulate=False).scatter_reduce_(0, row, logits, reduce="amax")
26
+ logits_centered = logits - max_per_row[row]
27
+ exp_logits = torch.exp(logits_centered)
28
+ denom = torch.zeros(N, device=device).index_add_(0, row, exp_logits)
29
+ attn = exp_logits / (denom[row] + 1e-9)
30
+ deg = torch.zeros(N, device=device).index_add_(0, row, ones)
31
+ norm = 1.0 / torch.clamp(deg[row], min=1.0)
32
+ msgs = norm.unsqueeze(-1) * attn.unsqueeze(-1) * x[col]
33
+ out = torch.zeros_like(x).index_add_(0, row, msgs)
34
+ return self.lin(out)
model_skeletons/model_class_19.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Auto-extracted class source (static)
2
+
3
+ class GNNDiracRRF(nn.Module):
4
+ def __init__(self, in_dim: int, hidden_dim: int, out_dim: int, num_layers: int, z_dim: int,
5
+ alpha_attn: float = 1.0, dropout: float = 0.1):
6
+ super().__init__()
7
+ self.z_dim = z_dim
8
+ self.layers = nn.ModuleList()
9
+ self.layers.append(DiracGraphConv(in_dim, hidden_dim, alpha=alpha_attn))
10
+ for _ in range(num_layers - 2):
11
+ self.layers.append(DiracGraphConv(hidden_dim, hidden_dim, alpha=alpha_attn))
12
+ self.layers.append(DiracGraphConv(hidden_dim, out_dim, alpha=alpha_attn))
13
+ self.dropout = nn.Dropout(dropout)
14
+
15
+ def forward(self, x: torch.Tensor, edge_index: torch.Tensor, z: torch.Tensor) -> torch.Tensor:
16
+ h = x
17
+ for i, layer in enumerate(self.layers):
18
+ h = layer(h, edge_index, z)
19
+ if i < len(self.layers) - 1:
20
+ h = F.gelu(h)
21
+ h = self.dropout(h)
22
+ return h
model_skeletons/model_class_2.py ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Auto-extracted class source (static)
2
+
3
+ class RRF_Ultra_CNN(nn.Module):
4
+ def __init__(self, input_dim=1, output_dim=1):
5
+ super(RRF_Ultra_CNN, self).__init__()
6
+ self.conv1 = nn.Conv1d(input_dim, 64, kernel_size=3, padding=1)
7
+ self.conv2 = nn.Conv1d(64, 128, kernel_size=3, padding=1)
8
+ self.fc1 = nn.Linear(128*160, 256)
9
+ self.fc2 = nn.Linear(256, output_dim)
10
+
11
+ def forward(self, x):
12
+ x = F.relu(self.conv1(x))
13
+ x = F.relu(self.conv2(x))
14
+ x = torch.flatten(x, 1)
15
+ x = F.relu(self.fc1(x))
16
+ return torch.sigmoid(self.fc2(x))
model_skeletons/model_class_20.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Auto-extracted class source (static)
2
+
3
+ class SavantRRF_Gauge(nn.Module):
4
+ def __init__(self, input_dim, hidden_dim, output_dim):
5
+ super(SavantRRF_Gauge, self).__init__()
6
+ self.conv1 = nn.Conv1d(input_dim, 64, kernel_size=3, padding=1)
7
+ self.conv2 = nn.Conv1d(64, 128, kernel_size=3, padding=1)
8
+ self.conv3 = nn.Conv1d(128, 256, kernel_size=3, padding=1)
9
+ self.dropout = nn.Dropout(0.25)
10
+ # Assuming input sequence length is 160
11
+ self.fc1 = nn.Linear(256*160, 512)
12
+ self.fc2 = nn.Linear(512, 256)
13
+ self.fc3 = nn.Linear(256, output_dim)
14
+
15
+ def forward(self, x):
16
+ x = F.relu(self.conv1(x))
17
+ x = F.relu(self.conv2(x))
18
+ x = F.relu(self.conv3(x))
19
+ x = torch.flatten(x, 1)
20
+ x = self.dropout(x)
21
+ x = F.relu(self.fc1(x))
22
+ x = F.relu(self.fc2(x))
23
+ return torch.sigmoid(self.fc3(x))
model_skeletons/model_class_21.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Auto-extracted class source (static)
2
+
3
+ class IcosahedralRRF(nn.Module):
4
+ def __init__(self, input_dim, hidden_dim, output_dim, gnn_num_layers=2, gnn_z_dim=16, gnn_alpha_attn=1.0, gnn_dropout=0.1):
5
+ super(IcosahedralRRF, self).__init__()
6
+ # 12 nodos gauge
7
+ self.nodes = nn.ModuleList([
8
+ SavantRRF_Gauge(input_dim, hidden_dim, output_dim) for _ in range(12)
9
+ ])
10
+ # Núcleo ético
11
+ self.ethical_core = nn.Linear(12 * output_dim, output_dim)
12
+
13
+ # Subconsciente (dodecaedro/icosaedro) using GNNDiracRRF
14
+ # The GNN operates on the 12 gauge node outputs.
15
+ # The input features to the GNN are the outputs of the 12 gauge nodes, shape [batch_size, output_dim].
16
+ # For GNN layer, input is [num_nodes, in_channels] = [12, output_dim] per batch item.
17
+ self.memory_map = GNNDiracRRF(in_dim=output_dim,
18
+ hidden_dim=hidden_dim,
19
+ out_dim=output_dim,
20
+ num_layers=gnn_num_layers,
21
+ z_dim=gnn_z_dim,
22
+ alpha_attn=gnn_alpha_attn,
23
+ dropout=gnn_dropout)
24
+
25
+
26
+ def forward(self, x, edge_index=None, z=None):
27
+ # x is the input to the gauge nodes, shape [batch_size, input_dim, sequence_length]
28
+ outputs = [node(x) for node in self.nodes]
29
+ # outputs is a list of 12 tensors, each [batch_size, output_dim]
30
+
31
+ # Concatenate outputs for the ethical core
32
+ concat = torch.cat(outputs, dim=1) # [batch_size, 12 * output_dim]
33
+ regulated = torch.sigmoid(self.ethical_core(concat)) # [batch_size, output_dim]
34
+
35
+ # GNN operation on the 12 gauge nodes
36
+ if edge_index is not None and z is not None:
37
+ # Prepare input for the GNN: Features for the 12 nodes (the gauge node outputs).
38
+ stacked_outputs = torch.stack(outputs, dim=1) # [batch_size, 12, output_dim]
39
+
40
+ gnn_outputs_list = []
41
+ for i in range(stacked_outputs.size(0)):
42
+ gnn_input_features_i = stacked_outputs[i]
43
+ edge_index_i = edge_index.to(x.device)
44
+ z_i = z.to(x.device)
45
+ gnn_output_i = self.memory_map(gnn_input_features_i, edge_index_i, z_i) # [12, output_dim]
46
+ gnn_outputs_list.append(gnn_output_i)
47
+
48
+ gnn_outputs_stacked = torch.stack(gnn_outputs_list, dim=0)
49
+ aggregated_gnn_output = gnn_outputs_stacked.mean(dim=1) # [batch_size, output_dim]
50
+
51
+ return aggregated_gnn_output # [batch_size, output_dim]
52
+
53
+ else:
54
+ return regulated
model_skeletons/model_class_22.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Auto-extracted class source (static)
2
+
3
+ class DiracGraphConv(nn.Module):
4
+ def __init__(self, in_dim: int, out_dim: int, alpha: float = 1.0, bias: bool = True):
5
+ super().__init__()
6
+ self.lin = nn.Linear(in_dim, out_dim, bias=bias)
7
+ self.alpha = nn.Parameter(torch.tensor(alpha, dtype=torch.float32))
8
+ self.bias_edge = nn.Parameter(torch.tensor(0.0, dtype=torch.float32))
9
+
10
+ @staticmethod
11
+ def cosine_corr(z_i: torch.Tensor, z_j: torch.Tensor, eps: float = 1e-9) -> torch.Tensor:
12
+ num = (z_i * z_j).sum(dim=-1)
13
+ den = torch.clamp(z_i.norm(dim=-1) * z_j.norm(dim=-1), min=eps)
14
+ return num / den
15
+
16
+ def forward(self, x: torch.Tensor, edge_index: torch.Tensor, z: torch.Tensor) -> torch.Tensor:
17
+ N = x.size(0)
18
+ row, col = edge_index
19
+ # Ensure z has correct shape for cosine_corr
20
+ # z should have shape [num_nodes, z_dim]
21
+ # x has shape [num_nodes, in_dim]
22
+ # When called from GNNDiracRRF, num_nodes is 12 (for icosahedral)
23
+ # z[row] and z[col] should broadcast correctly with x[col]
24
+ corr = self.cosine_corr(z[row], z[col])
25
+ logits = self.alpha * corr + self.bias_edge
26
+ device = x.device
27
+ E = row.size(0)
28
+ ones = torch.ones(E, device=device)
29
+ # Use scatter_reduce_ to calculate max per row
30
+ max_per_row = torch.full((N,), -1e9, device=device)
31
+ max_per_row = max_per_row.index_put((row,), logits, accumulate=False).scatter_reduce_(0, row, logits, reduce="amax")
32
+ logits_centered = logits - max_per_row[row]
33
+ exp_logits = torch.exp(logits_centered)
34
+ denom = torch.zeros(N, device=device).index_add_(0, row, exp_logits)
35
+ attn = exp_logits / (denom[row] + 1e-9)
36
+ deg = torch.zeros(N, device=device).index_add_(0, row, ones)
37
+ norm = 1.0 / torch.clamp(deg[row], min=1.0)
38
+ msgs = norm.unsqueeze(-1) * attn.unsqueeze(-1) * x[col]
39
+ out = torch.zeros_like(x).index_add_(0, row, msgs)
40
+ return self.lin(out)
model_skeletons/model_class_23.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Auto-extracted class source (static)
2
+
3
+ class GNNDiracRRF(nn.Module):
4
+ def __init__(self, in_dim: int, hidden_dim: int, out_dim: int, num_layers: int, z_dim: int,
5
+ alpha_attn: float = 1.0, dropout: float = 0.1):
6
+ super().__init__()
7
+ self.z_dim = z_dim
8
+ self.layers = nn.ModuleList()
9
+ # Ensure DiracGraphConv is defined before this line
10
+ self.layers.append(DiracGraphConv(in_dim, hidden_dim, alpha=alpha_attn))
11
+ for _ in range(num_layers - 2):
12
+ self.layers.append(DiracGraphConv(hidden_dim, hidden_dim, alpha=alpha_attn))
13
+ self.layers.append(DiracGraphConv(hidden_dim, out_dim, alpha=alpha_attn))
14
+ self.dropout = nn.Dropout(dropout)
15
+
16
+ def forward(self, x: torch.Tensor, edge_index: torch.Tensor, z: torch.Tensor) -> torch.Tensor:
17
+ h = x
18
+ for i, layer in enumerate(self.layers):
19
+ h = layer(h, edge_index, z)
20
+ if i < len(self.layers) - 1:
21
+ h = F.gelu(h)
22
+ h = self.dropout(h)
23
+ return h
model_skeletons/model_class_24.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Auto-extracted class source (static)
2
+
3
+ class RRF_Dataset(Dataset):
4
+ def __init__(self, strain, weights, seq_len=160): # Use seq_len=160 to match model input
5
+ self.seq_len = seq_len
6
+ self.strain = strain
7
+ self.weights = weights
8
+ print(f"Debug: RRF_Dataset __init__ - len(strain): {len(strain)}, seq_len: {self.seq_len}") # Debug print
9
+ # Calculate n only if strain is long enough
10
+ if len(strain) >= seq_len:
11
+ self.n = len(strain) // seq_len
12
+ else:
13
+ self.n = 0 # Set n to 0 if strain is too short
14
+ print(f"Debug: RRF_Dataset __init__ - Calculated self.n: {self.n}") # New debug print
15
+ # Add a check to ensure there's at least one sequence
16
+ if self.n == 0:
17
+ raise ValueError(f"Strain data length ({len(strain)}) is less than sequence length ({seq_len}). Cannot create any samples.")
18
+
19
+
20
+ def __len__(self):
21
+ return self.n
22
+
23
+ def __getitem__(self, idx):
24
+ start = idx * self.seq_len
25
+ # Extract the strain sequence x
26
+ x = self.strain[start:start+self.seq_len] # Shape: [seq_len]
27
+
28
+ # Use the mean of the provided weights as the global resonance factor w
29
+ w = np.mean(self.weights) # global resonance factor
30
+
31
+ # Define the target label y as the mean of the strain sequence x, scaled by w
32
+ # This creates a regression target derived from the strain data.
33
+ y = np.mean(x) * w # synthetic label (proxy resonance)
34
+
35
+ # Convert x and y to PyTorch tensors with float dtype
36
+ # The model expects input x as [1, seq_len] for a single sample, so add unsqueeze(0)
37
+ return torch.tensor(x).float().unsqueeze(0), torch.tensor(y).float()
model_skeletons/model_class_3.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Auto-extracted class source (static)
2
+
3
+ class SavantRRF_Gauge(nn.Module):
4
+ def __init__(self, input_dim, hidden_dim, output_dim):
5
+ super(SavantRRF_Gauge, self).__init__()
6
+ self.conv1 = nn.Conv1d(input_dim, 64, kernel_size=3, padding=1)
7
+ self.conv2 = nn.Conv1d(64, 128, kernel_size=3, padding=1)
8
+ self.conv3 = nn.Conv1d(128, 256, kernel_size=3, padding=1)
9
+ self.dropout = nn.Dropout(0.25)
10
+ # The input size to fc1 is based on the output size of conv3.
11
+ # Assuming input sequence length is 160, after 3 conv layers with kernel_size 3 and padding 1,
12
+ # the sequence length remains 160. 256 channels * 160 length = 40960.
13
+ self.fc1 = nn.Linear(256*160, 512) # Corrected input size based on sequence_length=160
14
+ self.fc2 = nn.Linear(512, 256)
15
+ self.fc3 = nn.Linear(256, output_dim)
16
+
17
+ def forward(self, x):
18
+ x = F.relu(self.conv1(x))
19
+ x = F.relu(self.conv2(x))
20
+ x = F.relu(self.conv3(x))
21
+ x = torch.flatten(x, 1)
22
+ x = self.dropout(x)
23
+ x = F.relu(self.fc1(x))
24
+ x = F.relu(self.fc2(x))
25
+ return torch.sigmoid(self.fc3(x))
model_skeletons/model_class_4.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Auto-extracted class source (static)
2
+
3
+ class DiracGraphConv(nn.Module):
4
+ def __init__(self, in_dim: int, out_dim: int, alpha: float = 1.0, bias: bool = True):
5
+ super().__init__()
6
+ self.lin = nn.Linear(in_dim, out_dim, bias=bias)
7
+ self.alpha = nn.Parameter(torch.tensor(alpha, dtype=torch.float32))
8
+ self.bias_edge = nn.Parameter(torch.tensor(0.0, dtype=torch.float32))
9
+
10
+ @staticmethod
11
+ def cosine_corr(z_i: torch.Tensor, z_j: torch.Tensor, eps: float = 1e-9) -> torch.Tensor:
12
+ num = (z_i * z_j).sum(dim=-1)
13
+ den = torch.clamp(z_i.norm(dim=-1) * z_j.norm(dim=-1), min=eps)
14
+ return num / den
15
+
16
+ def forward(self, x: torch.Tensor, edge_index: torch.Tensor, z: torch.Tensor) -> torch.Tensor:
17
+ N = x.size(0)
18
+ row, col = edge_index
19
+ corr = self.cosine_corr(z[row], z[col])
20
+ logits = self.alpha * corr + self.bias_edge
21
+ device = x.device
22
+ E = row.size(0)
23
+ ones = torch.ones(E, device=device)
24
+ max_per_row = torch.full((N,), -1e9, device=device)
25
+ max_per_row = max_per_row.index_put((row,), logits, accumulate=False).scatter_reduce_(0, row, logits, reduce="amax")
26
+ logits_centered = logits - max_per_row[row]
27
+ exp_logits = torch.exp(logits_centered)
28
+ denom = torch.zeros(N, device=device).index_add_(0, row, exp_logits)
29
+ attn = exp_logits / (denom[row] + 1e-9)
30
+ deg = torch.zeros(N, device=device).index_add_(0, row, ones)
31
+ norm = 1.0 / torch.clamp(deg[row], min=1.0)
32
+ msgs = norm.unsqueeze(-1) * attn.unsqueeze(-1) * x[col]
33
+ out = torch.zeros_like(x).index_add_(0, row, msgs)
34
+ return self.lin(out)
model_skeletons/model_class_5.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Auto-extracted class source (static)
2
+
3
+ class GNNDiracRRF(nn.Module):
4
+ def __init__(self, in_dim: int, hidden_dim: int, out_dim: int, num_layers: int, z_dim: int,
5
+ alpha_attn: float = 1.0, dropout: float = 0.1):
6
+ super().__init__()
7
+ self.z_dim = z_dim
8
+ self.layers = nn.ModuleList()
9
+ self.layers.append(DiracGraphConv(in_dim, hidden_dim, alpha=alpha_attn))
10
+ for _ in range(num_layers - 2):
11
+ self.layers.append(DiracGraphConv(hidden_dim, hidden_dim, alpha=alpha_attn))
12
+ self.layers.append(DiracGraphConv(hidden_dim, out_dim, alpha=alpha_attn))
13
+ self.dropout = nn.Dropout(dropout)
14
+
15
+ def forward(self, x: torch.Tensor, edge_index: torch.Tensor, z: torch.Tensor) -> torch.Tensor:
16
+ h = x
17
+ for i, layer in enumerate(self.layers):
18
+ h = layer(h, edge_index, z)
19
+ if i < len(self.layers) - 1:
20
+ h = F.gelu(h)
21
+ h = self.dropout(h)
22
+ return h
model_skeletons/model_class_6.py ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ # Auto-extracted class source (static)
2
+
3
+ class LossWeights:
4
+ lambda_task: float = 1.0
5
+ lambda_res: float = 0.5
6
+ lambda_ent: float = 0.2
model_skeletons/model_class_7.py ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Auto-extracted class source (static)
2
+
3
+ class IcosahedralRRF(nn.Module):
4
+ def __init__(self, input_dim, hidden_dim, output_dim, gnn_num_layers=2, gnn_z_dim=16, gnn_alpha_attn=1.0, gnn_dropout=0.1):
5
+ super(IcosahedralRRF, self).__init__()
6
+ # 12 nodos gauge
7
+ self.nodes = nn.ModuleList([
8
+ SavantRRF_Gauge(input_dim, hidden_dim, output_dim) for _ in range(12)
9
+ ])
10
+ # Núcleo ético
11
+ # The input to ethical_core is the concatenation of the outputs of the 12 gauge nodes.
12
+ # Each gauge node outputs a tensor of shape [batch_size, output_dim].
13
+ # Concatenating these along dim=1 results in a shape [batch_size, 12 * output_dim].
14
+ self.ethical_core = nn.Linear(12 * output_dim, output_dim)
15
+
16
+ # Subconsciente (dodecaedro) using GNNDiracRRF
17
+ # The input dimension (in_dim) for the GNN should match the feature dimension of its input nodes.
18
+ # There's ambiguity in the original code about what the GNN's nodes and features are.
19
+ # Interpretation 1 (based on original code passing 'regulated'): GNN operates on 'batch_size' nodes, with 'output_dim' features. in_dim = output_dim.
20
+ # Interpretation 2 (more conventional for graph on icosahedron/dodecahedron): GNN operates on 12 or 20 nodes, with features derived from gauge outputs.
21
+ # Let's assume interpretation 2, where the GNN operates on the 12 gauge nodes.
22
+ # The features for each of these 12 nodes would be the output of the corresponding gauge node, shape [batch_size, output_dim].
23
+ # For a GNN layer expecting [num_nodes, in_channels], the input should be [12, output_dim] per batch item.
24
+ # This means the GNN's in_dim should be output_dim. This matches the current GNN init below.
25
+ # The GNN's out_dim should match the desired output feature dimension per node (e.g., output_dim).
26
+ # The number of nodes for the GNN is 12 (for icosahedral).
27
+
28
+ # Let's define the memory_map GNN assuming it operates on the 12 gauge nodes.
29
+ # The input features to the GNN will be the outputs of the 12 gauge nodes.
30
+ # Each gauge node outputs a tensor of shape [batch_size, output_dim].
31
+ # We will treat output_dim as the feature dimension for the GNN nodes (the 12 gauge nodes).
32
+ # So, in_dim for GNN = output_dim.
33
+ # The GNN will output features for each of the 12 nodes. Let's assume out_dim for GNN is also output_dim.
34
+ self.memory_map = GNNDiracRRF(in_dim=output_dim, # Feature dimension for GNN nodes (output_dim of gauge nodes)
35
+ hidden_dim=hidden_dim,
36
+ out_dim=output_dim, # Output feature dimension per GNN node
37
+ num_layers=gnn_num_layers,
38
+ z_dim=gnn_z_dim,
39
+ alpha_attn=gnn_alpha_attn,
40
+ dropout=gnn_dropout)
41
+
42
+
43
+ def forward(self, x, edge_index=None, z=None):
44
+ # x is the input to the gauge nodes, shape [batch_size, input_dim, sequence_length]
45
+ outputs = [node(x) for node in self.nodes]
46
+ # outputs is a list of 12 tensors, each [batch_size, output_dim]
47
+
48
+ # Concatenate outputs for the ethical core
49
+ concat = torch.cat(outputs, dim=1) # [batch_size, 12 * output_dim]
50
+ regulated = torch.sigmoid(self.ethical_core(concat)) # [batch_size, output_dim]
51
+
52
+ # GNN operation on the 12 gauge nodes
53
+ if edge_index is not None and z is not None:
54
+ # Prepare input for the GNN: Features for the 12 nodes (the gauge node outputs).
55
+ # Stack the outputs to get [batch_size, 12, output_dim]
56
+ stacked_outputs = torch.stack(outputs, dim=1) # [batch_size, 12, output_dim]
57
+
58
+ # Reshape for GNN input: [num_nodes, in_channels] = [12, output_dim] per batch item.
59
+ # Need to process batch items. Simplest is to iterate.
60
+ # A more efficient way is to use torch_geometric.data.Batch
61
+
62
+ gnn_outputs_list = []
63
+ for i in range(stacked_outputs.size(0)):
64
+ # GNN input features for this batch item: [12, output_dim]
65
+ gnn_input_features_i = stacked_outputs[i]
66
+
67
+ # Ensure edge_index and z are on the correct device
68
+ edge_index_i = edge_index.to(x.device)
69
+ z_i = z.to(x.device)
70
+
71
+ # GNN forward pass for one batch item
72
+ gnn_output_i = self.memory_map(gnn_input_features_i, edge_index_i, z_i) # [12, output_dim]
73
+ gnn_outputs_list.append(gnn_output_i)
74
+
75
+ # Stack GNN outputs back into a batch tensor: [batch_size, 12, output_dim]
76
+ gnn_outputs_stacked = torch.stack(gnn_outputs_list, dim=0)
77
+
78
+ # Now, how to combine the GNN output [batch_size, 12, output_dim] with the 'regulated' output [batch_size, output_dim]?
79
+ # The original model returned just 'regulated'.
80
+ # A simple approach is to maybe combine them, e.g., add, concatenate, or use the GNN output as a modulation.
81
+ # Let's stick to returning the aggregated GNN output as the final output when GNN is used.
82
+ # This changes the model's behavior compared to the original.
83
+
84
+ # Alternative: The GNN output modulates the 'regulated' output.
85
+ # E.g., regulated * sigmoid(aggregated_gnn_output) or similar.
86
+ # Let's stick to returning the aggregated GNN output when edge_index and z are provided,
87
+ # and the original 'regulated' output otherwise. This seems the most direct path based on the conditional in the original forward.
88
+
89
+ # Aggregate the 12 nodes' outputs from the GNN
90
+ aggregated_gnn_output = gnn_outputs_stacked.mean(dim=1) # [batch_size, output_dim]
91
+
92
+ return aggregated_gnn_output # [batch_size, output_dim]
93
+
94
+ else:
95
+ # If edge_index and z are not provided, return the output of the ethical core as before.
96
+ return regulated
model_skeletons/model_class_8.py ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Auto-extracted class source (static)
2
+
3
+ class RRF_Ultra_CNN(nn.Module):
4
+ def __init__(self, input_dim=1, output_dim=1):
5
+ super(RRF_Ultra_CNN, self).__init__()
6
+ self.conv1 = nn.Conv1d(input_dim, 64, kernel_size=3, padding=1)
7
+ self.conv2 = nn.Conv1d(64, 128, kernel_size=3, padding=1)
8
+ self.fc1 = nn.Linear(128*160, 256)
9
+ self.fc2 = nn.Linear(256, output_dim)
10
+
11
+ def forward(self, x):
12
+ x = F.relu(self.conv1(x))
13
+ x = F.relu(self.conv2(x))
14
+ x = torch.flatten(x, 1)
15
+ x = F.relu(self.fc1(x))
16
+ return torch.sigmoid(self.fc2(x))
model_skeletons/model_class_9.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Auto-extracted class source (static)
2
+
3
+ class SavantRRF_Gauge(nn.Module):
4
+ def __init__(self, input_dim, hidden_dim, output_dim):
5
+ super(SavantRRF_Gauge, self).__init__()
6
+ self.conv1 = nn.Conv1d(input_dim, 64, kernel_size=3, padding=1)
7
+ self.conv2 = nn.Conv1d(64, 128, kernel_size=3, padding=1)
8
+ self.conv3 = nn.Conv1d(128, 256, kernel_size=3, padding=1)
9
+ self.dropout = nn.Dropout(0.25)
10
+ # The input size to fc1 is based on the output size of conv3.
11
+ # Assuming input sequence length is 160, after 3 conv layers with kernel_size 3 and padding 1,
12
+ # the sequence length remains 160. 256 channels * 160 length = 40960.
13
+ self.fc1 = nn.Linear(256*160, 512) # Corrected input size based on sequence_length=160
14
+ self.fc2 = nn.Linear(512, 256)
15
+ self.fc3 = nn.Linear(256, output_dim)
16
+
17
+ def forward(self, x):
18
+ x = F.relu(self.conv1(x))
19
+ x = F.relu(self.conv2(x))
20
+ x = F.relu(self.conv3(x))
21
+ x = torch.flatten(x, 1)
22
+ x = self.dropout(x)
23
+ x = F.relu(self.fc1(x))
24
+ x = F.relu(self.fc2(x))
25
+ return torch.sigmoid(self.fc3(x))
rrf_ultra_cnn_gauge_model.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:afcb0f7dfb7e7c28a8780bc88e1caa19c244f8550f718c797f81d694255dfd88
3
+ size 663939
rrf_ultra_cnn_model.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a1d41af3abc8e98b6d26268f5621ec02aa73d9b421a34ab318259865ae6f9dea
3
+ size 84913431