RRF / model_skeletons /model_class_24.py
antonypamo's picture
Upload 26 files (#6)
ce680a7 verified
Raw
History Blame Contribute Delete
1.71 kB
# Auto-extracted class source (static)
class RRF_Dataset(Dataset):
def __init__(self, strain, weights, seq_len=160): # Use seq_len=160 to match model input
self.seq_len = seq_len
self.strain = strain
self.weights = weights
print(f"Debug: RRF_Dataset __init__ - len(strain): {len(strain)}, seq_len: {self.seq_len}") # Debug print
# Calculate n only if strain is long enough
if len(strain) >= seq_len:
self.n = len(strain) // seq_len
else:
self.n = 0 # Set n to 0 if strain is too short
print(f"Debug: RRF_Dataset __init__ - Calculated self.n: {self.n}") # New debug print
# Add a check to ensure there's at least one sequence
if self.n == 0:
raise ValueError(f"Strain data length ({len(strain)}) is less than sequence length ({seq_len}). Cannot create any samples.")
def __len__(self):
return self.n
def __getitem__(self, idx):
start = idx * self.seq_len
# Extract the strain sequence x
x = self.strain[start:start+self.seq_len] # Shape: [seq_len]
# Use the mean of the provided weights as the global resonance factor w
w = np.mean(self.weights) # global resonance factor
# Define the target label y as the mean of the strain sequence x, scaled by w
# This creates a regression target derived from the strain data.
y = np.mean(x) * w # synthetic label (proxy resonance)
# Convert x and y to PyTorch tensors with float dtype
# The model expects input x as [1, seq_len] for a single sample, so add unsqueeze(0)
return torch.tensor(x).float().unsqueeze(0), torch.tensor(y).float()
Free AI Image Generator No sign-up. Instant results. Open Now