/** * \file LinearFit * \brief Linear fit of data points * * Copyright 2007-2013 IMP Inventors. All rights reserved. * */ #include "IMP/algebra/LinearFit.h" #include "IMP/base/utility.h" IMPALGEBRA_BEGIN_NAMESPACE LinearFit2D::LinearFit2D(const algebra::Vector2Ds& data, const Floats &errors) { // check that there are at least 3 points IMP_USAGE_CHECK(data.size() > 1, "At least 2 points are required for LinearFit2D " << data.size() << " given"); IMP_USAGE_CHECK(errors.empty() || errors.size()==data.size(), "Either there must be no error bars given or one per" << " point."); find_regression(data, errors); evaluate_error(data, errors); } void LinearFit2D::find_regression(const algebra::Vector2Ds& data, const Floats &errors) { double x(0.0), y(0.0), x2(0.0), xy(0.0), w(0.0); for(unsigned int i=0; i