How can we choose the best set of samples to accurately represent a curve with a fixed number of samples?

Background

Exploring my passion project involves analyzing an RC aircraft control input device. In the realm of this hobby, there is a common feature known as "stick expo" where control sticks vary in sensitivity based on their position. As I delve into this, I've come across some academic papers that are beyond my mathematical grasp.

I have devised a method to approximate the stick expo curve by taking samples and using linear interpolation between them. Now, I am seeking the most effective set of sample points for optimal results.

If we examine the growth curve typically seen in this scenario, it reveals both linear and curvy sections. While the current samples are equidistant from each other, I believe adjusting the density based on the rate of change can enhance resolution in curvier segments by reallocating points from straighter regions.

Is there a way to measure the margin of error? And if so, can we determine the ideal sample points for a given function with a fixed number of samples?

Reference Code

The code snippet below illustrates how a pre-calculated set of points is utilized to estimate an output value in C++.

/* Assumptions:
 *   1. The _points[] data member contains at least 2 defined Points.
 *   2. All defined Points have x and y values within certain limits.
 *   3. The Points in the array are arranged in ascending order of x values.
 */
int InterpolatedCurve::value( int x ) {
  if( _points[0].x >= x ) { return _points[0].y; }
  for( unsigned int i = 1; i < _point_count; i++ ) {
    if( _points[i].x >= 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;
}

While my main project is in C++, I'm utilizing a Google spreadsheet to generate numerical data as I brainstorm this dilemma.

// 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;
};

The following function generates evenly distributed (yet suboptimal) points between input values of -1 and 1. These outputs were transformed into integers for analysis, with a 'factor' parameter determining the level of curvature in the generated curve.

function Point( x, y ) {
  this.x = x;
  this.y = y;
};

function compute_points_iso( count, factor ) {
  var points = [];
  for( var i = 0; i < 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;
};

Relevant Academic Work

My exploration led me to this research paper detailing an algorithm for selecting significant data points. Though my current program faces challenges, I am dedicated to refining it further and will share updates once progress is made.

Answer №1

To improve your linear interpolation, it's important to consider how the error can be limited based on the function's second derivative. When approximating

f(x) \approx f(x_0) + f'(x_0)*(x-x_0)
, keep in mind that the error is bounded by abs[ 0.5*f''(x_0)(x-x_0)^2 ].

An effective iterative strategy may involve:

  1. Creating an initial uniformly spaced grid
  2. Calculating the function's second derivative on this grid
  3. Determining error bounds using the second derivative and inter-sample spacing
  4. Adjusting sample spacing based on error magnitude

This process likely requires iteration through steps 2, 3, and 4.

The crux lies in step 4. When working with a fixed number of sample points, one could utilize the median of error bounds to identify locations needing denser or sparser sampling (i.e., locations where error exceeds the median are candidates for tighter sample placement).

Define E_0 as the median error bounds; then, for each sample point, compute a new desired spacing (dx')^2=2*E_0/f''(x). Implement logic to adjust grid spacing accordingly.

This approach draws from experiences using the "Self-Organizing Map" algorithm on data; similar algorithms might offer insights for your situation. While I haven't encountered a problem resembling yours exactly, achieving uniform error estimates across the grid seems to be the overarching objective.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Incorporate HTML elements into a React component

Is there a way to render (move) a DOM element into a React Component? I am facing a situation where I have integrated a third-party script into my React project (such as incorporating a live chat widget with a script). This script generates a DOM node when ...

Adding libsodium to a CMake configuration file

After successfully installing libsodium and verifying its functionality with the compiler, I encountered a roadblock when trying to integrate it into my CMakeLists.txt file. Despite reading through the documentation, I struggled to follow the instructions ...

Show the Vue.js template in a Laravel Blade view

I have been struggling to integrate a Vue.js component into a Laravel blade file. Despite researching tutorials and Stack Overflow solutions, I have not been able to resolve the issue. Below is the template that I want to display: <template> < ...

Signal for a complete 360 degree rotation of an image

Looking to enhance my 360 image rotator with an indicator that fades out after the first image. I added this function to the end of my 360.js: (function(){ if( $('#first').css('visibility','hidden')) { $('#rotat ...

Elements that are added dynamically will not inherit the correct CSS styles, requiring JavaScript to style them properly

My <ul> element dynamically adds <li> elements, and I am attempting to make the first <li> wider at 63% while the others are at 60%. However, the first one is only getting a width of 60%. Any thoughts on why this might be happening? I ne ...

AngularJS multiple select dropdown with dynamic quantity selection

I am currently utilizing AngularJS instead of Angular and I am looking to implement a corresponding textbox next to the dynamic select box. Below is my code for dynamically adding select boxes: HTML <div ng-controller='MyController'> ...

Error: Conditional formatting not compatible with JavaScript detected

I have a jQuery DataTable that is populated with data from a JSON file. Everything works smoothly, but I'm encountering an issue with conditional formatting. The script I'm using assigns a 'positive' class to all cells in column 2, even ...

Encountering an issue when passing a response using coverage.js

I am utilizing coverage.js to showcase data. When I pass my variable containing the coverage response into an HTML file, similar to how it's done in Angular to display expressions, I encounter a syntax error: <div class="container" style="margin- ...

Implement VueJS functionality to prevent form submission upon submission and instead submit the form upon keyup

My form has the following structure: <form id="myForm" action="/searchuser" method="POST" @submit.prevent="onSubmit(inputValue)"> <div class="field"> <label class="label">Name</label> <div class="control"> ...

Restrict the quantity of recommendations provided by the AutoComplete feature

After exploring the autocomplete API from https://material-ui.com/api/autocomplete/, I am unable to figure out a way, given my basic understanding of javascript, to restrict the display of a specific number of options beneath the TextField. I am working o ...

The error message "Uncaught ReferenceError: req is not defined with [email protected]" indicates that the variable

Discovered a helpful post that seems to address the problems. https://github.com/angular/angular-cli/issues/8359 I'm unsure about the steps to take next to resolve this issue. Can anyone clarify? Could you please advise on which version of Angular ...

When attempting to load the table from JSON, the error message "Cannot read property 'name' of null" occurs in the fooplugins/Footable plugin

I am facing an issue while trying to integrate the "FooTable" plugin with ajax calls. Everything works perfectly fine when I directly input the JSON data or load it from a JSON file using $.get('....json'). However, when attempting to fetch the t ...

What is the best way to showcase two div elements side by side within my carousel

/* Implementing slideshow functionality */ var currentIndex = 0; displaySlides(); function displaySlides() { var i; var slides = document.getElementsByClassName("mySlides"); var dots = document.getElementsByClassName("dot"); for (i = 0; i ...

npm update fails to update specific packages

After React was updated to version 0.15 to address the issue of excessive generation of tags, I made the decision to update my project.</p> <p>However, when I ran the command <code>npm update, it only updated to version 0.14.8. Running ...

Press a single button to toggle between displaying and hiding the table

$(document).ready(function() { $("#t1").hide(); // hide table by default $('#sp1').on('click', function() { $("#t1").show(); }); $('#close').on('click', function() { $("#t1").hide(); }); }); <li ...

Build a brand new root component in Vue JS

I am facing a challenge with destroying and re-creating the root application component. Below is my template structure: <div id="app"> {{ num }} </div> Here is the code I have implemented: if (app) { app.$destroy(); } else { ...

Exploring potential arrays within a JSON file using TypeScript

Seeking guidance on a unique approach to handling array looping in TypeScript. Rather than the usual methods, my query pertains to a specific scenario which I will elaborate on. The structure of my JSON data is as follows: { "forename": "Maria", ...

Guide on placing stickers on an item in Three JS

Recently, I began experimenting with the three.js library and have a question about decals: I managed to create a sphere with a texture applied to it. Is there a way to overlay another texture on specific areas of the sphere without repeating the original ...

What is the best way to refrain from utilizing the && logical operator within the mapStateToProps function in Redux?

When I'm trying to access a nested state in a selector, I often find myself having to use the && logical operators. const mapStateToProps = store => ({ image: store.auth.user && store.auth.user.photoURL; }); If I don't use ...

Having trouble clicking or interacting with JavaScript using Selenium and Python

Issue: Unable to interact with elements on a specific webpage after opening a new tab. Using WebDriver Chrome. I can successfully navigate the initial webpage until I click a link that opens a new tab, at which point I am unable to perform any actions. ...