End-member modelling algorithm and supporting functions for