code: def first_n_three_layer_P(reference_patterns, estimated_patterns, n=5):
      
  
      validate(reference_patterns, estimated_patterns)
      # If no patterns were provided, metric is zero
      if _n_onset_midi(reference_patterns) == 0 or \
         _n_onset_midi(estimated_patterns) == 0:
          return 0., 0., 0.
  
      # Get only the first n patterns from the estimated results
      fn_est_patterns = estimated_patterns[:min(len(estimated_patterns), n)]
  
      # Compute the three-layer scores for the first n estimated patterns
      F, P, R = three_layer_FPR(reference_patterns, fn_est_patterns)
  
      return P
docs: First n three-layer precision.
  
      This metric is basically the same as the three-layer FPR but it is only
      applied to the first n estimated patterns, and it only returns the
      precision. In MIREX and typically, n = 5.
  
      Examples
      --------
      >>> ref_patterns = mir_eval.io.load_patterns("ref_pattern.txt")
      >>> est_patterns = mir_eval.io.load_patterns("est_pattern.txt")
      >>> P = mir_eval.pattern.first_n_three_layer_P(ref_patterns,
      ...                                            est_patterns, n=5)
  
      Parameters
      ----------
      reference_patterns : list
          The reference patterns in the format returned by
          :func:`mir_eval.io.load_patterns()`
      estimated_patterns : list
          The estimated patterns in the same format
      n : int
          Number of patterns to consider from the estimated results, in
          the order they appear in the matrix
          (Default value = 5)
  
      Returns
      -------
      precision : float
          The first n three-layer Precision