@@ -34,7 +34,6 @@ export function estimateUsersSinceLaunch(input: { daily: Day[]; weekly: Week[];
3434 : 1 ,
3535 )
3636 const fit = search ( days , activity , targets )
37- if ( ! fit ) return fallback
3837 const total = fit . adopters . reduce ( ( sum , value , index ) => ( days [ index ] ! . date >= input . launch ? sum + value : sum ) , 0 )
3938 return Math . round ( Math . min ( Math . max ( total , floor ) , fallback ) )
4039}
@@ -47,11 +46,8 @@ function search(days: Day[], activity: number[], targets: { start: number; end:
4746 const best = ( regulars : number [ ] , chances : number [ ] ) =>
4847 regulars
4948 . flatMap ( ( regular ) => chances . map ( ( chance ) => simulate ( days , activity , targets , regular , chance ) ) )
50- . reduce <
51- ReturnType < typeof simulate >
52- > ( ( top , item ) => ( item && ( ! top || item . error < top . error ) ? item : top ) , undefined )
49+ . reduce ( ( top , item ) => ( item . error < top . error ? item : top ) )
5350 const coarse = best ( grid ( undefined , 0.05 ) , grid ( undefined , 0.05 ) )
54- if ( ! coarse ) return undefined
5551 return best ( grid ( coarse . regular , 0.01 ) , grid ( coarse . chance , 0.01 ) )
5652}
5753
@@ -66,12 +62,14 @@ function simulate(
6662 // earlier[t]: adopters before day t, each weighted by the chance they are still around on day t.
6763 const earlier : number [ ] = [ ]
6864 const adopters : number [ ] = [ ]
69- for ( const [ index , day ] of days . entries ( ) ) {
65+ // Returning users the day can't hold. Small days are noisy (one user, then none), so a shortfall is a miss to fit
66+ // away rather than a reason to rule the parameters out.
67+ const shortfall = days . reduce ( ( sum , day , index ) => {
7068 earlier . push ( index === 0 ? 0 : STAY * ( earlier [ index - 1 ] ! + adopters [ index - 1 ] ! ) )
7169 const value = day . users - regular * chance * activity [ index ] ! * earlier [ index ] !
72- if ( value < 0 ) return undefined
73- adopters . push ( value )
74- }
70+ adopters . push ( Math . max ( 0 , value ) )
71+ return sum + Math . min ( 0 , value ) ** 2
72+ } , 0 )
7573 const error = targets . reduce ( ( sum , target ) => {
7674 // Chance that a regular still around on the week's first day uses the model at least once that week.
7775 const back = Array . from ( { length : target . end - target . start + 1 } , ( _ , offset ) => target . start + offset ) . reduce (
@@ -82,9 +80,16 @@ function simulate(
8280 { chance : 0 , unseen : 1 } ,
8381 ) . chance
8482 const fresh = adopters . slice ( target . start , target . end + 1 ) . reduce ( ( total , value ) => total + value , 0 )
85- return sum + ( ( fresh + regular * back * earlier [ target . start ] ! - target . users ) / target . users ) ** 2
83+ return sum + ( fresh + regular * back * earlier [ target . start ] ! - target . users ) ** 2
8684 } , 0 )
87- return { error, regular, chance, adopters }
85+ // Misses are measured against all weeks together: per-week shares would let a near-empty early-access week, where
86+ // one user is a 100% miss, outweigh the weeks that hold the launch.
87+ return {
88+ error : ( error + shortfall ) / targets . reduce ( ( sum , target ) => sum + target . users ** 2 , 0 ) ,
89+ regular,
90+ chance,
91+ adopters,
92+ }
8893}
8994
9095function isoAfter ( date : string , days : number ) {
0 commit comments