Skip to content

Python code to fit curve using different methods for given points.

License

Notifications You must be signed in to change notification settings

prat1kbhujbal/Curve_Fitting

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Curve_Fitting

Directory tree

Problem 1

A ball is thrown against a white background and a camera sensor is used to track its trajectory. We have a near perfect sensor tracking the ball in video1 and the second sensor is faulty and tracks the ball as shown in video2. Clearly, there is no noise added to the first video whereas there is significant noise in the second video. Assuming that the trajectory of the ball follows the equation of a parabola:

  1. Use Standard Least Squares to fit curves to the given videos in each case. You have to plot the data and your best fit curve for each case. Submit your code along with the instructions to run it.

Execution

1. To generate .csv file from video

python3 generate_csv_file.py --FilePath='./data_files/video1.mp4' --CSVFilePath='./<Path>/<File_Name>.csv' 
  • FilePath - Video file path. Default :- ' ./data_files/video1.mp4 '
  • CSVFilePath - File path to save csv file. Default :- ' ./data_files/data1.csv '

2. To fit the curves

  • Using Standard Least Squares to fit from generated .csv file.
  • Specify your .csv file paths in python file for both videos and run the following command.
python3 standard_least_squares.py

Results:

For video1-

Points

video1.png

Standard Least Squares Method

video1.png

For video2-

Points

video1

Standard Least Squares Method

video1

Problem 2

In the above problem, we used the least squares method to fit a curve. However, if the data is scattered, this might not be the best choice for curve fitting. In this problem, you are given data for health insurance costs based on the person’s age. There are other fields as well, but you have to fit a line only for age and insurance cost data. The data is given in .csv file format here

  1. Compute the covariance matrix (from scratch) and find its eigenvalues and eigenvectors. Plot the eigenvectors on the same graph as the data.
  2. Fit a line to the data using linear least square method, total least square method and RANSAC.

Execution

  • Run the following command-
python3 curve_fitting.py

Results:

Eigen Value Representation

eigen

Linear least square method

llsm

Total least square method

tsm

RANSAC

ransac

Problem 3

Write python code to compute the SVD for given matrix- refer this

Execution

  • Run the following command-
python3 SVD.py

Releases

No releases published

Packages

No packages published

Languages