public inbox for gsl-discuss@sourceware.org
 help / color / mirror / Atom feed
From: Giulio Bottazzi <bottazzi@sssup.it>
To: gsl-discuss@sources.redhat.com
Subject: gsl_multifit_linear_est
Date: Fri, 04 Mar 2005 16:09:00 -0000	[thread overview]
Message-ID: <20050304151143.6abcc503.bottazzi@sssup.it> (raw)

[-- Attachment #1: Type: text/plain, Size: 1629 bytes --]

hello

I've noticed that the function in subject is not currently
implemented in GSL. The following code is a possible (highly
non-optimal) candidate. I can send patch w.r.t. CVS if preferred.

	Giulio.


int
gsl_multifit_linear_est (const gsl_vector *x,
			 const gsl_vector *c,
			 const gsl_matrix *cov,
			 double *y, double *y_err)
{

  if (x->size != c->size)
    {
      GSL_ERROR ("number of parameters c does not match number of
observations x",                 GSL_EBADLEN);
    }
  else if (cov->size1 != cov->size2)
    {
      GSL_ERROR ("covariance matrix is not square", GSL_ENOTSQR);
    }
  else if (c->size != cov->size1)
    {
      GSL_ERROR
        ("number of parameters does not match size of covariance
matrix",         GSL_EBADLEN);
    }
  else{

    size_t dim = x->size;
    size_t i,j;
    double estimate,estimate_err;

    estimate=0.0;
    for(i=0;i<x->size;i++)
      estimate += gsl_vector_get (x,i)*gsl_vector_get (c,i);

    estimate_err=0.0;
    for(i=0;i<x->size;i++){
      const double dtmp1=gsl_vector_get (x,i);
      estimate_err += dtmp1*dtmp1*gsl_matrix_get(cov,i,i);
      for(j=0;j<i;j++)
	estimate_err += 2.*dtmp1*gsl_vector_get (x,j)*gsl_matrix_get(cov,i,j);
    }
    
    *y = estimate;
    *y_err =  sqrt(estimate_err);
    
    return GSL_SUCCESS;
  }
}





-- 
Giulio Bottazzi                 PGP Key ID:BAB0A33F 

CAFiM  Center for the Analysis of Financial Markets
LEM          Laboratory of Economics and Management
Sant'Anna School for Advanced Studies, Pisa, Italy
Phone: (+39)-050-883365       Fax: (+39)-050-883344
email: bottazzi@sssup.it    www.sssup.it/~bottazzi/

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

                 reply	other threads:[~2005-03-04 16:09 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20050304151143.6abcc503.bottazzi@sssup.it \
    --to=bottazzi@sssup.it \
    --cc=gsl-discuss@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).