Inmathematics aloss function orcost function is amathematical function that maps an event, or the values of one or more variables onto areal number. This number is then given asemantic value, such as cost orutility.Optimisation can then be used to find the value where the function is minimal, or at one of its maxima.