Implementing an offline guitar monophonic pitch detector I am implementing an offline guitar monophonic pitch detector. I was wondering about the trade-off of the standard methods: Autocorrelation, HPS, Cepstrum, picking the peak from an STFT, the YIN algorithm.

I am working with audio that could will be segmented according to onset times, but let's assume this is done, so let's assume that I am given 5 segments which have been correctly segmented (start at the onset time, finish a frames afterwards).

My first question is: How long should a be? I guess that for algorithms like Autocorrelation, the bigger the segment the better?

Also, when working with guitar in particular, is there any issue I should take care of and is one of those methods preferable? I would assume HPS is good as the guitar produces a lot of harmonics.

I tried implementing Autocorrelation but I get a lot of octave errors. Would the YIN algorithm correct many of those? I also implemented a simple peak picking from an STFT but I often get strongest harmonics instead of the perceived pitch.
Each of the "standard methods" you listed has a failure mode (or modes) and an estimation error (which may vary with the guitar and the note). Characterize the failure modes or each method, and evaluate the estimation errors of the more successful methods, then match them to your samples, and perhaps pick the least bad (or other suitable statistical fit.)

With "the guitar in particular", one thing to watch for is that some notes on some guitars can produce a slightly (but measurably) inharmonic overtone series.  If so, the waveform will never be perfectly periodic.  This can cause successive periods of the fundamental mode waveform to never exactly match (which can throw off both autocorrelation and AMDF lag estimation methods, etc.).  Thus, one may need a psychoacoustic model to determine what might likely be the perceived pitch to a human (assuming that's what you care about).  Also, the ratios between overtone magnitudes will usually change (evolve) over time, not just decay linearly as per an ADSR envelope model, which might also affect periodicity and your choice of method.