コード例 #1
0
ファイル: linreg.go プロジェクト: kofron/gogsl
/* FitWLinear wraps gsl_fit_wlinear.h
 * Paraphrasing the GSL manual:
 * This function computes the best-fit linear regression coefficients
 * (Y0,Slope) of the model Y = Y0 + Slope*X for the weighted dataset
 * (x, y), two vectors of length n with strides xstride and ystride.
 * The vector w, of length n and stride wstride, specifies the weight of
 * each datapoint. The weight is the reciprocal of the variance for each
 * datapoint in y.  The covariance matrix for the parameters (Y0, Slope) is
 * computed using the weights and returned via the parameters
 * (Cov00, Cov01, Cov11). The weighted sum of squares of the residuals from
 * the best-fit line, χ2, is returned in ChiSq.
 */
func FitWLinear(x, y, w *[]float64, sx, sy, sw uint) (f *LinearFit, e error) {
	f = &LinearFit{}
	xptr := (*C.double)(unsafe.Pointer(&(*x)[0]))
	yptr := (*C.double)(unsafe.Pointer(&(*y)[0]))
	wptr := (*C.double)(unsafe.Pointer(&(*w)[0]))
	er := C.gsl_fit_wlinear(
		xptr,
		(C.size_t)(sx),
		wptr,
		(C.size_t)(sw),
		yptr,
		(C.size_t)(sy),
		(C.size_t)(len(*x)),
		(*C.double)(&f.Y0),
		(*C.double)(&f.Slope),
		(*C.double)(&f.Cov00),
		(*C.double)(&f.Cov01),
		(*C.double)(&f.Cov11),
		(*C.double)(&f.ChiSq))
	if er == (C.int)(0) {
		e = nil
	} else {
		e = gsl.NewGSLError(int(er))
	}
	return
}
コード例 #2
0
ファイル: fit.go プロジェクト: postfix/gsl-1
func Wlinear(x []float64, xstride int, w []float64, wstride int, y []float64, ystride int, n int) (int32, float64, float64, float64, float64, float64, float64) {
	var _outptr_7 C.double
	var _outptr_8 C.double
	var _outptr_9 C.double
	var _outptr_10 C.double
	var _outptr_11 C.double
	var _outptr_12 C.double
	_slice_header_0 := (*reflect.SliceHeader)(unsafe.Pointer(&x))
	_slice_header_2 := (*reflect.SliceHeader)(unsafe.Pointer(&w))
	_slice_header_4 := (*reflect.SliceHeader)(unsafe.Pointer(&y))
	_result := int32(C.gsl_fit_wlinear((*C.double)(unsafe.Pointer(_slice_header_0.Data)), C.size_t(xstride), (*C.double)(unsafe.Pointer(_slice_header_2.Data)), C.size_t(wstride), (*C.double)(unsafe.Pointer(_slice_header_4.Data)), C.size_t(ystride), C.size_t(n), &_outptr_7, &_outptr_8, &_outptr_9, &_outptr_10, &_outptr_11, &_outptr_12))
	return _result, *(*float64)(unsafe.Pointer(&_outptr_7)), *(*float64)(unsafe.Pointer(&_outptr_8)), *(*float64)(unsafe.Pointer(&_outptr_9)), *(*float64)(unsafe.Pointer(&_outptr_10)), *(*float64)(unsafe.Pointer(&_outptr_11)), *(*float64)(unsafe.Pointer(&_outptr_12))
}