import matplotlib.pyplot as plt
from some_module import LSTMNeuralNet, extract_window_size, extract_window_info # Placeholder for actual imports
for feature_file in feature_files:
features_csv = os.path.join(data_folder, feature_file)
labels_csv = os.path.join(data_folder, feature_to_label[feature_file])
model_loc = os.path.join(model_folder, feature_to_model[feature_file])
# Extract window size from filename
win_size = extract_window_size(feature_file)
info = extract_window_info(feature_file)
key_column = "Sequence_ID" # Common column in both CSV files to match features with labels
tsne_save = os.path.join(viz_folder, feature_to_export[feature_file])
if os.path.exists(tsne_save.replace("csv", "png")):
print(f"Skipping {feature_to_model[feature_file]}")
print(f"Dimensionality Reduction on model file: {feature_to_model[feature_file]}")
config = base_config.copy()
config['TRAINING']['csv_data_file_loc'] = features_csv
config['TRAINING']['csv_label_file_loc'] = labels_csv
config['TRAINING']['h5file_loc'] = model_loc
neural_net = LSTMNeuralNet(config)
classes, reduced_activations = neural_net.run_pacmap(features_csv, labels_csv, key_column, model_loc, win_size)
# Convert one_hot class encoding to integer
class_indices = np.argmax(classes, axis=1)
fig = plt.figure(figsize=(10, 8))
plt.style.use('dark_background')
ax = fig.add_subplot(111, projection='3d')
ax.xaxis.pane.fill = False
ax.yaxis.pane.fill = False
ax.zaxis.pane.fill = False
# Extracting the reduced dimensions
x = reduced_activations[:, 0]
y = reduced_activations[:, 1]
z = reduced_activations[:, 2]
scatter = ax.scatter(x, y, z, c=class_indices, cmap='RdYlBu', alpha=0.2, s=2)
plt.savefig(tsne_save.replace("csv", "png"), dpi=150)
plt.close(fig) # Close the figure to free memory
except (RuntimeError, TypeError, NameError):
print(f"Error encountered. Will skip {model_loc}")
# Explicitly delete objects to free memory