Table of Contents
In regression analysis, curve fitting is the process of specifying the model that provides the best fit to the specific curves in your dataset. Curved relationships between variables are not as straightforward to fit and interpret as linear relationships. For linear relationships, as you increase the independent variable by one unit, the mean of the dependent variable always changes by a specific amount. This relationship holds true regardless of where you are in the observation space.
Unfortunately, the real world isn’t always nice and neat like this. Sometimes your data have curved relationships between variables. In a curved relationship, the change in the dependent variable associated with a one unit shift in the independent variable varies based on the location in the observation space.
In other words, the effect of the independent variable is not a constant value. Most curves used to fit experimental data are non-linear.
In this project two c++ frameworks, namely, ceres
and g2o
are used to estimate the parameter of the model given a set of experimenal data.
The fitting model is as follows:
.
├── CMakeLists.txt
├── include
│ ├── CeresCost.h
│ └── CommonCurve.h
├── README.md
└── src
├── ceres
│ ├── CMakeLists.txt
│ ├── cmake_modules
│ │ └── CeresConfig.cmake.in
│ └── demoCeres.cpp
└── g2o
├── CMakeLists.txt
├── cmake_modules
│ └── FindG2O.cmake
└── demoG2O.cpp
6 directories, 10 files
This is a sample code of how you may use g2o
and ceres
to perform curve fitting.
To get a local copy up and running follow these simple steps.
This is an example of how to list things you need to use the software and how to install them.
- cmake
sudo apt-get install cmake
- eigen
sudo apt-get install -y libeigen3-dev
- suitesparse
sudo apt-get install -y libsuitesparse-dev
- qt
sudo apt-get install -y qtdeclarative5-dev qt5-qmake libqglviewer-dev
- g2o
sudo su
cd /opt && mkdir g2oInstall && cd g2oInstall \
&& git clone https://github.com/RainerKuemmerle/g2o.git \
&& cd g2o && mkidr build && cd build && cmake .. \
&& make -j4 && make install
- ceres
sudo apt-get install libgoogle-glog-dev libatlas-base-dev && \
&& cd /opt && mkdir ceresInstall && cd ceresInstall \
&& git clone https://github.com/ceres-solver/ceres-solver.git \
&& cd ceres-solver && mkdir build && cd build && cmake .. \
&& make -j4 && make install
- opencv4
sudo su
git clone https://github.com/zoumson/OpencvInstall.git \
&& cd OpencvInstall && chmod +x install.sh && ./install.sh
- Boost
sudo apt-get install libboost-all-dev
- Clone the repo
git clone https://github.com/zoumson/CurveFitting.git
- Go to the project directory source
cd CurveFitting
- Create empty directories
build
, andbin
mkdir build && mkdir bin
- Generate the exectutables and move them to
bin
cd build && cmake .. && make -j4 && cd ..
- Command line options
Usage: options_description [options]
Allowed options:
-h [ --help ] produce help message
-a [ --first ] arg first parameter
-b [ --second ] arg second parameter
-c [ --third ] arg third parameter
-n [ --number ] [=arg(=500)] (=100) number of data
-i [ --iteration ] [=arg(=200)] (=100)
number of iterations
-s [ --noise ] [=arg(=5)] (=1) noise added
- Run with
ceres
./bin/demoCeres -a 1 -b 1 -c 1
- Sample Data generated as
29_06_2021_13_46_37_readDataCeres.txt
in directoryresult
- Parameter for the model saved in
29_06_2021_13_46_37_parametersCeres.txt
Estimated a,b,c =0.660982 1.5863 -0.190824
- Run with
g2o
./bin/demoG2O -a 1 -b 1 -c 1
- Sample Data generated as
29_06_2021_13_49_32_readDataG2O.txt
in directoryresult
- Parameter for the model saved in
29_06_2021_13_46_37_parametersCeres.txt
estimated model a, b, c: 0.656489 1.59246 -0.19271
- Back to the initial file structure configuration
rm -r bin build result
All the headers files are well docummented, read through the comments
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the MIT License. See LICENSE
for more information.
Adama Zouma - - [email protected]
Project Link: https://github.com/zoumson/CurveFitting