[docs]defcalculate_expected_distributions(start,stop):# Convert Starsim dates to datetime for calculationifhasattr(start,'date'):start_date=start.date()else:start_date=startifhasattr(stop,'date'):stop_date=stop.date()else:stop_date=stopduration_days=(stop_date-start_date).daysmin_value=150# Minimum dwell time for all statesmax_value=duration_days# Maximum dwell time is the total duration of the simulation# Scale parameters for each statescales={TBS.NONE:126,TBS.LATENT_SLOW:365,TBS.LATENT_FAST:200,TBS.ACTIVE_PRESYMP:100,TBS.ACTIVE_SMPOS:150,TBS.ACTIVE_SMNEG:300,TBS.ACTIVE_EXPTB:250,TBS.DEAD:400,}# Generate truncated exponential distributions for all statesreturn{state:lambdax,scale=scale:stats.truncexpon(b=(max_value-min_value)/scale,loc=min_value,scale=scale).cdf(x)forstate,scaleinscales.items()}
if__name__=='__main__':sim_tb=build_tbsim()sim_tb.run()start=sim_tb.pars.startstop=sim_tb.pars.stop# Calculate expected distributionsexpected_distributions=calculate_expected_distributions(start,stop)# # Extract the analyzerana:mtb.DwtAnalyzer=sim_tb.analyzers[0]#shortcut to the dwell time analyzerana.graph_state_transitions()ana.sankey_agents_by_age_subplots(bins=[0,5,200])# Sample using directly from the generated file(s)file=ana.file_path# (uses the file from the analyzer)plotter=mtb.DwtPlotter(file_path=file)plotter.histogram_with_kde()