"""Auturnal analytical examples. Save as analysis.py and run: python analysis.py --slug biomolecular-interactions Requires Python 3 and NumPy. Outputs inputs, curves and numeric checks as JSON. These are explicit hypothetical examples, not experimental or benchmark results. """ import argparse,json,math import numpy as np def line(x,ys,xlabel,ylabel,logx=False,logy=False): return {'kind':'line','x':np.asarray(x).tolist(),'series':[{'label':k,'y':np.asarray(v).tolist()}for k,v in ys.items()],'xlabel':xlabel,'ylabel':ylabel,'logx':logx,'logy':logy} def bar(labels,ys,ylabel): return {'kind':'bar','labels':labels,'series':[{'label':k,'y':np.asarray(v).tolist()}for k,v in ys.items()],'ylabel':ylabel} cdf=lambda x:(1+np.vectorize(math.erf)(np.asarray(x)/math.sqrt(2)))/2 pdf=lambda x:np.exp(-np.asarray(x)**2/2)/math.sqrt(2*math.pi) def scenario(key): d={'analytic':key,'kind':'declared_analytical_or_constructed_example','experimental_model_result':False,'panels':[]} p=d['panels'] if key=='biomolecular-interactions': x=np.geomspace(.1,1e4,160);n=np.arange(1,201) p.extend([line(x,{f'KD = {k} nM':x/(k+x) for k in [1,10,1000]},'Free ligand (nM)','Fraction occupied',True),line(n,{'False-pass probability, q=0.01':1-.99**n},'Independent wrong candidates','At least one false pass')]) d.update(title='Coordinates, occupancy and selection answer different questions',assumptions='Single independent binding site at equilibrium; no depletion/cooperativity. KD values 1,10,1000 nM are hypothetical. Wrong-candidate checks independent with false-pass rate 0.01.',worked='自由配体10 nM时,三条假定占据率为0.90909、0.5、0.009901;100个独立错误候选至少一项假通过概率为0.633968。没有对应真实分子。',checks={'occupancy_at_10':[10/(k+10)for k in [1,10,1000]],'false_pass_100':1-.99**100}) elif key=='programmable-protein-design': rho=np.linspace(0,.5,151) p.extend([bar(['Start','Backbone','Sequence','Sample','Function'],{'Expected candidates':[1000,800,480,240,48]},'Expected count'),line(rho,{f'n = {n}':n/(1+(n-1)*rho) for n in [10,100,1000]},'Equal pairwise correlation','Effective mean sample size')]) d.update(title='Complete denominators and dependence change design evidence',assumptions='Funnel conditional pass rates 0.8,0.6,0.5,0.2. Effective sample size is for equal-variance, equal-correlation means, not a fitted binary protein-success model.',worked='1000×0.8×0.6×0.5×0.2=48,起始口径4.8%,最后样品口径20%;100个等相关样本在rho=0.2时有效样本量约4.80769。',checks={'funnel_final':48.,'effective_100_rho_02':100/(1+99*.2),'zero_failure_upper_30':1-.05**(1/30)}) elif key=='regulatory-genome': z=np.linspace(-6,6,161);sig=lambda x:1/(1+np.exp(-x));r=np.linspace(0,9,151) p.extend([line(z,{'Baseline response':sig(z),'Change for +1 input':sig(z+1)-sig(z)},'Constructed regulatory coordinate','Normalized response / change'),line(r,{'Ideal signal correlation':1/np.sqrt(1+r)},'Noise variance / signal variance','Correlation ceiling')]) d.update(title='Background saturation and measurement noise alter effect interpretation',assumptions='Sigmoid constructed response, +1 input shift. Independent additive noise; ideal predictor equals latent signal. No DNA or genome-model outputs.',worked='基线z=0时增量0.231059,z=3时约0.029440;噪声方差等于信号方差时理想相关sqrt(1/2)≈0.707107。',checks={'delta_z0':float(sig(1)-sig(0)),'delta_z3':float(sig(4)-sig(3)),'ceiling_equal_noise':1/math.sqrt(2)}) elif key=='virtual-cell-perturbations': p.append(bar(['Zero change','Half effect','Effect + noise'],{'All genes MSE':[.04,.01,990*.25**2/1000],'Effect genes MSE':[4.,1.,0.]},'Mean squared error')) g=np.arange(1,101);p.append(line(g,{'Zero-change all-gene MSE':4*g/1000,'Half-effect all-gene MSE':g/1000},'Responsive genes among 1000','All-gene MSE')) d.update(title='Sparse biological effects can be diluted by aggregate metrics',assumptions='1000 genes; 10 have true delta 2. Third predictor is exact on effects, has error 0.25 on each of 990 background genes. No cell data; weights are not the source paper metric implementation.',worked='零变化MSE=10×4/1000=0.04;半效应为0.01;响应基因完全正确而背景误差0.25时,总MSE=0.061875。',checks={'zero_mse':.04,'half_mse':.01,'background_mse':.061875}) elif key=='spatial-cellular-ecology': eps=np.geomspace(.001,1,130);conds=[np.linalg.cond(np.array([[1.,1.],[0.,e]]))for e in eps] r=np.linspace(.1,5,160);q=np.zeros_like(r);mask=r>1;t=1/r[mask];q[mask]=(np.arccos(t)-t*np.sqrt(1-t*t))/math.pi p.extend([line(eps,{'Signature matrix condition number':conds},'Signature distinction epsilon','2-norm condition number',True,True),line(r,{'Opposite-side neighborhood fraction':q},'Radius / distance to boundary','Area fraction')]) d.update(title='Expression identifiability and neighborhood scale are separate',assumptions='Two signatures A=[[1,1],[0,epsilon]]. Uniform planar tissue split by a straight boundary; center distance d=1, circular radius r. No real tissue.',worked='epsilon降低100倍使第二分量区分信号降低100倍;r<=d时另一侧占比0,r=2d时占比约0.195501;r/d趋向无穷时趋近0.5。',checks={'opposite_fraction_r2':(math.acos(.5)-.5*math.sqrt(.75))/math.pi}) elif key=='probabilistic-weather': mu=np.linspace(-3,3,161) p.append(line(mu,{f'Gaussian sigma={s}':s*((-mu/s)*(2*cdf(-mu/s)-1)+2*pdf(-mu/s)-1/math.sqrt(math.pi))for s in [.5,1,2]},'Forecast mean; observed y=0','Gaussian CRPS')) rho=np.linspace(-.9,.9,151);p.append(line(rho,{'Variance of two-location sum':2+2*rho},'Correlation; each variance = 1','Aggregate error variance')) d.update(title='Marginal scoring does not determine joint risk',assumptions='Analytical Gaussian forecasts for y=0; two zero-mean errors each variance 1. No weather output, grid or power-system data.',worked='无偏单位高斯在y=0时CRPS=(sqrt(2)-1)/sqrt(pi)≈0.233695;rho=-0.5与0.8时总方差为1与3.6;50独立成员漏见1%事件概率约0.605006。',checks={'normal_crps_y0':(math.sqrt(2)-1)/math.sqrt(math.pi),'miss_1pct_M50':.99**50}) elif key=='hybrid-climate-dynamics': t=np.arange(301);s=np.linspace(0,12,150) p.extend([line(t,{'Stable multiplier 0.98':.98**t,'Unstable multiplier 1.01':1.01**t},'Time steps','Normalized state'),line(s,{f'Heat capacity C={c}':1-np.exp(-s/c)for c in [1,4]},'Normalized time','Energy-balance response')]) d.update(title='Short-run fit, stability and equilibration are distinct',assumptions='Scalar recurrence initial 1. Energy balance F=lambda=1, initial T=0, capacities 1 and 4 in normalized units. Not a climate projection.',worked='相同初值300步后0.98^300≈0.002333,而1.01^300≈19.7885。两种热容量长期都趋向1,但调整时间不同;这些参数没有地球气候含义。',checks={'stable_300':.98**300,'unstable_300':1.01**300}) elif key=='fusion-plasma-control': n=np.arange(51);cur=1.;prev=0.;xs=[cur] for _ in n[1:]:nxt=1.2*cur-1.1*prev;prev,cur=cur,nxt;xs.append(cur) gain=np.linspace(.05,1.8,150);radius=[max(abs(np.roots([1,-1.2,k])))for k in gain] p.extend([line(n,{'No delay, a=1.2 k=1.1':.1**n,'One-step delay, same gain':xs},'Discrete step','Normalized state'),line(gain,{'No-delay spectral radius':abs(1.2-gain),'One-delay spectral radius':radius,'Unit-circle boundary':np.ones_like(gain)},'Feedback gain k','Spectral radius')]) d.update(title='A single delay changes the feedback stability boundary',assumptions='Scalar normalized system a=1.2; no reactor or actuator parameters. Delayed initial x[-1]=0,x[0]=1. No real device control.',worked='无延迟乘子0.1;一拍延迟特征方程z^2-1.2z+1.1的根模sqrt(1.1)≈1.04881,超过1。',checks={'delayed_root_radius':float(max(abs(np.roots([1,-1.2,1.1]))))}) elif key=='quantum-error-decoding': rounds=np.arange(501);mu=np.linspace(.5,1.5,151) p.extend([line(rounds,{f'Independent flip epsilon={e}':(1-(1-2*e)**rounds)/2 for e in [.001,.01]},'Error-correction rounds','Odd logical-flip probability'),line(mu,{'Backlog growth, lambda=1':np.maximum(0,1-mu)},'Service rate / arrival rate','Normalized backlog growth')]) d.update(title='Logical reliability and real-time capacity must both hold',assumptions='Independent Bernoulli logical flips, not physical-code simulation. Queue is deterministic fluid approximation. Class example probabilities A=0.35,B=0.33+0.32 are constructed.',worked='同syndrome下最大单路径0.35属于A,但B类总概率0.65更大。逻辑翻转公式100轮epsilon=0.001约0.090717;服务率不足时积压增长。',checks={'class_A':.35,'class_B':.33+.32,'odd_100_e001':(1-.998**100)/2}) elif key=='neural-quantum-wavefunctions': a=np.geomspace(.25,4,170);rho=np.linspace(0,.99,150) p.extend([line(a,{'Variational energy':(a+1/a)/4,'Exact ground energy':np.full_like(a,.5),'Local-energy variance':(1-a*a)**2/(8*a*a)},'Gaussian width alpha','Dimensionless energy / variance',True),line(rho,{'Effective independent fraction':(1-rho)/(1+rho)},'AR(1) correlation','N_eff / N')]) d.update(title='An exact variational example and correlated sampling',assumptions='H=(-d^2/dx^2+x^2)/2, psi proportional to exp(-alpha*x^2/2). AR(1) long-chain limit; no molecular energy or neural training.',worked='alpha=1精确能量0.5且局域能量方差0;alpha=2能量0.625、方差0.28125。rho=0.9时10000步长链有效样本量约526.316。',checks={'energy_alpha2':.625,'variance_alpha2':.28125,'neff_10000_rho09':10000/19}) elif key=='machine-checked-mathematics': n=np.arange(101);x=np.linspace(-.5,3.5,200);g=(x*(x-1)*(x-2)*(x-3))**2 p.extend([line(n,{f'Independent candidate p={q}':1-(1-q)**n for q in [.02,.1]},'Independent candidates','At least one correct candidate'),line(x,{'Polynomial passing tests 0,1,2,3':g},'Input x','Counterexample g(x)')]) d.update(title='Search coverage and finite tests provide different evidence',assumptions='Independent candidate probabilities hypothetical. g(x)=[x(x-1)(x-2)(x-3)]^2 is exactly zero at four test points, not elsewhere. Not a theorem-prover benchmark.',worked='p=0.1、n=20时至少一次正确约0.878423;g在0,1,2,3全为0,但g(0.5)=0.87890625,有限测试不证明无界性质。',checks={'coverage_p01_n20':1-.9**20,'counterexample_half':(.5*(-.5)*(-1.5)*(-2.5))**2}) elif key=='autonomous-science-laboratory': pi=np.geomspace(.001,.5,150);mu=np.linspace(-2,2,160) p.extend([line(pi,{f'Specificity={s}':.9*pi/(.9*pi+(1-s)*(1-pi))for s in [.9,.99]},'Actual target proportion','Positive predictive value',True),line(mu,{f'Predicted sigma={s}':mu*cdf(mu/s)+s*pdf(mu/s)for s in [.2,1]},'Predicted mean; best=0','Expected improvement')]) d.update(title='Measurement reliability and acquisition choice shape discovery',assumptions='Sensitivity 0.9, hypothetical prevalence/specificity. Gaussian predictive EI for maximization over best=0. No experiment or material data.',worked='目标比例0.1时,特异度0.9得到PPV=0.5,特异度0.99时约0.909091。均值0时高斯EI=sigma/sqrt(2pi)。',checks={'ppv_09':.5,'ppv_099':.09/(.09+.009),'ei_mu0_sigma1':1/math.sqrt(2*math.pi)}) elif key=='antibiotic-discovery-evidence': pi=np.geomspace(.001,.2,150) p.extend([line(pi,{f'False-positive rate={f}':.8*pi/(.8*pi+f*(1-pi))for f in [.05,.01]},'Actual active fraction','Positive predictive value',True),bar(['Start','After filter','Confirmed'],{'Constructed count':[100,50,20]},'Candidate count')]) d.update(title='Candidate prevalence and selection denominators alter hit rates',assumptions='Sensitivity 0.8; false-positive rates 0.05/0.01 hypothetical. Selection example starts100,filters50,confirms20. No real molecule or antimicrobial measurements.',worked='活性比例1%、s=0.8、f=0.05时PPV约0.139130;比例10%时约0.64。20/50=40%与20/100=20%是不同分母。',checks={'ppv_prevalence01':.008/(.008+.0495),'ppv_prevalence10':.08/(.08+.045)}) elif key=='retinal-foundation-models': pi=np.linspace(.001,.3,160);s=.9;sp=.95 p.extend([line(pi,{'PPV, Se=0.9 Sp=0.95':s*pi/(s*pi+(1-sp)*(1-pi))},'Hypothetical prevalence','Positive predictive value'),bar(['Prevalence1%','Prevalence20%'],{'True positive':[90,1800],'False positive':[495,400]},'Expected count among 10000')]) d.update(title='Identical classifier properties imply different workflow burden',assumptions='Hypothetical sensitivity 0.9,specificity0.95,N=10000; not RETFound performance, patient data,diagnosis or referral guidance.',worked='患病率1%:TP90、FP495、PPV≈0.153846;患病率20%:TP1800、FP400、PPV≈0.818182。这些只是期望计数。',checks={'ppv_01':90/585,'ppv_20':1800/2200}) elif key=='connectome-structure-function': t=np.linspace(0,8,180);w=np.linspace(.05,1.5,150) p.extend([line(t,{f'Same graph, coupling w={v}':.5*(np.exp((-1+v)*t)+np.exp((-1-v)*t))for v in [.2,.9,1.1]},'Normalized time','Node1 impulse response'),line(w,{'Largest eigenvalue':w-1,'Stability boundary':np.zeros_like(w)},'Coupling strength','Largest real eigenvalue')]) d.update(title='A fixed connection graph does not fix neural dynamics',assumptions='Two-node linear W=[[-1,w],[w,-1]], initial state[1,0]. Synthetic graph,not real neurons or reconstructed brain.',worked='相同双向拓扑在w=0.2、0.9、1.1时最大特征值分别-0.8、-0.1、0.1;最后一种不稳定。',checks={'largest_eigenvalues':[-.8,-.1,.1]}) elif key=='seismic-signal-inference': sig=np.linspace(.005,.2,150);m=np.linspace(0,5,180);coef=1/(1/3.5-1/6) p.extend([line(sig,{'Distance sd, independent equal P/S error':coef*math.sqrt(2)*sig},'Each arrival-time standard deviation (s)','Distance standard deviation (km)'),line(m,{f'Detection midpoint m_c={mc}':1000*10**(-m)/(1+np.exp(-5*(m-mc)))for mc in [1,2]},'Constructed magnitude','Expected observed count')]) d.update(title='Picking error and catalogue completeness affect different conclusions',assumptions='Homogeneous vP=6,vS=3.5 km/s; fixed independent P/S time errors. Latent count1000*10^-m,logistic detection k=5. Not real earthquake data or warning.',worked='距离系数8.4 km/s;各相0.05s独立误差给sigma_r≈0.593970 km。相同潜在计数在不同门槛下有不同观测曲线。',checks={'distance_coefficient':coef,'distance_sd_005':coef*math.sqrt(2)*.05}) elif key=='gravitational-lens-inference': beta=np.linspace(-.9,.9,170);r=np.linspace(.4,2.0,160) p.extend([line(beta,{'Image theta+':beta+1,'Image theta-':beta-1,'Source beta':beta},'Source angle / Einstein radius','Image angle / Einstein radius'),line(r,{f'Mass-sheet lambda={v}':v*.5/r+(1-v)for v in [.5,.8,1.]},'Radius / Einstein radius','Dimensionless surface density kappa')]) d.update(title='Lens images constrain a model while mass-sheet freedom remains',assumptions='Ideal 1D isothermal lens thetaE=1; algebraic branches shown for source range. Density kappa=0.5/r and lambda0.5,0.8,1. No telescope data.',worked='beta=0.2、thetaE=1时像位置1.2与-0.8。质量片变换同时缩放源位置,保持相应透镜映射;不声称所有外部物理条件不变。',checks={'images_beta02':[1.2,-.8],'mass_sheet_identity_residual':0.}) elif key=='bioacoustic-biodiversity': prob=np.linspace(.001,1,160);k=np.arange(1,1001) p.extend([line(prob,{f'Independent visits K={n}':1-(1-prob)**n for n in [1,3,10]},'Per-visit detection given presence','At least one detection'),line(k,{f'False-positive probability per interval={f}':1-(1-f)**k for f in [.001,.01]},'Independent target-absent intervals','At least one false record')]) d.update(title='Presence, detection and accumulated false records are distinct',assumptions='Independent repeated visits and absent intervals, no real recordings. Occupancy set to1 for plotted conditional curves. Environmental correlation not modeled.',worked='p=0.2时K=3检出0.488,K=10约0.892626;p由0.5降至0.2且K=3,检出由0.875降0.488,变化约-44.23%,不代表存在状态变化。',checks={'detect_p02_K3':1-.8**3,'detect_p02_K10':1-.8**10,'apparent_decline':(1-.8**3)/(1-.5**3)-1}) elif key=='rna-structure-ensembles': z=np.linspace(-4,4,170);prob=1/(1+np.exp(z));mat=np.zeros((10,10)) for i,j,v in [(1,5,.8),(1,8,.7),(2,7,.9),(3,6,.6)]:mat[i,j]=mat[j,i]=v p.extend([line(z,{'Population of state B':prob,'Population of state A':1-prob},'Free-energy difference / RT','Equilibrium population'),{'kind':'heat','matrix':mat.tolist(),'xlabel':'Constructed position','ylabel':'Constructed position','unit':'Independent pair score (not legal ensemble)'}]) d.update(title='Conformational populations and pairing consistency are different',assumptions='Two-state equilibrium; pair-score matrix intentionally violates the single-partner row-sum constraint at position1. No RNA sequence,3D prediction or measurement.',worked='DeltaG/RT=-2与2时B占比分别0.880797与0.119203;构造矩阵位置1的行和1.5,说明独立高分配对未必形成合法整体。',checks={'population_minus2':1/(1+math.exp(-2)),'population_plus2':1/(1+math.exp(2)),'invalid_row_sum':1.5}) elif key=='photonic-inverse-design': shift=np.linspace(-10,10,181);qs=np.geomspace(30,2000,150);lam=1550. p.extend([line(shift,{f'Q={q}':1/(1+(2*shift/(lam/q))**2)for q in [50,200,1000]},'Resonance-center shift (nm)','Response at nominal operating wavelength'),line(qs,{'Half-maximum center-shift tolerance':lam/(2*qs)},'Quality factor Q','Tolerance (nm)',True,True)]) d.update(title='Narrow resonances trade nominal selectivity for shift tolerance',assumptions='Lorentz intensity response,lambda0=1550 nm,Gamma=lambda0/Q. Hypothetical Q values; no full-wave simulation, fabrication or device measurement.',worked='Q=1000时半高全宽1.55nm,中心偏移0.775nm使本例响应降为0.5;同样偏差对低Q更不敏感。',checks={'fwhm_Q1000':1.55,'halfmax_shift_Q1000':.775,'response_at_halfmax':.5}) else:raise ValueError(key) return d if __name__=='__main__': ap=argparse.ArgumentParser();ap.add_argument('--slug',required=True) print(json.dumps(scenario(ap.parse_args().slug),ensure_ascii=False,indent=2,allow_nan=False))