LeafLabs Garden » Topic: Recursive vs Ordinary Least Squares & Fixed Point
http://forums.leaflabs.com/topic.php?id=1545
A place to share, learn, and grow...en-USFri, 22 Jan 2016 00:07:48 +0000http://bbpress.org/?v=1.0.2<![CDATA[Search]]>q
http://forums.leaflabs.com/search.php
iainism on "Recursive vs Ordinary Least Squares & Fixed Point"
http://forums.leaflabs.com/topic.php?id=1545#post-10495
Sat, 05 May 2012 08:28:18 +0000iainism10495@http://forums.leaflabs.com/<p>OK, so I'm still grinding away on this - I realised that by using Vector CANoe I can simulate what I want to do on the Olimexino. The fun stuff comes in when you realise that CAPL (the language used to programme in CANoe) doesn't support the struct or pointer concepts that one would normally use in implementing FIFOs and the like (and I need FIFOs as part of my final piece of work).</p>
<p>Anyway, as part of my general hackery I've now implemented a recursive least squares function, which is (also) based on an assumption of a linear system (YMMV).</p>
<p>I've stuck it in pastebin: <a href="http://pastebin.com/wFsdECwa" rel="nofollow">http://pastebin.com/wFsdECwa</a></p>
<p>Enjoy!
</p>iainism on "Recursive vs Ordinary Least Squares & Fixed Point"
http://forums.leaflabs.com/topic.php?id=1545#post-10168
Wed, 11 Apr 2012 17:17:09 +0000iainism10168@http://forums.leaflabs.com/<p>At the moment I have Code::Blocks as I don't generally work down amongst the bits and bytes and it provides some nice features for wxWidgets (and integrating libBoost into it is quite easy too) ;-)</p>
<p>GCC is built-in to Code::Blocks via MinGW in Windows at 4.4.1 - the last time I tried to alter this I borked some things!</p>
<p>However, I've checked the docs and it seems that 4.4.1 supports the _Fract and _Accum types - I didn't know they existed. Thanks very much for the pointer. I will have a play. (It looks as though they came in around 4.3.0)</p>
<p>Iain
</p>gbulmer on "Recursive vs Ordinary Least Squares & Fixed Point"
http://forums.leaflabs.com/topic.php?id=1545#post-10166
Wed, 11 Apr 2012 15:06:16 +0000gbulmer10166@http://forums.leaflabs.com/<p>ianism - What compiler have you got on your host system? </p>
<p>If you have a relatively modern compiler, you might be able to do some fixed-point experiments using the C compilers built in _Fract, _Accum types to see how much precision is lost. They aren't ideal, but it might be easier writing code for them rather than trying to make a library or class-libary work.</p>
<p>You might then time the two fixed-point programs to see if there is much difference.</p>
<p>Edit: It is probably worth mentioning that if you install a newer version of gcc (e.g. gcc 4.6.x) than LeafLabs distribute in the Maple IDE, then that should compile code using _Fract _Accum types for Maple.
</p>iainism on "Recursive vs Ordinary Least Squares & Fixed Point"
http://forums.leaflabs.com/topic.php?id=1545#post-10162
Tue, 10 Apr 2012 17:55:14 +0000iainism10162@http://forums.leaflabs.com/<p>In fact, because I'm feeling nice, here's a link to a PDF write-up I just completed on hardcoding OLS: <a href="http://iainism.co.uk/public/OLS_hardcode.pdf" rel="nofollow">http://iainism.co.uk/public/OLS_hardcode.pdf</a>
</p>iainism on "Recursive vs Ordinary Least Squares & Fixed Point"
http://forums.leaflabs.com/topic.php?id=1545#post-10160
Tue, 10 Apr 2012 12:30:07 +0000iainism10160@http://forums.leaflabs.com/<p>Hi, thanks.</p>
<p>It's a bit of all of those!</p>
<p>I'm trying to find out two things, firstly, whether I can tolerate the loss of precision due to using Fixed Point, but at the moment I can't easily simulate this. I will build up the system and test with debug code as I go if I have to, but I'd prefer to benchmark beforehand if possible. Secondly, given the restriction of scope of OLS whether using it is a better solution than RLS.</p>
<p>So I have 4 options to compare:<br />
1. RLS fixed<br />
2. RLS float<br />
3. OLS fixed<br />
4. OLS float</p>
<p>I'm just mindful that using RLS requires 3 steps with a total of 7 matrix multiplications for each iteration, while doing a hardcoded OLS for a fixed (low) number of points is one matrix multiplication and an inversion (but for a 2x2 this is trivial). So it 'feels' as though the hardcoded OLS will present a lower load. But this kind of contradicts the whole motivation for RLS (and hence gives rise to my desire to simulate before coding).</p>
<p>If I do get a lower load in a hardcoded OLS, then it might lead me to the situation where I could use the 'OLS float' option and outperform 'RLS fixed'...</p>
<p>If there's anywhere that I can post up PDF then I'm happy to outline hardcoded OLS for the situation in question so others can use it.</p>
<p>Iain
</p>gbulmer on "Recursive vs Ordinary Least Squares & Fixed Point"
http://forums.leaflabs.com/topic.php?id=1545#post-10159
Tue, 10 Apr 2012 11:04:33 +0000gbulmer10159@http://forums.leaflabs.com/<p>iainism - I'm not sure what the core of your question or concern is.</p>
<p>Is it that you are concerned about the amount of error introduced by using fixed point vs floating point techniques?</p>
<p>Or are you asking:<br />
-which one will consume the least amount of CPU time?<br />
- for suggestions of techniques which may have some better properties than either of them?<br />
- or tools to simulate the two?</p>
<p>Or something else? </p>
<p>If I had the time, and no alternatives, I'd try to find code, or write them both, time them and compare them.
</p>iainism on "Recursive vs Ordinary Least Squares & Fixed Point"
http://forums.leaflabs.com/topic.php?id=1545#post-10158
Tue, 10 Apr 2012 10:34:48 +0000iainism10158@http://forums.leaflabs.com/<p>For my project I need to predict when a level will get to a certain point. I'm going to assume a linear model (y=ax+b, with y=level, x=time and b=y_0), finding the x value when y=0 is then trivial (y_end=-b/a). My initial thoughts are to approach the parameter estimation for this in one of two ways:</p>
<p>1. To run a recursive least squares algorithm over all time that the system runs<br />
2. To run ordinary least squares over a fifo of the last 'n' readings of the level</p>
<p>The level changes in a roughly constant manner (give or take measurement noise), so the two methods should give the same answer (to within an acceptable tolerance). My question is:</p>
<p>Which would give the least load - assuming that any matrix/vector work is carried out in fixed point (and either done in the form of precalculated expressions or using Trenki's matrix library)?</p>
<p>Normally I'd simulate the two different *LS approaches in Matlab but I only have Matlab student R2009a, which doesn't include the fixed-point toolbox, so I seem to have hit a bit of a brick wall!</p>
<p>Any ideas please? I've seen that Octave has a FP toolbox, but development seems to have stopped on this a while ago - has anyone used it?
</p>