[TUT][DIS] Polynomial regression GUI.

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello.
This is the coolest thing I coded for embedded chips. It is a polynomial regression with gui, yet it can also run without the screen, once configured. It works this way that user adds manually points(x, y), than chooses which polynomial regresion coefficient model fits and observes the calculated function on the screen. Once set up, settings can be saved to the eeprom(save button). After entire gui object can be destroyed, allowing for operation without the screen. Thought this would be very useful pice of code allowing for example to calibrate any non linear sensor in any circuit independently even from programmer's knowledge of theoretical model of inaccuracy. Think about 3d printers, and their struggle to keep the temperature values coherent beetween different models. Instead of using overcomplicated models of thermocouples in circuits user can just put two in one hotend and calibrate them on the screen.
Think about circuits where you want to leave user freedom to choose replacement parts from a buck of photoresistors, phototransistors, and photodiodes. Putting new device next to the reference one and filling a screen chart simplifies everything.

Currently gui sketch takes about 100kB of flash. I will code a version with simple buttons to save space, when the Adafruit_GFX_Button pull resolves. Which version to display will be controlled through a single define. Width and height of the chart are programmer configurable and I recommend screens of 240x320 or bigger for nice looking display. It is possible to use smaller screens, yet buttons will be overlapping each other(still every button should be displayed on the screen).
There are 2 examples. One is for the first run, other for the next runs. It is this way, because first eeprom save location has to be determined, and than there can be used Load_From_Eeprom(this location) at every startup. Although when I think about it now there can be a failed read, than empty save call as well as sucessfull read, than unnecessary save at every startup, providing there isnt garbage data in eeprom earlier.

Library only external dependency is Adafruit_GFX if you want to run GUI.

Github: https://github.com/63n0m3/PolynomialRegressionGUI-ard

Video tutorial: https://youtu.be/icBz3evB9uE

Licence: free to use. Please consider donation if you find it usefull. Support info in github files.

btc: bc1qn8xgw5rlfm7xnxnrxcqk0ulhrmrqjy07s3zmfp

 

Feel free to comment.

Last Edited: Sun. Nov 14, 2021 - 04:01 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

That looks pretty cool.

You don't mention, but it is using least square fitting?

Does it provide a goodness of fit indication?

By the way, you usually want the inverse curve----you measure the sensor and see its curve, ok, ...so now your pressure sensor is reading 2.198V volts on the sensor curve and you need to know the pressure that created it.   So that is essentially defining the fitting with  x & Y swapped.

The original curve must be monotonic to do so.

 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes it uses the least sum of square rests. For every point x there is calculated polynomial function value. Difference between this calculated value and point y is raised to ^2. Those values are added for every point. As the PolynomialRegression function can only calculate one given polynomial order, all polynomial regression functions with orders 1 to n are calculated up to the given 8/16/24/... (or manual Find_Best_Fit_Coeff_Num(..)). Lowest sum of square rests is selected.

I wonder if I should implement Reeves criterion from here: https://stats.stackexchange.com/... He divides this sums by number related to points number and order of the polynomial.

avrcandies wrote:

 

Does it provide a goodness of fit indication?

 

The PolynomialRegression(..) return value is the sum of the square rests for a given order. It is not indicated in a GUI right now.

Last Edited: Mon. Nov 15, 2021 - 08:04 AM