Skip to content

Commit 71cf3e0

Browse files
committed
Find the appropriate PCA pipeline to fetch components for.
1 parent 662f900 commit 71cf3e0

2 files changed

Lines changed: 19 additions & 8 deletions

File tree

src/components/convo-explorer/App.tsx

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -361,10 +361,21 @@ export const App: React.FC<AppProps> = ({ testAnimation = false, kedroBaseUrl, i
361361
} else if (metricConfig.type === "principal-components") {
362362
// Load principal component metrics (new logic)
363363
const componentIndex = metricConfig.component - 1; // Convert 1-based to 0-based index
364-
365-
// For principal components, we need to use the PCA pipeline, not the current pipeline
366-
const pcaPipelineId = kedroBaseUrl ? 'mean_pca_bestkmeans' : currentPipelineId;
367-
364+
365+
// Extract the imputer from the current pipeline ID and construct the PCA pipeline ID
366+
// e.g., "mean_localmap_bestkmeans" -> "mean_pca_bestkmeans"
367+
// e.g., "median_umap_bestkmeans" -> "median_pca_bestkmeans"
368+
const pipelineParts = currentPipelineId.split('_');
369+
let pcaPipelineId = 'mean_pca_bestkmeans'; // fallback default
370+
371+
if (pipelineParts.length >= 3) {
372+
const imputer = pipelineParts[0]; // e.g., "mean", "median"
373+
const clustering = "bestkmeans"; // alwasy assume "bestkmeans"
374+
pcaPipelineId = `${imputer}_pca_${clustering}`;
375+
}
376+
377+
console.log(`Using PCA pipeline "${pcaPipelineId}" derived from current pipeline "${currentPipelineId}"`);
378+
368379
const componentValues = await getPrincipalComponentValues(componentIndex, {
369380
kedroBaseUrl,
370381
pipelineId: pcaPipelineId

src/lib/kedro-api.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -573,11 +573,11 @@ export async function loadFullProjections(kedroBaseUrl?: string, pipelineId?: st
573573
const { resolveAssetPath } = await import('./paths');
574574
const projectionsUrl = resolveAssetPath('/projections.json');
575575
const response = await fetch(projectionsUrl);
576-
576+
577577
if (!response.ok) {
578578
throw new Error(`Failed to fetch local projections: ${response.status} ${response.statusText}`);
579579
}
580-
580+
581581
projectionsArray = await response.json();
582582
console.log('✅ Successfully loaded projections from local file');
583583
}
@@ -615,7 +615,7 @@ export async function getPrincipalComponentValues(
615615
try {
616616
// Load full projections data
617617
const fullProjections = await loadFullProjections(kedroBaseUrl, pipelineId);
618-
618+
619619
const componentValues = new Map<string, number>();
620620
let minValue = Infinity;
621621
let maxValue = -Infinity;
@@ -633,7 +633,7 @@ export async function getPrincipalComponentValues(
633633
// Second pass: normalize values to 0-1 range
634634
const normalizedValues = new Map<string, number>();
635635
const range = maxValue - minValue;
636-
636+
637637
if (range > 0) {
638638
componentValues.forEach((value, participantId) => {
639639
normalizedValues.set(participantId, (value - minValue) / range);

0 commit comments

Comments
 (0)