Pātuhitia tēnei: Analysis and optimization of stochastic systems