code: def solve_potts_approx(y, w, gamma=None, min_size=1, **kw):
      
      n = len(y)
  
      if n == 0:
          return [], [], []
  
      mu_dist = kw.get('mu_dist')
      if mu_dist is None:
          mu_dist = get_mu_dist(y, w)
          kw['mu_dist'] = mu_dist
  
      if gamma is None:
          mu, dist = mu_dist.mu, mu_dist.dist
          gamma = 3 * dist(0,n-1) * math.log(n) / n
  
      if min_size < 10:
          max_size = 20
      else:
          max_size = min_size + 50
  
      right, values, dists = solve_potts(y, w, gamma, min_size=min_size, max_size=max_size, **kw)
      return merge_pieces(gamma, right, values, dists, mu_dist, max_size=max_size)
docs: Fit penalized stepwise constant function (Potts model) to data
      approximatively, in linear time.
  
      Do this by running the exact solver using a small maximum interval
      size, and then combining consecutive intervals together if it
      decreases the cost function.