@wafertools/wafermap 0.35.1 → 0.36.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +11 -8
- package/CHANGELOG.md +117 -0
- package/README.md +3 -3
- package/dist/packages/canvas-adapter/chartPrefs.d.ts +16 -0
- package/dist/packages/canvas-adapter/chartPrefs.js +1 -0
- package/dist/packages/canvas-adapter/charts/boxplot.js +1 -1
- package/dist/packages/canvas-adapter/charts/correlation.js +1 -1
- package/dist/packages/canvas-adapter/dataTab.js +1 -1
- package/dist/packages/canvas-adapter/drilldown.js +1 -1
- package/dist/packages/canvas-adapter/index.d.ts +1 -0
- package/dist/packages/canvas-adapter/index.js +1 -1
- package/dist/packages/canvas-adapter/insightsTab.d.ts +7 -0
- package/dist/packages/canvas-adapter/insightsTab.js +1 -1
- package/dist/packages/canvas-adapter/renderWaferGallery.d.ts +20 -5
- package/dist/packages/canvas-adapter/renderWaferGallery.js +1 -1
- package/dist/packages/canvas-adapter/renderWaferMap.d.ts +71 -37
- package/dist/packages/canvas-adapter/renderWaferMap.js +1 -1
- package/dist/packages/canvas-adapter/summaryPanel.d.ts +7 -4
- package/dist/packages/canvas-adapter/summaryPanel.js +4 -4
- package/dist/packages/canvas-adapter/testValueOffer.d.ts +14 -0
- package/dist/packages/canvas-adapter/testValueOffer.js +1 -0
- package/dist/packages/canvas-adapter/toCanvas.js +1 -1
- package/dist/packages/canvas-adapter/toolbar.d.ts +0 -6
- package/dist/packages/canvas-adapter/toolbar.js +1 -1
- package/dist/packages/canvas-adapter/userGuideHtml.d.ts +1 -1
- package/dist/packages/canvas-adapter/userGuideHtml.js +10 -3
- package/dist/packages/canvas-adapter/version.d.ts +2 -2
- package/dist/packages/canvas-adapter/version.js +1 -1
- package/dist/packages/canvas-adapter/warnings.js +1 -1
- package/dist/packages/core/aggregates.d.ts +10 -0
- package/dist/packages/core/aggregates.js +1 -1
- package/dist/packages/core/dieTable.d.ts +5 -0
- package/dist/packages/core/dieTable.js +1 -1
- package/dist/packages/core/wafer.d.ts +10 -1
- package/dist/packages/core/wafer.js +1 -1
- package/dist/packages/renderer/buildView.d.ts +5 -0
- package/dist/packages/renderer/buildView.js +1 -1
- package/dist/packages/renderer/buildWaferMap.d.ts +19 -4
- package/dist/packages/renderer/buildWaferMap.js +1 -1
- package/dist/packages/renderer/derivedTests/parser.js +1 -1
- package/dist/packages/renderer/fmt.d.ts +10 -0
- package/dist/packages/renderer/fmt.js +1 -1
- package/dist/packages/renderer/index.d.ts +1 -0
- package/dist/packages/renderer/index.js +1 -1
- package/dist/packages/renderer/valueFilter.d.ts +1 -1
- package/dist/packages/renderer/valueFilter.js +1 -1
- package/dist/packages/stats/analyzeWaferLot.d.ts +16 -0
- package/dist/packages/stats/analyzeWaferLot.js +1 -1
- package/dist/packages/stats/analyzeWaferMap.d.ts +18 -1
- package/dist/packages/stats/analyzeWaferMap.js +1 -1
- package/dist/packages/stats/clusterDetection.js +1 -1
- package/dist/packages/stats/connectedComponents.js +1 -1
- package/dist/packages/stats/correlation.d.ts +36 -4
- package/dist/packages/stats/correlation.js +1 -1
- package/dist/packages/stats/filterFindings.d.ts +1 -1
- package/dist/packages/stats/filterFindings.js +1 -1
- package/dist/packages/stats/findingText.d.ts +8 -0
- package/dist/packages/stats/findingText.js +2 -2
- package/dist/packages/stats/index.d.ts +2 -1
- package/dist/packages/stats/index.js +1 -1
- package/dist/packages/stats/lotDrift.js +1 -1
- package/dist/packages/stats/mergeTestDefs.js +1 -1
- package/dist/packages/stats/plotData.js +1 -1
- package/dist/packages/stats/renderSummaryReport.js +27 -27
- package/dist/packages/stats/reportHtml.d.ts +5 -12
- package/dist/packages/stats/reportHtml.js +96 -34
- package/dist/packages/stats/synthesis.d.ts +4 -0
- package/dist/packages/stats/synthesis.js +1 -1
- package/dist/packages/stats/testPassRate.js +1 -1
- package/dist/packages/stats/testValueBudget.d.ts +15 -0
- package/dist/packages/stats/testValueBudget.js +1 -0
- package/dist/packages/stats/types.d.ts +77 -22
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{stepDecimals as m}from"./axisTicks.js";const
|
|
1
|
+
import{stepDecimals as m}from"./axisTicks.js";const p=[[1e12,"T"],[1e9,"G"],[1e6,"M"],[1e3,"k"],[1,""],[.001,"m"],[1e-6,"\xB5"],[1e-9,"n"],[1e-12,"p"],[1e-15,"f"]];export const SI_PREFIX_SCALE={T:1e12,G:1e9,M:1e6,k:1e3,m:.001,\u00B5:1e-6,u:1e-6,n:1e-9,p:1e-12,f:1e-15},KNOWN_BASE_UNITS=["Hz","V","A","W","F","\u03A9","Ohm","ohm","S","H","J","C","s"];function M(t){for(const e of KNOWN_BASE_UNITS)if(t.length===e.length+1&&t.endsWith(e)){const r=t[0];if(r in SI_PREFIX_SCALE)return{preScale:SI_PREFIX_SCALE[r],base:e}}return{preScale:1,base:t}}function F(t,e){const{preScale:r,base:n}=M(e),o=t*r,i=Math.abs(o),[c,b]=p.find(([s])=>i>=s*.9999)??[1e-15,"f"],f=o/c,h=Math.abs(f),u=h>=100?0:h>=10?1:2;return`${f.toFixed(u)} ${b}${n}`}function $(t){const e=Math.abs(t),r=Math.floor(Math.log10(e)/3)*3,n=Math.max(-15,Math.min(12,r)),o=t/Math.pow(10,n),i=Math.abs(o),c=i>=100?0:i>=10?1:2,b=n===0?"":`E${n>0?"+":""}${n}`;return`${o.toFixed(c)}${b}`}export const AGGREGATION_METHOD_LABELS={mean:"mean",median:"median",stddev:"std dev",min:"min",max:"max",count:"count",countBin:"occurrence count",percent:"occurrence %"};export function fmtAggregationMethod(t){return AGGREGATION_METHOD_LABELS[t??""]??t??"aggregated"}export function plainBinTerms(t){return t.replace(/\bHBin\b/g,"hard bin").replace(/\bSBin\b/g,"soft bin")}export function fmtExact(t){if(!Number.isFinite(t)||Math.fround(t)!==t)return String(t);for(let e=1;e<=9;e++){const r=Number(t.toPrecision(e));if(Math.fround(r)===t)return String(r)}return String(t)}export function fmt(t,e,r){if(!isFinite(t))return String(t);const n=Math.abs(t);return n===0?e?`0 ${e}`:"0":e!==void 0?F(t,e):r==="si"?F(t,""):n>=.1&&n<1e4?n>=1e3?t.toFixed(0):n>=100?t.toFixed(1):n>=10?t.toFixed(2):t.toFixed(3):$(t)}function E(t,e){const r=e!==void 0&&e>0?m(e/t):void 0;return n=>{if(!isFinite(n))return String(n);if(n===0)return"0";const o=n/t;if(r!==void 0)return o.toFixed(r);const i=Math.abs(o),c=i>=100?0:i>=10?1:2;return o.toFixed(c)}}function A(t,e,r){if(e===void 0||!(e>0))return r;const n=m(e/t)+1;return o=>{if(!isFinite(o))return String(o);if(o===0)return"0";const i=(o/t).toFixed(n);return i.endsWith("0")?i.slice(0,n===1?-2:-1):i}}export function fmtColorbarAxis(t,e,r,n="engineering",o){const i=Math.abs(t),c=(s,d,a,x)=>{const g=x&&o===void 0?x:E(s,o);return{tickFmt:g,edgeFmt:A(s,o,g),axisLabel:d,scaledUnit:a}};if(r){const{preScale:s,base:d}=M(r),a=i*s,[x,g]=a===0?[1,""]:p.find(([S])=>a>=S*.9999)??[1e-15,"f"],l=`${g}${d}`;return c(x/s,e?`${e} (${l})`:l,l)}if(i===0||i>=.1&&i<1e4)return c(1,e??"","",s=>fmt(s,void 0,n));if(n==="si"){const[s]=p.find(([x])=>i>=x*.9999)??[1e-15,"f"],d=Math.round(Math.log10(s)),a=d===0?"":`\xD710E${d}`;return c(s,e?a?`${e} (${a})`:e:a,a)}const b=Math.floor(Math.log10(i)/3)*3,f=Math.max(-15,Math.min(12,b)),h=Math.pow(10,f),u=f===0?"":`\xD710E${f}`;return c(h,e?u?`${e} (${u})`:e:u,u)}
|
|
@@ -9,4 +9,5 @@ export type { ValueColorScheme, BinColorScheme } from './colorSchemes.js';
|
|
|
9
9
|
export type { BinColors, BinColorSource, MapBinColorOptions } from './binColors.js';
|
|
10
10
|
export { binColorsForMaps } from './binColors.js';
|
|
11
11
|
export { DERIVED_MARK, DERIVED_KEY } from './testLabel.js';
|
|
12
|
+
export { fmtExact } from './fmt.js';
|
|
12
13
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export{getDieKey}from"./buildView.js";export{buildWaferMap,getTestPassStatus}from"./buildWaferMap.js";export{registerValueColorScheme,listValueColorSchemes,resolveValueColorFn,registerBinColorScheme,listBinColorSchemes}from"./colorSchemes.js";export{binColorsForMaps}from"./binColors.js";export{DERIVED_MARK,DERIVED_KEY}from"./testLabel.js";
|
|
1
|
+
export{getDieKey}from"./buildView.js";export{buildWaferMap,getTestPassStatus}from"./buildWaferMap.js";export{registerValueColorScheme,listValueColorSchemes,resolveValueColorFn,registerBinColorScheme,listBinColorSchemes}from"./colorSchemes.js";export{binColorsForMaps}from"./binColors.js";export{DERIVED_MARK,DERIVED_KEY}from"./testLabel.js";export{fmtExact}from"./fmt.js";
|
|
@@ -47,7 +47,7 @@ export declare function applyValueFilter(table: DieTable, testDefs: readonly Tes
|
|
|
47
47
|
* The caption fragment for `testNumber` over `dies`: " · 3 values outside validity limits excluded", or ''
|
|
48
48
|
* when the filter took nothing out of them. One wording for every chart caption.
|
|
49
49
|
*/
|
|
50
|
-
export declare function excludedNote(dies: readonly DieData[], testNumber: number): string;
|
|
50
|
+
export declare function excludedNote(dies: readonly DieData[], testNumber: number | null): string;
|
|
51
51
|
/** Sums per-wafer outcomes into one (a lot is filtered wafer by wafer). */
|
|
52
52
|
export declare function mergeValueFilterTests(parts: readonly ValueFilterTest[][]): ValueFilterTest[];
|
|
53
53
|
/** The log line for an outcome: what was excluded, per test, and under which limits. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{excludedCountFor as m,withExcluded as p}from"../core/dieTable.js";import{isYieldEligibleDie as v}from"../core/dies.js";import{aboveHigh as w,belowLow as N}from"./spec.js";export function limitSetName(e){return e==="validity"?"validity limits":e==="spec"?"specification limits":"test limits"}function x(e,t){const n=t==="validity"?{low:e.validLow,high:e.validHigh}:t==="spec"?{low:e.specLow,high:e.specHigh}:{low:e.limitLow,high:e.limitHigh,lowInclusive:e.limitLowInclusive,highInclusive:e.limitHighInclusive};return n.low===void 0&&n.high===void 0?void 0:n}export function applyValueFilter(e,t,n){if(n==="none"||!t)return{table:e,tests:[]};const o=new Map,l=new Map,s=[];for(const i of t){if(i.testType==="F")continue;const u=x(i,n),c=e.values.get(i.testNumber);if(u===void 0||c===void 0)continue;let r,a,h=0,g=0;for(let d=0;d<c.length;d++){const f=c[d];Number.isNaN(f)||(h++,!(u.low!==void 0&&N(f,u.low,u.lowInclusive)||u.high!==void 0&&w(f,u.high,u.highInclusive)))||(r===void 0&&(r=c.slice(),a=new c.constructor(c.length).fill(NaN)),r[d]=NaN,a[d]=f,g++)}r===void 0||a===void 0||(o.set(i.testNumber,r),l.set(i.testNumber,a),s.push({testNumber:i.testNumber,excluded:g,total:h}))}return s.length===0?{table:e,tests:s}:{table:p(e,o,l,n),tests:s}}export function excludedNote(e,t){const n=t===null?void 0:m(e.filter(o=>v(o)),t);return n?` \xB7 ${n.count.toLocaleString("en-GB")} value${n.count===1?"":"s"} outside ${limitSetName(n.by)} excluded`:""}export function mergeValueFilterTests(e){const t=new Map;for(const n of e)for(const o of n){const l=t.get(o.testNumber);l?(l.excluded+=o.excluded,l.total+=o.total):t.set(o.testNumber,{...o})}return[...t.values()].sort((n,o)=>n.testNumber-o.testNumber)}export function valueFilterWarning(e,t,n){if(t.length===0)return;const o=i=>n?.find(u=>u.testNumber===i)?.name??`test ${i}`,l=t.reduce((i,u)=>i+u.excluded,0),s=t.slice(0,5).map(i=>`${o(i.testNumber)}: ${i.excluded} of ${i.total}`).join("; ")+(t.length>5?`; and ${t.length-5} more tests`:"");return{code:"values-excluded",message:`${l} value${l===1?"":"s"} outside the ${limitSetName(e)} treated as missing (${s}).`,severity:"info"}}
|
|
@@ -30,4 +30,20 @@ export declare function outlierWafers(yields: readonly number[]): {
|
|
|
30
30
|
export declare function analyzeWaferLot(items: AnalyzeWaferLotInput, options?: AnalyzeWaferMapOptions & {
|
|
31
31
|
perWaferSummaries?: StatsSummary[];
|
|
32
32
|
}): LotStatsSummary;
|
|
33
|
+
/** Options of {@link analyzeWaferLotAsync}: the lot's, with progress and cancellation. */
|
|
34
|
+
export interface AnalyzeWaferLotAsyncOptions extends AnalyzeWaferMapOptions {
|
|
35
|
+
perWaferSummaries?: StatsSummary[];
|
|
36
|
+
/** Called after each wafer is analysed, then once more with `done === total` before the lot-level pass. */
|
|
37
|
+
onProgress?: (done: number, total: number) => void;
|
|
38
|
+
/** Abort to stop between wafers; the promise rejects with the signal's reason. */
|
|
39
|
+
signal?: AbortSignal;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* `analyzeWaferLot` that hands control back to the browser between wafers, so a
|
|
43
|
+
* large lot does not hang the page while it is analysed — the same result, one
|
|
44
|
+
* test-value decision for the whole lot. It yields whenever about 100 ms of work
|
|
45
|
+
* has passed (a pause costs a frame; one per wafer would add a third to a big lot)
|
|
46
|
+
* and before the lot-level pass.
|
|
47
|
+
*/
|
|
48
|
+
export declare function analyzeWaferLotAsync(items: AnalyzeWaferLotInput, options?: AnalyzeWaferLotAsyncOptions): Promise<LotStatsSummary>;
|
|
33
49
|
//# sourceMappingURL=analyzeWaferLot.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{waferDisplayLabel as se}from"../core/waferLabel.js";import{requireRingCount as ae}from"../core/ringCount.js";import{analyzeWaferMap as G,candidatesOf as H,describeRegional as U,resolveOptions as re,adjustPValues as oe,twoProportionZ as Q,welchOfSums as X,rateRelativeEffect as ce,passesRateGate as le,severityForFinding as Z,severityForScore as J,collapseRedundantFindings as fe,findContiguousRuns as de,mergedRegionLabel as ue}from"./analyzeWaferMap.js";import{normalizeInput as me}from"./normalizeInput.js";import{poolCapability as ge,poolRegionYield as pe,poolPassRates as he}from"./summaryFigures.js";import{mergeTestDefs as ye}from"./mergeTestDefs.js";import{findingPatternKey as be}from"./filterFindings.js";import{median as ee}from"../core/utils.js";import{robustFence as te,zPValue as K}from"./math.js";import{findLotPattern as we}from"./lotPattern.js";import{buildDriftFindings as ve}from"./lotDrift.js";import{claimForPattern as Se,confirmRegionalFindings as ze,weakestMultiplier as Ie}from"./analyzeWaferMap.js";import{PATTERN_LABELS as ke}from"./patternClassification.js";import{describeWaferPopulation as Re,populationStat as Me}from"./population.js";const W=8,Pe={3:[.97,.994],4:[.829,.926],5:[.71,.821],6:[.625,.74],7:[.568,.68]},xe=3;export function outlierWafers(i){const o=i.length;if(o<3)return null;const r=ee([...i]),s=t=>Math.abs(t-r)>=xe;if(o>=W){const t=te(i,1.5,W),f=te(i,3,W);if(!t||!f)return null;const d=(t.hi-t.lo)/4,b=[];return i.forEach((y,a)=>{if(y>=t.lo&&y<=t.hi||!s(y))return;const e=y<f.lo||y>f.hi?"unusual":"notable";b.push({index:a,severity:e,statistic:(y-r)/d})}),{method:"tukey-fence",outliers:b}}const u=i.map((t,f)=>f).sort((t,f)=>i[t]-i[f]),g=i[u[o-1]]-i[u[0]];if(g===0)return null;const[n,c]=Pe[o],m=[],p=(t,f)=>{const d=Math.abs(i[t]-i[f])/g;d>n&&s(i[t])&&m.push({index:t,severity:d>c?"unusual":"notable",statistic:d})};return p(u[0],u[1]),p(u[o-1],u[o-2]),{method:"dixon-q",outliers:m}}const N=2;function T(i,o){const r={info:0,notable:1,unusual:2};return r[i]>=r[o]?i:o}const $e=new Set(["ring","quadrant","sector"]),Be=new Set(["ring","quadrant","sector","reticle-position","test-site"]),De=new Set(["yield","hardBin","softBin","functionalTest","test"]);function Le(i){return Be.has(i.comparison.family)&&De.has(i.variable.kind)}function Ee(i,o){const r=i.map(n=>n.facts);if(!r.length||r.some(n=>!n))return{coincident:new Set,yieldSoftBin:void 0,passBins:[],sectorCount:o};const[s,...u]=r,g=u.every(n=>n.passBins.length===s.passBins.length&&n.passBins.every(c=>s.passBins.includes(c)));return{coincident:new Set([...s.coincident].filter(n=>u.every(c=>c.coincident.has(n)))),yieldSoftBin:u.every(n=>n.yieldSoftBin===s.yieldSoftBin)?s.yieldSoftBin:void 0,passBins:g?s.passBins:[],sectorCount:o}}function _(i,o){let r=0,s=0,u=0,g=0,n=0,c=0,m=0,p=0,t=0,f=!0,d=0;for(const{waferIndex:a,c:e}of i){const l=o(a,e),h=e.rate??e.mean,S=Math.sqrt(h.n+l.n);if(e.rate)r+=S*Q(e.rate.hits,e.rate.n,l.hits,l.n),u+=e.rate.hits,g+=e.rate.n,n+=l.hits,c+=l.n;else{const v=X(e.mean,l.n,l.sum,l.sq);r+=S*v.z,m+=e.mean.n*v.effectSize,p+=e.mean.n*v.delta,d+=e.mean.n,e.relativeDelta===void 0?f=!1:t+=e.mean.n*e.relativeDelta}s+=S*S}const b=s>0?r/Math.sqrt(s):0,y=i[0].c;if(y.rate){const a=n/c,e=u/g-a;return{z:b,delta:e,relativeDelta:a===0?void 0:e/a,size:ce({hits:u,n:g,restHits:n,restN:c,passRate:y.rate.passRate})}}return{z:b,delta:p/d,relativeDelta:f?t/d:void 0,size:m/d}}function j(i,o,r,s){return i.rate?le(o,r.delta,r.size,s):o<=s.significanceLevel&&Math.abs(r.size)>=s.minimumEffectSize}function qe(i,o,r,s){const u=new Map;for(const{waferIndex:a,byKey:e}of i)for(const l of e.values())(u.get(l.key)??u.set(l.key,[]).get(l.key)).push({waferIndex:a,c:l});const g=new Map(i.map(a=>[a.waferIndex,a.byKey])),n=(a,e)=>e.rate?{hits:e.rate.restHits,n:e.rate.restN,sum:0,sq:0}:{hits:0,n:e.mean.restN,sum:e.mean.restSum,sq:e.mean.restSq},c=[];for(const[a,e]of u){if(e.length<N)continue;const l=_(e,n);if(l.z===0)continue;const h=e[0].c;c.push({key:a,entries:e,combined:l,finding:{id:`lot-region:${a}`,level:"lot",severity:"info",variable:{...h.variable,label:h.label},comparison:{...h.comparison},effect:{direction:l.z>0?"higher":"lower",absoluteDelta:l.delta,relativeDelta:l.relativeDelta,effectSize:h.rate?l.delta:l.size},stats:{method:"stouffer-z",pValue:K(l.z),sampleSizeLeft:0,sampleSizeRight:0},summary:"",highlight:{kind:"wafer",waferIndices:[]}}})}oe(c.map(a=>a.finding));const m=c.filter(a=>j(a.entries[0].c,a.finding.stats.adjustedPValue??1,a.combined,o)),f=ze(m,a=>{const e=a.entries[0].c;return[e.source,e.variable.kind,e.variable.bin??"",e.variable.index??"",e.region.family].join("\0")},(a,e)=>{const l=(M,B)=>{const k=n(M,B);for(const z of e){const R=g.get(M)?.get(z.key);R&&(R.rate?(k.hits-=R.rate.hits,k.n-=R.rate.n):(k.n-=R.mean.n,k.sum-=R.mean.sum,k.sq-=R.mean.sq))}return k},h=a.entries.filter(M=>l(M.waferIndex,M.c).n>=o.minimumSampleSize);if(!h.length)return"baseline-too-small";const S=_(h,l),v=a.finding.stats.pValue??1,$=v>0?(a.finding.stats.adjustedPValue??v)/v:1,w=Math.min(1,K(S.z)*$);return{pValue:w,passes:Math.sign(S.z)===Math.sign(a.combined.z)&&j(a.entries[0].c,w,S,o)}},a=>{const e=a.entries[0].c.rate;return e!==void 0&&(e.passRate?a.combined.z<0:a.combined.z>0)},c),d=[],b=new Map;for(const a of m){if(!f.has(a))continue;const e=a.finding.stats.pValue??1,l=Math.sign(a.combined.z),h=a.entries.filter(z=>Math.sign(z.c.delta)===l),S=i.length,v=a.entries[0].c,$=a.finding.stats.adjustedPValue??e,w=v.rate?Z($,a.combined.delta,a.combined.size):J($,a.combined.size),M=T(w,h.length/S>=.6?"unusual":"info"),B={};for(const z of h)B[z.waferIndex]=[...z.c.region.dieKeys];const k={...a.finding,severity:M,stats:{...a.finding.stats,sampleSizeLeft:h.length,sampleSizeRight:S-h.length},summary:`${U(v,a.combined.delta,a.combined.relativeDelta)} \u2014 ${a.finding.effect.direction} on ${h.length}/${S} wafers, all wafers' data combined`,highlight:{kind:"wafer",waferIndices:h.map(z=>z.waferIndex),dieKeysByWafer:B}};d.push(k),b.set(k,a)}const y=Fe(b,g,i.length,o,s,n);return d.splice(0,d.length,...d.filter(a=>!y.replaced.has(a)),...y.findings),fe(d,r),d}function Fe(i,o,r,s,u,g){const n=new Map;for(const[p,t]of i){const f=t.entries[0].c;if(!$e.has(f.region.family))continue;const d=[f.source,f.variable.kind,f.variable.bin??"",f.variable.index??"",f.region.family,p.effect.direction].join("|");(n.get(d)??n.set(d,[]).get(d)).push({finding:p,c:f,key:t.key})}const c=[],m=new Set;for(const p of n.values()){if(p.length<2)continue;const t=p[0].c.region.family;for(const f of de(p,t,s.sectorCount,d=>d.c.region.key)){if(f.length<2)continue;const d=Ke(f,o,r,s,u,g);if(d){c.push(d);for(const b of f)m.add(b.finding)}}}return{findings:c,replaced:m}}function Ke(i,o,r,s,u,g){const n=i[0].c,c=i[0].finding.effect.direction==="higher"?1:-1,m=ue(n.region.family,i.map(w=>w.c.region.key),u),p=[];for(const[w,M]of o){const B=i.map(I=>M.get(I.key));if(B.some(I=>!I))continue;const k=B,z=k[0];let R,A;if(z.rate){const I=k.reduce((x,D)=>x+D.rate.hits,0),P=k.reduce((x,D)=>x+D.rate.n,0),E=z.rate.hits+z.rate.restHits-I,L=z.rate.n+z.rate.restN-P;if(P<s.minimumSampleSize||L<s.minimumSampleSize)continue;R={...z,rate:{hits:I,n:P,restHits:E,restN:L,passRate:z.rate.passRate}},A=Q(I,P,E,L)}else{const I=z.mean,P=k.reduce((q,F)=>q+F.mean.n,0),E=k.reduce((q,F)=>q+F.mean.sum,0),L=k.reduce((q,F)=>q+F.mean.sq,0),x=I.n+I.restN-P,D=I.sum+I.restSum-E,O=I.sq+I.restSq-L;if(P<s.minimumSampleSize||x<s.minimumSampleSize)continue;const V={n:P,sum:E,sq:L,restN:x,restSum:D,restSq:O,shift:I.shift},C=X(V,x,D,O),Y=D/x+I.shift;R={...z,mean:V,relativeDelta:Y!==0?C.delta/Math.abs(Y):void 0},A=C.z}const ie=[...new Set(k.flatMap(I=>[...I.region.dieKeys]))];p.push({waferIndex:w,c:R,z:A,dieKeys:ie})}if(p.length<N)return;const t=_(p,g);if(t.z===0||Math.sign(t.z)!==c)return;const f=K(t.z),d=Ie(i.map(w=>w.finding)),b=Math.min(1,f*d);if(!j(n,b,t,s))return;const y=p.filter(w=>Math.sign(w.z)===c&&K(w.z)<=s.significanceLevel);if(!y.length)return;const a=n.rate?Z(b,t.delta,t.size):J(b,t.size),e=T(a,y.length/r>=.6?"unusual":"info"),l={};for(const w of y)l[w.waferIndex]=w.dieKeys;const h=i.map(w=>w.c.region.key.slice(w.c.region.key.indexOf(":")+1)).join("-"),S={...n,comparison:{...n.comparison,left:m}},v=i[0].finding,$=v.effect.direction;return{...v,id:`lot-region:${i[0].key.split("|").slice(0,-1).join("|")}|${n.region.family}:${h}`,severity:e,comparison:{...v.comparison,left:m},effect:{direction:$,absoluteDelta:t.delta,relativeDelta:t.relativeDelta,effectSize:n.rate?t.delta:t.size},stats:{method:"stouffer-z",pValue:f,adjustedPValue:b,sampleSizeLeft:y.length,sampleSizeRight:r-y.length},summary:`${U(S,t.delta,t.relativeDelta)} \u2014 ${$} on ${y.length}/${r} wafers, all wafers' data combined`,highlight:{kind:"wafer",waferIndices:y.map(w=>w.waferIndex),dieKeysByWafer:l},relatedIds:i.map(w=>w.finding.id)}}const ne={"Edge-ring":"edge","Edge-local":"edge","Center cluster":"centre or donut",Donut:"centre or donut"};function Ne(i,o){const r=new Map,s=n=>{const c=n.variable.kind==="spatialPattern"?ne[n.comparison.left]:void 0;return c?`spatialPattern|${c}`:be(n)};for(const n of i){const c=new Set,m=new Map;for(const t of n.summary.findings)if(t.variable.kind==="spatialPattern")for(const f of t.relatedIds??[])m.set(f,s(t));const p=new Set(n.summary.findings.flatMap(t=>t.absorbedIds??[]));for(const t of n.summary.findings){if(p.has(t.id)||Le(t)||t.variable.kind==="spatialPattern"&&o?.carriers.has(n.waferIndex))continue;const f=s(t);if(c.has(f))continue;c.add(f);const d=r.get(f)??{finding:t,waferIndices:[],severity:t.severity,labels:new Map,dieKeysByWafer:{},explainedBy:new Map};d.waferIndices.push(n.waferIndex);const b=m.get(t.id);if(b&&d.explainedBy.set(b,(d.explainedBy.get(b)??0)+1),t.variable.kind==="spatialPattern"){d.labels.set(t.comparison.left,(d.labels.get(t.comparison.left)??0)+1);const y=t.highlight.dieKeys;y&&(d.dieKeysByWafer[n.waferIndex]=y)}d.severity=T(d.severity,t.severity),r.set(f,d)}}const u=[];for(const[n,c]of r){if(c.waferIndices.length<N)continue;const m=c.waferIndices.length/Math.max(1,i.length),p=m>=.6||c.severity==="unusual"?"unusual":"notable",t=c.finding;u.push({id:`lot-repeat:${n}`,level:"lot",severity:p,variable:{...t.variable},comparison:{...t.comparison},effect:{direction:t.effect.direction,absoluteDelta:t.effect.absoluteDelta,relativeDelta:t.effect.relativeDelta,effectSize:t.effect.effectSize},stats:{method:"wafer-finding-frequency",sampleSizeLeft:c.waferIndices.length,sampleSizeRight:i.length-c.waferIndices.length},summary:`${Te(t,c.labels)} \u2014 seen on ${c.waferIndices.length}/${i.length} wafers (${Math.round(m*100)}%)`,highlight:{kind:"wafer",waferIndices:c.waferIndices,...c.labels.size?{dieKeysByWafer:c.dieKeysByWafer}:{}}})}const g=new Map(u.map(n=>[n.id,n]));for(const[n,c]of r){const m=g.get(`lot-repeat:${n}`);if(m)for(const[p,t]of c.explainedBy){const f=g.get(`lot-repeat:${p}`);!f||t!==c.waferIndices.length||(f.relatedIds??=[]).push(m.id)}}return u}function Ae(i,o){const{classification:r,carriers:s}=i,u=ke[r.pattern],g=s.size/Math.max(1,o),n={};for(const[c,m]of s)n[c]=m;return{id:"lot-repeat:spatialPattern|lot",level:"lot",severity:g>=.6||r.confidence==="high"?"unusual":"notable",variable:{kind:"spatialPattern",label:u},comparison:{family:"spatial-pattern",left:u,right:"Wafer"},effect:{direction:"different",effectSize:r.features.globalRdd},stats:{method:"wafer-finding-frequency",sampleSizeLeft:s.size,sampleSizeRight:o-s.size},summary:`Spatial pattern: ${u.toLowerCase()} \u2014 seen on ${s.size}/${o} wafers (${Math.round(g*100)}%)`,highlight:{kind:"wafer",waferIndices:[...s.keys()].sort((c,m)=>c-m),dieKeysByWafer:n}}}function We(i){const o=/^Rings? (\d+)(?:\s*[–-]\s*(\d+))?/.exec(i.comparison.left);if(!o)return[];const r=+o[1],s=o[2]?+o[2]:r;return Array.from({length:Math.max(0,s-r+1)},(u,g)=>r+g)}function Te(i,o){if(!o.size)return i.summary;const r=g=>g.toLowerCase();if(o.size===1)return`Spatial pattern: ${r([...o.keys()][0])}`;const s=ne[i.comparison.left],u=[...o].sort((g,n)=>n[1]-g[1]).map(([g,n])=>`${r(g)} on ${n}`);return`Spatial pattern: ${s} (${u.join(", ")})`}function _e(i,o){const r=Me(o,"median"),s=i.map(m=>({waferIndex:m.waferIndex,yieldPercent:m.summary.stats.yieldPercent})).filter(m=>m.yieldPercent!==null),u=s.map(m=>m.yieldPercent),g=outlierWafers(u);if(!g)return[];const n=ee(u),c=[];for(const{index:m,severity:p,statistic:t}of g.outliers){const f=s[m],d=f.yieldPercent-n,b=se({wafer:{metadata:i.find(y=>y.waferIndex===f.waferIndex)?.summary.wafer}},f.waferIndex);c.push({id:`inter-wafer:yield:${f.waferIndex}`,level:"inter-wafer",severity:p,variable:{kind:"yield",label:"Yield"},comparison:{family:"wafer",left:b,right:r.charAt(0).toUpperCase()+r.slice(1)},effect:{direction:d>0?"higher":"lower",absoluteDelta:d/100,relativeDelta:n===0?void 0:d/n,effectSize:t},stats:{method:g.method,sampleSizeLeft:1,sampleSizeRight:s.length-1},summary:`${b} yield is ${Math.abs(d).toFixed(1)} percentage points ${d>0?"higher":"lower"} than the ${r}`,highlight:{kind:"wafer",waferIndices:[f.waferIndex]}})}return c}export function analyzeWaferLot(i,o={}){const r=i.map(me),s=r.map((e,l)=>({waferIndex:l,summary:o.perWaferSummaries?.[l]??G(e,o)})),u=s.map(({waferIndex:e,summary:l})=>H(l)??H(G(r[e],o))),g=u.map((e,l)=>({waferIndex:l,byKey:new Map(e.candidates.map(h=>[h.key,h]))})),n=re(o).resolved,c=r.length>0?ae(r[0],"analyzeWaferLot"):void 0,m=we(r,n),p=m&&m.carriers.size>=N?m:null,t=[...c===void 0?[]:qe(g,n,Ee(u,n.sectorCount),c),...Ne(s,p),..._e(s,Re(s.map(e=>e.summary.wafer))),...ve(s,n.significanceLevel)];if(p&&c!==void 0){const e=Ae(p,s.length);e.relatedIds=Se([p.classification.pattern],e.severity,t,We,c),e.relatedIds.length||delete e.relatedIds,t.push(e)}t.sort((e,l)=>{const h=e.severity==="unusual"?2:e.severity==="notable"?1:0,S=l.severity==="unusual"?2:l.severity==="notable"?1:0;return h!==S?S-h:e.summary.localeCompare(l.summary,"en")});const f=s.map(e=>e.summary.wafer).filter(e=>!!e),d={},b=[];if(f.length>0){const e=new Set;for(const l of f)for(const h of Object.keys(l))e.add(h);e.delete("wafer"),e.delete("waferId");for(const l of e){const h=f.filter(v=>l in v).map(v=>v[l]);h.every(v=>v===h[0])?d[l]=h[0]:b.push(l)}}const y=s.map(({waferIndex:e,summary:l})=>({waferIndex:e,yieldPercent:l.stats.yieldPercent})),a=s.map(({waferIndex:e,summary:l})=>l.stats.perTestStats?.length?{waferIndex:e,tests:l.stats.perTestStats}:null).filter(e=>e!==null);return{level:"lot",hasNotableFindings:t.some(e=>e.severity!=="info")||s.some(e=>e.summary.hasNotableFindings),findings:t,lot:Object.keys(d).length>0?d:void 0,...b.length>0?{mixedIdentityFields:b}:{},stats:{waferCount:i.length,...je(r,s.map(e=>e.summary))},lotYieldSeries:y,perWafer:s,...a.length>0?{perWaferTestStats:a}:{}}}function je(i,o){const r={...he(o)},s=ge(o,ye(i).defs);s&&(r.capability=s);const u=pe(o,i.map(g=>g.ringCount));return u&&(r.regionYield=u),r}
|
|
1
|
+
import{waferDisplayLabel as oe}from"../core/waferLabel.js";import{requireRingCount as ce}from"../core/ringCount.js";import{analyzeWaferMapDecided as T,candidatesOf as H,describeRegional as U,resolveOptions as le,adjustPValues as fe,testValueSize as de,recordedOptions as ue,twoProportionZ as Q,welchOfSums as X,rateRelativeEffect as me,passesRateGate as pe,severityForFinding as Z,severityForScore as J,collapseRedundantFindings as ge,findContiguousRuns as he,mergedRegionLabel as ye}from"./analyzeWaferMap.js";import{normalizeInput as ee}from"./normalizeInput.js";import{autoDecision as we,lotTestValueStatus as be}from"./testValueBudget.js";import{poolCapability as Se,poolRegionYield as ve,poolPassRates as ze}from"./summaryFigures.js";import{mergeTestDefs as Ie}from"./mergeTestDefs.js";import{findingPatternKey as ke}from"./filterFindings.js";import{median as te}from"../core/utils.js";import{robustFence as ne,zPValue as F}from"./math.js";import{findLotPattern as Pe}from"./lotPattern.js";import{buildDriftFindings as Re}from"./lotDrift.js";import{claimForPattern as Me,confirmRegionalFindings as xe,weakestMultiplier as $e}from"./analyzeWaferMap.js";import{PATTERN_LABELS as De}from"./patternClassification.js";import{describeWaferPopulation as Be,populationStat as Le}from"./population.js";const W=8,Ee={3:[.97,.994],4:[.829,.926],5:[.71,.821],6:[.625,.74],7:[.568,.68]},qe=3;export function outlierWafers(e){const a=e.length;if(a<3)return null;const s=te([...e]),o=t=>Math.abs(t-s)>=qe;if(a>=W){const t=ne(e,1.5,W),d=ne(e,3,W);if(!t||!d)return null;const u=(t.hi-t.lo)/4,w=[];return e.forEach((y,l)=>{if(y>=t.lo&&y<=t.hi||!o(y))return;const f=y<d.lo||y>d.hi?"unusual":"notable";w.push({index:l,severity:f,statistic:(y-s)/u})}),{method:"tukey-fence",outliers:w}}const r=e.map((t,d)=>d).sort((t,d)=>e[t]-e[d]),m=e[r[a-1]]-e[r[0]];if(m===0)return null;const[i,c]=Ee[a],p=[],h=(t,d)=>{const u=Math.abs(e[t]-e[d])/m;u>i&&o(e[t])&&p.push({index:t,severity:u>c?"unusual":"notable",statistic:u})};return h(r[0],r[1]),h(r[a-1],r[a-2]),{method:"dixon-q",outliers:p}}const K=2;function O(e,a){const s={info:0,notable:1,unusual:2};return s[e]>=s[a]?e:a}const Ae=new Set(["ring","quadrant","sector"]),Fe=new Set(["ring","quadrant","sector","reticle-position","test-site"]),Ke=new Set(["yield","hardBin","softBin","functionalTest","test"]);function Ne(e){return Fe.has(e.comparison.family)&&Ke.has(e.variable.kind)}function Te(e,a){const s=e.map(i=>i.facts);if(!s.length||s.some(i=>!i))return{coincident:new Set,yieldSoftBin:void 0,passBins:[],sectorCount:a};const[o,...r]=s,m=r.every(i=>i.passBins.length===o.passBins.length&&i.passBins.every(c=>o.passBins.includes(c)));return{coincident:new Set([...o.coincident].filter(i=>r.every(c=>c.coincident.has(i)))),yieldSoftBin:r.every(i=>i.yieldSoftBin===o.yieldSoftBin)?o.yieldSoftBin:void 0,passBins:m?o.passBins:[],sectorCount:a}}function V(e,a){let s=0,o=0,r=0,m=0,i=0,c=0,p=0,h=0,t=0,d=!0,u=0;for(const{waferIndex:l,c:f}of e){const n=a(l,f),g=f.rate??f.mean,b=Math.sqrt(g.n+n.n);if(f.rate)s+=b*Q(f.rate.hits,f.rate.n,n.hits,n.n),r+=f.rate.hits,m+=f.rate.n,i+=n.hits,c+=n.n;else{const v=X(f.mean,n.n,n.sum,n.sq);s+=b*v.z,p+=f.mean.n*v.effectSize,h+=f.mean.n*v.delta,u+=f.mean.n,f.relativeDelta===void 0?d=!1:t+=f.mean.n*f.relativeDelta}o+=b*b}const w=o>0?s/Math.sqrt(o):0,y=e[0].c;if(y.rate){const l=i/c,f=r/m-l;return{z:w,delta:f,relativeDelta:l===0?void 0:f/l,size:me({hits:r,n:m,restHits:i,restN:c,passRate:y.rate.passRate})}}return{z:w,delta:h/u,relativeDelta:d?t/u:void 0,size:p/u}}function _(e,a,s,o){return e.rate?pe(a,s.delta,s.size,o):a<=o.significanceLevel&&Math.abs(s.size)>=o.minimumEffectSize}function We(e,a,s,o){const r=new Map;for(const{waferIndex:l,byKey:f}of e)for(const n of f.values())(r.get(n.key)??r.set(n.key,[]).get(n.key)).push({waferIndex:l,c:n});const m=new Map(e.map(l=>[l.waferIndex,l.byKey])),i=(l,f)=>f.rate?{hits:f.rate.restHits,n:f.rate.restN,sum:0,sq:0}:{hits:0,n:f.mean.restN,sum:f.mean.restSum,sq:f.mean.restSq},c=[];for(const[l,f]of r){if(f.length<K)continue;const n=V(f,i);if(n.z===0)continue;const g=f[0].c;c.push({key:l,entries:f,combined:n,finding:{id:`lot-region:${l}`,level:"lot",severity:"info",variable:{...g.variable,label:g.label},comparison:{...g.comparison},effect:{direction:n.z>0?"higher":"lower",absoluteDelta:n.delta,relativeDelta:n.relativeDelta,effectSize:g.rate?n.delta:n.size},stats:{method:"stouffer-z",pValue:F(n.z),sampleSizeLeft:0,sampleSizeRight:0},summary:"",highlight:{kind:"wafer",waferIndices:[]}}})}fe(c.map(l=>l.finding));const p=c.filter(l=>_(l.entries[0].c,l.finding.stats.adjustedPValue??1,l.combined,a)),d=xe(p,l=>{const f=l.entries[0].c;return[f.source,f.variable.kind,f.variable.bin??"",f.variable.index??"",f.region.family].join("\0")},(l,f)=>{const n=(M,D)=>{const k=i(M,D);for(const z of f){const R=m.get(M)?.get(z.key);R&&(R.rate?(k.hits-=R.rate.hits,k.n-=R.rate.n):(k.n-=R.mean.n,k.sum-=R.mean.sum,k.sq-=R.mean.sq))}return k},g=l.entries.filter(M=>n(M.waferIndex,M.c).n>=a.minimumSampleSize);if(!g.length)return"baseline-too-small";const b=V(g,n),v=l.finding.stats.pValue??1,P=v>0?(l.finding.stats.adjustedPValue??v)/v:1,S=Math.min(1,F(b.z)*P);return{pValue:S,passes:Math.sign(b.z)===Math.sign(l.combined.z)&&_(l.entries[0].c,S,b,a)}},l=>{const f=l.entries[0].c.rate;return f!==void 0&&(f.passRate?l.combined.z<0:l.combined.z>0)},c),u=[],w=new Map;for(const l of p){if(!d.has(l))continue;const f=l.finding.stats.pValue??1,n=Math.sign(l.combined.z),g=l.entries.filter(z=>Math.sign(z.c.delta)===n),b=e.length,v=l.entries[0].c,P=l.finding.stats.adjustedPValue??f,S=v.rate?Z(P,l.combined.delta,l.combined.size):J(P,l.combined.size),M=O(S,g.length/b>=.6?"unusual":"info"),D={};for(const z of g)D[z.waferIndex]=[...z.c.region.dieKeys];const k={...l.finding,severity:M,stats:{...l.finding.stats,sampleSizeLeft:g.length,sampleSizeRight:b-g.length},summary:`${U(v,l.combined.delta,l.combined.relativeDelta)} \u2014 ${l.finding.effect.direction} on ${g.length}/${b} wafers, all wafers' data combined`,highlight:{kind:"wafer",waferIndices:g.map(z=>z.waferIndex),dieKeysByWafer:D}};u.push(k),w.set(k,l)}const y=Oe(w,m,e.length,a,o,i);return u.splice(0,u.length,...u.filter(l=>!y.replaced.has(l)),...y.findings),ge(u,s),u}function Oe(e,a,s,o,r,m){const i=new Map;for(const[h,t]of e){const d=t.entries[0].c;if(!Ae.has(d.region.family))continue;const u=[d.source,d.variable.kind,d.variable.bin??"",d.variable.index??"",d.region.family,h.effect.direction].join("|");(i.get(u)??i.set(u,[]).get(u)).push({finding:h,c:d,key:t.key})}const c=[],p=new Set;for(const h of i.values()){if(h.length<2)continue;const t=h[0].c.region.family;for(const d of he(h,t,o.sectorCount,u=>u.c.region.key)){if(d.length<2)continue;const u=Ve(d,a,s,o,r,m);if(u){c.push(u);for(const w of d)p.add(w.finding)}}}return{findings:c,replaced:p}}function Ve(e,a,s,o,r,m){const i=e[0].c,c=e[0].finding.effect.direction==="higher"?1:-1,p=ye(i.region.family,e.map(S=>S.c.region.key),r),h=[];for(const[S,M]of a){const D=e.map(I=>M.get(I.key));if(D.some(I=>!I))continue;const k=D,z=k[0];let R,N;if(z.rate){const I=k.reduce(($,B)=>$+B.rate.hits,0),x=k.reduce(($,B)=>$+B.rate.n,0),E=z.rate.hits+z.rate.restHits-I,L=z.rate.n+z.rate.restN-x;if(x<o.minimumSampleSize||L<o.minimumSampleSize)continue;R={...z,rate:{hits:I,n:x,restHits:E,restN:L,passRate:z.rate.passRate}},N=Q(I,x,E,L)}else{const I=z.mean,x=k.reduce((q,A)=>q+A.mean.n,0),E=k.reduce((q,A)=>q+A.mean.sum,0),L=k.reduce((q,A)=>q+A.mean.sq,0),$=I.n+I.restN-x,B=I.sum+I.restSum-E,j=I.sq+I.restSq-L;if(x<o.minimumSampleSize||$<o.minimumSampleSize)continue;const C={n:x,sum:E,sq:L,restN:$,restSum:B,restSq:j,shift:I.shift},Y=X(C,$,B,j),G=B/$+I.shift;R={...z,mean:C,relativeDelta:G!==0?Y.delta/Math.abs(G):void 0},N=Y.z}const re=[...new Set(k.flatMap(I=>[...I.region.dieKeys]))];h.push({waferIndex:S,c:R,z:N,dieKeys:re})}if(h.length<K)return;const t=V(h,m);if(t.z===0||Math.sign(t.z)!==c)return;const d=F(t.z),u=$e(e.map(S=>S.finding)),w=Math.min(1,d*u);if(!_(i,w,t,o))return;const y=h.filter(S=>Math.sign(S.z)===c&&F(S.z)<=o.significanceLevel);if(!y.length)return;const l=i.rate?Z(w,t.delta,t.size):J(w,t.size),f=O(l,y.length/s>=.6?"unusual":"info"),n={};for(const S of y)n[S.waferIndex]=S.dieKeys;const g=e.map(S=>S.c.region.key.slice(S.c.region.key.indexOf(":")+1)).join("-"),b={...i,comparison:{...i.comparison,left:p}},v=e[0].finding,P=v.effect.direction;return{...v,id:`lot-region:${e[0].key.split("|").slice(0,-1).join("|")}|${i.region.family}:${g}`,severity:f,comparison:{...v.comparison,left:p},effect:{direction:P,absoluteDelta:t.delta,relativeDelta:t.relativeDelta,effectSize:i.rate?t.delta:t.size},stats:{method:"stouffer-z",pValue:d,adjustedPValue:w,sampleSizeLeft:y.length,sampleSizeRight:s-y.length},summary:`${U(b,t.delta,t.relativeDelta)} \u2014 ${P} on ${y.length}/${s} wafers, all wafers' data combined`,highlight:{kind:"wafer",waferIndices:y.map(S=>S.waferIndex),dieKeysByWafer:n},relatedIds:e.map(S=>S.finding.id)}}const ie={"Edge-ring":"edge","Edge-local":"edge","Center cluster":"centre or donut",Donut:"centre or donut"};function _e(e,a){const s=new Map,o=i=>{const c=i.variable.kind==="spatialPattern"?ie[i.comparison.left]:void 0;return c?`spatialPattern|${c}`:ke(i)};for(const i of e){const c=new Set,p=new Map;for(const t of i.summary.findings)if(t.variable.kind==="spatialPattern")for(const d of t.relatedIds??[])p.set(d,o(t));const h=new Set(i.summary.findings.flatMap(t=>t.absorbedIds??[]));for(const t of i.summary.findings){if(h.has(t.id)||Ne(t)||t.variable.kind==="spatialPattern"&&a?.carriers.has(i.waferIndex))continue;const d=o(t);if(c.has(d))continue;c.add(d);const u=s.get(d)??{finding:t,waferIndices:[],severity:t.severity,labels:new Map,dieKeysByWafer:{},explainedBy:new Map};u.waferIndices.push(i.waferIndex);const w=p.get(t.id);if(w&&u.explainedBy.set(w,(u.explainedBy.get(w)??0)+1),t.variable.kind==="spatialPattern"){u.labels.set(t.comparison.left,(u.labels.get(t.comparison.left)??0)+1);const y=t.highlight.dieKeys;y&&(u.dieKeysByWafer[i.waferIndex]=y)}u.severity=O(u.severity,t.severity),s.set(d,u)}}const r=[];for(const[i,c]of s){if(c.waferIndices.length<K)continue;const p=c.waferIndices.length/Math.max(1,e.length),h=p>=.6||c.severity==="unusual"?"unusual":"notable",t=c.finding;r.push({id:`lot-repeat:${i}`,level:"lot",severity:h,variable:{...t.variable},comparison:{...t.comparison},effect:{direction:t.effect.direction,absoluteDelta:t.effect.absoluteDelta,relativeDelta:t.effect.relativeDelta,effectSize:t.effect.effectSize},stats:{method:"wafer-finding-frequency",sampleSizeLeft:c.waferIndices.length,sampleSizeRight:e.length-c.waferIndices.length},summary:`${Ye(t,c.labels)} \u2014 seen on ${c.waferIndices.length}/${e.length} wafers (${Math.round(p*100)}%)`,highlight:{kind:"wafer",waferIndices:c.waferIndices,...c.labels.size?{dieKeysByWafer:c.dieKeysByWafer}:{}}})}const m=new Map(r.map(i=>[i.id,i]));for(const[i,c]of s){const p=m.get(`lot-repeat:${i}`);if(p)for(const[h,t]of c.explainedBy){const d=m.get(`lot-repeat:${h}`);!d||t!==c.waferIndices.length||(d.relatedIds??=[]).push(p.id)}}return r}function je(e,a){const{classification:s,carriers:o}=e,r=De[s.pattern],m=o.size/Math.max(1,a),i={};for(const[c,p]of o)i[c]=p;return{id:"lot-repeat:spatialPattern|lot",level:"lot",severity:m>=.6||s.confidence==="high"?"unusual":"notable",variable:{kind:"spatialPattern",label:r},comparison:{family:"spatial-pattern",left:r,right:"Wafer"},effect:{direction:"different",effectSize:s.features.globalRdd},stats:{method:"wafer-finding-frequency",sampleSizeLeft:o.size,sampleSizeRight:a-o.size},summary:`Spatial pattern: ${r.toLowerCase()} \u2014 seen on ${o.size}/${a} wafers (${Math.round(m*100)}%)`,highlight:{kind:"wafer",waferIndices:[...o.keys()].sort((c,p)=>c-p),dieKeysByWafer:i}}}function Ce(e){const a=/^Rings? (\d+)(?:\s*[–-]\s*(\d+))?/.exec(e.comparison.left);if(!a)return[];const s=+a[1],o=a[2]?+a[2]:s;return Array.from({length:Math.max(0,o-s+1)},(r,m)=>s+m)}function Ye(e,a){if(!a.size)return e.summary;const s=m=>m.toLowerCase();if(a.size===1)return`Spatial pattern: ${s([...a.keys()][0])}`;const o=ie[e.comparison.left],r=[...a].sort((m,i)=>i[1]-m[1]).map(([m,i])=>`${s(m)} on ${i}`);return`Spatial pattern: ${o} (${r.join(", ")})`}function Ge(e,a){const s=Le(a,"median"),o=e.map(p=>({waferIndex:p.waferIndex,yieldPercent:p.summary.stats.yieldPercent})).filter(p=>p.yieldPercent!==null),r=o.map(p=>p.yieldPercent),m=outlierWafers(r);if(!m)return[];const i=te(r),c=[];for(const{index:p,severity:h,statistic:t}of m.outliers){const d=o[p],u=d.yieldPercent-i,w=oe({wafer:{metadata:e.find(y=>y.waferIndex===d.waferIndex)?.summary.wafer}},d.waferIndex);c.push({id:`inter-wafer:yield:${d.waferIndex}`,level:"inter-wafer",severity:h,variable:{kind:"yield",label:"Yield"},comparison:{family:"wafer",left:w,right:s.charAt(0).toUpperCase()+s.slice(1)},effect:{direction:u>0?"higher":"lower",absoluteDelta:u/100,relativeDelta:i===0?void 0:u/i,effectSize:t},stats:{method:m.method,sampleSizeLeft:1,sampleSizeRight:o.length-1},summary:`${w} yield is ${Math.abs(u).toFixed(1)} percentage points ${u>0?"higher":"lower"} than the ${s}`,highlight:{kind:"wafer",waferIndices:[d.waferIndex]}})}return c}function se(e,a){if((a.enableTestValueAnalysis??"auto")!=="auto")return;let s=0;for(const o of e){const{tests:r,dies:m}=de(o,a);s+=r*m}return we(s)}export function analyzeWaferLot(e,a={}){const s=e.map(ee),o=se(s,a),r=s.map((n,g)=>({waferIndex:g,summary:a.perWaferSummaries?.[g]??T(n,a,o)})),m=r.map(({waferIndex:n,summary:g})=>H(g)??H(T(s[n],a,o))),i=m.map((n,g)=>({waferIndex:g,byKey:new Map(n.candidates.map(b=>[b.key,b]))})),c=le(a).resolved,p=s.length>0?ce(s[0],"analyzeWaferLot"):void 0,h=Pe(s,c),t=h&&h.carriers.size>=K?h:null,d=[...p===void 0?[]:We(i,c,Te(m,c.sectorCount),p),..._e(r,t),...Ge(r,Be(r.map(n=>n.summary.wafer))),...Re(r,c.significanceLevel)];if(t&&p!==void 0){const n=je(t,r.length);n.relatedIds=Me([t.classification.pattern],n.severity,d,Ce,p),n.relatedIds.length||delete n.relatedIds,d.push(n)}d.sort((n,g)=>{const b=n.severity==="unusual"?2:n.severity==="notable"?1:0,v=g.severity==="unusual"?2:g.severity==="notable"?1:0;return b!==v?v-b:n.summary.localeCompare(g.summary,"en")});const u=r.map(n=>n.summary.wafer).filter(n=>!!n),w={},y=[];if(u.length>0){const n=new Set;for(const g of u)for(const b of Object.keys(g))n.add(b);n.delete("wafer"),n.delete("waferId");for(const g of n){const b=u.filter(P=>g in P).map(P=>P[g]);b.every(P=>P===b[0])?w[g]=b[0]:y.push(g)}}const l=r.map(({waferIndex:n,summary:g})=>({waferIndex:n,yieldPercent:g.stats.yieldPercent})),f=r.map(({waferIndex:n,summary:g})=>g.stats.perTestStats?.length?{waferIndex:n,tests:g.stats.perTestStats}:null).filter(n=>n!==null);return{level:"lot",hasNotableFindings:d.some(n=>n.severity!=="info")||r.some(n=>n.summary.hasNotableFindings),findings:d,lot:Object.keys(w).length>0?w:void 0,...y.length>0?{mixedIdentityFields:y}:{},analysisOptions:ue(a),stats:{waferCount:e.length,...He(s,r.map(n=>n.summary)),...Ue(be(r.map(n=>n.summary)))},lotYieldSeries:l,perWafer:r,...f.length>0?{perWaferTestStats:f}:{}}}function He(e,a){const s={...ze(a)},o=Se(a,Ie(e).defs);o&&(s.capability=o);const r=ve(a,e.map(m=>m.ringCount));return r&&(s.regionYield=r),s}const Ue=e=>e?{testValueAnalysis:e}:{},ae=()=>new Promise(e=>setTimeout(e,0));export async function analyzeWaferLotAsync(e,a={}){const{onProgress:s,signal:o,...r}=a,m=e.map(ee),i=se(m,r),c=[];let p=Date.now();for(let h=0;h<m.length;h++)o?.throwIfAborted(),c.push(r.perWaferSummaries?.[h]??T(m[h],r,i)),s?.(h+1,m.length),Date.now()-p>100&&(await ae(),p=Date.now());return await ae(),o?.throwIfAborted(),analyzeWaferLot(m,{...r,perWaferSummaries:c})}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Die } from '../core/dies.js';
|
|
2
|
-
import type { TestDef, WaferWarning } from '../renderer/buildWaferMap.js';
|
|
2
|
+
import type { TestDef, WaferWarning, WaferMapResult } from '../renderer/buildWaferMap.js';
|
|
3
3
|
import type { AnalyzeWaferMapInput, AnalyzeWaferMapOptions, StatsFinding, StatsSeverity, StatsSummary } from './types.js';
|
|
4
4
|
import { type StatsRegion } from './regions.js';
|
|
5
5
|
import { type PatternLabel } from './patternClassification.js';
|
|
@@ -185,6 +185,17 @@ export declare function welchFromStats(leftN: number, leftMean: number, leftVar:
|
|
|
185
185
|
delta: number;
|
|
186
186
|
z: number;
|
|
187
187
|
};
|
|
188
|
+
/**
|
|
189
|
+
* The size of one built wafer's test-value analysis under `options`: the tests it
|
|
190
|
+
* would cover and the dies it reads, counted as `analyzeWaferMap` counts them. For
|
|
191
|
+
* `analyzeWaferLot`, which takes the `'auto'` decision over the whole lot.
|
|
192
|
+
*/
|
|
193
|
+
export declare function testValueSize(result: WaferMapResult, options: AnalyzeWaferMapOptions): {
|
|
194
|
+
tests: number;
|
|
195
|
+
dies: number;
|
|
196
|
+
};
|
|
197
|
+
/** The options a summary records (`analysisOptions`): the public ones that were passed. */
|
|
198
|
+
export declare function recordedOptions(options: AnalyzeWaferMapOptions): AnalyzeWaferMapOptions;
|
|
188
199
|
/**
|
|
189
200
|
* A connected set of quadrants in reading order round the wafer, starting after
|
|
190
201
|
* a gap when there is one ("NW, SW & SE", not whatever order the search met
|
|
@@ -217,5 +228,11 @@ export interface RedundancyFacts {
|
|
|
217
228
|
export declare function redundancyFacts(eligibleDies: EligibleDie[], passBins: number[], sectorCount: number): RedundancyFacts;
|
|
218
229
|
export declare function collapseRedundantFindings(findings: RawFinding[], facts: RedundancyFacts): void;
|
|
219
230
|
export declare function analyzeWaferMap(input: AnalyzeWaferMapInput, options?: AnalyzeWaferMapOptions): StatsSummary;
|
|
231
|
+
/**
|
|
232
|
+
* `analyzeWaferMap` with the `'auto'` test-value decision already taken — by
|
|
233
|
+
* `analyzeWaferLot`, over the whole lot, so each wafer follows it rather than its
|
|
234
|
+
* own size. Internal.
|
|
235
|
+
*/
|
|
236
|
+
export declare function analyzeWaferMapDecided(input: AnalyzeWaferMapInput, options?: AnalyzeWaferMapOptions, lotDecision?: 'done' | 'skipped'): StatsSummary;
|
|
220
237
|
export {};
|
|
221
238
|
//# sourceMappingURL=analyzeWaferMap.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{normalizeInput as Ze}from"./normalizeInput.js";import{computeCapability as Je,computeTestFlagYield as et,computeRegionYield as tt}from"./summaryFigures.js";import{binPassSets as xe}from"../renderer/binColors.js";import{diePassStatus as pe,isYieldEligibleDie as ge,getDieKey as be,isPositionedDie as Pe,positionKey as ye}from"../core/dies.js";import{dieHasValues as nt,testsPresent as Ce,testValue as j}from"../core/dieTable.js";import{getTestPassStatus as re,isParametricTest as _}from"../renderer/buildWaferMap.js";import{markedTestLabel as T,derivedFields as fe}from"../renderer/testLabel.js";import{buildQuadrantRegions as it,buildReticlePositionRegions as st,buildRingRegions as ot,buildSectorRegions as at,buildTestSiteRegions as rt,sectorCompassNames as Ve,areQuadrantsAdjacent as ft,parseRegionKey as Q,QUADRANT_CYCLE as Se,regionAngleBins as lt}from"./regions.js";import{buildClusterFindings as ct}from"./clusterDetection.js";import{classifyPattern as ut,patternExplains as dt,patternFailVerdict as mt,PATTERN_LABELS as ht}from"./patternClassification.js";import{requirePassBins as pt}from"../core/passBins.js";import{requireRingCount as gt}from"../core/ringCount.js";import{benjaminiHochberg as bt,fisherExact as yt,fiveNumberSummary as St,sampleVariance as we,zPValue as Ee}from"./math.js";import{mean as le,maxOf as wt}from"../core/utils.js";import{classifySpec as ce,isOutOfSpec as ve}from"../renderer/spec.js";const vt={significanceLevel:{min:1e-6,max:1},minimumEffectSize:{min:0,max:1},minimumRelativeEffect:{min:0,max:Number.MAX_SAFE_INTEGER}},Le=[4,8,16];export function resolveOptions(t){const n=Object.fromEntries(Object.entries(t).filter(([,r])=>r!==void 0)),i={...J,...n},s=[],e=[];for(const r of["significanceLevel","minimumEffectSize","minimumRelativeEffect"]){const{min:c,max:o}=vt[r],u=i[r];if(typeof u!="number"||!Number.isFinite(u)){e.push(`${r}=${String(u)} is not a finite number (using ${J[r]})`),i[r]=J[r];continue}const f=Math.min(o,Math.max(c,u));f!==u&&(e.push(`${r}=${u} is outside ${c}\u2013${o} (using ${f})`),i[r]=f)}if(Le.includes(i.sectorCount)||(e.push(`sectorCount=${i.sectorCount} is not one of ${Le.join(", ")} (using ${J.sectorCount})`),i.sectorCount=J.sectorCount),e.length){const r=`analyzeWaferMap: ${e.join("; ")}. The analysis ran with the corrected values.`;console.warn(`[wafermap] ${r}`),s.push({code:"analysis-option-corrected",message:r,severity:"warning"})}const a=["passBins","ringCount"].filter(r=>n[r]!==void 0);if(a.length){const r=`analyzeWaferMap: ${a.join(" and ")} ${a.length>1?"are":"is"} no longer an analysis option and was ignored. Set ${a.length>1?"them":"it"} on buildWaferMap; the analysis used the value the map was built with.`;console.warn(`[wafermap] ${r}`),s.push({code:"analysis-option-corrected",message:r,severity:"warning"})}const l=["enableYieldAnalysis","enableHardBinAnalysis","enableSoftBinAnalysis","enableReticlePositionAnalysis","enableTestSiteAnalysis","enableClusterAnalysis","enableAngularAnalysis","enablePatternClassification"].filter(r=>n[r]!==void 0);if(l.length){const r=`analyzeWaferMap: ${l.join(", ")} ${l.length>1?"are":"is"} no longer an option and was ignored: every analysis now runs. Filter the findings (filterFindings) to show fewer.`;console.warn(`[wafermap] ${r}`),s.push({code:"analysis-option-corrected",message:r,severity:"warning"})}return{resolved:i,warnings:s}}const J={significanceLevel:.05,minimumEffectSize:.2,minimumRelativeEffect:1,minimumSampleSize:5,enableTestValueAnalysis:!1,computePerTestStats:!1,sectorCount:8,minimumClusterSize:5};function $t(t,n){const i={...t};return i.minimumClusterSize=Math.max(5,Math.round(n*.003)),i}function kt(t){return ge(t)?t.hbin!==void 0||t.sbin!==void 0||nt(t):!1}function Rt(t,n,i){if(!t||n)return;const s=(i??[]).filter(e=>_(e)&&(e.limitLow!==void 0||e.limitHigh!==void 0));if(s.length!==0)return e=>{for(const a of s)if(ve(ce(j(e,a.testNumber),a)))return!0;return!1}}function Dt(t,n,i){const s=new Set,e=new Set,a=new Set,l=new Map,r=new Map;for(const c of Ce(t))s.add(c);for(const c of t)c.hbin!==void 0&&e.add(c.hbin),c.sbin!==void 0&&a.add(c.sbin),ge(c)&&(c.hbin!==void 0&&l.set(c.hbin,(l.get(c.hbin)??0)+1),c.sbin!==void 0&&r.set(c.sbin,(r.get(c.sbin)??0)+1));return{totalDies:t.length,analyzedDies:n,excludedDies:t.length-n,yieldPercent:i,testsConsidered:[...s].sort((c,o)=>c-o),hardBinsConsidered:[...e].sort((c,o)=>c-o),softBinsConsidered:[...a].sort((c,o)=>c-o),...l.size?{hardBinCounts:Object.fromEntries(l)}:{},...r.size?{softBinCounts:Object.fromEntries(r)}:{}}}function Mt(t,n,i){if(!n?.length)return;const s=n.filter(a=>_(a)&&(a.limitLow!==void 0||a.limitHigh!==void 0));if(!s.length)return;const e=[];for(const a of s){const l=a.testNumber;let r=0,c=0,o=0,u=0;for(const f of t){if(f.partial||f.edgeExcluded)continue;const h=ce(j(f,l),a);if(h!==null){if(u++,h==="failLow")c++;else if(h==="failHigh")o++;else{r++;continue}i?.(l,f)}}e.push({testNumber:l,label:a.name,passDies:r,failLowDies:c,failHighDies:o,totalDies:u,yieldPercent:u>0?r/u*100:null})}return e.length?e:void 0}export function computeFunctionalYield(t,n,i){if(!n?.length)return;const s=n.filter(a=>!_(a));if(!s.length)return;const e=[];for(const a of s){const l=a.testNumber;let r=0,c=0;for(const u of t){if(u.partial||u.edgeExcluded)continue;const f=re(u,l,a);if(f!==void 0){if(f){r++;continue}c++,i?.(l,u)}}const o=r+c;e.push({testNumber:l,label:T(a,l),...fe(a),passDies:r,failDies:c,totalDies:o,passRatePercent:o>0?r/o*100:null})}return e.length?e:void 0}function zt(t,n,i,s){const e=[];for(const a of n){const l=[];for(const f of t){if(f.partial||f.edgeExcluded)continue;const h=j(f,a);h!==void 0&&Number.isFinite(h)&&l.push(h)}if(l.length<s)continue;const r=le(l),c=Math.sqrt(we(l,r)),o=St(Float64Array.from(l)),u=i?.find(f=>f.testNumber===a)?.name??String(a);e.push({testNumber:a,label:u,count:l.length,min:o.min,max:o.max,mean:r,stddev:c,median:o.median,q1:o.q1,q3:o.q3})}return e.length?e:void 0}export function twoProportionZ(t,n,i,s){const e=(t+i)/(n+s),a=e*(1-e)*(1/n+1/s);return!Number.isFinite(a)||a<=0?0:(t/n-i/s)/Math.sqrt(a)}const Bt=5;function q(t,n,i,s){const e=n+s,a=t+i;if((e>0?Math.min(a,e-a)*Math.min(n,s)/e:0)<Bt)return{pValue:yt(t,n-t,i,s-i),method:"fisher-exact"};const r=twoProportionZ(t,n,i,s);return{pValue:r===0?1:Ee(r),method:"two-proportion-z"}}function Ft(t,n,i,s){return q(t,n,i,s).pValue}export function adjustPValues(t){const n=t.filter(s=>s.stats.pValue!==void 0),i=bt(n.map(s=>s.stats.pValue));return n.forEach((s,e)=>{s.stats.adjustedPValue=i[e]}),t}export function rateRelativeEffect(t){const n=(t.passRate?t.n-t.hits:t.hits)/t.n,i=(t.passRate?t.restN-t.restHits:t.restHits)/t.restN;return i===0?n===0?0:1/0:Math.abs(n-i)/i}export function severityForFinding(t,n,i){const s=Math.abs(n),e=i;return t<=.01&&(s>=.3||e>=2.5)?"unusual":t<=.05&&(s>=.2||e>=1.5)?"notable":"info"}export function severityForScore(t,n){return t<=.01&&Math.abs(n)>=.5?"unusual":t<=.05&&Math.abs(n)>=.15?"notable":"info"}function ue(t){return t==="reticle-position"?"other reticle positions":t==="test-site"?"other test sites":"the rest of the map"}function U(t){return t==="reticle-position"?"Other reticle positions":t==="test-site"?"Other test sites":"Rest of map"}function $e(t,n,i){const s=(Math.abs(n)*100).toFixed(1);return`${t} yield is ${s} percentage points ${n>0?"higher":"lower"} than ${ue(i)}`}function ke(t,n){return n==="quadrant"&&!t.startsWith("Quadrant")?`quadrant ${t}`:t}function Ke(t){return/^(Rings|Sectors|Quadrants)\b/.test(t)?"have":"has"}function Re(t,n,i,s){const e=ke(t,s),a=(Math.abs(i)*100).toFixed(1);return`${e} ${Ke(e)} ${n} occurrence ${a} percentage points ${i>0?"higher":"lower"} than ${ue(s)}`}function De(t,n,i,s){const e=ke(t,s),a=(Math.abs(i)*100).toFixed(1);return`${e} ${Ke(e)} ${n} pass rate ${a} percentage points ${i>0?"higher":"lower"} than ${ue(s)}`}function Me(t,n,i,s,e,a){const l=ke(t,e),r=ue(e),c=i>0?"higher":"lower";if(s!==void 0&&Number.isFinite(s)){const u=(Math.abs(s)*100).toFixed(1);return`${l} mean ${n} is ${u}% ${c} than ${r}`}const o=a?` ${a}`:"";return`${l} mean ${n} is ${Math.abs(i).toPrecision(3)}${o} ${c} than ${r}`}function Oe(t,n,i){const s=n?.find(e=>e.bin===t);return s?.name?`${i} ${t} (${s.name})`:`${i} ${t}`}function Nt(t,n){const i=n?.find(s=>s.testNumber===t);return{label:T(i,t),unit:i?.unit,...fe(i)}}const qe=new WeakMap,Te=new WeakMap,Ae=new WeakMap;function ee(t,n){const i=n.highlight.dieKeys;return i&&Ae.set(i,t),n}let G=null,te;const je=new WeakMap;export function candidatesOf(t){return je.get(t)}function He(t,n,i,s){if(!G)return;const e=Ie(t);if(!e)return;const a=t.id.slice(0,t.id.indexOf(":")),l=a==="specLimit"?"limitFail":a,{kind:r,bin:c,index:o}=t.variable;G.push({key:[l,r,c??"",o??"",e.family,e.key].join("|"),source:l,variable:t.variable,label:t.variable.label,comparison:t.comparison,region:e,z:n,delta:t.effect.absoluteDelta??0,effectSize:t.effect.effectSize??0,relativeDelta:t.effect.relativeDelta,rate:i,mean:s})}export function describeRegional(t,n,i){const s=t.comparison.left,e=t.region.family;switch(t.source){case"yield":return $e(s,n,e);case"hardBin":case"softBin":return Re(s,t.label,n,e);case"functional":return De(s,t.label.replace(/ pass rate$/,""),n,e);case"limitFail":return ze(s,t.label,n);case"test":return Me(s,t.label,n,i,e,t.variable.unit)}}function ze(t,n,i){return`${t} limit fail rate for ${n} is ${(Math.abs(i)*100).toFixed(1)} pp ${i>0?"higher":"lower"} than the rest of the wafer`}const H=new WeakMap;function de(t,n){return H.set(t,n),t}function Ie(t){const n=t.highlight.dieKeys;return n?Ae.get(n):void 0}const We=new WeakMap;function I(t){let n=We.get(t);return n||We.set(t,n=t.map(ye)),n}function xt(t){let n=qe.get(t);return n||qe.set(t,n=t.map(be)),n}function me(t,n){let i=Te.get(t);i||Te.set(t,i={members:new Set(t),byFamily:new WeakMap});const s=i.byFamily.get(n);if(s)return s;const{members:e}=i,a=new Map;for(const l of n)a.set(l.key,l.dies.filter(r=>e.has(r)));return i.byFamily.set(n,a),a}function Pt(t,n){adjustPValues(t);for(const e of t){const a=H.get(e);He(e,twoProportionZ(a.hits,a.n,a.restHits,a.restN),a)}const i=t.filter(e=>passesRateGate(e.stats.adjustedPValue??e.stats.pValue??1,e.effect.absoluteDelta??0,rateRelativeEffect(H.get(e)),n)),s=confirmRegionalFindings(i,Ye,(e,a)=>Ct(e,a,n),e=>isRateLoss(H.get(e)),t);return i.filter(e=>s.has(e)).map(e=>({...e,severity:severityForFinding(e.stats.adjustedPValue??e.stats.pValue??1,e.effect.absoluteDelta??0,rateRelativeEffect(H.get(e)))}))}export function passesRateGate(t,n,i,s){return t<=s.significanceLevel&&(Math.abs(n)>=s.minimumEffectSize||i>=s.minimumRelativeEffect)}export function claimForPattern(t,n,i,s,e){const a=[];for(const l of i){const r=l.comparison.family,c=r==="ring"?s(l):[];t.some(o=>dt(o,r,c,e))&&(a.push(l.id),n!=="info"&&(r==="ring"||r==="quadrant"||r==="sector")&&(l.severity="info"))}return a}export function confirmRegionalFindings(t,n,i,s,e=t){const a=new Map;for(const c of t)(a.get(n(c))??a.set(n(c),[]).get(n(c))).push(c);const l=new Map;if(s)for(const c of e)s(c)&&(l.get(n(c))??l.set(n(c),[]).get(n(c))).push(c);const r=new Set;for(const[c,o]of a){const u=l.get(c)??[],f=(d,p)=>s&&!s(d)?i(d,[...new Set([...p,...u])].filter(m=>m!==d)):i(d,p);if(o.length===1){r.add(o[0]);continue}const h=[];let b=[...o];for(;;){let d;for(const p of b){const m=f(p,h);if(m==="baseline-too-small"||!m.passes)continue;const S=s?.(p)??!1;(!d||S&&!d.loss||S===d.loss&&m.pValue<d.p)&&(d={t:p,p:m.pValue,loss:S})}if(!d)break;h.push(d.t),b=b.filter(p=>p!==d.t)}for(;;){let d;for(const p of h){const m=f(p,h.filter(S=>S!==p));m==="baseline-too-small"||m.passes||(!d||m.pValue>d.p)&&(d={t:p,p:m.pValue})}if(!d)break;h.splice(h.indexOf(d.t),1)}for(const d of h)r.add(d)}return r}function Ye(t){return[t.variable.kind,t.variable.bin??"",t.variable.index??"",t.comparison.family].join("\0")}function _e(t){const n=t.stats.pValue??1;return n>0?(t.stats.adjustedPValue??n)/n:1}export function isRateLoss(t){const n=t.hits/t.n-t.restHits/t.restN;return t.passRate?n<0:n>0}function Ct(t,n,i){const s=H.get(t);let{restHits:e,restN:a}=s;for(const o of n){const u=H.get(o);u&&(e-=u.hits,a-=u.n)}if(a<i.minimumSampleSize)return"baseline-too-small";const l=s.hits/s.n-e/a,r=Math.min(1,Ft(s.hits,s.n,e,a)*_e(t)),c=Math.sign(l)===Math.sign(t.effect.absoluteDelta??0)&&passesRateGate(r,l,rateRelativeEffect({...s,restHits:e,restN:a}),i);return{pValue:r,passes:c}}const Be=new WeakMap;export function welchOfSums(t,n,i,s){const e=(a,l,r)=>r>1?Math.max(0,a-l*l/r)/(r-1):0;return welchFromStats(t.n,t.sum/t.n,e(t.sq,t.sum,t.n),n,i/n,e(s,i,n))}function Vt(t,n,i){const s=Be.get(t);let{restN:e,restSum:a,restSq:l}=s;for(const h of n){const b=Be.get(h);b&&(e-=b.n,a-=b.sum,l-=b.sq)}if(e<i.minimumSampleSize)return"baseline-too-small";const{pValue:r,effectSize:c,delta:o}=welchOfSums(s,e,a,l),u=Math.min(1,r*_e(t)),f=Math.sign(o)===Math.sign(t.effect.absoluteDelta??0)&&u<=i.significanceLevel&&Math.abs(c)>=i.minimumEffectSize;return{pValue:u,passes:f}}function ne(t,n,i,s){const e=new Set(i),a=me(t,n),l=new Map,r=new Map;for(const[o,u]of a){let f=0,h=0;for(const b of u)b.hbin!==void 0&&(h++,e.has(b.hbin)&&f++);l.set(o,f),r.set(o,h)}const c=[];for(const o of n){const u=r.get(o.key)??0,f=l.get(o.key)??0;let h=0,b=0;for(const[w,M]of r)w!==o.key&&(h+=M,b+=l.get(w)??0);if(u<s.minimumSampleSize||h<s.minimumSampleSize)continue;const d=f/u,p=b/h,m=d-p,{pValue:S,method:D}=q(f,u,b,h);c.push(de(ee(o,{id:`yield:${o.key}`,level:"wafer",severity:"info",variable:{kind:"yield",label:"Yield"},comparison:{family:o.family,left:o.label,right:U(o.family)},effect:{direction:m===0?"different":m>0?"higher":"lower",absoluteDelta:m,relativeDelta:p===0?void 0:m/p,effectSize:m},stats:{method:D,pValue:S,sampleSizeLeft:u,sampleSizeRight:h},summary:$e(o.label,m,o.family),highlight:{kind:"region",regionFamily:o.family,regionKeys:[o.key],dieKeys:[...o.dieKeys]}}),{hits:f,n:u,restHits:b,restN:h,passRate:!0}))}return c}function O(t,n,i,s,e,a){const l=d=>i==="soft"?d.sbin:d.hbin,r=[...new Set(t.map(l).filter(d=>d!==void 0))].sort((d,p)=>d-p),c=me(t,n),o=new Map,u=new Map;for(const[d,p]of c){const m=new Map;for(const S of p){const D=l(S);D!==void 0&&m.set(D,(m.get(D)??0)+1)}o.set(d,m),u.set(d,p.length)}const f=[],h=e==="hardBin"?"HBin":"SBin",b=i==="hard"?new Set(a.passBins):a.softPassBins??xe(t,a.passBins).soft;for(const d of n){const p=u.get(d.key)??0,m=o.get(d.key);let S=0;const D=new Map;for(const[w,M]of o)if(w!==d.key){S+=u.get(w)??0;for(const[z,N]of M)D.set(z,(D.get(z)??0)+N)}if(!(p<a.minimumSampleSize||S<a.minimumSampleSize))for(const w of r){const M=m.get(w)??0,z=D.get(w)??0,N=M/p,y=z/S,$=N-y,{pValue:v,method:k}=q(M,p,z,S),R=Oe(w,s,h);f.push(de(ee(d,{id:`${e}:${w}:${d.key}`,level:"wafer",severity:"info",variable:{kind:e,bin:w,label:R},comparison:{family:d.family,left:d.label,right:U(d.family)},effect:{direction:$===0?"different":$>0?"higher":"lower",absoluteDelta:$,relativeDelta:y===0?void 0:$/y,effectSize:$},stats:{method:k,pValue:v,sampleSizeLeft:p,sampleSizeRight:S},summary:Re(d.label,R,$,d.family),highlight:{kind:"bin",bin:w,regionKeys:[d.key],dieKeys:[...d.dieKeys]}}),{hits:M,n:p,restHits:z,restN:S,passRate:b.has(w)}))}}return f}function ie(t,n,i,s){const e=(i??[]).filter(u=>!_(u));if(!e.length)return[];const a=e.map(u=>u.testNumber),l=me(t,n),r=new Map,c=new Map;for(const[u,f]of l){const h=new Uint32Array(e.length),b=new Uint32Array(e.length);for(const d of f)for(let p=0;p<e.length;p++){const m=re(d,a[p],e[p]);m!==void 0&&(b[p]++,m&&h[p]++)}r.set(u,h),c.set(u,b)}const o=[];for(const u of n){const f=r.get(u.key),h=c.get(u.key);for(let b=0;b<e.length;b++){let d=0,p=0;for(const[$,v]of c)$!==u.key&&(p+=v[b],d+=r.get($)[b]);const m=h[b],S=f[b];if(m<s.minimumSampleSize||p<s.minimumSampleSize)continue;const D=S/m,w=d/p,M=D-w,{pValue:z,method:N}=q(S,m,d,p),y=a[b];o.push(de(ee(u,{id:`functional:${y}:${u.key}`,level:"wafer",severity:"info",variable:{kind:"functionalTest",index:y,label:`${T(e[b],y)} pass rate`,...fe(e[b])},comparison:{family:u.family,left:u.label,right:U(u.family)},effect:{direction:M===0?"different":M>0?"higher":"lower",absoluteDelta:M,relativeDelta:w===0?void 0:M/w,effectSize:M},stats:{method:N,pValue:z,sampleSizeLeft:m,sampleSizeRight:p},summary:De(u.label,T(e[b],y),M,u.family),highlight:{kind:"region",regionFamily:u.family,regionKeys:[u.key],dieKeys:[...u.dieKeys]}}),{hits:S,n:m,restHits:d,restN:p,passRate:!0}))}}return o}export function welchFromStats(t,n,i,s,e,a){const l=Math.sqrt(i/t+a/s),r=n-e;if(!Number.isFinite(l)||l===0)return{pValue:1,effectSize:0,delta:r,z:0};const c=r/l,o=Math.sqrt(Math.max(0,(i+a)/2)),u=o===0?r:r/o;return{pValue:Ee(c),effectSize:u,delta:r,z:c}}function Et(t,n){const i=le(t),s=le(n);return welchFromStats(t.length,i,we(t,i),n.length,s,we(n,s))}const Qe=250;function Ue(t,n,i){const s=l=>l.filter(r=>_(i?.find(c=>c.testNumber===r)));if(n)return{testNumbers:s(n.slice().sort((l,r)=>l-r))};const e=Ce(t,"values");if(e.length>Qe){const l=`Test-value analysis was skipped: more than ${Qe} tests were found in the die data, so no test findings were computed. Pass testNumbers: [...] to analyse specific tests.`;return console.warn(`[wafermap] analyzeWaferMap: ${l}`),{testNumbers:[],warning:{code:"test-count-capped",message:l,severity:"warning"}}}return{testNumbers:s(e)}}function se(t,n,i,s){const e=Ue(t,s.testNumbers,i);if(e.warning)return{findings:[],warning:e.warning};const a=e.testNumbers,l=new Map;for(let m=0;m<n.length;m++)for(const S of I(n[m].dies))l.set(S,m);const r=n.length,c=[],o=[];for(const m of t){const S=l.get(ye(m));S!==void 0&&(c.push(m),o.push(S))}const u=[],f=new Float64Array(r),h=new Float64Array(r),b=new Float64Array(r);for(const m of a){f.fill(0),h.fill(0),b.fill(0);let S=0,D=0,w=0,M;for(let z=0;z<c.length;z++){const N=c[z],y=j(N,m);if(y===void 0)continue;M===void 0&&(M=y);const $=y-M,v=o[z];f[v]+=1,h[v]+=$,b[v]+=$*$,S+=1,D+=$,w+=$*$}if(M!==void 0)for(let z=0;z<r;z++){const N=f[z],y=S-N;if(N<s.minimumSampleSize||y<s.minimumSampleSize)continue;const $=h[z]/N,k=(D-h[z])/y,R=$+M,C=k+M,P=N>1?Math.max(0,b[z]-N*$*$)/(N-1):0,V=y>1?Math.max(0,w-b[z]-y*k*k)/(y-1):0,{pValue:E,effectSize:L,delta:g,z:B}=welchFromStats(N,R,P,y,C,V),x=n[z],{label:F,unit:K,...W}=Nt(m,i),ae=C!==0?g/Math.abs(C):void 0,Y=ee(x,{id:`test:${m}:${x.key}`,level:"wafer",severity:"info",variable:{kind:"test",index:m,label:F,unit:K,...W},comparison:{family:x.family,left:x.label,right:U(x.family)},effect:{direction:g===0?"different":g>0?"higher":"lower",absoluteDelta:g,relativeDelta:ae,effectSize:L},stats:{method:"welch-z-approx",pValue:E,sampleSizeLeft:N,sampleSizeRight:y},summary:Me(x.label,F,g,ae,x.family,K),highlight:{kind:"region",regionFamily:x.family,regionKeys:[x.key],dieKeys:[...x.dieKeys]}}),Z={n:N,sum:h[z],sq:b[z],restN:y,restSum:D-h[z],restSq:w-b[z],shift:M};Be.set(Y,Z),He(Y,B,void 0,Z),u.push(Y)}}adjustPValues(u);const d=u.filter(m=>{const S=m.stats.adjustedPValue??m.stats.pValue??1,D=Math.abs(m.effect.effectSize??0);return S<=s.significanceLevel&&D>=s.minimumEffectSize}),p=confirmRegionalFindings(d,Ye,(m,S)=>Vt(m,S,s));return{activeTestNumbers:a,findings:d.filter(m=>p.has(m)).map(m=>({...m,severity:severityForScore(m.stats.adjustedPValue??m.stats.pValue??1,m.effect.effectSize??0)}))}}function Lt(t,n,i,s){if(!i?.length)return[];const e=i.filter(l=>_(l)&&(l.limitLow!==void 0||l.limitHigh!==void 0));if(!e.length)return[];const a=[];for(const l of e){const r=l.testNumber;for(const c of n){const o=me(t,c),u=[],f=new Map;let h=0,b=0;for(const[d,p]of o){let m=0,S=0;for(const D of p){const w=j(D,r);w!==void 0&&(m++,ve(ce(w,l))&&S++)}f.set(d,{valid:m,fail:S}),h+=m,b+=S}for(const d of c){const p=f.get(d.key),m=p.valid,S=h-p.valid;if(m<s.minimumSampleSize||S<s.minimumSampleSize)continue;const D=p.fail,w=b-p.fail,M=D/m,z=w/S,N=M-z,{pValue:y,method:$}=q(D,m,w,S);u.push(de(ee(d,{id:`specLimit:${r}:${d.key}`,level:"wafer",severity:"info",variable:{kind:"test",index:r,label:T(l,r),unit:l.unit,...fe(l)},comparison:{family:d.family,left:d.label,right:U(d.family)},effect:{direction:N===0?"different":N>0?"higher":"lower",absoluteDelta:N,relativeDelta:z===0?void 0:N/z,effectSize:N},stats:{method:$,pValue:y,sampleSizeLeft:m,sampleSizeRight:S},summary:ze(d.label,T(l,r),N),highlight:{kind:"region",regionFamily:d.family,regionKeys:[d.key],dieKeys:[...d.dieKeys]}}),{hits:D,n:m,restHits:w,restN:S,passRate:!1}))}a.push(...u)}}return a}function Fe(t,n){return t==="softBin"?n.softEligibleDies:t==="test"?n.testDies:n.eligibleDies}function Kt(t){return t.id.startsWith("specLimit:")}function oe(t){return t.highlight.regionKeys??[]}function Ot(t){const n=t.variable.bin??t.variable.index??"";return`${t.comparison.family}\0${Ge(t)}\0${t.variable.kind}\0${n}\0${t.effect.direction}`}function qt(t,n){const i=Q(t);return i.family==="ring"?i.ring??0:i.family==="sector"?Ve(n).indexOf(i.sector??""):0}export function inQuadrantOrder(t){const n=new Set(t),i=Se.findIndex((e,a)=>n.has(e)&&!n.has(Se[(a+3)%4])),s=i<0?0:i;return Array.from({length:4},(e,a)=>Se[(s+a)%4]).filter(e=>n.has(e))}export function findContiguousRuns(t,n,i,s){if(n==="quadrant"){const c=new Map;for(const h of t){const b=Q(s(h)).quadrant;b&&c.set(b,h)}const o=[...c.keys()],u=new Set,f=[];for(const h of o){if(u.has(h))continue;const b=[],d=[h];for(u.add(h);d.length;){const p=d.pop();b.push(p);for(const m of o)!u.has(m)&&ft(p,m)&&(u.add(m),d.push(m))}f.push(inQuadrantOrder(b).map(p=>c.get(p)))}return f}const e=c=>qt(s(c),i),a=[...t].sort((c,o)=>e(c)-e(o)),l=[];let r=[];for(const c of a){if(r.length===0){r.push(c);continue}const o=e(r[r.length-1]);e(c)-o===1?r.push(c):(l.push(r),r=[c])}if(r.length&&l.push(r),n==="sector"&&l.length>1){const o=Ve(i).length,u=e(l[0][0]),f=e(l[l.length-1][l[l.length-1].length-1]);if(u===0&&f===o-1){const h=l.pop();l[0]=[...h,...l[0]]}}return l}export function mergedRegionLabel(t,n,i){if(t==="ring"){const e=n.map(c=>Q(c).ring).filter(c=>c!==void 0).sort((c,o)=>c-o),a=e[0],l=e[e.length-1];let r="";return a===l&&a===1&&i>1?r=" (core)":a===l&&a===i&&i>1&&(r=" (edge)"),a===l?`Ring ${a}${r}`:`Rings ${a}\u2013${l}`}if(t==="sector"){const e=n.map(a=>Q(a).sector??"");return e.length===1?`Sector ${e[0]}`:`Sectors ${e[0]}\u2013${e[e.length-1]}`}const s=n.map(e=>Q(e).quadrant??"");return s.length===1?s[0]:s.length===2?`Quadrants ${s[0]} & ${s[1]}`:`Quadrants ${s.slice(0,-1).join(", ")} & ${s[s.length-1]}`}function Ne(t){return[...new Set(t)]}export function weakestMultiplier(t){return wt(t.map(n=>{const i=n.stats.pValue??1;return i>0?(n.stats.adjustedPValue??i)/i:1}))}function X(t,n){return Math.min(1,t*n)}function Tt(t,n){const i=t[0],s=i.comparison.family,e=i.variable.kind,a=Ne(t.flatMap(oe));let l,r;const c=t.map(Ie);if(c.every(y=>y!==void 0)){const y=new Set;l=[];for(const v of c){const k=I(v.dies);for(let R=0;R<k.length;R++)y.has(k[R])||(y.add(k[R]),l.push(v.dieKeys[R]))}const $=I(Fe(i.variable.kind,n));r=v=>y.has($[v])}else{l=Ne(t.flatMap(v=>v.highlight.dieKeys??[]));const y=new Set(l),$=xt(Fe(i.variable.kind,n));r=v=>y.has($[v])}const o=mergedRegionLabel(s,t.map(y=>oe(y)[0]??""),n.ringCount),u=Fe(e,n),f=n.regionDies[s],h=I(u),b=[],d=[];for(let y=0;y<u.length;y++)f.has(h[y])&&(r(y)?b:d).push(u[y]);const p=weakestMultiplier(t);let m,S,D,w,M;if(Kt(i)){const y=i.variable.index,$=n.testDefs?.find(B=>B.testNumber===y),v=B=>{let x=0,F=0;for(const K of B){const W=j(K,y);W!==void 0&&(x++,$&&ve(ce(W,$))&&F++)}return{valid:x,fail:F}},k=v(b),R=v(d),C=k.valid>0?k.fail/k.valid:0,P=R.valid>0?R.fail/R.valid:0,V=C-P,{pValue:E,method:L}=q(k.fail,k.valid,R.fail,R.valid);m={direction:V===0?"different":V>0?"higher":"lower",absoluteDelta:V,relativeDelta:P===0?void 0:V/P,effectSize:V},S={method:L,pValue:E,sampleSizeLeft:k.valid,sampleSizeRight:R.valid};const g=X(E,p);D=severityForFinding(g,V,rateRelativeEffect({hits:k.fail,n:k.valid,restHits:R.fail,restN:R.valid,passRate:!1})),w=ze(o,T($,y),V),M=`specLimit:${y}`}else if(e==="test"){const y=i.variable.index,$=g=>j(g,y),v=b.map($).filter(g=>g!==void 0),k=d.map($).filter(g=>g!==void 0),{pValue:R,effectSize:C,delta:P}=Et(v,k),V=le(k),E=V!==0?P/Math.abs(V):void 0;m={direction:P===0?"different":P>0?"higher":"lower",absoluteDelta:P,relativeDelta:E,effectSize:C},S={method:"welch-z-approx",pValue:R,sampleSizeLeft:v.length,sampleSizeRight:k.length};const L=X(R,p);D=severityForScore(L,C),w=Me(o,i.variable.label,P,E,s,i.variable.unit),M=`test:${y}`}else if(e==="yield"){const y=new Set(n.passBins),$=b.filter(F=>F.hbin!==void 0),v=d.filter(F=>F.hbin!==void 0),k=$.length,R=v.length,C=$.filter(F=>y.has(F.hbin)).length,P=v.filter(F=>y.has(F.hbin)).length,V=k>0?C/k:0,E=R>0?P/R:0,L=V-E,{pValue:g,method:B}=q(C,k,P,R);m={direction:L===0?"different":L>0?"higher":"lower",absoluteDelta:L,relativeDelta:E===0?void 0:L/E,effectSize:L},S={method:B,pValue:g,sampleSizeLeft:k,sampleSizeRight:R};const x=X(g,p);D=severityForFinding(x,L,rateRelativeEffect({hits:C,n:k,restHits:P,restN:R,passRate:!0})),w=$e(o,L,s),M="yield"}else if(e==="functionalTest"){const y=i.variable.index,$=n.testDefs?.find(x=>x.testNumber===y);let v=0,k=0,R=0,C=0;for(const x of b){const F=re(x,y,$);F!==void 0&&(k++,F&&v++)}for(const x of d){const F=re(x,y,$);F!==void 0&&(C++,F&&R++)}const P=k>0?v/k:0,V=C>0?R/C:0,E=P-V,{pValue:L,method:g}=q(v,k,R,C);m={direction:E===0?"different":E>0?"higher":"lower",absoluteDelta:E,relativeDelta:V===0?void 0:E/V,effectSize:E},S={method:g,pValue:L,sampleSizeLeft:k,sampleSizeRight:C};const B=X(L,p);D=severityForFinding(B,E,rateRelativeEffect({hits:v,n:k,restHits:R,restN:C,passRate:!0})),w=De(o,T($,y),E,s),M=`functional:${y}`}else{const y=i.variable.bin,$=B=>e==="softBin"?B.sbin:B.hbin,v=b.filter(B=>$(B)===y).length,k=d.filter(B=>$(B)===y).length,R=v/b.length,C=k/d.length,P=R-C,{pValue:V,method:E}=q(v,b.length,k,d.length);m={direction:P===0?"different":P>0?"higher":"lower",absoluteDelta:P,relativeDelta:C===0?void 0:P/C,effectSize:P},S={method:E,pValue:V,sampleSizeLeft:b.length,sampleSizeRight:d.length};const L=X(V,p);D=severityForFinding(L,P,rateRelativeEffect({hits:v,n:b.length,restHits:k,restN:d.length,passRate:!1}));const g=e==="softBin"?n.sbinDefs:n.hbinDefs;w=Re(o,Oe(y,g,e==="softBin"?"SBin":"HBin"),P,s),M=`${e}:${y}`}S={...S,adjustedPValue:X(S.pValue??1,p)};const z=Ne(a.map(y=>y.replace(`${s}:`,""))).join("-"),N=e==="hardBin"||e==="softBin"?{kind:"bin",bin:i.variable.bin,regionKeys:a,dieKeys:l}:{kind:"region",regionFamily:s,regionKeys:a,dieKeys:l};return{...i,id:`${M}:${s}:${z}`,severity:D,comparison:{family:s,left:o,right:U(s)},effect:m,stats:S,summary:w,highlight:N,relatedIds:t.map(y=>y.id)}}function At(t,n){const i=new Set(["ring","quadrant","sector"]),s=[],e=new Map;for(const l of t){if(!i.has(l.comparison.family)){s.push(l);continue}const r=Ot(l),c=e.get(r)??[];c.push(l),e.set(r,c)}const a=[];for(const l of e.values()){if(l.length===1){a.push(l[0]);continue}const r=l[0].comparison.family;for(const c of findContiguousRuns(l,r,n.sectorCount,o=>oe(o)[0]??""))a.push(c.length===1?c[0]:Tt(c,n))}return[...s,...a]}function jt(t){const n=new Map,i=new Map;for(const e of t){const a=ye(e);e.hbin!==void 0&&e.hbin!==null&&(n.get(e.hbin)??n.set(e.hbin,new Set).get(e.hbin)).add(a),e.sbin!==void 0&&e.sbin!==null&&(i.get(e.sbin)??i.set(e.sbin,new Set).get(e.sbin)).add(a)}const s=new Set;for(const[e,a]of n)for(const[l,r]of i){if(a.size!==r.size)continue;let c=!0;for(const o of a)if(!r.has(o)){c=!1;break}c&&s.add(`${e}:${l}`)}return s}function Ht(t,n){const i=new Set(n);let s;for(const e of t){const a=pe(e,i);if(a!==void 0&&a){if(e.sbin==null||s!==void 0&&e.sbin!==s)return;s=e.sbin}}if(s!==void 0){for(const e of t)if(e.sbin===s&&pe(e,i)!==!0)return;return s}}function It(t){return`${t.comparison.family}\0${t.comparison.left}`}export function redundancyFacts(t,n,i){return{coincident:jt(t),yieldSoftBin:Ht(t,n),passBins:n,sectorCount:i}}const Wt=3/5;function Ge(t){return/^(?:lot-region:)?([^:|]+)/.exec(t.id)?.[1]??t.id}function Yt(t){const n=oe(t);if(n.length)return n;const i=/(ring|sector|quadrant):([^:|]+)$/.exec(t.id);return i?i[2].split("-").map(s=>`${i[1]}:${s}`):[]}function Xe(t,n){const i=new Set;for(const s of Yt(t)){const e=lt(s,n);if(!e)return;for(const a of e)i.add(a)}return i.size?i:void 0}export function collapseRedundantFindings(t,n){const{coincident:i,yieldSoftBin:s,passBins:e}=n,a=(o,u)=>{o.absorbedIds=[...o.absorbedIds??[],u.id]},l=new Map;for(const o of t){const u=It(o);(l.get(u)??l.set(u,[]).get(u)).push(o)}const r=new Set;for(const o of l.values()){for(const f of o)if(!(f.variable.kind!=="hardBin"||f.variable.bin===void 0))for(const h of o){if(h.variable.kind!=="softBin"||h.variable.bin===void 0||r.has(h.id)||!i.has(`${f.variable.bin}:${h.variable.bin}`)||h.effect.direction!==f.effect.direction)continue;a(f,h),r.add(h.id);const b=f.variable.label.replace(/^HBin\s+/,""),d=h.variable.label.replace(/^SBin\s+/,""),p=b===d?`HBin and SBin ${b} (same dies)`:`${f.variable.label} and ${h.variable.label} (same dies)`;f.summary=f.summary.replace(f.variable.label,p),f.variable.label=p;break}const u=o.find(f=>f.variable.kind==="yield");if(u){for(const f of o)if(!(f===u||r.has(f.id)||!(f.variable.kind==="hardBin"&&e.length===1&&f.variable.bin===e[0]||f.variable.kind==="softBin"&&f.variable.bin===s))){a(u,f),r.add(f.id);for(const b of f.absorbedIds??[])u.absorbedIds=[...u.absorbedIds??[],b]}}}const c=new Map;for(const o of t){if(r.has(o.id)||o.comparison.family!=="sector"&&o.comparison.family!=="quadrant")continue;const u=[Ge(o),o.variable.kind,o.variable.bin??"",o.variable.index??"",o.effect.direction].join("\0");(c.get(u)??c.set(u,[]).get(u)).push(o)}for(const o of c.values()){const u=[];for(const f of o.filter(h=>h.comparison.family==="sector")){const h=Xe(f,n.sectorCount);if(h)for(const b of o.filter(d=>d.comparison.family==="quadrant")){const d=Xe(b,n.sectorCount);if(!d)continue;let p=0;for(const S of h)d.has(S)&&p++;const m=h.size+d.size-p;p/m>=Wt-1e-9&&u.push({sector:f,quadrant:b,overlap:p/m})}}u.sort((f,h)=>h.overlap-f.overlap);for(const{sector:f,quadrant:h}of u){if(r.has(f.id)||r.has(h.id))continue;const b=(h.stats.pValue??1)<(f.stats.pValue??1),[d,p]=b?[h,f]:[f,h];a(d,p),r.add(p.id),d.absorbedIds=[...d.absorbedIds??[],...p.absorbedIds??[]]}}}export function analyzeWaferMap(t,n={}){const i=G,s=te,e=[];G=e,te=void 0;try{const a=_t(t,n);return je.set(a,{candidates:e,facts:te}),a}finally{G=i,te=s}}function _t(t,n){const{resolved:i,warnings:s}=resolveOptions(n),e=Ze(t),a={...i,passBins:[...pt(e,"analyzeWaferMap")],ringCount:gt(e,"analyzeWaferMap")},l=e.isLotStack,r=e.aggrMethod,c=!l||r==="mode"||r==="countBin"||r==="percent",o=e.dies.filter(g=>kt(g)),u=o.filter(Pe),f=$t(a,o.length);f.softPassBins=xe(o,f.passBins).soft;const h=e.dies.filter(g=>ge(g)),b=h.filter(Pe),d=ot(b,e.wafer,f.ringCount),p=it(b,e.wafer,f.ringCount),m=st(b,e.reticleConfig),S=rt(h,!1),D=at(b,e.wafer,f.sectorCount),w=[],M=[];c&&M.push(...ne(o,d,f.passBins,f),...ne(o,p,f.passBins,f),...ne(o,m,f.passBins,f),...ne(o,S,f.passBins,f),...ne(o,D,f.passBins,f)),c&&M.push(...O(o,d,"hard",e.hbinDefs,"hardBin",f),...O(o,p,"hard",e.hbinDefs,"hardBin",f),...O(o,m,"hard",e.hbinDefs,"hardBin",f),...O(o,S,"hard",e.hbinDefs,"hardBin",f),...O(o,D,"hard",e.hbinDefs,"hardBin",f));{const g=o.filter(B=>B.sbin!==void 0);M.push(...O(g,d,"soft",e.sbinDefs,"softBin",f),...O(g,p,"soft",e.sbinDefs,"softBin",f),...O(g,m,"soft",e.sbinDefs,"softBin",f),...O(g,S,"soft",e.sbinDefs,"softBin",f),...O(g,D,"soft",e.sbinDefs,"softBin",f))}const z=[...s];let N;if(f.enableTestValueAnalysis){const g=se(o,d,e.testDefs,f),B=se(o,p,e.testDefs,f),x=se(o,m,e.testDefs,f),F=se(o,S,e.testDefs,f),K=se(o,D,e.testDefs,f);w.push(...g.findings,...B.findings,...x.findings,...F.findings,...K.findings),g.warning&&z.push(g.warning),N=g.activeTestNumbers,M.push(...Lt(o,[d,p,m,S,D],e.testDefs,f)),M.push(...ie(o,d,e.testDefs,f),...ie(o,p,e.testDefs,f),...ie(o,m,e.testDefs,f),...ie(o,S,e.testDefs,f),...ie(o,D,e.testDefs,f))}w.push(...Pt(M,f));{const g=Rt(l,c,e.testDefs);(!l||c||g!==void 0)&&w.push(...ct(u,e.wafer,{...f,isFailingDie:g}))}const y=At(w,{eligibleDies:o,softEligibleDies:o.filter(g=>g.sbin!==void 0),testDies:o,passBins:f.passBins,ringCount:f.ringCount,sectorCount:f.sectorCount,regionDies:{ring:new Set(d.flatMap(g=>I(g.dies))),quadrant:new Set(p.flatMap(g=>I(g.dies))),sector:new Set(D.flatMap(g=>I(g.dies)))},hbinDefs:e.hbinDefs,sbinDefs:e.sbinDefs,testDefs:e.testDefs});w.length=0,w.push(...y);let $;if(c){const g=ut(u,e.wafer,{passBins:f.passBins,ringCount:f.ringCount});if($=g??void 0,g!==null&&g.pattern!=="random"&&g.pattern!=="none"){const B=ht[g.pattern],x=g.confidence==="high"?"unusual":g.confidence==="medium"?"notable":"info",F=g.features,K=A=>`${(A*100).toFixed(0)}%`,W=g.pattern==="edge-ring"||g.pattern==="edge-local"?`${K(F.edgeRdd)} of edge dies failing`:g.pattern==="center"?`centroid at ${K(F.centroidDistNorm)} of wafer radius from centre`:g.pattern==="donut"?`${K(Math.max(F.radialFailRates[1],F.radialFailRates[2]))} of dies failing at mid-radius, ${K(F.radialFailRates[0])} at the centre`:g.pattern==="scratch"?`a line ${Math.round(F.lineLength)} dies long and about ${Math.max(1,Math.round(F.lineWidth*2))} wide`:`${K(F.globalRdd)} of dies failing`,ae=new Set(f.passBins),Y=o.filter(A=>mt(A,ae)===!0),Z=claimForPattern([g.pattern],x,w,A=>oe(A).map(he=>Q(he).ring).filter(he=>he!==void 0),f.ringCount);w.push({id:`spatial-pattern:${g.pattern}`,level:"wafer",severity:x,variable:{kind:"spatialPattern",label:B},comparison:{family:"spatial-pattern",left:B,right:"Wafer"},effect:{direction:"different",effectSize:F.globalRdd},stats:{method:"geometry",sampleSizeLeft:Y.length,sampleSizeRight:o.length},summary:`Spatial pattern: ${B.toLowerCase()} (${g.confidence} confidence) \u2014 ${W}${g.note?` [${g.note}]`:""}`,highlight:{kind:"dies",dieKeys:Y.map(A=>be(A))},relatedIds:Z.length>0?Z:void 0})}}w.sort((g,B)=>{const x=g.stats.adjustedPValue??g.stats.pValue??1,F=B.stats.adjustedPValue??B.stats.pValue??1;return x!==F?x-F:Math.abs(B.effect.absoluteDelta??0)-Math.abs(g.effect.absoluteDelta??0)});const v=Dt(e.dies,o.length,e.yield.yieldPercent);l&&(v.isLotStack=!0,r&&(v.aggregationMethod=r));const k=new Set(a.passBins),R={},C=(g,B)=>{const x=R[g]??={dieKeys:[],lostDies:0};x.dieKeys.push(be(B)),pe(B,k)!==!0&&x.lostDies++},P=Mt(e.dies,e.testDefs,C);P&&(v.testSpecYield=P);const V=computeFunctionalYield(e.dies,e.testDefs,C);if(V&&(v.functionalYield=V),Object.keys(R).length&&(v.testFailures=R),$&&(v.spatialPattern=$),N===void 0&&f.computePerTestStats){const g=Ue(o,f.testNumbers,e.testDefs);g.warning&&z.push(g.warning),N=g.testNumbers}if(N?.length){const g=zt(e.dies,N,e.testDefs,f.minimumSampleSize);g&&(v.perTestStats=g);const B=Je([{dies:e.dies}],e.testDefs,N);B&&(v.capability=B)}Object.assign(v,et(e.dies,e.testDefs));const E=tt([{dies:e.dies,wafer:e.wafer,passBins:f.passBins,ringCount:f.ringCount}]);E&&(v.regionYield=E),z.length>0&&(v.warnings=z);const L=redundancyFacts(o,f.passBins,f.sectorCount);return collapseRedundantFindings(w,L),G&&(te=L),{level:"wafer",hasNotableFindings:w.some(g=>g.severity==="notable"||g.severity==="unusual"),findings:w,wafer:e.wafer.metadata??void 0,stats:v}}
|
|
1
|
+
import{normalizeInput as st}from"./normalizeInput.js";import{autoDecision as ot,testValueStatus as at}from"./testValueBudget.js";import{computeCapability as rt,computeTestFlagYield as ft,computeRegionYield as lt}from"./summaryFigures.js";import{binPassSets as Ee}from"../renderer/binColors.js";import{diePassStatus as be,isYieldEligibleDie as ye,getDieKey as Se,isPositionedDie as Ke,positionKey as ve}from"../core/dies.js";import{dieHasValues as ct,testsPresent as Oe,testValue as Y}from"../core/dieTable.js";import{stackBinsAreData as ut}from"../core/aggregates.js";import{getTestPassStatus as le,isParametricTest as X}from"../renderer/buildWaferMap.js";import{markedTestLabel as I,derivedFields as ce}from"../renderer/testLabel.js";import{buildQuadrantRegions as dt,buildReticlePositionRegions as mt,buildRingRegions as ht,buildSectorRegions as pt,buildTestSiteRegions as gt,sectorCompassNames as Le,areQuadrantsAdjacent as bt,parseRegionKey as Z,QUADRANT_CYCLE as we,regionAngleBins as yt}from"./regions.js";import{buildClusterFindings as St}from"./clusterDetection.js";import{classifyPattern as vt,patternExplains as wt,patternFailVerdict as $t,PATTERN_LABELS as Rt}from"./patternClassification.js";import{requirePassBins as kt}from"../core/passBins.js";import{requireRingCount as Mt}from"../core/ringCount.js";import{benjaminiHochberg as Dt,fisherExact as zt,fiveNumberSummary as Bt,sampleVariance as $e,zPValue as Ae}from"./math.js";import{mean as ue,maxOf as Ft}from"../core/utils.js";import{classifySpec as de,isOutOfSpec as Re}from"../renderer/spec.js";const xt={significanceLevel:{min:1e-6,max:1},minimumEffectSize:{min:0,max:1},minimumRelativeEffect:{min:0,max:Number.MAX_SAFE_INTEGER}},qe=[4,8,16];export function resolveOptions(e){const t=Object.fromEntries(Object.entries(e).filter(([,a])=>a!==void 0)),s={...ie,...t},o=[],n=[];for(const a of["significanceLevel","minimumEffectSize","minimumRelativeEffect"]){const{min:u,max:l}=xt[a],d=s[a];if(typeof d!="number"||!Number.isFinite(d)){n.push(`${a}=${String(d)} is not a finite number (using ${ie[a]})`),s[a]=ie[a];continue}const f=Math.min(l,Math.max(u,d));f!==d&&(n.push(`${a}=${d} is outside ${u}\u2013${l} (using ${f})`),s[a]=f)}if(qe.includes(s.sectorCount)||(n.push(`sectorCount=${s.sectorCount} is not one of ${qe.join(", ")} (using ${ie.sectorCount})`),s.sectorCount=ie.sectorCount),n.length){const a=`analyzeWaferMap: ${n.join("; ")}. The analysis ran with the corrected values.`;console.warn(`[wafermap] ${a}`),o.push({code:"analysis-option-corrected",message:a,severity:"warning"})}const i=["passBins","ringCount"].filter(a=>t[a]!==void 0);if(i.length){const a=`analyzeWaferMap: ${i.join(" and ")} ${i.length>1?"are":"is"} no longer an analysis option and was ignored. Set ${i.length>1?"them":"it"} on buildWaferMap; the analysis used the value the map was built with.`;console.warn(`[wafermap] ${a}`),o.push({code:"analysis-option-corrected",message:a,severity:"warning"})}const r=["enableYieldAnalysis","enableHardBinAnalysis","enableSoftBinAnalysis","enableReticlePositionAnalysis","enableTestSiteAnalysis","enableClusterAnalysis","enableAngularAnalysis","enablePatternClassification"].filter(a=>t[a]!==void 0);if(r.length){const a=`analyzeWaferMap: ${r.join(", ")} ${r.length>1?"are":"is"} no longer an option and was ignored: every analysis now runs. Filter the findings (filterFindings) to show fewer.`;console.warn(`[wafermap] ${a}`),o.push({code:"analysis-option-corrected",message:a,severity:"warning"})}return{resolved:s,warnings:o}}const ie={significanceLevel:.05,minimumEffectSize:.2,minimumRelativeEffect:1,minimumSampleSize:5,enableTestValueAnalysis:"auto",computePerTestStats:!1,sectorCount:8,minimumClusterSize:5};function Pt(e,t){const s={...e};return s.minimumClusterSize=Math.max(5,Math.round(t*.003)),s}function Te(e){return ye(e)?e.hbin!==void 0||e.sbin!==void 0||ct(e):!1}function Nt(e,t,s){if(!e||t)return;const o=(s??[]).filter(n=>X(n)&&(n.limitLow!==void 0||n.limitHigh!==void 0));if(o.length!==0)return n=>{for(const i of o)if(Re(de(Y(n,i.testNumber),i)))return!0;return!1}}function Ct(e,t,s){const o=new Set,n=new Set,i=new Set,r=new Map,a=new Map;for(const u of Oe(e))o.add(u);for(const u of e)u.hbin!==void 0&&n.add(u.hbin),u.sbin!==void 0&&i.add(u.sbin),ye(u)&&(u.hbin!==void 0&&r.set(u.hbin,(r.get(u.hbin)??0)+1),u.sbin!==void 0&&a.set(u.sbin,(a.get(u.sbin)??0)+1));return{totalDies:e.length,analyzedDies:t,excludedDies:e.length-t,yieldPercent:s,testsConsidered:[...o].sort((u,l)=>u-l),hardBinsConsidered:[...n].sort((u,l)=>u-l),softBinsConsidered:[...i].sort((u,l)=>u-l),...r.size?{hardBinCounts:Object.fromEntries(r)}:{},...a.size?{softBinCounts:Object.fromEntries(a)}:{}}}function Vt(e,t,s){if(!t?.length)return;const o=t.filter(i=>X(i)&&(i.limitLow!==void 0||i.limitHigh!==void 0));if(!o.length)return;const n=[];for(const i of o){const r=i.testNumber;let a=0,u=0,l=0,d=0;for(const f of e){if(f.partial||f.edgeExcluded)continue;const p=de(Y(f,r),i);if(p!==null){if(d++,p==="failLow")u++;else if(p==="failHigh")l++;else{a++;continue}s?.(r,f)}}n.push({testNumber:r,label:i.name,passDies:a,failLowDies:u,failHighDies:l,totalDies:d,yieldPercent:d>0?a/d*100:null})}return n.length?n:void 0}export function computeFunctionalYield(e,t,s){if(!t?.length)return;const o=t.filter(i=>!X(i));if(!o.length)return;const n=[];for(const i of o){const r=i.testNumber;let a=0,u=0;for(const d of e){if(d.partial||d.edgeExcluded)continue;const f=le(d,r,i);if(f!==void 0){if(f){a++;continue}u++,s?.(r,d)}}const l=a+u;n.push({testNumber:r,label:I(i,r),...ce(i),passDies:a,failDies:u,totalDies:l,passRatePercent:l>0?a/l*100:null})}return n.length?n:void 0}function Et(e,t,s,o){const n=[];for(const i of t){const r=[];for(const f of e){if(f.partial||f.edgeExcluded)continue;const p=Y(f,i);p!==void 0&&Number.isFinite(p)&&r.push(p)}if(r.length<o)continue;const a=ue(r),u=Math.sqrt($e(r,a)),l=Bt(Float64Array.from(r)),d=s?.find(f=>f.testNumber===i)?.name??String(i);n.push({testNumber:i,label:d,count:r.length,min:l.min,max:l.max,mean:a,stddev:u,median:l.median,q1:l.q1,q3:l.q3})}return n.length?n:void 0}export function twoProportionZ(e,t,s,o){const n=(e+s)/(t+o),i=n*(1-n)*(1/t+1/o);return!Number.isFinite(i)||i<=0?0:(e/t-s/o)/Math.sqrt(i)}const Kt=5;function T(e,t,s,o){const n=t+o,i=e+s;if((n>0?Math.min(i,n-i)*Math.min(t,o)/n:0)<Kt)return{pValue:zt(e,t-e,s,o-s),method:"fisher-exact"};const a=twoProportionZ(e,t,s,o);return{pValue:a===0?1:Ae(a),method:"two-proportion-z"}}function Ot(e,t,s,o){return T(e,t,s,o).pValue}export function adjustPValues(e){const t=e.filter(o=>o.stats.pValue!==void 0),s=Dt(t.map(o=>o.stats.pValue));return t.forEach((o,n)=>{o.stats.adjustedPValue=s[n]}),e}export function rateRelativeEffect(e){const t=(e.passRate?e.n-e.hits:e.hits)/e.n,s=(e.passRate?e.restN-e.restHits:e.restHits)/e.restN;return s===0?t===0?0:1/0:Math.abs(t-s)/s}export function severityForFinding(e,t,s){const o=Math.abs(t),n=s;return e<=.01&&(o>=.3||n>=2.5)?"unusual":e<=.05&&(o>=.2||n>=1.5)?"notable":"info"}export function severityForScore(e,t){return e<=.01&&Math.abs(t)>=.5?"unusual":e<=.05&&Math.abs(t)>=.15?"notable":"info"}function me(e){return e==="reticle-position"?"other reticle positions":e==="test-site"?"other test sites":"the rest of the map"}function J(e){return e==="reticle-position"?"Other reticle positions":e==="test-site"?"Other test sites":"Rest of map"}function ke(e,t,s){const o=(Math.abs(t)*100).toFixed(1);return`${e} yield is ${o} percentage points ${t>0?"higher":"lower"} than ${me(s)}`}function Me(e,t){return t==="quadrant"&&!e.startsWith("Quadrant")?`quadrant ${e}`:e}function je(e){return/^(Rings|Sectors|Quadrants)\b/.test(e)?"have":"has"}function De(e,t,s,o){const n=Me(e,o),i=(Math.abs(s)*100).toFixed(1);return`${n} ${je(n)} ${t} occurrence ${i} percentage points ${s>0?"higher":"lower"} than ${me(o)}`}function ze(e,t,s,o){const n=Me(e,o),i=(Math.abs(s)*100).toFixed(1);return`${n} ${je(n)} ${t} pass rate ${i} percentage points ${s>0?"higher":"lower"} than ${me(o)}`}function Be(e,t,s,o,n,i){const r=Me(e,n),a=me(n),u=s>0?"higher":"lower";if(o!==void 0&&Number.isFinite(o)){const d=(Math.abs(o)*100).toFixed(1);return`${r} mean ${t} is ${d}% ${u} than ${a}`}const l=i?` ${i}`:"";return`${r} mean ${t} is ${Math.abs(s).toPrecision(3)}${l} ${u} than ${a}`}function He(e,t,s){const o=t?.find(n=>n.bin===e);return o?.name?`${s} ${e} (${o.name})`:`${s} ${e}`}function Lt(e,t){const s=t?.find(o=>o.testNumber===e);return{label:I(s,e),unit:s?.unit,...ce(s)}}const Ie=new WeakMap,We=new WeakMap,Ye=new WeakMap;function se(e,t){const s=t.highlight.dieKeys;return s&&Ye.set(s,e),t}let ee=null,oe;const _e=new WeakMap;export function candidatesOf(e){return _e.get(e)}function Qe(e,t,s,o){if(!ee)return;const n=Ue(e);if(!n)return;const i=e.id.slice(0,e.id.indexOf(":")),r=i==="specLimit"?"limitFail":i,{kind:a,bin:u,index:l}=e.variable;ee.push({key:[r,a,u??"",l??"",n.family,n.key].join("|"),source:r,variable:e.variable,label:e.variable.label,comparison:e.comparison,region:n,z:t,delta:e.effect.absoluteDelta??0,effectSize:e.effect.effectSize??0,relativeDelta:e.effect.relativeDelta,rate:s,mean:o})}export function describeRegional(e,t,s){const o=e.comparison.left,n=e.region.family;switch(e.source){case"yield":return ke(o,t,n);case"hardBin":case"softBin":return De(o,e.label,t,n);case"functional":return ze(o,e.label.replace(/ pass rate$/,""),t,n);case"limitFail":return Fe(o,e.label,t);case"test":return Be(o,e.label,t,s,n,e.variable.unit)}}function Fe(e,t,s){return`${e} limit fail rate for ${t} is ${(Math.abs(s)*100).toFixed(1)} pp ${s>0?"higher":"lower"} than the rest of the wafer`}const _=new WeakMap;function he(e,t){return _.set(e,t),e}function Ue(e){const t=e.highlight.dieKeys;return t?Ye.get(t):void 0}const Ge=new WeakMap;function Q(e){let t=Ge.get(e);return t||Ge.set(e,t=e.map(ve)),t}function At(e){let t=Ie.get(e);return t||Ie.set(e,t=e.map(Se)),t}function pe(e,t){let s=We.get(e);s||We.set(e,s={members:new Set(e),byFamily:new WeakMap});const o=s.byFamily.get(t);if(o)return o;const{members:n}=s,i=new Map;for(const r of t)i.set(r.key,r.dies.filter(a=>n.has(a)));return s.byFamily.set(t,i),i}function qt(e,t){adjustPValues(e);for(const n of e){const i=_.get(n);Qe(n,twoProportionZ(i.hits,i.n,i.restHits,i.restN),i)}const s=e.filter(n=>passesRateGate(n.stats.adjustedPValue??n.stats.pValue??1,n.effect.absoluteDelta??0,rateRelativeEffect(_.get(n)),t)),o=confirmRegionalFindings(s,Xe,(n,i)=>Tt(n,i,t),n=>isRateLoss(_.get(n)),e);return s.filter(n=>o.has(n)).map(n=>({...n,severity:severityForFinding(n.stats.adjustedPValue??n.stats.pValue??1,n.effect.absoluteDelta??0,rateRelativeEffect(_.get(n)))}))}export function passesRateGate(e,t,s,o){return e<=o.significanceLevel&&(Math.abs(t)>=o.minimumEffectSize||s>=o.minimumRelativeEffect)}export function claimForPattern(e,t,s,o,n){const i=[];for(const r of s){const a=r.comparison.family,u=a==="ring"?o(r):[];e.some(l=>wt(l,a,u,n))&&(i.push(r.id),t!=="info"&&(a==="ring"||a==="quadrant"||a==="sector")&&(r.severity="info"))}return i}export function confirmRegionalFindings(e,t,s,o,n=e){const i=new Map;for(const u of e)(i.get(t(u))??i.set(t(u),[]).get(t(u))).push(u);const r=new Map;if(o)for(const u of n)o(u)&&(r.get(t(u))??r.set(t(u),[]).get(t(u))).push(u);const a=new Set;for(const[u,l]of i){const d=r.get(u)??[],f=(h,m)=>o&&!o(h)?s(h,[...new Set([...m,...d])].filter(g=>g!==h)):s(h,m);if(l.length===1&&(!o||o(l[0])||d.length===0)){a.add(l[0]);continue}const p=[];let c=[...l];for(;;){let h;for(const m of c){const g=f(m,p);if(g==="baseline-too-small"||!g.passes)continue;const S=o?.(m)??!1;(!h||S&&!h.loss||S===h.loss&&g.pValue<h.p)&&(h={t:m,p:g.pValue,loss:S})}if(!h)break;p.push(h.t),c=c.filter(m=>m!==h.t)}for(;;){let h;for(const m of p){const g=f(m,p.filter(S=>S!==m));g==="baseline-too-small"||g.passes||(!h||g.pValue>h.p)&&(h={t:m,p:g.pValue})}if(!h)break;p.splice(p.indexOf(h.t),1)}for(const h of p)a.add(h)}return a}function Xe(e){return[e.variable.kind,e.variable.bin??"",e.variable.index??"",e.comparison.family].join("\0")}function Ze(e){const t=e.stats.pValue??1;return t>0?(e.stats.adjustedPValue??t)/t:1}export function isRateLoss(e){const t=e.hits/e.n-e.restHits/e.restN;return e.passRate?t<0:t>0}function Tt(e,t,s){const o=_.get(e);let{restHits:n,restN:i}=o;for(const l of t){const d=_.get(l);d&&(n-=d.hits,i-=d.n)}if(i<s.minimumSampleSize)return"baseline-too-small";const r=o.hits/o.n-n/i,a=Math.min(1,Ot(o.hits,o.n,n,i)*Ze(e)),u=Math.sign(r)===Math.sign(e.effect.absoluteDelta??0)&&passesRateGate(a,r,rateRelativeEffect({...o,restHits:n,restN:i}),s);return{pValue:a,passes:u}}const xe=new WeakMap;export function welchOfSums(e,t,s,o){const n=(i,r,a)=>a>1?Math.max(0,i-r*r/a)/(a-1):0;return welchFromStats(e.n,e.sum/e.n,n(e.sq,e.sum,e.n),t,s/t,n(o,s,t))}function jt(e,t,s){const o=xe.get(e);let{restN:n,restSum:i,restSq:r}=o;for(const p of t){const c=xe.get(p);c&&(n-=c.n,i-=c.sum,r-=c.sq)}if(n<s.minimumSampleSize)return"baseline-too-small";const{pValue:a,effectSize:u,delta:l}=welchOfSums(o,n,i,r),d=Math.min(1,a*Ze(e)),f=Math.sign(l)===Math.sign(e.effect.absoluteDelta??0)&&d<=s.significanceLevel&&Math.abs(u)>=s.minimumEffectSize;return{pValue:d,passes:f}}function ae(e,t,s,o){const n=new Set(s),i=pe(e,t),r=new Map,a=new Map;for(const[l,d]of i){let f=0,p=0;for(const c of d)c.hbin!==void 0&&(p++,n.has(c.hbin)&&f++);r.set(l,f),a.set(l,p)}const u=[];for(const l of t){const d=a.get(l.key)??0,f=r.get(l.key)??0;let p=0,c=0;for(const[k,w]of a)k!==l.key&&(p+=w,c+=r.get(k)??0);if(d<o.minimumSampleSize||p<o.minimumSampleSize)continue;const h=f/d,m=c/p,g=h-m,{pValue:S,method:F}=T(f,d,c,p);u.push(he(se(l,{id:`yield:${l.key}`,level:"wafer",severity:"info",variable:{kind:"yield",label:"Yield"},comparison:{family:l.family,left:l.label,right:J(l.family)},effect:{direction:g===0?"different":g>0?"higher":"lower",absoluteDelta:g,relativeDelta:m===0?void 0:g/m,effectSize:g},stats:{method:F,pValue:S,sampleSizeLeft:d,sampleSizeRight:p},summary:ke(l.label,g,l.family),highlight:{kind:"region",regionFamily:l.family,regionKeys:[l.key],dieKeys:[...l.dieKeys]}}),{hits:f,n:d,restHits:c,restN:p,passRate:!0}))}return u}function q(e,t,s,o,n,i){const r=h=>s==="soft"?h.sbin:h.hbin,a=[...new Set(e.map(r).filter(h=>h!==void 0))].sort((h,m)=>h-m),u=pe(e,t),l=new Map,d=new Map;for(const[h,m]of u){const g=new Map;for(const S of m){const F=r(S);F!==void 0&&g.set(F,(g.get(F)??0)+1)}l.set(h,g),d.set(h,m.length)}const f=[],p=n==="hardBin"?"HBin":"SBin",c=s==="hard"?new Set(i.passBins):i.softPassBins??Ee(e,i.passBins).soft;for(const h of t){const m=d.get(h.key)??0,g=l.get(h.key);let S=0;const F=new Map;for(const[k,w]of l)if(k!==h.key){S+=d.get(k)??0;for(const[B,z]of w)F.set(B,(F.get(B)??0)+z)}if(!(m<i.minimumSampleSize||S<i.minimumSampleSize))for(const k of a){const w=g.get(k)??0,B=F.get(k)??0,z=w/m,b=B/S,$=z-b,{pValue:M,method:v}=T(w,m,B,S),R=He(k,o,p);f.push(he(se(h,{id:`${n}:${k}:${h.key}`,level:"wafer",severity:"info",variable:{kind:n,bin:k,label:R},comparison:{family:h.family,left:h.label,right:J(h.family)},effect:{direction:$===0?"different":$>0?"higher":"lower",absoluteDelta:$,relativeDelta:b===0?void 0:$/b,effectSize:$},stats:{method:v,pValue:M,sampleSizeLeft:m,sampleSizeRight:S},summary:De(h.label,R,$,h.family),highlight:{kind:"bin",bin:k,regionKeys:[h.key],dieKeys:[...h.dieKeys]}}),{hits:w,n:m,restHits:B,restN:S,passRate:c.has(k)}))}}return f}function re(e,t,s,o){const n=(s??[]).filter(d=>!X(d));if(!n.length)return[];const i=n.map(d=>d.testNumber),r=pe(e,t),a=new Map,u=new Map;for(const[d,f]of r){const p=new Uint32Array(n.length),c=new Uint32Array(n.length);for(const h of f)for(let m=0;m<n.length;m++){const g=le(h,i[m],n[m]);g!==void 0&&(c[m]++,g&&p[m]++)}a.set(d,p),u.set(d,c)}const l=[];for(const d of t){const f=a.get(d.key),p=u.get(d.key);for(let c=0;c<n.length;c++){let h=0,m=0;for(const[$,M]of u)$!==d.key&&(m+=M[c],h+=a.get($)[c]);const g=p[c],S=f[c];if(g<o.minimumSampleSize||m<o.minimumSampleSize)continue;const F=S/g,k=h/m,w=F-k,{pValue:B,method:z}=T(S,g,h,m),b=i[c];l.push(he(se(d,{id:`functional:${b}:${d.key}`,level:"wafer",severity:"info",variable:{kind:"functionalTest",index:b,label:`${I(n[c],b)} pass rate`,...ce(n[c])},comparison:{family:d.family,left:d.label,right:J(d.family)},effect:{direction:w===0?"different":w>0?"higher":"lower",absoluteDelta:w,relativeDelta:k===0?void 0:w/k,effectSize:w},stats:{method:z,pValue:B,sampleSizeLeft:g,sampleSizeRight:m},summary:ze(d.label,I(n[c],b),w,d.family),highlight:{kind:"region",regionFamily:d.family,regionKeys:[d.key],dieKeys:[...d.dieKeys]}}),{hits:S,n:g,restHits:h,restN:m,passRate:!0}))}}return l}export function welchFromStats(e,t,s,o,n,i){const r=Math.sqrt(s/e+i/o),a=t-n;if(!Number.isFinite(r)||r===0)return{pValue:1,effectSize:0,delta:a,z:0};const u=a/r,l=Math.sqrt(Math.max(0,(s+i)/2)),d=l===0?a:a/l;return{pValue:Ae(u),effectSize:d,delta:a,z:u}}function Ht(e,t){const s=ue(e),o=ue(t);return welchFromStats(e.length,s,$e(e,s),t.length,o,$e(t,o))}function Je(e,t,s){const o=n=>n.filter(i=>X(s?.find(r=>r.testNumber===i)));return o(t?t.slice().sort((n,i)=>n-i):Oe(e,"values"))}export function testValueSize(e,t){const s=e.dies.filter(Te);return{tests:Je(s,t.testNumbers,e.testDefs).length,dies:s.length}}export function recordedOptions(e){const t={};return e.enableTestValueAnalysis!==void 0&&(t.enableTestValueAnalysis=e.enableTestValueAnalysis),e.computePerTestStats!==void 0&&(t.computePerTestStats=e.computePerTestStats),e.sectorCount!==void 0&&(t.sectorCount=e.sectorCount),e.testNumbers!==void 0&&(t.testNumbers=[...e.testNumbers]),t}function It(e,t,s,o,n){const i=new Map;for(let m=0;m<t.length;m++)for(const g of Q(t[m].dies))i.set(g,m);const r=t.length,a=[],u=[];for(const m of e){const g=i.get(ve(m));g!==void 0&&(a.push(m),u.push(g))}const l=[],d=new Float64Array(r),f=new Float64Array(r),p=new Float64Array(r);for(const m of s){d.fill(0),f.fill(0),p.fill(0);let g=0,S=0,F=0,k;for(let w=0;w<a.length;w++){const B=a[w],z=Y(B,m);if(z===void 0)continue;k===void 0&&(k=z);const b=z-k,$=u[w];d[$]+=1,f[$]+=b,p[$]+=b*b,g+=1,S+=b,F+=b*b}if(k!==void 0)for(let w=0;w<r;w++){const B=d[w],z=g-B;if(B<n.minimumSampleSize||z<n.minimumSampleSize)continue;const b=f[w]/B,M=(S-f[w])/z,v=b+k,R=M+k,C=B>1?Math.max(0,p[w]-B*b*b)/(B-1):0,x=z>1?Math.max(0,F-p[w]-z*M*M)/(z-1):0,{pValue:V,effectSize:N,delta:D,z:K}=welchFromStats(B,v,C,z,R,x),P=t[w],{label:O,unit:E,...U}=Lt(m,o),j=R!==0?D/Math.abs(R):void 0,G=se(P,{id:`test:${m}:${P.key}`,level:"wafer",severity:"info",variable:{kind:"test",measure:"mean",index:m,label:O,unit:E,...U},comparison:{family:P.family,left:P.label,right:J(P.family)},effect:{direction:D===0?"different":D>0?"higher":"lower",absoluteDelta:D,relativeDelta:j,effectSize:N},stats:{method:"welch-z-approx",pValue:V,sampleSizeLeft:B,sampleSizeRight:z},summary:Be(P.label,O,D,j,P.family,E),highlight:{kind:"region",regionFamily:P.family,regionKeys:[P.key],dieKeys:[...P.dieKeys]}}),y={n:B,sum:f[w],sq:p[w],restN:z,restSum:S-f[w],restSq:F-p[w],shift:k};xe.set(G,y),Qe(G,K,void 0,y),l.push(G)}}adjustPValues(l);const c=l.filter(m=>{const g=m.stats.adjustedPValue??m.stats.pValue??1,S=Math.abs(m.effect.effectSize??0);return g<=n.significanceLevel&&S>=n.minimumEffectSize}),h=confirmRegionalFindings(c,Xe,(m,g)=>jt(m,g,n));return c.filter(m=>h.has(m)).map(m=>({...m,severity:severityForScore(m.stats.adjustedPValue??m.stats.pValue??1,m.effect.effectSize??0)}))}function Wt(e,t,s,o){if(!s?.length)return[];const n=s.filter(r=>X(r)&&(r.limitLow!==void 0||r.limitHigh!==void 0));if(!n.length)return[];const i=[];for(const r of n){const a=r.testNumber;for(const u of t){const l=pe(e,u),d=[],f=new Map;let p=0,c=0;for(const[h,m]of l){let g=0,S=0;for(const F of m){const k=Y(F,a);k!==void 0&&(g++,Re(de(k,r))&&S++)}f.set(h,{valid:g,fail:S}),p+=g,c+=S}for(const h of u){const m=f.get(h.key),g=m.valid,S=p-m.valid;if(g<o.minimumSampleSize||S<o.minimumSampleSize)continue;const F=m.fail,k=c-m.fail,w=F/g,B=k/S,z=w-B,{pValue:b,method:$}=T(F,g,k,S);d.push(he(se(h,{id:`specLimit:${a}:${h.key}`,level:"wafer",severity:"info",variable:{kind:"test",measure:"limitFailRate",index:a,label:I(r,a),...ce(r)},comparison:{family:h.family,left:h.label,right:J(h.family)},effect:{direction:z===0?"different":z>0?"higher":"lower",absoluteDelta:z,relativeDelta:B===0?void 0:z/B,effectSize:z},stats:{method:$,pValue:b,sampleSizeLeft:g,sampleSizeRight:S},summary:Fe(h.label,I(r,a),z),highlight:{kind:"region",regionFamily:h.family,regionKeys:[h.key],dieKeys:[...h.dieKeys]}}),{hits:F,n:g,restHits:k,restN:S,passRate:!1}))}i.push(...d)}}return i}function Pe(e,t){return e==="softBin"?t.softEligibleDies:e==="test"?t.testDies:t.eligibleDies}function Yt(e){return e.variable.measure==="limitFailRate"}function fe(e){return e.highlight.regionKeys??[]}function _t(e){const t=e.variable.bin??e.variable.index??"";return`${e.comparison.family}\0${et(e)}\0${e.variable.kind}\0${t}\0${e.effect.direction}`}function Qt(e,t){const s=Z(e);return s.family==="ring"?s.ring??0:s.family==="sector"?Le(t).indexOf(s.sector??""):0}export function inQuadrantOrder(e){const t=new Set(e),s=we.findIndex((n,i)=>t.has(n)&&!t.has(we[(i+3)%4])),o=s<0?0:s;return Array.from({length:4},(n,i)=>we[(o+i)%4]).filter(n=>t.has(n))}export function findContiguousRuns(e,t,s,o){if(t==="quadrant"){const u=new Map;for(const p of e){const c=Z(o(p)).quadrant;c&&u.set(c,p)}const l=[...u.keys()],d=new Set,f=[];for(const p of l){if(d.has(p))continue;const c=[],h=[p];for(d.add(p);h.length;){const m=h.pop();c.push(m);for(const g of l)!d.has(g)&&bt(m,g)&&(d.add(g),h.push(g))}f.push(inQuadrantOrder(c).map(m=>u.get(m)))}return f}const n=u=>Qt(o(u),s),i=[...e].sort((u,l)=>n(u)-n(l)),r=[];let a=[];for(const u of i){if(a.length===0){a.push(u);continue}const l=n(a[a.length-1]);n(u)-l===1?a.push(u):(r.push(a),a=[u])}if(a.length&&r.push(a),t==="sector"&&r.length>1){const l=Le(s).length,d=n(r[0][0]),f=n(r[r.length-1][r[r.length-1].length-1]);if(d===0&&f===l-1){const p=r.pop();r[0]=[...p,...r[0]]}}return r}export function mergedRegionLabel(e,t,s){if(e==="ring"){const n=t.map(u=>Z(u).ring).filter(u=>u!==void 0).sort((u,l)=>u-l),i=n[0],r=n[n.length-1];let a="";return i===r&&i===1&&s>1?a=" (core)":i===r&&i===s&&s>1&&(a=" (edge)"),i===r?`Ring ${i}${a}`:`Rings ${i}\u2013${r}`}if(e==="sector"){const n=t.map(i=>Z(i).sector??"");return n.length===1?`Sector ${n[0]}`:`Sectors ${n[0]}\u2013${n[n.length-1]}`}const o=t.map(n=>Z(n).quadrant??"");return o.length===1?o[0]:o.length===2?`Quadrants ${o[0]} & ${o[1]}`:`Quadrants ${o.slice(0,-1).join(", ")} & ${o[o.length-1]}`}function Ne(e){return[...new Set(e)]}export function weakestMultiplier(e){return Ft(e.map(t=>{const s=t.stats.pValue??1;return s>0?(t.stats.adjustedPValue??s)/s:1}))}function te(e,t){return Math.min(1,e*t)}function Ut(e,t){const s=e[0],o=s.comparison.family,n=s.variable.kind,i=Ne(e.flatMap(fe));let r,a;const u=e.map(Ue);if(u.every(b=>b!==void 0)){const b=new Set;r=[];for(const M of u){const v=Q(M.dies);for(let R=0;R<v.length;R++)b.has(v[R])||(b.add(v[R]),r.push(M.dieKeys[R]))}const $=Q(Pe(s.variable.kind,t));a=M=>b.has($[M])}else{r=Ne(e.flatMap(M=>M.highlight.dieKeys??[]));const b=new Set(r),$=At(Pe(s.variable.kind,t));a=M=>b.has($[M])}const l=mergedRegionLabel(o,e.map(b=>fe(b)[0]??""),t.ringCount),d=Pe(n,t),f=t.regionDies[o],p=Q(d),c=[],h=[];for(let b=0;b<d.length;b++)f.has(p[b])&&(a(b)?c:h).push(d[b]);const m=weakestMultiplier(e);let g,S,F,k,w;if(Yt(s)){const b=s.variable.index,$=t.testDefs?.find(P=>P.testNumber===b),M=P=>{let O=0,E=0;for(const U of P){const j=Y(U,b);j!==void 0&&(O++,$&&Re(de(j,$))&&E++)}return{valid:O,fail:E}},v=M(c),R=M(h),C=v.valid>0?v.fail/v.valid:0,x=R.valid>0?R.fail/R.valid:0,V=C-x,{pValue:N,method:D}=T(v.fail,v.valid,R.fail,R.valid);g={direction:V===0?"different":V>0?"higher":"lower",absoluteDelta:V,relativeDelta:x===0?void 0:V/x,effectSize:V},S={method:D,pValue:N,sampleSizeLeft:v.valid,sampleSizeRight:R.valid};const K=te(N,m);F=severityForFinding(K,V,rateRelativeEffect({hits:v.fail,n:v.valid,restHits:R.fail,restN:R.valid,passRate:!1})),k=Fe(l,I($,b),V),w=`specLimit:${b}`}else if(n==="test"){const b=s.variable.index,$=K=>Y(K,b),M=c.map($).filter(K=>K!==void 0),v=h.map($).filter(K=>K!==void 0),{pValue:R,effectSize:C,delta:x}=Ht(M,v),V=ue(v),N=V!==0?x/Math.abs(V):void 0;g={direction:x===0?"different":x>0?"higher":"lower",absoluteDelta:x,relativeDelta:N,effectSize:C},S={method:"welch-z-approx",pValue:R,sampleSizeLeft:M.length,sampleSizeRight:v.length};const D=te(R,m);F=severityForScore(D,C),k=Be(l,s.variable.label,x,N,o,s.variable.unit),w=`test:${b}`}else if(n==="yield"){const b=new Set(t.passBins),$=c.filter(E=>E.hbin!==void 0),M=h.filter(E=>E.hbin!==void 0),v=$.length,R=M.length,C=$.filter(E=>b.has(E.hbin)).length,x=M.filter(E=>b.has(E.hbin)).length,V=v>0?C/v:0,N=R>0?x/R:0,D=V-N,{pValue:K,method:P}=T(C,v,x,R);g={direction:D===0?"different":D>0?"higher":"lower",absoluteDelta:D,relativeDelta:N===0?void 0:D/N,effectSize:D},S={method:P,pValue:K,sampleSizeLeft:v,sampleSizeRight:R};const O=te(K,m);F=severityForFinding(O,D,rateRelativeEffect({hits:C,n:v,restHits:x,restN:R,passRate:!0})),k=ke(l,D,o),w="yield"}else if(n==="functionalTest"){const b=s.variable.index,$=t.testDefs?.find(O=>O.testNumber===b);let M=0,v=0,R=0,C=0;for(const O of c){const E=le(O,b,$);E!==void 0&&(v++,E&&M++)}for(const O of h){const E=le(O,b,$);E!==void 0&&(C++,E&&R++)}const x=v>0?M/v:0,V=C>0?R/C:0,N=x-V,{pValue:D,method:K}=T(M,v,R,C);g={direction:N===0?"different":N>0?"higher":"lower",absoluteDelta:N,relativeDelta:V===0?void 0:N/V,effectSize:N},S={method:K,pValue:D,sampleSizeLeft:v,sampleSizeRight:C};const P=te(D,m);F=severityForFinding(P,N,rateRelativeEffect({hits:M,n:v,restHits:R,restN:C,passRate:!0})),k=ze(l,I($,b),N,o),w=`functional:${b}`}else{const b=s.variable.bin,$=P=>n==="softBin"?P.sbin:P.hbin,M=c.filter(P=>$(P)===b).length,v=h.filter(P=>$(P)===b).length,R=M/c.length,C=v/h.length,x=R-C,{pValue:V,method:N}=T(M,c.length,v,h.length);g={direction:x===0?"different":x>0?"higher":"lower",absoluteDelta:x,relativeDelta:C===0?void 0:x/C,effectSize:x},S={method:N,pValue:V,sampleSizeLeft:c.length,sampleSizeRight:h.length};const D=te(V,m);F=severityForFinding(D,x,rateRelativeEffect({hits:M,n:c.length,restHits:v,restN:h.length,passRate:!1}));const K=n==="softBin"?t.sbinDefs:t.hbinDefs;k=De(l,He(b,K,n==="softBin"?"SBin":"HBin"),x,o),w=`${n}:${b}`}S={...S,adjustedPValue:te(S.pValue??1,m)};const B=Ne(i.map(b=>b.replace(`${o}:`,""))).join("-"),z=n==="hardBin"||n==="softBin"?{kind:"bin",bin:s.variable.bin,regionKeys:i,dieKeys:r}:{kind:"region",regionFamily:o,regionKeys:i,dieKeys:r};return{...s,id:`${w}:${o}:${B}`,severity:F,comparison:{family:o,left:l,right:J(o)},effect:g,stats:S,summary:k,highlight:z,relatedIds:e.map(b=>b.id)}}function Gt(e,t){const s=new Set(["ring","quadrant","sector"]),o=[],n=new Map;for(const r of e){if(!s.has(r.comparison.family)){o.push(r);continue}const a=_t(r),u=n.get(a)??[];u.push(r),n.set(a,u)}const i=[];for(const r of n.values()){if(r.length===1){i.push(r[0]);continue}const a=r[0].comparison.family;for(const u of findContiguousRuns(r,a,t.sectorCount,l=>fe(l)[0]??""))i.push(u.length===1?u[0]:Ut(u,t))}return[...o,...i]}function Xt(e){const t=new Map,s=new Map;for(const n of e){const i=ve(n);n.hbin!==void 0&&n.hbin!==null&&(t.get(n.hbin)??t.set(n.hbin,new Set).get(n.hbin)).add(i),n.sbin!==void 0&&n.sbin!==null&&(s.get(n.sbin)??s.set(n.sbin,new Set).get(n.sbin)).add(i)}const o=new Set;for(const[n,i]of t)for(const[r,a]of s){if(i.size!==a.size)continue;let u=!0;for(const l of i)if(!a.has(l)){u=!1;break}u&&o.add(`${n}:${r}`)}return o}function Zt(e,t){const s=new Set(t);let o;for(const n of e){const i=be(n,s);if(i!==void 0&&i){if(n.sbin==null||o!==void 0&&n.sbin!==o)return;o=n.sbin}}if(o!==void 0){for(const n of e)if(n.sbin===o&&be(n,s)!==!0)return;return o}}function Jt(e){return`${e.comparison.family}\0${e.comparison.left}`}export function redundancyFacts(e,t,s){return{coincident:Xt(e),yieldSoftBin:Zt(e,t),passBins:t,sectorCount:s}}const en=3/5;function et(e){return/^(?:lot-region:)?([^:|]+)/.exec(e.id)?.[1]??e.id}function tn(e){const t=fe(e);if(t.length)return t;const s=/(ring|sector|quadrant):([^:|]+)$/.exec(e.id);return s?s[2].split("-").map(o=>`${s[1]}:${o}`):[]}function tt(e,t){const s=new Set;for(const o of tn(e)){const n=yt(o,t);if(!n)return;for(const i of n)s.add(i)}return s.size?s:void 0}export function collapseRedundantFindings(e,t){const{coincident:s,yieldSoftBin:o,passBins:n}=t,i=(l,d)=>{l.absorbedIds=[...l.absorbedIds??[],d.id]},r=new Map;for(const l of e){const d=Jt(l);(r.get(d)??r.set(d,[]).get(d)).push(l)}const a=new Set;for(const l of r.values()){for(const f of l)if(!(f.variable.kind!=="hardBin"||f.variable.bin===void 0))for(const p of l){if(p.variable.kind!=="softBin"||p.variable.bin===void 0||a.has(p.id)||!s.has(`${f.variable.bin}:${p.variable.bin}`)||p.effect.direction!==f.effect.direction)continue;i(f,p),a.add(p.id);const c=f.variable.label.replace(/^HBin\s+/,""),h=p.variable.label.replace(/^SBin\s+/,""),m=c===h?`HBin and SBin ${c} (same dies)`:`${f.variable.label} and ${p.variable.label} (same dies)`;f.summary=f.summary.replace(f.variable.label,m),f.variable.label=m;break}const d=l.find(f=>f.variable.kind==="yield");if(d){for(const f of l)if(!(f===d||a.has(f.id)||!(f.variable.kind==="hardBin"&&n.length===1&&f.variable.bin===n[0]||f.variable.kind==="softBin"&&f.variable.bin===o))){i(d,f),a.add(f.id);for(const c of f.absorbedIds??[])d.absorbedIds=[...d.absorbedIds??[],c]}}}const u=new Map;for(const l of e){if(a.has(l.id)||l.comparison.family!=="sector"&&l.comparison.family!=="quadrant")continue;const d=[et(l),l.variable.kind,l.variable.bin??"",l.variable.index??"",l.effect.direction].join("\0");(u.get(d)??u.set(d,[]).get(d)).push(l)}for(const l of u.values()){const d=[];for(const f of l.filter(p=>p.comparison.family==="sector")){const p=tt(f,t.sectorCount);if(p)for(const c of l.filter(h=>h.comparison.family==="quadrant")){const h=tt(c,t.sectorCount);if(!h)continue;let m=0;for(const S of p)h.has(S)&&m++;const g=p.size+h.size-m;m/g>=en-1e-9&&d.push({sector:f,quadrant:c,overlap:m/g})}}d.sort((f,p)=>p.overlap-f.overlap);for(const{sector:f,quadrant:p}of d){if(a.has(f.id)||a.has(p.id))continue;const c=(p.stats.pValue??1)<(f.stats.pValue??1),[h,m]=c?[p,f]:[f,p];i(h,m),a.add(m.id),h.absorbedIds=[...h.absorbedIds??[],...m.absorbedIds??[]]}}}export function analyzeWaferMap(e,t={}){return analyzeWaferMapDecided(e,t)}export function analyzeWaferMapDecided(e,t={},s){const o=ee,n=oe,i=[];ee=i,oe=void 0;try{const r=nn(e,t,s);return _e.set(r,{candidates:i,facts:oe}),r}finally{ee=o,oe=n}}function nn(e,t,s){const{resolved:o,warnings:n}=resolveOptions(t),i=st(e),r={...o,passBins:[...kt(i,"analyzeWaferMap")],ringCount:Mt(i,"analyzeWaferMap")},a=i.isLotStack,u=i.aggrMethod,l=ut(a,u),d=l,f=i.dies.filter(y=>Te(y)),p=f.filter(Ke),c=Pt(r,f.length);c.softPassBins=Ee(f,c.passBins).soft;const h=Je(f,c.testNumbers,i.testDefs),m=c.enableTestValueAnalysis,g=m===!1?"off":m===!0?"done":s??ot(h.length*f.length),S=i.dies.filter(y=>ye(y)),F=S.filter(Ke),k=l?f.filter(y=>y.sbin!==void 0):[],w=d&&f.some(y=>y.hbin!==void 0)||k.length>0||m!==!1,B=w?ht(F,i.wafer,c.ringCount):[],z=w?dt(F,i.wafer,c.ringCount):[],b=w?mt(F,i.reticleConfig):[],$=w?gt(S,!1):[],M=w?pt(F,i.wafer,c.sectorCount):[],v=[],R=[];d&&R.push(...ae(f,B,c.passBins,c),...ae(f,z,c.passBins,c),...ae(f,b,c.passBins,c),...ae(f,$,c.passBins,c),...ae(f,M,c.passBins,c)),d&&R.push(...q(f,B,"hard",i.hbinDefs,"hardBin",c),...q(f,z,"hard",i.hbinDefs,"hardBin",c),...q(f,b,"hard",i.hbinDefs,"hardBin",c),...q(f,$,"hard",i.hbinDefs,"hardBin",c),...q(f,M,"hard",i.hbinDefs,"hardBin",c));{const y=k;R.push(...q(y,B,"soft",i.sbinDefs,"softBin",c),...q(y,z,"soft",i.sbinDefs,"softBin",c),...q(y,b,"soft",i.sbinDefs,"softBin",c),...q(y,$,"soft",i.sbinDefs,"softBin",c),...q(y,M,"soft",i.sbinDefs,"softBin",c))}const C=[...n];let x;if(m!==!1){if(g==="done"){for(const y of[B,z,b,$,M])v.push(...It(f,y,h,i.testDefs,c));x=h}R.push(...Wt(f,[B,z,b,$,M],i.testDefs,c)),R.push(...re(f,B,i.testDefs,c),...re(f,z,i.testDefs,c),...re(f,b,i.testDefs,c),...re(f,$,i.testDefs,c),...re(f,M,i.testDefs,c))}v.push(...qt(R,c));{const y=Nt(a,d,i.testDefs);(!a||d||y!==void 0)&&v.push(...St(p,i.wafer,{...c,isFailingDie:y}))}const V=Gt(v,{eligibleDies:f,softEligibleDies:k,testDies:f,passBins:c.passBins,ringCount:c.ringCount,sectorCount:c.sectorCount,regionDies:{ring:new Set(B.flatMap(y=>Q(y.dies))),quadrant:new Set(z.flatMap(y=>Q(y.dies))),sector:new Set(M.flatMap(y=>Q(y.dies)))},hbinDefs:i.hbinDefs,sbinDefs:i.sbinDefs,testDefs:i.testDefs});v.length=0,v.push(...V);let N;if(d){const y=vt(p,i.wafer,{passBins:c.passBins,ringCount:c.ringCount});if(N=y??void 0,y!==null&&y.pattern!=="random"&&y.pattern!=="none"){const L=Rt[y.pattern],H=y.confidence==="high"?"unusual":y.confidence==="medium"?"notable":"info",A=y.features,ne=W=>`${(W*100).toFixed(0)}%`,nt=y.pattern==="edge-ring"||y.pattern==="edge-local"?`${ne(A.edgeRdd)} of edge dies failing`:y.pattern==="center"?`centroid at ${ne(A.centroidDistNorm)} of wafer radius from centre`:y.pattern==="donut"?`${ne(Math.max(A.radialFailRates[1],A.radialFailRates[2]))} of dies failing at mid-radius, ${ne(A.radialFailRates[0])} at the centre`:y.pattern==="scratch"?`a line ${Math.round(A.lineLength)} dies long and about ${Math.max(1,Math.round(A.lineWidth*2))} wide`:`${ne(A.globalRdd)} of dies failing`,it=new Set(c.passBins),Ce=f.filter(W=>$t(W,it)===!0),Ve=claimForPattern([y.pattern],H,v,W=>fe(W).map(ge=>Z(ge).ring).filter(ge=>ge!==void 0),c.ringCount);v.push({id:`spatial-pattern:${y.pattern}`,level:"wafer",severity:H,variable:{kind:"spatialPattern",label:L},comparison:{family:"spatial-pattern",left:L,right:"Wafer"},effect:{direction:"different",effectSize:A.globalRdd},stats:{method:"geometry",sampleSizeLeft:Ce.length,sampleSizeRight:f.length},summary:`Spatial pattern: ${L.toLowerCase()} (${y.confidence} confidence) \u2014 ${nt}${y.note?` [${y.note}]`:""}`,highlight:{kind:"dies",dieKeys:Ce.map(W=>Se(W))},relatedIds:Ve.length>0?Ve:void 0})}}v.sort((y,L)=>{const H=y.stats.adjustedPValue??y.stats.pValue??1,A=L.stats.adjustedPValue??L.stats.pValue??1;return H!==A?H-A:Math.abs(L.effect.absoluteDelta??0)-Math.abs(y.effect.absoluteDelta??0)});const D=Ct(i.dies,f.length,i.yield.yieldPercent);a&&(D.isLotStack=!0,u&&(D.aggregationMethod=u));const K=new Set(r.passBins),P={},O=(y,L)=>{const H=P[y]??={dieKeys:[],lostDies:0};H.dieKeys.push(Se(L)),be(L,K)!==!0&&H.lostDies++},E=Vt(i.dies,i.testDefs,O);E&&(D.testSpecYield=E);const U=computeFunctionalYield(i.dies,i.testDefs,O);if(U&&(D.functionalYield=U),Object.keys(P).length&&(D.testFailures=P),N&&(D.spatialPattern=N),x===void 0&&c.computePerTestStats&&(x=h),h.length&&(D.testValueAnalysis=at(g,h.length,f.length)),x?.length){const y=Et(i.dies,x,i.testDefs,c.minimumSampleSize);y&&(D.perTestStats=y);const L=rt([{dies:i.dies}],i.testDefs,x);L&&(D.capability=L)}Object.assign(D,ft(i.dies,i.testDefs));const j=lt([{dies:i.dies,wafer:i.wafer,passBins:c.passBins,ringCount:c.ringCount}]);j&&(D.regionYield=j),C.length>0&&(D.warnings=C);const G=redundancyFacts(f,c.passBins,c.sectorCount);return collapseRedundantFindings(v,G),ee&&(oe=G),{level:"wafer",hasNotableFindings:v.some(y=>y.severity==="notable"||y.severity==="unusual"),findings:v,wafer:i.wafer.metadata??void 0,analysisOptions:recordedOptions(t),stats:D}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{seededRandom as
|
|
1
|
+
import{seededRandom as et}from"./math.js";import{ringOf as nt}from"../core/classify.js";import{compassBucket as it,sectorCompassNames as st}from"./regions.js";import{getDieKey as ot,gridKey as N}from"../core/dies.js";import{findConnectedComponents as rt,LargestComponentSizer as at}from"./connectedComponents.js";function ct(t,n){return st(16)[it(t,n,16)]}function lt(t){if(t.length<2)return 0;const n=[...t].sort((s,e)=>s-e);let i=n[0]+2*Math.PI-n[n.length-1];for(let s=1;s<n.length;s++)i=Math.max(i,n[s]-n[s-1]);return 2*Math.PI-i}function ut(t,n,i,s){const e=s!==void 0?Math.abs(s):0;return t<=.01&&(n>=.25||e>=2||i>=.1)?"unusual":t<=.05&&(n>=.15||e>=1||i>=.03)?"notable":"info"}const ft=99,ht=9999,j=10;class mt{sizer;failCount;maxima=[];random;order;failing;constructor(n,i,s,e){this.sizer=n,this.failCount=s,this.random=et(e),this.order=new Int32Array(i);for(let f=0;f<i;f++)this.order[f]=f;this.failing=new Uint8Array(i)}at(n){const{order:i,failing:s,failCount:e,random:f}=this,m=i.length;for(;this.maxima.length<=n;){for(let r=0;r<e;r++){const M=r+Math.floor(f()*(m-r)),g=i[r];i[r]=i[M],i[M]=g,s[i[r]]=1}this.maxima.push(this.sizer.largest(s));for(let r=0;r<e;r++)s[i[r]]=0}return this.maxima[n]}pValue(n,i){let s=0;for(let e=0;e<i;e++)if(this.at(e)>=n&&++s===j)return j/(e+1);return(1+s)/(1+i)}}function gt(t){let n=0,i=0;for(let s=0;s<t.length;s++){let e=Math.imul(t[s].x|0,2654435761)^Math.imul(t[s].y|0,2246822507);e=Math.imul(e^e>>>16,2146121005),e=Math.imul(e^e>>>15,2221713035),n=n+(e^e>>>16)|0,i=i+Math.imul(e,668265263)+374761393|0}return`${t.length}:${n>>>0}:${i>>>0}`}function pt(t,n){return t<=20?t:Math.min(n,Math.ceil(20*1.05**Math.ceil(Math.log(t/20)/Math.log(1.05))))}const dt=new Map,yt=new Map;function G(t,n,i,s){let e=t.get(n);return e===void 0&&(e=s(),t.set(n,e),t.size>i&&t.delete(t.keys().next().value)),e}function Mt(t,n,i,s){const e=t.length,f=Math.min(ht,Math.max(ft,Math.ceil(1/s))),m=gt(t),r=pt(n,e),M=G(yt,`${m}:${r}`,16,()=>{const g=G(dt,m,4,()=>new at([...t].sort((v,d)=>v.y-d.y||v.x-d.x))),[,P,R]=m.split(":").map(Number);return new mt(g,e,r,(P^Math.imul(R,739982445)^Math.imul(r+1,2246822507))>>>0)});return i.map(g=>M.pValue(g,f))}export function buildClusterFindings(t,n,i){const{passBins:s,significanceLevel:e,minimumEffectSize:f,minimumRelativeEffect:m,minimumSampleSize:r,minimumClusterSize:M,ringCount:g}=i,P=new Set(s);if(t.length<r)return[];const R=o=>{const a=o.hbin??o.sbin;return a===void 0||!P.has(a)},v=i.isFailingDie??R,d=t.filter(v),x=d.length/t.length;if(d.length===0)return[];if(x===1&&f>0&&m>0)return[];const D=t[0],L=D?D.width:10,V=D?D.height:10,X=Math.max(L,V)*1.5,I=new Map;for(const o of t)I.set(N(o.x,o.y),o);const K=Math.ceil(X/L),T=Math.ceil(X/V),Z=rt(d),O=[],E=[],Y=n.center.x,k=n.center.y,q=n.radius;for(const o of Z){if(o.length<M)continue;const a=new Set(o.map(u=>N(u.x,u.y)));for(const u of o)for(let h=-T;h<=T;h++)for(let z=-K;z<=K;z++){const w=N(u.x+z,u.y+h);if(a.has(w))continue;const F=I.get(w);F&&Math.hypot(F.physX-u.physX,F.physY-u.physY)<=X&&a.add(w)}const l=[...a].map(u=>I.get(u)).filter(Boolean),p=o.length,b=l.length;if(b<r)continue;const S=p/b,$=S-x,y=x>0?$/x:void 0;($>=f||y!==void 0&&y>=m)&&E.push({component:o,k:p,clusterRate:S,delta:$,relativeDelta:y})}if(!E.length)return[];const H=Mt(t,d.length,E.map(o=>o.k),e);for(let o=0;o<E.length;o++){const{component:a,k:l,clusterRate:p,delta:b,relativeDelta:S}=E[o],$=H[o],y=$;if(y>e)continue;const A=a.reduce((c,C)=>c+C.physX,0)/l,u=a.reduce((c,C)=>c+C.physY,0)/l;let h=a[0],z=1/0;for(const c of a){const C=Math.hypot(c.physX-A,c.physY-u);C<z&&(z=C,h=c)}const w=lt(a.map(c=>Math.atan2(c.physY-k,c.physX-Y)))*180/Math.PI,B=a.filter(c=>nt(c.physX-Y,c.physY-k,q,g)===g).length>l/2&&w<120,U=B?"edge-arc":"cluster",_=ct(A-Y,u-k),J=B?`Edge arc ~${_}`:`Cluster at (${h.x}, ${h.y})`,Q=l/t.length,W=ut(y,b,Q,S),tt=a.map(c=>ot(c));O.push({id:`${U}:${h.x},${h.y}`,level:"wafer",severity:W,variable:{kind:"yield",label:"Yield"},comparison:{family:U,left:J,right:"Rest of wafer"},effect:{direction:"lower",absoluteDelta:-b,relativeDelta:S!==void 0?-S:void 0,effectSize:b},stats:{method:"permutation",pValue:$,adjustedPValue:y,sampleSizeLeft:l,sampleSizeRight:t.length-l},summary:B?`Edge arc near ${_}: ${l} contiguous failing dies (${(p*100).toFixed(0)}% vs ${(x*100).toFixed(0)}% background)`:`Failure cluster at (${h.x}, ${h.y}): ${l} contiguous failing dies (${(p*100).toFixed(0)}% vs ${(x*100).toFixed(0)}% background)`,highlight:{kind:"dies",dieKeys:tt}})}return O.sort((o,a)=>{const l=o.stats.pValue??1,p=a.stats.pValue??1;return l!==p?l-p:Math.abs(a.effect.effectSize??0)-Math.abs(o.effect.effectSize??0)})}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{gridKey as
|
|
1
|
+
import{gridKey as m}from"../core/dies.js";const A=[-1,0,1,-1,1,-1,0,1],k=[-1,-1,-1,0,0,1,1,1];export function findConnectedComponents(h){if(h.length===0)return[];const o=S(h);if(o)return o;const s=new Map;for(const n of h)s.set(m(n.x,n.y),n);const u=new Set,c=[];for(const n of h){const t=m(n.x,n.y);if(u.has(t))continue;const r=[],i=[n];for(u.add(t);i.length>0;){const p=i.pop();r.push(p);for(let f=0;f<8;f++){const d=m(p.x+A[f],p.y+k[f]);if(u.has(d))continue;const y=s.get(d);y&&(u.add(d),i.push(y))}}c.push(r)}return c}function S(h){const o=h.length;let s=1/0,u=-1/0,c=1/0,n=-1/0;for(let e=0;e<o;e++){const{x:l,y:a}=h[e];if(!Number.isInteger(l)||!Number.isInteger(a))return;l<s&&(s=l),l>u&&(u=l),a<c&&(c=a),a>n&&(n=a)}const t=u-s+1,r=n-c+1;if(t*r>4*o+1024||t*r>1<<26)return;const i=(e,l)=>(e-s)*r+(l-c),p=new Int32Array(t*r);for(let e=0;e<o;e++)p[i(h[e].x,h[e].y)]=e+1;const f=new Uint8Array(t*r),d=[],y=[];for(let e=0;e<o;e++){const l=h[e],a=i(l.x,l.y);if(f[a])continue;f[a]=1;const C=[];for(y.push(l);y.length>0;){const I=y.pop();C.push(I);for(let x=0;x<8;x++){const b=I.x+A[x],g=I.y+k[x];if(b<s||b>u||g<c||g>n)continue;const w=i(b,g);f[w]||p[w]===0||(f[w]=1,y.push(h[p[w]-1]))}}d.push(C)}return d}export class LargestComponentSizer{start;list;seen;stack;stamp=0;constructor(o){const s=o.length,u=new Map;for(let t=0;t<s;t++)u.set(m(o[t].x,o[t].y),t);const c=new Int32Array(s+1),n=[];for(let t=0;t<s;t++){c[t]=n.length;for(let r=0;r<8;r++){const i=u.get(m(o[t].x+A[r],o[t].y+k[r]));i!==void 0&&n.push(i)}}c[s]=n.length,this.start=c,this.list=Int32Array.from(n),this.seen=new Int32Array(s),this.stack=new Int32Array(s)}largest(o){const{start:s,list:u,seen:c,stack:n}=this,t=++this.stamp;let r=0;for(let i=0;i<o.length;i++){if(!o[i]||c[i]===t)continue;c[i]=t;let p=0;n[p++]=i;let f=0;for(;p>0;){const d=n[--p];f++;for(let y=s[d];y<s[d+1];y++){const e=u[y];o[e]&&c[e]!==t&&(c[e]=t,n[p++]=e)}}f>r&&(r=f)}return r}}
|
|
@@ -57,6 +57,16 @@ export interface CorrelationMatrix {
|
|
|
57
57
|
of: number;
|
|
58
58
|
used: number;
|
|
59
59
|
};
|
|
60
|
+
/**
|
|
61
|
+
* Present only when the matrix covers a selection of the tests — see
|
|
62
|
+
* `CORRELATION_TEST_BUDGET`. `of` is how many parametric tests there were, `used`
|
|
63
|
+
* how many entered the matrix. Same rule as `sample`: a surface showing the matrix
|
|
64
|
+
* says so (`correlationSampleNote`).
|
|
65
|
+
*/
|
|
66
|
+
testSample?: {
|
|
67
|
+
of: number;
|
|
68
|
+
used: number;
|
|
69
|
+
};
|
|
60
70
|
}
|
|
61
71
|
/**
|
|
62
72
|
* Dies read before `buildCorrelationMatrix` starts sampling.
|
|
@@ -72,11 +82,33 @@ export interface CorrelationMatrix {
|
|
|
72
82
|
* already invisible at two decimal places.
|
|
73
83
|
*/
|
|
74
84
|
export declare const CORRELATION_DIE_BUDGET = 25000;
|
|
75
|
-
/** The sentence a panel puts next to a sampled matrix. */
|
|
76
|
-
export declare function correlationSampleNote(sample: CorrelationMatrix['sample']): string | undefined;
|
|
77
85
|
/**
|
|
78
|
-
*
|
|
79
|
-
*
|
|
86
|
+
* Tests entering the pairwise pass of `buildCorrelationMatrix`.
|
|
87
|
+
*
|
|
88
|
+
* The pass is quadratic in tests: 6 accumulators per pair and one cell per ordered
|
|
89
|
+
* pair. A real test program reaches thousands of parametric tests — at 2,002 the
|
|
90
|
+
* matrix took 38 s to build, at 15,000 (112M pairs, ~5 GB of accumulators) it never
|
|
91
|
+
* finished. The panel shows at most 100 tests (20 by default), the strongest pairs
|
|
92
|
+
* first, so the candidates are chosen before pairing instead of after.
|
|
93
|
+
*
|
|
94
|
+
* 300 tests is 44,850 pairs: about a second and a half on a 3,000-die wafer.
|
|
95
|
+
*/
|
|
96
|
+
export declare const CORRELATION_TEST_BUDGET = 300;
|
|
97
|
+
/**
|
|
98
|
+
* Pair updates (test pairs × dies) the pairwise pass may make. Within it the die
|
|
99
|
+
* sample is `CORRELATION_DIE_BUDGET`; past it the dies are thinned, evenly, to fit:
|
|
100
|
+
* 300 tests (44,850 pairs) read about 5,600 dies, where the standard error of r is
|
|
101
|
+
* ~0.013 — while 300 tests over the full 25,000-die budget was 1.1×10⁹ updates and
|
|
102
|
+
* 12 s in a browser.
|
|
103
|
+
*/
|
|
104
|
+
export declare const CORRELATION_WORK_BUDGET = 250000000;
|
|
105
|
+
/** The sentence a panel puts next to a matrix built from a sample of the dies or the tests. */
|
|
106
|
+
export declare function correlationSampleNote(m: Pick<CorrelationMatrix, 'sample' | 'testSample'>): string | undefined;
|
|
107
|
+
/**
|
|
108
|
+
* Pearson correlation matrix for the parametric tests in `testDefs` across the
|
|
109
|
+
* dies in `dies` — every test up to `CORRELATION_TEST_BUDGET` (above it, the
|
|
110
|
+
* chosen ones: `testSample`), every die up to `CORRELATION_DIE_BUDGET` (above it,
|
|
111
|
+
* an even spread: `sample`).
|
|
80
112
|
*
|
|
81
113
|
* Running-accumulator algorithm: one die-walk, 6 Float64 accumulators per
|
|
82
114
|
* upper-triangle pair (count, sumX, sumY, sumXX, sumYY, sumXY). No pair
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{dieHasValues as
|
|
1
|
+
import{dieHasValues as O,testValue as _}from"../core/dieTable.js";import{isParametricTest as E}from"../renderer/buildWaferMap.js";import{markedTestLabel as P,derivedFields as k}from"../renderer/testLabel.js";export function pearsonFromSums(e,s,f,m,u,d){if(e<3)return null;const g=s/e,i=f/e,a=d/e-g*i,p=m/e-g*g,b=u/e-i*i,M=Math.sqrt(p*b);return M===0?null:Math.max(-1,Math.min(1,a/M))}export function pearsonOfPairs(e){let s=0,f=0,m=0,u=0,d=0,g=0;for(let i=0;i<e.length;i++){const{x:a,y:p}=e[i];!Number.isFinite(a)||!Number.isFinite(p)||(s++,f+=a,m+=p,u+=a*a,d+=p*p,g+=a*p)}return{r:pearsonFromSums(s,f,m,u,d,g),n:s}}export const CORRELATION_DIE_BUDGET=25e3;function v(e,s){const f=[],m=e/s;for(let u=0;u<s;u++)f.push(Math.floor(u*m));return f}export const CORRELATION_TEST_BUDGET=300,CORRELATION_WORK_BUDGET=25e7;export function correlationSampleNote(e){const s=[];return e.testSample&&s.push(`Among the ${e.testSample.used.toLocaleString()} of ${e.testSample.of.toLocaleString()} tests with the most dies outside their limits, then the widest spread`),e.sample&&s.push(`${s.length?"from":"From"} a ${e.sample.used.toLocaleString()}-die sample of ${e.sample.of.toLocaleString()}, spread evenly across the lot`),s.length?s.join(", "):void 0}function z(e,s,f,m){const u=e.length,d=new Float64Array(u),g=new Float64Array(u),i=new Float64Array(u),a=new Float64Array(u),p=e.map(r=>s.get(r.testNumber)?.limitLow),b=e.map(r=>s.get(r.testNumber)?.limitHigh);for(const r of f)for(let n=0;n<u;n++){const t=_(r,e[n].testNumber);t===void 0||!Number.isFinite(t)||(d[n]++,g[n]+=t,i[n]+=t*t,(p[n]!==void 0&&t<p[n]||b[n]!==void 0&&t>b[n])&&a[n]++)}const M=r=>{if(d[r]<3)return-1;const n=g[r]/d[r],t=Math.sqrt(Math.max(0,i[r]/d[r]-n*n)),c=p[r]!==void 0&&b[r]!==void 0?b[r]-p[r]:Math.abs(n);return c>0?t/c:0},h=e.map((r,n)=>({i:n,fails:d[n]<3?-1:a[n],spread:M(n)}));return h.sort((r,n)=>n.fails-r.fails||n.spread-r.spread||r.i-n.i),h.slice(0,m).map(r=>r.i).sort((r,n)=>r-n).map(r=>e[r])}function D(e){return e.filter(s=>s.testNumber!==void 0&&E(s)).map(s=>({testNumber:s.testNumber,label:P(s,s.testNumber),unit:s.unit,...k(s)}))}export function buildCorrelationMatrix(e,s){const f=D(s);if(f.length<2)return{tests:f,cells:[]};const m=e.filter(O),d=m.length>CORRELATION_DIE_BUDGET?v(m.length,CORRELATION_DIE_BUDGET).map(o=>m[o]):m,g=f.length>CORRELATION_TEST_BUDGET,i=g?z(f,new Map(s.flatMap(o=>o.testNumber===void 0?[]:[[o.testNumber,o]])),d,CORRELATION_TEST_BUDGET):f,a=i.length*(i.length-1)/2,p=Math.max(1,Math.floor(CORRELATION_WORK_BUDGET/Math.max(1,a))),b=d.length>p?v(d.length,p).map(o=>d[o]):d,M=b.length<m.length,h=i.length,r=i.map(o=>o.testNumber),n=h*(h-1)/2,t=new Float64Array(n),c=new Float64Array(h),x=new Float64Array(n),N=new Float64Array(n),y=new Float64Array(n),w=new Float64Array(n),R=new Float64Array(n);function Y(o,l){return o*h-(o*(o+1)>>1)+(l-o-1)}const L=new Float64Array(h),T=new Uint8Array(h);for(const o of b){T.fill(0);for(let l=0;l<h;l++){const I=_(o,r[l]);I!==void 0&&Number.isFinite(I)&&(L[l]=I,T[l]=1)}for(let l=0;l<h;l++){if(!T[l])continue;c[l]++;const I=L[l];for(let F=l+1;F<h;F++){if(!T[F])continue;const A=L[F],S=Y(l,F);t[S]++,x[S]+=I,N[S]+=A,y[S]+=I*I,w[S]+=A*A,R[S]+=I*A}}}const C=o=>pearsonFromSums(t[o],x[o],N[o],y[o],w[o],R[o]),X=[];for(let o=0;o<h;o++)for(let l=0;l<h;l++){if(l===o){X.push({xIndex:l,yIndex:o,r:1,n:c[l]});continue}const I=Math.min(l,o),F=Math.max(l,o),A=Y(I,F);X.push({xIndex:l,yIndex:o,r:C(A),n:t[A]})}return{tests:i,cells:X,...M?{sample:{of:m.length,used:b.length}}:{},...g?{testSample:{of:f.length,used:i.length}}:{}}}export function filterCorrelationMatrix(e,{threshold:s=.3,minTests:f=6,maxTests:m=20}={}){const u=[];let d=0,g=0,i=null;for(const t of e.cells){if(t.xIndex>=t.yIndex||t.r===null)continue;const c=Math.abs(t.r);u.push({xi:t.xIndex,yi:t.yIndex,absR:c}),(i===null||c>Math.abs(i.r))&&(i={xLabel:e.tests[t.xIndex].label,yLabel:e.tests[t.yIndex].label,r:t.r})}u.sort((t,c)=>c.absR-t.absR);const a=new Set;for(const{xi:t,yi:c,absR:x}of u){const N=x<s;a.size>=m||N&&a.size>=f||(a.add(t),a.size<m&&a.add(c))}if(a.size<Math.min(f,e.tests.length))for(let t=0;t<e.tests.length&&a.size<Math.min(m,f,e.tests.length);t++)a.add(t);const p=(()=>{const t=Array.from(a),c=new Map,x=new Map;for(const{xi:y,yi:w,absR:R}of u)!a.has(y)||!a.has(w)||(c.set(y,(c.get(y)??0)+R),c.set(w,(c.get(w)??0)+R),x.set(y,(x.get(y)??0)+1),x.set(w,(x.get(w)??0)+1));const N=y=>(x.get(y)??0)>0?c.get(y)/x.get(y):0;return t.sort((y,w)=>N(w)-N(y))})(),b=p.map(t=>e.tests[t]),M=new Map(p.map((t,c)=>[t,c])),h=new Set(b.map(t=>t.testNumber)),r=e.cells.filter(t=>h.has(e.tests[t.xIndex].testNumber)&&h.has(e.tests[t.yIndex].testNumber)).map(t=>({xIndex:M.get(t.xIndex),yIndex:M.get(t.yIndex),r:t.r,n:t.n}));let n=0;for(const{xi:t,yi:c,absR:x}of u)a.has(t)&&a.has(c)?x>=.7?d++:x>=.4&&g++:x<s&&n++;return{matrix:{tests:b,cells:r},strongPairs:d,moderatePairs:g,hiddenWeakPairs:n,strongestPair:i}}
|
|
@@ -31,7 +31,7 @@ export declare function visibleFindings<T extends {
|
|
|
31
31
|
export declare function findingPatternKey(f: StatsFinding): string;
|
|
32
32
|
/** A findings list as the reader sees it: patterns with the findings they explain, then the rest grouped by region. */
|
|
33
33
|
export interface ArrangedFindings {
|
|
34
|
-
/** Spatial-pattern findings, each with the findings in the list it names as supporting detail. */
|
|
34
|
+
/** Spatial-pattern findings, each with the findings in the list it names as supporting detail, most severe first. */
|
|
35
35
|
patterns: Array<{
|
|
36
36
|
finding: StatsFinding;
|
|
37
37
|
children: StatsFinding[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function s(e){return Array.isArray(e)?e:[e]}export function filterFindings(e,i){let t=e.findings;if(i.severity!==void 0){const r=new Set(s(i.severity));t=t.filter(
|
|
1
|
+
function s(e){return Array.isArray(e)?e:[e]}export function filterFindings(e,i){let t=e.findings;if(i.severity!==void 0){const r=new Set(s(i.severity));t=t.filter(o=>r.has(o.severity))}if(i.kind!==void 0){const r=new Set(s(i.kind));t=t.filter(o=>r.has(o.variable.kind))}if(i.family!==void 0){const r=new Set(s(i.family));t=t.filter(o=>r.has(o.comparison.family))}if(i.level!==void 0){const r=new Set(s(i.level));t=t.filter(o=>r.has(o.level))}return t}export function visibleFindings(e){const i=new Set(e.flatMap(t=>t.absorbedIds??[]));return e.filter(t=>!i.has(t.id))}export function findingPatternKey(e){return[e.variable.kind,e.variable.index??"",e.variable.bin??"",e.comparison.family,e.comparison.left,e.effect.direction].join("|")}const l={unusual:0,notable:1,info:2};export function arrangeFindings(e){const i=e.filter(n=>n.comparison.family==="spatial-pattern"),t=new Set([...i.flatMap(n=>n.relatedIds??[]),...e.flatMap(n=>n.absorbedIds??[])]),r=(n,a)=>l[n.severity]-l[a.severity],o=i.map(n=>({finding:n,children:e.filter(a=>n.relatedIds?.includes(a.id)).sort(r)})),d=new Map;for(const n of e){if(n.comparison.family==="spatial-pattern"||t.has(n.id))continue;const a=`${n.comparison.family}\0${n.comparison.left}`;d.set(a,[...d.get(a)??[],n])}const c=[...d.entries()].map(([n,a])=>{const f=[...a].sort(r),[p,y]=n.split("\0");return{family:p,left:y,worst:f[0].severity,findings:f}});return c.sort((n,a)=>l[n.worst]-l[a.worst]),{patterns:o,groups:c}}
|
|
@@ -6,4 +6,12 @@ import type { StatsFinding } from './types.js';
|
|
|
6
6
|
* line of their own.
|
|
7
7
|
*/
|
|
8
8
|
export declare function formatFindingTooltip(finding: StatsFinding): string;
|
|
9
|
+
/**
|
|
10
|
+
* What a finding measured, for a column headed "Metric": the variable's label,
|
|
11
|
+
* and for a test which statistic of it. A test's mean and its limit fail rate
|
|
12
|
+
* share a label, and without the word a rate reads as a shift in the values.
|
|
13
|
+
*/
|
|
14
|
+
export declare function findingMetricLabel(finding: Pick<StatsFinding, 'variable'>): string;
|
|
15
|
+
/** True when the finding compares a proportion (a fraction of dies), so its `absoluteDelta` is a fraction. */
|
|
16
|
+
export declare function isProportionFinding(finding: Pick<StatsFinding, 'variable'>): boolean;
|
|
9
17
|
//# sourceMappingURL=findingText.d.ts.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{derivedTestNote as
|
|
2
|
-
${
|
|
1
|
+
import{derivedTestNote as n}from"../renderer/testLabel.js";export function formatFindingTooltip(e){const t=n(e.variable);return t?`${e.summary}
|
|
2
|
+
${t}`:e.summary}export function findingMetricLabel(e){const{kind:t,label:i,measure:r}=e.variable;return t!=="test"?i:r==="limitFailRate"?`${i} limit fail rate`:`${i} mean`}export function isProportionFinding(e){const{kind:t,measure:i}=e.variable;return t==="yield"||t==="hardBin"||t==="softBin"||t==="functionalTest"||t==="test"&&i==="limitFailRate"}
|