SystemsAgeLung#
Index#
Load reference values
Check all clock parameters
Let’s first import some packages:
[1]:
import os
import inspect
import sys
import subprocess
import shutil
import json
import torch
import pandas as pd
import pyaging as pya
from pathlib import Path
import numpy as np
import torch.nn as nn
Instantiate model class#
[2]:
def print_entire_class(cls):
source = inspect.getsource(cls)
print(source)
print_entire_class(pya.models.SystemsAgeLung)
class SystemsAgeLung(SystemsAgeBase):
def __init__(self):
super().__init__()
self.prediction_index = 9
[3]:
model = pya.models.SystemsAgeLung()
Define clock metadata#
[4]:
model.metadata["clock_name"] = 'systemsagelung'
model.metadata["data_type"] = 'methylation'
model.metadata["species"] = 'Homo sapiens'
model.metadata["year"] = 2025
model.metadata["approved_by_author"] = '⌛'
model.metadata["citation"] = "Sehgal, Raghav, et al. \"Systems Age: A single blood methylation test to quantify aging heterogeneity across 11 physiological systems.\" Nature Aging (2025): 1-17."
model.metadata["doi"] = "https://doi.org/10.1038/s43587-025-00958-3"
model.metadata["research_only"] = True
model.metadata["notes"] = None
Download clock dependencies#
Download from R package#
[ ]:
FILE_ID = "14HBIhA-gkp9-RWD0HVAekRGWOHQBqvhc"
OUT_PATH = "SystemsAge_data.RData"
if not os.path.exists(OUT_PATH):
try:
import gdown # type: ignore
except Exception:
subprocess.check_call([sys.executable, "-m", "pip", "install", "--quiet", "gdown"])
import gdown # type: ignore
url = f"https://drive.google.com/uc?id={FILE_ID}"
gdown.download(url, OUT_PATH, quiet=False)
print(f"Downloaded: {os.path.exists(OUT_PATH)} -> {OUT_PATH}")
Downloading...
From (original): https://drive.google.com/uc?id=14HBIhA-gkp9-RWD0HVAekRGWOHQBqvhc
From (redirected): https://drive.google.com/uc?id=14HBIhA-gkp9-RWD0HVAekRGWOHQBqvhc&confirm=t&uuid=77f24763-0c22-4b2b-b5dc-08d50fb4cc3b
To: /Users/lucascamillo/pyaging/clocks/notebooks/SystemsAge_data.RData
100%|██████████| 3.86G/3.86G [10:30<00:00, 6.13MB/s]
Downloaded: True -> SystemsAge_data.RData
[ ]:
%%writefile export_systemsage.R
suppressPackageStartupMessages(library(jsonlite))
suppressPackageStartupMessages(library(readr))
suppressPackageStartupMessages(library(tibble))
use_arrow <- requireNamespace("arrow", quietly = TRUE)
write_matrix <- function(df, base_name) {
if (use_arrow) {
parquet_path <- paste0(base_name, ".parquet")
written <- tryCatch({
arrow::write_parquet(df, parquet_path, compression = "snappy")
TRUE
}, error = function(e) {
message(sprintf("arrow parquet export failed for %s (%s); writing gzip CSV instead.", base_name, e$message))
FALSE
})
if (isTRUE(written)) {
return(parquet_path)
}
if (file.exists(parquet_path) && file.info(parquet_path)$size == 0) {
unlink(parquet_path)
}
}
csv_path <- paste0(base_name, ".csv.gz")
readr::write_csv(df, csv_path)
return(csv_path)
}
rds <- "SystemsAge_data.RData"
if (!file.exists(rds)) {
stop(paste("Missing", rds, "- run the download cell first."))
}
load(rds)
# 1) CpG list used by the clock
CpGs <- rownames(DNAmPCA$rotation)
write_json(CpGs, "systemsage_CpGs.json", auto_unbox = TRUE)
# 2) Mean-imputation values for missing CpGs (named vector)
write_json(as.list(imputeMissingCpGs), "systemsage_impute_means.json", digits = 10, auto_unbox = TRUE)
# 3) DNAm PCA components: rotation matrix plus supporting statistics
rot_tbl <- as_tibble(DNAmPCA$rotation, rownames = "CpG")
rotation_path <- write_matrix(rot_tbl, "systemsage_dnam_pca_rotation")
write_json(as.list(DNAmPCA$center), "systemsage_dnam_pca_center.json", digits = 10, auto_unbox = TRUE)
write_json(DNAmPCA$scale, "systemsage_dnam_pca_scale.json", digits = 10, auto_unbox = TRUE)
write_json(as.numeric(DNAmPCA$sdev), "systemsage_dnam_pca_sdev.json", digits = 10, auto_unbox = TRUE)
# 4) Map DNAm PCs to system-level components
svc_tbl <- as_tibble(system_vector_coefficients, rownames = "PC")
system_vector_path <- write_matrix(svc_tbl, "systemsage_system_vector_coefficients")
write_json(as.list(system_scores_coefficients_scale), "systemsage_system_scores_coefficients_scale.json", digits = 10, auto_unbox = TRUE)
component_map <- tibble(
component = colnames(system_vector_coefficients),
system = gsub("[0-9]+$", "", component)
)
write_csv(component_map, "systemsage_system_component_map.csv")
# 5) Predicted chronological age model (DNAm PCs -> age before calibration)
pred_age <- list(
intercept = as.numeric(Predicted_age_coefficients[1]),
loadings = as.numeric(Predicted_age_coefficients[-1])
)
write_json(pred_age, "systemsage_predicted_age_linear.json", digits = 10, auto_unbox = TRUE)
write_json(list(a = Age_prediction_model[1], b = Age_prediction_model[2], c = Age_prediction_model[3]),
"systemsage_predicted_age_poly.json", digits = 10, auto_unbox = TRUE)
# 6) PCA on system scores (11 systems + age prediction)
sys_rot_tbl <- as_tibble(systems_PCA$rotation, rownames = "variable")
systems_pca_rotation_path <- write_matrix(sys_rot_tbl, "systemsage_systems_pca_rotation")
write_json(as.list(systems_PCA$center), "systemsage_systems_pca_center.json", digits = 10, auto_unbox = TRUE)
write_json(as.list(systems_PCA$scale), "systemsage_systems_pca_scale.json", digits = 10, auto_unbox = TRUE)
write_json(as.numeric(systems_PCA$sdev), "systemsage_systems_pca_sdev.json", digits = 10, auto_unbox = TRUE)
# 7) Final SystemsAge coefficients (systems PCA -> SystemsAge)
write_json(as.numeric(Systems_clock_coefficients), "systemsage_final_coefficients.json", digits = 10, auto_unbox = TRUE)
# 8) Transformation coefficients for scaling outputs (11 systems + age prediction + SystemsAge)
system_labels <- c("Blood", "Brain", "Inflammation", "Heart", "Hormone", "Immune", "Kidney", "Liver", "Metabolic", "Lung", "MusculoSkeletal", "Age_prediction", "SystemsAge")
trans_tbl <- tibble(
label = system_labels,
Coef1 = transformation_coefs[, 1],
Coef2 = transformation_coefs[, 2],
Coef3 = transformation_coefs[, 3],
Coef4 = transformation_coefs[, 4]
)
write_csv(trans_tbl, "systemsage_transformation_coeffs.csv")
# 9) Metadata summary
meta <- list(
n_cpgs = length(CpGs),
n_dnam_pcs = ncol(DNAmPCA$rotation),
n_system_components = ncol(system_vector_coefficients),
n_systems = length(system_labels),
files = list(
dnam_pca_rotation = rotation_path,
system_vector_coefficients = system_vector_path,
systems_pca_rotation = systems_pca_rotation_path
)
)
write_json(meta, "systemsage_export_summary.json", auto_unbox = TRUE)
cat("Export complete\n")
[ ]:
os.system("Rscript export_systemsage.R")
Load features#
From exported assets#
[5]:
with open('systemsage_CpGs.json', 'r') as f:
model.features = json.load(f)
Load weights into base model#
From JSON file#
[6]:
with open('systemsage_predicted_age_linear.json', 'r') as f:
predicted_age_linear = json.load(f)
with open('systemsage_predicted_age_poly.json', 'r') as f:
predicted_age_poly = json.load(f)
with open('systemsage_system_scores_coefficients_scale.json', 'r') as f:
system_scores_coeff_scale = json.load(f)
with open('systemsage_systems_pca_center.json', 'r') as f:
systems_pca_center = json.load(f)
with open('systemsage_systems_pca_scale.json', 'r') as f:
systems_pca_scale = json.load(f)
with open('systemsage_dnam_pca_center.json', 'r') as f:
dnam_pca_center = json.load(f)
with open('systemsage_dnam_pca_scale.json', 'r') as f:
dnam_pca_scale = json.load(f)
with open('systemsage_final_coefficients.json', 'r') as f:
systemsage_final_coeffs = json.load(f)
transformation_coeffs = pd.read_csv('systemsage_transformation_coeffs.csv')
system_component_map = pd.read_csv('systemsage_system_component_map.csv')
systems_pca_asset = Path('systemsage_systems_pca_rotation.csv.gz')
rotation_asset = Path('systemsage_dnam_pca_rotation.csv.gz')
system_vector_asset = Path('systemsage_system_vector_coefficients.csv.gz')
with open('systemsage_export_summary.json', 'r') as f:
export_summary = json.load(f)
export_summary
[6]:
{'n_cpgs': 125175,
'n_dnam_pcs': 4018,
'n_system_components': 84,
'n_systems': 13,
'files': {'dnam_pca_rotation': 'systemsage_dnam_pca_rotation.csv.gz',
'system_vector_coefficients': 'systemsage_system_vector_coefficients.csv.gz',
'systems_pca_rotation': 'systemsage_systems_pca_rotation.csv.gz'}}
Build SystemsAge base model#
[8]:
# DNAm PCA rotation and centering
rotation_df = pd.read_csv(rotation_asset, compression='gzip')
if rotation_df['CpG'].tolist() != model.features:
raise ValueError('Feature order mismatch between rotation matrix and model features')
model.dnam_rotation = torch.tensor(rotation_df.drop(columns=['CpG']).to_numpy(dtype=np.float32))
model.dnam_center = torch.tensor([dnam_pca_center[cpg] for cpg in model.features], dtype=torch.float32)
del rotation_df
# System vector coefficients (DNAm PCs -> system components)
system_vector_df = pd.read_csv(system_vector_asset, compression='gzip')
component_names = system_vector_df.columns.tolist()[1:]
model.system_vector = torch.tensor(
system_vector_df.drop(columns=['PC']).fillna(0.0).to_numpy(dtype=np.float32)
)
del system_vector_df
component_index = {name: idx for idx, name in enumerate(component_names)}
system_label_map = {'Inflammation': 'Cytokine'}
system_labels = transformation_coeffs['label'].tolist()[:11]
model.system_labels = system_labels
system_indices = []
system_modules = []
for label in system_labels:
lookup = system_label_map.get(label, label)
components = system_component_map.loc[
system_component_map['system'] == lookup, 'component'
].tolist()
if not components:
raise ValueError(f'No components found for system {label}')
indices = torch.tensor([component_index[c] for c in components], dtype=torch.long)
weights = torch.tensor([system_scores_coeff_scale[c] for c in components], dtype=torch.float32)
if weights.numel() == 1:
weights = torch.tensor([-1.0], dtype=torch.float32)
linear = pya.models.LinearModel(weights.numel())
linear.linear.weight.data.zero_()
linear.linear.bias.data.zero_()
linear.linear.weight.data.copy_(weights.view(1, -1))
linear.linear.bias.requires_grad_(False)
linear.linear.weight.requires_grad_(False)
system_indices.append(indices)
system_modules.append(linear)
model.system_component_indices = system_indices
model.system_modules = nn.ModuleList(system_modules)
# Predicted chronological age assets
predicted_age_weights = torch.tensor(predicted_age_linear['loadings'], dtype=torch.float32)
predicted_age_model = pya.models.LinearModel(predicted_age_weights.numel())
predicted_age_model.linear.weight.data.zero_()
predicted_age_model.linear.bias.data.zero_()
predicted_age_model.linear.weight.data.copy_(predicted_age_weights.unsqueeze(0))
predicted_age_model.linear.bias.data.fill_(float(predicted_age_linear['intercept']))
for param in predicted_age_model.parameters():
param.requires_grad = False
model.predicted_age_model = predicted_age_model
model.predicted_age_poly = torch.tensor(
[predicted_age_poly['a'], predicted_age_poly['b'], predicted_age_poly['c']],
dtype=torch.float32,
)
# Systems PCA assets (system scores + age prediction)
systems_pca_order = transformation_coeffs['label'].tolist()[:12]
systems_pca_df = pd.read_csv(systems_pca_asset, compression='gzip').set_index('variable')
rotation_cols = [col for col in systems_pca_df.columns if col.startswith('PC')]
scale_vec = torch.tensor([systems_pca_scale[label] for label in systems_pca_order], dtype=torch.float32)
center_vec = torch.tensor([systems_pca_center[label] for label in systems_pca_order], dtype=torch.float32)
rotation_mat = torch.tensor(
systems_pca_df.loc[systems_pca_order, rotation_cols].to_numpy(dtype=np.float32)
)
rotation_scaled = rotation_mat / scale_vec.unsqueeze(1)
systems_pca_model = pya.models.PCLinearModel(input_dim=len(systems_pca_order), pc_dim=rotation_scaled.size(1))
systems_pca_model.center.data.copy_(center_vec)
systems_pca_model.rotation.data.copy_(rotation_scaled)
systems_pca_model.linear.weight.data.zero_()
systems_pca_model.linear.bias.data.zero_()
systems_pca_model.linear.weight.data.copy_(
torch.tensor(systemsage_final_coeffs, dtype=torch.float32).view(1, -1)
)
systems_pca_model.linear.bias.requires_grad_(False)
systems_pca_model.linear.weight.requires_grad_(False)
for param in systems_pca_model.parameters():
param.requires_grad = False
model.systems_pca_model = systems_pca_model
# Transformation assets
model.transformation_coefs = torch.tensor(
transformation_coeffs[['Coef1', 'Coef2', 'Coef3', 'Coef4']].to_numpy(dtype=np.float32)
)
model.transformation_labels = transformation_coeffs['label'].tolist()
# Record summary metadata for downstream reference
model.export_summary = export_summary
From JSON file#
[9]:
with open('systemsage_impute_means.json', 'r') as f:
reference_feature_values = json.load(f)
model.reference_values = torch.tensor(
[reference_feature_values[cpg] for cpg in model.features], dtype=torch.float32
)
Load preprocess and postprocess objects#
[10]:
model.preprocess_name = None
model.preprocess_dependencies = None
[11]:
model.postprocess_name = None
model.postprocess_dependencies = None
[12]:
pya.utils.print_model_details(model)
%==================================== Model Details ====================================%
Model Attributes:
training: True
metadata: {'approved_by_author': '⌛',
'citation': 'Sehgal, Raghav, et al. "Systems Age: A single blood methylation '
'test to quantify aging heterogeneity across 11 physiological '
'systems." Nature Aging (2025): 1-17.',
'clock_name': 'systemsagelung',
'data_type': 'methylation',
'doi': 'https://doi.org/10.1038/s43587-025-00958-3',
'notes': None,
'research_only': True,
'species': 'Homo sapiens',
'version': None,
'year': 2025}
reference_values: [0.7703027725219727, 0.10787541419267654, 0.14593413472175598, 0.15467368066310883, 0.05177399888634682, 0.7689204812049866, 0.09734559804201126, 0.5384307503700256, 0.03857552260160446, 0.14853332936763763, 0.03710409998893738, 0.7541770339012146, 0.05995236337184906, 0.7082317471504211, 0.9218639731407166, 0.04736267030239105, 0.11038260161876678, 0.16661499440670013, 0.08505702018737793, 0.8980633020401001, 0.44178515672683716, 0.04835095629096031, 0.2284272015094757, 0.04166311398148537, 0.04188517853617668, 0.1550152450799942, 0.18579867482185364, 0.14117033779621124, 0.04062004014849663, 0.046620775014162064]... [Tensor of shape torch.Size([125175])]
preprocess_name: None
preprocess_dependencies: None
postprocess_name: None
postprocess_dependencies: None
features: ['cg01763666', 'cg02115394', 'cg19607165', 'cg15998406', 'cg11890956', 'cg11947782', 'cg14361409', 'cg00376553', 'cg21650422', 'cg22782271', 'cg00172270', 'cg17505155', 'cg14428027', 'cg25593794', 'cg26676405', 'cg15241920', 'cg25857090', 'cg00347904', 'cg18764577', 'cg01846046', 'cg04586126', 'cg15004949', 'cg24500959', 'cg15283028', 'cg08193650', 'cg13481974', 'cg21855135', 'cg14491479', 'cg11739541', 'cg26196700']... [Total elements: 125175]
base_model_features: None
base_model: None
prediction_index: 9
dnam_center: [0.8258556723594666, 0.05573316663503647, 0.058175552636384964, 0.16283440589904785, 0.020828289911150932, 0.7620843648910522, 0.08140864223241806, 0.4882557988166809, 0.019841225817799568, 0.05279502272605896, 0.01341407373547554, 0.8174307942390442, 0.024278903380036354, 0.6846079230308533, 0.9660204648971558, 0.02498844638466835, 0.0645182803273201, 0.06545444577932358, 0.05297725275158882, 0.9388992786407471, 0.33690470457077026, 0.0214790478348732, 0.15520553290843964, 0.014546176418662071, 0.014784707687795162, 0.15396034717559814, 0.1592680811882019, 0.05003071576356888, 0.012521471828222275, 0.017569566145539284]... [Tensor of shape torch.Size([125175])]
dnam_rotation: [-0.0006869738572277129, 0.0038640284910798073, -0.0012635828461498022, 0.0007870842237025499, -0.0012677146587520838, 0.006102594546973705, 0.006675826385617256, -0.0004881693748757243, 0.0031523199286311865, -0.002742027398198843, 0.004634317941963673, -0.0022342982701957226, -0.003684432478621602, 0.005017344374209642, -0.00214009010232985, -0.004212546162307262, -0.001904419157654047, -0.001993611454963684, 0.0002256415318697691, 0.004155374597758055, 0.0018408787436783314, -0.004885646980255842, 0.00027931606746278703, 0.0003587851533666253, -0.0005096819368191063, -0.00012601316848304123, -0.0004541595990303904, -0.0010596434585750103, -0.0007061095675453544, -0.0007520628860220313]... [Tensor of shape torch.Size([125175, 4018])]
system_vector: [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -0.0002808159915730357, 0.0, 0.0, 0.27329912781715393, 0.0, 0.0, -0.11009273678064346, 0.19336724281311035, -0.14641909301280975, -0.761561393737793, 2.403021812438965, 0.15886220335960388, -0.03239140659570694, -0.07976681739091873, -0.06844867765903473, 0.0, -0.0005787260015495121]... [Tensor of shape torch.Size([4018, 84])]
system_labels: ['Blood',
'Brain',
'Inflammation',
'Heart',
'Hormone',
'Immune',
'Kidney',
'Liver',
'Metabolic',
'Lung',
'MusculoSkeletal']
system_component_indices: [tensor([0, 1, 2, 3, 4, 5, 6]),
tensor([ 7, 8, 9, 10, 11, 12]),
tensor([13, 14, 15]),
tensor([16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27]),
tensor([28]),
tensor([29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46,
47]),
tensor([48, 49, 50, 51, 52, 53]),
tensor([54, 55, 56, 57, 58, 59]),
tensor([65, 66, 67, 68, 69, 70]),
tensor([60, 61, 62, 63, 64]),
tensor([71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83])]
predicted_age_poly: tensor([-6.4341e+02, 2.1224e+00, -4.3686e-04])
transformation_coefs: [-0.13082726299762726, 0.08089754730463028, 701.9954223632812, 158.3132781982422, -0.20473948121070862, 0.10236957669258118, 701.9954223632812, 158.3132781982422, -0.050485897809267044, 0.12262580543756485, 701.9954223632812, 158.3132781982422, -0.1948918253183365, 0.14121989905834198, 701.9954223632812, 158.3132781982422, -0.3021743595600128, 0.24332834780216217, 701.9954223632812, 158.3132781982422, 0.04260144382715225, 0.041371069848537445, 701.9954223632812, 158.3132781982422, -0.10534755140542984, 0.17005649209022522, 701.9954223632812, 158.3132781982422, -0.08745717257261276, 0.18173155188560486]... [Tensor of shape torch.Size([13, 4])]
transformation_labels: ['Blood',
'Brain',
'Inflammation',
'Heart',
'Hormone',
'Immune',
'Kidney',
'Liver',
'Metabolic',
'Lung',
'MusculoSkeletal',
'Age_prediction',
'SystemsAge']
export_summary: {'files': {'dnam_pca_rotation': 'systemsage_dnam_pca_rotation.csv.gz',
'system_vector_coefficients': 'systemsage_system_vector_coefficients.csv.gz',
'systems_pca_rotation': 'systemsage_systems_pca_rotation.csv.gz'},
'n_cpgs': 125175,
'n_dnam_pcs': 4018,
'n_system_components': 84,
'n_systems': 13}
%==================================== Model Details ====================================%
Model Structure:
system_modules: ModuleList(
(0): LinearModel(
(linear): Linear(in_features=7, out_features=1, bias=True)
)
(1): LinearModel(
(linear): Linear(in_features=6, out_features=1, bias=True)
)
(2): LinearModel(
(linear): Linear(in_features=3, out_features=1, bias=True)
)
(3): LinearModel(
(linear): Linear(in_features=12, out_features=1, bias=True)
)
(4): LinearModel(
(linear): Linear(in_features=1, out_features=1, bias=True)
)
(5): LinearModel(
(linear): Linear(in_features=19, out_features=1, bias=True)
)
(6-8): 3 x LinearModel(
(linear): Linear(in_features=6, out_features=1, bias=True)
)
(9): LinearModel(
(linear): Linear(in_features=5, out_features=1, bias=True)
)
(10): LinearModel(
(linear): Linear(in_features=13, out_features=1, bias=True)
)
)
predicted_age_model: LinearModel(
(linear): Linear(in_features=4018, out_features=1, bias=True)
)
systems_pca_model: PCLinearModel(
(linear): Linear(in_features=12, out_features=1, bias=True)
)
%==================================== Model Details ====================================%
Model Parameters and Weights:
system_modules.0.linear.weight: tensor([[ 0.2417, -0.0264, 0.0000, -0.0299, -0.1483, 0.0530, -0.2911]])
system_modules.0.linear.bias: tensor([0.])
system_modules.1.linear.weight: tensor([[ 0.4734, 0.0093, -0.3984, -0.2834, 0.0000, 0.0000]])
system_modules.1.linear.bias: tensor([0.])
system_modules.2.linear.weight: tensor([[ 0.2195, 0.2346, -0.1890]])
system_modules.2.linear.bias: tensor([0.])
system_modules.3.linear.weight: tensor([[-0.0019, -0.0073, 0.0006, -0.0120, 0.0020, 0.0052, 0.0023, 0.0004,
0.0032, -0.0007, -0.0191, -0.0033]])
system_modules.3.linear.bias: tensor([0.])
system_modules.4.linear.weight: tensor([[-1.]])
system_modules.4.linear.bias: tensor([0.])
system_modules.5.linear.weight: tensor([[-0.0101, 0.0143, 0.0000, 0.0023, 0.0455, -0.0198, -0.0396, 0.0034,
0.0000, 0.0000, -0.0945, -0.1349, 0.0063, 0.1958, 0.0000, -0.0651,
-0.0975, -0.2673, 0.6696]])
system_modules.5.linear.bias: tensor([0.])
system_modules.6.linear.weight: tensor([[ 0.2375, 0.2883, 0.0232, -0.3228, 0.6635, 0.2668]])
system_modules.6.linear.bias: tensor([0.])
system_modules.7.linear.weight: tensor([[ 0.2323, -0.0565, 0.2820, 1.3307, 1.1750, -0.5682]])
system_modules.7.linear.bias: tensor([0.])
system_modules.8.linear.weight: tensor([[ 0.1536, 0.0000, 0.4502, -0.3308, -0.0246, -0.6582]])
system_modules.8.linear.bias: tensor([0.])
system_modules.9.linear.weight: tensor([[-0.0270, -0.2845, 0.2487, 0.0478, 0.2502]])
system_modules.9.linear.bias: tensor([0.])
system_modules.10.linear.weight: tensor([[-0.0066, -0.0189, -0.0063, -0.0091, 0.0029, 0.0033, 0.0000, -0.0229,
-0.0009, -0.0169, 0.0148, 0.0308, 0.0167]])
system_modules.10.linear.bias: tensor([0.])
predicted_age_model.linear.weight: [-0.2724407911300659, 1.3232460021972656, 0.0, 11.594740867614746, 2.8045454025268555, 10.507875442504883, 0.38123732805252075, 0.0, 24.096769332885742, 4.509000778198242, 7.230065822601318, 17.05602264404297, -17.76302146911621, -12.903092384338379, -10.236844062805176, -8.605022430419922, 2.662332534790039, 0.0, -0.39519476890563965, 11.368020057678223, -3.425773859024048, -4.283892631530762, 14.685194969177246, -5.893307209014893, 3.771191358566284, -25.85748863220215, 0.0, -2.187864065170288, -2.016566514968872, 0.0]... [Tensor of shape torch.Size([1, 4018])]
predicted_age_model.linear.bias: tensor([855.7034])
systems_pca_model.center: tensor([-1.3083e-01, -2.0474e-01, -5.0486e-02, -1.9489e-01, -1.0903e-01,
4.2601e-02, -1.0535e-01, -8.7457e-02, -2.1566e-01, 9.7069e-02,
1.0829e-02, 6.0997e+01])
systems_pca_model.rotation: [1.609099268913269, -0.06755393743515015, -1.0445926189422607, 0.33840256929397583, -1.9766627550125122, 3.0764424800872803, -2.3690080642700195, 0.1746765673160553, -1.2944000959396362, -0.45856714248657227, 1.5674749612808228, 0.6277533769607544, 1.1023108959197998, 1.7608975172042847, -1.2658442258834839, 0.8253107070922852, -1.4267181158065796, -0.2949528396129608, 0.23251882195472717, -1.6551636457443237, 1.9466115236282349, 0.8668460249900818, -0.7407866716384888, -0.3994610905647278, 1.125208854675293, -0.009071183390915394, 0.16698575019836426, -0.5564174056053162, 0.650899350643158, -0.5170385837554932]... [Tensor of shape torch.Size([12, 12])]
systems_pca_model.linear.weight: tensor([[ 1.2396, 0.6278, 2.1838, -0.1105, -0.6525, -0.4498, -0.9124, 0.4811,
0.0000, 0.2999, 0.0464, -0.0344]])
systems_pca_model.linear.bias: tensor([0.])
%==================================== Model Details ====================================%
Basic test#
[13]:
torch.manual_seed(42)
input_sample = torch.randn(1, len(model.features), dtype=torch.float32)
model.eval()
model.to(torch.float32)
pred = model(input_sample)
pred
[13]:
tensor([[170.6917]])
Save torch model#
[14]:
torch.save(model, f"../weights/{model.metadata['clock_name']}.pt")
Clear directory#
[ ]:
# Function to remove a folder and all its contents
def remove_folder(path):
try:
shutil.rmtree(path)
print(f"Deleted folder: {path}")
except Exception as e:
print(f"Error deleting folder {path}: {e}")
# Get a list of all files and folders in the current directory
all_items = os.listdir('.')
# Loop through the items
for item in all_items:
# Check if it's a file and does not end with .ipynb
if os.path.isfile(item) and not item.endswith('.ipynb'):
os.remove(item)
print(f"Deleted file: {item}")
# Check if it's a folder
elif os.path.isdir(item):
remove_folder(item)