// Return the value for vector c which best fits the linear model y = Xc. // X is a matrix given by its row vectors: each row corresponds to a y value; // columns within the row correspond to coefficients for parameters in c. func Linear(y vec.Vector, X []vec.Vector) vec.Vector { n := C.size_t(len(y)) // number of observations p := C.size_t(len(X[0])) // number of parameters c, gslY := C.gsl_vector_alloc(p), C.gsl_vector_alloc(n) cov, gslX := C.gsl_matrix_alloc(p, p), C.gsl_matrix_alloc(n, p) vecToGSL(y, gslY) matrixToGSL(X, gslX) chisq := C.double(0) work := C.gsl_multifit_linear_alloc(n, p) C.gsl_multifit_linear(gslX, gslY, c, cov, &chisq, work) C.gsl_multifit_linear_free(work) result := vecFromGSL(c) C.gsl_matrix_free(gslX) C.gsl_matrix_free(cov) C.gsl_vector_free(gslY) C.gsl_vector_free(c) return result }
func GslMultifitLinear(x *matrix.GslMatrix, y *vector.GslVector, c *vector.GslVector, cov *matrix.GslMatrix, work *GslMultifitLinearWorkspace) (int32, float64) { var _outptr_4 C.double _result := int32(C.gsl_multifit_linear((*C.gsl_matrix)(unsafe.Pointer(x.Ptr())), (*C.gsl_vector)(unsafe.Pointer(y.Ptr())), (*C.gsl_vector)(unsafe.Pointer(c.Ptr())), (*C.gsl_matrix)(unsafe.Pointer(cov.Ptr())), &_outptr_4, (*C.gsl_multifit_linear_workspace)(unsafe.Pointer(work.Ptr())))) return _result, *(*float64)(unsafe.Pointer(&_outptr_4)) }