Note that there are some explanatory texts on larger screens.

plurals
  1. POSelect optimal set of samples to approximate a curve with predetermined number of samples?
    primarykey
    data
    text
    <h2>Background</h2> <p>I have a pet project that I love to overthink from time to time. The project has to do with an RC aircraft control input device. People familiar with that hobby are probably also familiar with what is known as "stick expo", which is a common feature of RC transmitters where the control sticks are either more or less sensitive near the neutral center position and become less or more sensitive as the stick moves closer to its minimum or maximum values.</p> <p>I've read some papers that I don't fully understand. I clearly don't have the math background to solve this, so I'm hoping that perhaps one of you might.</p> <h2>Problem</h2> <p>I have decided to approximate the curve by taking a pre-determined number of samples and use linear interpolation to determine output values for any input values between the sample points. <em>I'm trying to find a way to determine the most optimal set of sample points.</em></p> <p>If you look at this example of a typical growth curve for this application, you will notice that some sections are more linear (straighter), and some are less linear (more curvy).</p> <p><img src="https://i.stack.imgur.com/j63LF.png" alt="typical curve example"></p> <p>These samples are equally distant from each other, but they don't have to be. It would be smart to increase the sample density where there is more change and thereby increasing the resolution in the curvy segments by borrowing redundant points from the straight segments.</p> <p>Is it possible to quantify the degree of error? If it is, then is it also possible to determine the optimal set of samples for a given function and a pre-determined number of samples?</p> <h2>Reference Code</h2> <p>Snippet from the class that uses a pre-calculated set of points to approximate an output value.</p> <pre class="lang-cpp prettyprint-override"><code>/* This makes the following assumptions: * 1. The _points[] data member contians at least 2 defined Points. * 2. All defined Points have x and y values between MIN_VALUE and MAX_VALUE. * 3. The Points in the array are ordered by ascending values of x. */ int InterpolatedCurve::value( int x ) { if( _points[0].x &gt;= x ) { return _points[0].y; } for( unsigned int i = 1; i &lt; _point_count; i++ ) { if( _points[i].x &gt;= x ) { return map(x, _points[i-1].x, _points[i].x, _points[i-1].y, _points[i].y); } } // This is an error condition that is not otherwise reported. // It won't happen as long as the points are set up correctly. return x; } // Example map function (borrowed from Arduino site) long map( long x, long x1, long x2, long y1, long y2 ) { return (x - x1) * (y2 - y1) / (x2 - x1) + y1; } </code></pre> <p>Although my project is actually in C++, I'm using a Google spreadsheet to produce some numbers while I ponder this problem.</p> <pre class="lang-js prettyprint-override"><code>// x: Input value between -1 and 1 // s: Scaling factor for curve between 0 (linear) and 1 (maximum curve) // c: Tunable constant function expo_fn( x, s, c ) { s = typeof s !== 'undefined' ? s : 1.0; c = typeof c !== 'undefined' ? c : 4.0; var k = c * ((c - 1.0) * s*s*s + s)/c + 1.0; return ((k - 1.0) * x*x*x*x*x + x)/k; }; </code></pre> <p>The following creates a set of isometrically distributed (non-optimal) points between input values -1 and 1. These output values were expanded to integers between -16383 and 16383 for the above example spreadsheet. Factor is a value between 0 and 1 that determines the "curviness"--zero being a flat, linear curve and 1 being the least-linear curve I care to generate.</p> <pre class="lang-js prettyprint-override"><code>function Point( x, y ) { this.x = x; this.y = y; }; function compute_points_iso( count, factor ) { var points = []; for( var i = 0; i &lt; count; ++i ) { var x = 2.0/(count - 1.0) * i - 1.0; var y = expo_fn(x, factor); points.push(new Point(x,y)); } return points; }; </code></pre> <h2>Relevant Academic Work</h2> <p>I have been studying <a href="http://www.idav.ucdavis.edu/func/return_pdf?pub_id=272" rel="nofollow noreferrer">this paper</a> describing an algorithm for selecting significant data points, but my program doesn't quite work right yet. I will report back if I ever get this thing working.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload