How to get a best fit line given points

309 views
Skip to first unread message

Batman

unread,
Feb 12, 2015, 2:24:02 PM2/12/15
to ceres-...@googlegroups.com
Hey CSers,

So I want to get the best fit line given an array of 10 points. How can I do that using Ceres solver?

Thanks in advance!

Sameer Agarwal

unread,
Feb 12, 2015, 2:25:15 PM2/12/15
to ceres-...@googlegroups.com
have a look at curve_fitting.cc in the examples directory.


though for fitting a line you do not need ceres, any linear algebra library will do.
Sameer




--
You received this message because you are subscribed to the Google Groups "Ceres Solver" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ceres-solver...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ceres-solver/02e97e5f-35a1-4d22-8110-e2a51ffc0841%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Batman

unread,
Feb 13, 2015, 1:15:32 AM2/13/15
to ceres-...@googlegroups.com
Can you explain to me why there is a huge array of data in the example code? And also, can you tell me how the solver knows the function has parameters m=0.3 and c=0.1?

Thanks

Julius Ziegler

unread,
Feb 13, 2015, 4:11:17 AM2/13/15
to ceres-...@googlegroups.com
On 02/13/2015 07:15 AM, Batman wrote:
> Can you explain to me why there is a huge array of data in the example
> code?

Thats the input data to be fit (like the 10 points you mentioned in your
initial post).

> And also, can you tell me how the solver knows the function has
> parameters m=0.3 and c=0.1?

Thats the result of the fit (like the line parameters you are searching
for).

Julius

> Thanks
>
> On Thursday, February 12, 2015 at 2:25:15 PM UTC-5, Sameer Agarwal wrote:
>
> have a look at curve_fitting.cc in the examples directory.
>
> http://ceres-solver.org/nnls_tutorial.html#curve-fitting
> <http://ceres-solver.org/nnls_tutorial.html#curve-fitting>
>
> though for fitting a line you do not need ceres, any linear algebra
> library will do.
> Sameer
>
>
>
>
> On Thu Feb 12 2015 at 11:24:03 AM Batman <rohit....@gmail.com
> <javascript:>> wrote:
>
> Hey CSers,
>
> So I want to get the best fit line given an array of 10 points.
> How can I do that using Ceres solver?
>
> Thanks in advance!
>
> --
> You received this message because you are subscribed to the
> Google Groups "Ceres Solver" group.
> To unsubscribe from this group and stop receiving emails from
> it, send an email to ceres-solver...@googlegroups.com <javascript:>.
> <https://groups.google.com/d/msgid/ceres-solver/02e97e5f-35a1-4d22-8110-e2a51ffc0841%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout
> <https://groups.google.com/d/optout>.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Ceres Solver" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to ceres-solver...@googlegroups.com
> <mailto:ceres-solver...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ceres-solver/9033653c-cf04-435e-84a9-9fd386d791c8%40googlegroups.com
> <https://groups.google.com/d/msgid/ceres-solver/9033653c-cf04-435e-84a9-9fd386d791c8%40googlegroups.com?utm_medium=email&utm_source=footer>.

Sameer Agarwal

unread,
Feb 13, 2015, 6:02:30 AM2/13/15
to ceres-...@googlegroups.com
Since this is example code, we packaged the data with the fitting code to save on an extra file and file i/o code.

As for how the solver knows that the function has these parameters, I am not quite sure what you are asking. Are you asking how the solver works? that is described to some extend in the solving part of the documentation, and can be learned by reading any book on curve fitting/nonlinear optimization.

Sameer


Batman

unread,
Feb 13, 2015, 10:28:13 AM2/13/15
to ceres-...@googlegroups.com
OK, so now when I'm trying to generate my random points, I get the following error: "error: expected unqualified-id before ‘for’"

Here's the code:
float data[20];
for(int i = 0; i < kNumObservations; i++)
{data[2*i]=i;
 data[2*i+1]= 2*i+5+((rand()%10)*0.5);
}

Can you guys tell me where I'm going wrong?

Sameer Agarwal

unread,
Feb 13, 2015, 11:53:08 AM2/13/15
to ceres-...@googlegroups.com
Rohit,
I am sorry but this is not a general c++ programming discussion group. I suggest developing some basic c++ skill before diving into ceres.
Sameer



Reply all
Reply to author
Forward
0 new messages