Problem 600123 · hard · Level 06 Heuristics & Optimization

How Gusty Is the Hill?

maximum likelihood · Weibull model · numerical maximisation · profile likelihood · two parameters

Before building a wind turbine on a hill, engineers log the wind speed (in metres per second) once an hour. Wind speeds are commonly modelled with the Weibull distribution, which has a shape k > 0 and a scale lam > 0 and density

f(x) = (k / lam) * (x / lam)**(k - 1) * exp(-(x / lam)**k)        for x > 0

A small shape means gusty, erratic wind; a large shape means a steady breeze near lam. Under this model the wind exceeds a speed v with probability exp(-(v / lam)**k).

Write fit_wind(speeds, cut_in) that returns a tuple of four floats:

  1. the shape k and
  2. the scale lam that together maximise the likelihood of the logged speeds,
  3. the log-likelihood at that maximum,
  4. the fitted probability that the wind is faster than the turbine's cut-in speed cut_in.

Your k and lam must be accurate to at least 7 significant digits.

The setup provides wind_speeds(n, shape, scale, seed), which simulates n hourly readings from a Weibull distribution with the given parameters.

Examples

Input:  speeds = [3.2, 5.1, 7.4, 4.0, 9.8, 6.3], cut_in = 4.0
Output: (2.94712087298024, 6.707879582494118, -13.108879480123427, 0.8041898506519666)
Explanation: the best fit has shape 2.947 and scale 6.708 m/s; it says the wind is
above 4 m/s about 80% of the time.

Input:  speeds = [1.0, 2.0], cut_in = 1.5
Output: (3.4615408499204943, 1.678677413815532, -1.3965617046231804, 0.5079608043474922)

Constraints

  • 2 <= len(speeds) <= 5000, every speed is > 0 and at most 100, and the speeds are not all equal
  • cut_in > 0
  • floats are compared with a tolerance of 1e-6

Goals

  • Maximise a two-parameter log-likelihood that has no closed-form solution
  • Reduce a two-dimensional search to one dimension by solving for one parameter exactly
  • Use the fitted model to answer a practical question
Starting Python…