Spaces:
Running
Running
Update index.html
Browse files585 unmodified lines586587588589590589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625592593594595626627628629630597598599600601602603631632633634635636637605606607638639640609610641642643644645646647648585 unmodified lines }
// Helper to generate simple exponential/log trendline points function generateTrendline(data, quantileOffset) { if (data.length === 0) return []; function generateTrendline(data, quantileOffset = 0.5) { if (!data || data.length < 2) return [];
// 1. Sort data by parameter count (X) const sorted = [...data].sort((a, b) => a.x - b.x);
// 2. Compute Ordinary Least Squares (OLS) for Y = a * log10(X) + b let sumLnX = 0, sumY = 0, sumLnX2 = 0, sumLnXY = 0; const n = sorted.length;
sorted.forEach(p => { const logX = Math.log10(p.x); sumLnX += logX; sumY += p.y; sumLnX2 += logX * logX; sumLnXY += logX * p.y; });
const slope = (n * sumLnXY - sumLnX * sumY) / (n * sumLnX2 - sumLnX * sumLnX); const intercept = (sumY - slope * sumLnX) / n;
// 3. Calculate residuals to find standard deviation (for accurate top-10% curve) const residuals = sorted.map(p => p.y - (slope * Math.log10(p.x) + intercept)); const meanResidual = residuals.reduce((a, b) => a + b, 0) / n; const stdDev = Math.sqrt(residuals.reduce((sq, r) => sq + Math.pow(r - meanResidual, 2), 0) / n);
// Determine vertical offset based on quantile // quantileOffset = 0.5 -> Mean trend // quantileOffset = 0.9 -> Top 10% (~1.28 standard deviations above mean) let offset = 0; if (quantileOffset > 0.5) { // 1.28 * stdDev corresponds to the ~90th percentile in a normal distribution const zScore = quantileOffset >= 0.9 ? 1.28 : (quantileOffset - 0.5) * 2.56; offset = zScore * stdDev; }
// 4. Generate smooth curve points across log space const minLog = Math.log10(data[0].x); const maxLog = Math.log10(data[data.length - 1].x); const points = []; const steps = 20; const minLog = Math.log10(sorted[0].x); const maxLog = Math.log10(sorted[sorted.length - 1].x); const points = []; const steps = 30;
for (let i = 0; i <= steps; i++) { const currentLog = minLog + (i / steps) * (maxLog - minLog); const currentX = Math.pow(10, currentLog); // Simple logarithmic fit estimation: Y = a * log10(X) + b let estimatedY = 15 + 8 * (currentLog - 6); if (quantileOffset > 0.8) estimatedY += 12; // Push top 10% higher for (let i = 0; i <= steps; i++) { const currentLog = minLog + (i / steps) * (maxLog - minLog); const currentX = Math.pow(10, currentLog); // Y = fitted_line + quantile_offset let estimatedY = (slope * currentLog + intercept) + offset;
estimatedY = Math.min(98, Math.max(5, estimatedY)); points.push({ x: currentX, y: estimatedY }); } // Clamp between 0% and 100% estimatedY = Math.min(100, Math.max(0, estimatedY));
return points; } points.push({ x: currentX, y: estimatedY }); }
return points;}
function initShareChart() { const ctx = document.getElementById('shareChart').getContext('2d');index.html+53-18