From 11:00 PM CDT Friday, Nov 8 - 2:30 PM CDT Saturday, Nov 9, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From 11:00 PM CDT Friday, Nov 8 - 2:30 PM CDT Saturday, Nov 9, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
01-23-2013 08:48 AM
I have been working with a client on a spectroscopy system and he wants me to perform the component analysis in the application I am building for him. The common method I have found is Partial Least Squares which several people have built MatLab scripts for. This is great and it works; however, I wanted to convert the script into native GCode because I am that guy.
After several days, I was finally able to get the results of the two VIs to be similar, but not the same. I have not been able to find any explanation for this on the forums or elsewhere. The major thing that I found is that LabVIEW breaks a bit when you have a vector calculation such as a'*a which should result in a scalar value, or a 1x1 matrix. When you use this value in another equation, such as the projection X'*a/(a'*a), LabVIEW only operates on the first element of X'*a.
Here it is in GCode with the work around to correct for the a'*a result:
It seems unusual that GCode would treat a scalar result incorrectly. This was annoying, but I was able to get past this.
My next issue is there is some apparent rounding differences between GCode and MathScript that I have not been able to account for. This difference amounts to about 1% in the data that I have to analyze. I have included the project that I have been working on to compare the two methods. In the NIPALS_Conversion_LV.vi, the left side of the block diagram has a For loop structure that is where the model is built using the NIPALS method, and the right side is the application of the model. The NIPALS_Converison.vi contains the original MathScript code that I have been working with.
Notice that the difference between the two results is due to the calculation of the U and B matrices, which are related to each other because of U. I have probed both vi's extensively and everything is equal between them up to the calculation of the elements in u. The equation in question is u = Y*((Y'*t1)/||(Y'*t1)||), although it is expressed a bit differently in the code.
Any help explaining this would be greatly appreciated.
Thanks,
Drew
Solved! Go to Solution.
01-24-2013 04:54 PM
Drew,
I've taken a look at your project and to me it looks like you have properly translated the MathScript into it's equivalent graphical representation.
My first inclination about why you might see this slight rounding error is that the functions used in MathScript and LabVIEW may be different (from different DLLs). How these functions handing floating point rounding may be different, and the error propogates through every iteration of your loop. I suspect that you only notice the error at that point in the program. If you compare each step of the script versus the LabVIEW execution and look out past 10 or so bits of precision, I think you will see this error grow slighty after each step.
If you can track down a specific function at which the a significant difference between the script and LabVIEW execution occurs, I'd be happy to look into the functions and the differences between the MathScript and LabVIEW implementations of the functions.
-Nick-