Skip to content

Commit d99b53d

Browse files
committed
adjust pca metrics to use proportion, plot percent
1 parent 6fdbebc commit d99b53d

3 files changed

Lines changed: 10 additions & 12 deletions

File tree

gelos/analysis.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -262,11 +262,11 @@ def run_analysis(
262262
)
263263

264264
cache_path = layer_dir / f"{prefix}_{met_type}.csv"
265-
if cache_path.exists():
266-
logger.info(f"cached {met_type} result exists at {cache_path}, skipping")
267-
else:
268-
met_fn = METRICS[met_type]
269-
met_fn(embeddings, output_dir=layer_dir, prefix=prefix, **met_params)
265+
# if cache_path.exists():
266+
# logger.info(f"cached {met_type} result exists at {cache_path}, skipping")
267+
# else:
268+
met_fn = METRICS[met_type]
269+
met_fn(embeddings, output_dir=layer_dir, prefix=prefix, **met_params)
270270

271271
# --- Run plots ---
272272
for p_cfg in strategy_cfg.get("plots", []):

gelos/comp_plots.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def pca_ablation_table(
3232
pivot = df.pivot_table(
3333
index="experiment",
3434
columns="threshold",
35-
values="percent_of_total_components",
35+
values="proportion_of_total_components",
3636
aggfunc="first",
3737
)
3838

@@ -55,14 +55,14 @@ def pca_ablation_table(
5555
aggfunc="first",
5656
).reindex(index=pivot.index, columns=pivot.columns)
5757

58-
# Annotate cells with percent and total count
58+
# Annotate cells with proportion and total count
5959
for i in range(pivot.shape[0]):
6060
for j in range(pivot.shape[1]):
6161
pct = pivot.values[i, j]
6262
n = n_comp_pivot.values[i, j]
6363
if not np.isnan(pct):
6464
ax.text(
65-
j, i, f"{int(pct)}%\n({int(n)})",
65+
j, i, f"{int(pct*100)}%\n({int(n)})",
6666
ha="center", va="center", fontsize=9,
6767
)
6868

gelos/metrics.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,14 @@ def pca_ablation(
4141
{
4242
"threshold": threshold,
4343
"n_components": pca.n_components_,
44-
"percent_of_total_components": pca.n_components_ / D,
45-
"proportion_of_total_components": f"{pca.n_components_} / {D}",
44+
"proportion_of_total_components": pca.n_components_ / D,
4645
"total_variance_explained": float(pca.explained_variance_ratio_.sum()),
4746
}
4847
)
4948
logger.info(
5049
f"PCA ablation: threshold={threshold}, "
5150
f"n_components={pca.n_components_}, "
52-
f"percent_of_total_components={pca.n_components_ / D}, "
53-
f"proportion_of_total_components={pca.n_components_} / {D}, "
51+
f"proportion_of_total_components={pca.n_components_ / D}, "
5452
f"variance={pca.explained_variance_ratio_.sum():.4f}"
5553
)
5654

0 commit comments

Comments
 (0)