New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uncertainties in Vector Fitting fit parameters #1000
Comments
Hi Tony! Please clarify what you mean by uncertainty. I was initially thinking this is about random deviations between subsequent measurements (due to noise), resulting in deviations of the fitted models. But I'm assuming it is about the accuracy of the individual fits, i.e. the error between the fit and the data. If that's the case, are you aware of the function Apparently, the various types of error calculations are often correlated or even equal: In the final step of the vector fitting process in scikit-rf, the model residues are fitted using scikit-rf/skrf/vectorFitting.py Lines 534 to 537 in 74ddb7f
Is this already what you need? It would also be possible to add new error functions other than rms error. Regards, |
Hi Vincent — thanks for the thoughtful reply. I spent some time in the intervening weeks thinking about this (and reading up more on the vector fitting algorithm itself). With respect to your questions:
To clarify, I am asking first thing you mentioned: I'm looking to quantify the level of variation I could expect in the fit parameters (poles, residues, …) were I to run the exact same fit on new measurement of the same system.
This was an interesting lead, but after reading up on the vector fitting algorithm in more detail, I don't think this will provide quite what I need. The interesting part: Since the residue fit procedure is just ordinary least-squares ( But this only gives the uncertainty on the residues, and only in the situation where we assume the poles are fixed/certain (at the locations given by the pole relocation procedure, by design). To get uncertainties on the poles (which I care more about anyway), we would need to propagate uncertainties through a matrix diagonalization operation (Appendix B of Gustavsen and Semlyen (1999)), which seems difficult. (And then this pole uncertainty would then also need to go into the Instead, I did have success with the "second fit" idea I mentioned before — I took the vector fitting results and used them as an initial guess for a nonlinear least squares curve fitting procedure ( |
OK, thanks for clarifying. It would certainly be cool if we could extend the existing code with uncertainty indicators for the fitted poles and the residues. I must admit that I'm not a huge expert on the mathematical details, but my linear algebra skills were sufficient to take the algorithms from Gustavsen's papers and implemented them in Python. You mentioned the difficulties to propagate uncertainties through the eigenvalue computation step. I'm afraid it gets worse because of an additional QR decomposition before the eigenvalue computation in order to reduce the size of the coefficient matrix for faster computation [1]. scikit-rf/skrf/vectorFitting.py Line 394 in b4a6567
Another idea: In [3], they propose to weigh the individual data samples by their variance: scikit-rf/skrf/vectorFitting.py Lines 234 to 246 in b4a6567
As you can see, I have also played around with different types of weights. It would be possible to have the user provide weights as a parameter for Finally, I'm also wondering why it is at all required to have uncertainty estimates on the poles. Aren't the poles just providing some sort of basis function, similar to providing a polynomial to be fitted to the data? Sure, the pole locations will be (slightly) different if you repeat the fit with new data of the same electrical network, due to noise. Still, given a reasonable set of poles placed at roughly the "right" positions, I would expect the residues to have a much stronger effect on the overall uncertainty. But I might be wrong here. [1] D. Deschrijver, M. Mrozowski, T. Dhaene, D. De Zutter, “Marcomodeling of Multiport Systems Using a Fast Implementation of the Vector Fitting Method”, IEEE Microwave and Wireless Components Letters, vol. 18, no. 6, pp. 383-385, June 2008, DOI: https://doi.org/10.1109/LMWC.2008.922585 [2] B. Gustavsen, A. Semlyen, “Rational Approximation of Frequency Domain Responses by Vector Fitting”, IEEE Transactions on Power Delivery, vol. 14, no. 3, pp. 1052-1061, July 1999, DOI: https://doi.org/10.1109/61.772353 [3] F. Ferranti, Y. Rolain, L. Knockaert and T. Dhaene, "Variance Weighted Vector Fitting for Noisy Frequency Responses," in IEEE Microwave and Wireless Components Letters, vol. 20, no. 4, pp. 187-189, April 2010, DOI: https://doi.org/10.1109/LMWC.2010.2042546 |
I'm wondering what kind of results you get from scipy.optimize.curve_fit(). Is there any significant change in the model parameters? Or does it more or less return the same parameters you got from In case there is not much change in the poles and the variation mostly happens in the residues, what if you fit the poles only once for your network and then always work with the same set of poles, without having them re-fitted to the new data? For this to work, we would need to split the procedures in |
Another idea: what about brute force? You take a number of |
My science goal here is to extract the
This is interesting — is there a way to use the singular values to quantify the uncertainty on the fitted poles? (I don't have great intuition for singular value decomposition…)
Nice! This is exactly what the
The fitted parameters change very little, which is a good sign (barely any visible change when plotting model responses). The extra uncertainty information looks reasonable as well and agrees with intuition. (For numerical stability, I had to work in frequency units where the average network frequency is 1, as the current vector_fit implementation does. With raw frequencies in Hz, I get very unreasonably small uncertainty estimates. I'm considering further improving this by working in units where the frequency span is 1 and shifting pole imaginary parts to center the average network frequency at 0.)
Yes! I'm making some plots and will get back to you on this after I'm done with them.
Could you elaborate? I'm not sure how this would give an estimate of the pole uncertainty.
Estimating uncertainties Monte Carlo–style is an option, but would be difficult for us logistically: our apparatus is cryogenic, and we share the cryostat with others, so we have limited time to take data. |
Here's an example of a Vector Fit together with a refined fit. (The panels are just different views of the same data.) The refined fit looks almost the same as the original fit. There is a slight improvement in rms error which is partly due to shifts in the pole locations and partly due to the assumption of i.i.d. errors in my fit (which actually makes the optimization equivalent to minimizing rms error; this is in contrast with the implicit assumption The four fitted complex poles
The first two just help fit the background (so the large uncertainties in their linewidths is understandable), while the other two correspond to the obvious resonance features in the plot (and have correspondingly tight uncertainty in frequency and linewidth). |
Apparently, one can do all sorts of cool things with SVD. I found these lecture notes online, but it did not help me very much. It became once again obvious that I'm not a mathematician. Maybe it does help you. See page 11 for example: I'm afraid I'm not very helpful here, but one last question: Again, with |
I think I agree with you now: you are right that the additional sweep time isn't infeasible. After ruminating a bit more carefully on this, I think the problem is a combination of the additional sweep time required (1, 2), the technical effort required to integrate this with our existing sequences (3, 4), and the time we would need to retake old measurements (5, 6).
|
Thanks for sharing the details, very interesting stuff! I did not expect such a long sweep time, but only a few Hz of bandwidth is pretty extreme... It would be cool if you could keep us updated how the new approach works out. Regarding the vector fitting code, I'm not sure if there is much we can do about your measurement challenges. Maybe we can keep this issue open as a reminder for the feature request of user-specific sample weighting. |
Your questions were still helpful — I actually had to think hard about why exactly we take our measurements the way we do now, and I think the answer is just that our circumstances are rather unique. (Though I'm sure there are optimizations to be made to our process if we thought hard enough about it.) I think I have a solution that works well enough for now (the second fit), but since it seems out of scope for scikit-rf, I don't personally have any outstanding issues here. The user-specific weighting seems easy enough to implement, though. |
Hi! I currently use the the Vector Fitting functionality implemented in scikit-rf for extracting Q-factors of modes in spectra with a lot of background -- the generality of the functional form (arbitrary number of poles) is very convenient for fitting both signal and background features. (In contrast,
skrf.qfactor
is very sensitive to background, which in our system is very difficult to eliminate.)Currently, there is no uncertainty estimate for the parameters returned from a Vector Fit. For our work we'd like to bound the error on the fitted Q-factors, so I'm wondering:
skrf.vectorFitting
? It seems natural to provide uncertainty estimates on the results of a fit.For (1), one idea I have is to take a Vector Fit result and use it as a starting guess for
scipy.optimize.curve_fit
(or anotherscipy.optimize
routine) to "refine" the fit returned by Vector Fitting. Of course, one would not expect much refinement, but crucially the optimization would return a covariance matrix for the fit parameters. (This "second fit" step would also allow specifying a custom loss function for the fit -- since the uncertainties on VNA measurements can vary depending on signal strength, for example.)I'd love to get feedback on this "second fit" idea and hear any other ideas for estimating uncertainties on Vector Fit params. Since I need to get some such uncertainty estimates for my work anyway, I'd also be interested in contributing my code back, should it be natural to include here.
The text was updated successfully, but these errors were encountered: