[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Bayani
- To: Development Discussions <developer at arabeyes dot org>
- Subject: Re: Bayani
- From: Baker Abdulhaq <baker at aows10 dot uab dot es>
- Date: Wed, 03 Mar 2004 16:17:59 +0100
- User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6b) Gecko/20031208
Youcef Rabah Rahal wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Salam,
On Thursday 26 February 2004 12:40, Baker Abdulhaq wrote:
GNU Scientific Library GSL have great functions that are very useful
for curve fitting (not only linear). (
http://www.gnu.org/software/gsl/ ) I think it can bey helpful. Curve
fitting is very interesting for many areas from physics to economics. I
think such a program will have useful application in the universities.
Yeah, that's the spirit behind Bayani ;-)
I am actually the only developer of Bayani. There are "lots" of TODOS (in
fact, you can't even imagine the number :-). Please let me know if you are
interested to work at least on one of the two issues above. There is also
the postscript issue, but it may be boring.
Sure, I am interesting in the work.
On the fitting algorithms ? If so, OK then.
I would like first to be sure that you know where to start.
Have you an experience with C/C++ ? CVS ? Or are you in a learning process ?
In either case, please have a look at the files:
http://cvs.arabeyes.org/viewcvs/projects/bayani/src/fit.h
http://cvs.arabeyes.org/viewcvs/projects/bayani/src/fit.cc
These contain the definition/implementation that Bayani uses for the time
being.
I suggest that, as an introductory exercise, you write a smallish C++ class
that fits linearly a set of data (there is no algorithm to implement, since
there is an analytical solution).
In a test program (independent from Bayani) you would create an object and fit
a small set of data :-) Don't take care of the errors that would be
associated with the data [therefore, the fit parameters will be given without
errors on them].
OK, My first C++ program. please tell me the marks.
what next.
I have only used gsl. I did nothing important.
I hope this makes sense.
Please let me know as soon as possible if this suits you or not, and don't
hesitate to ask !
I know that if you are familiar with C++, this would look like a very childish
test ;-) It is necessary though, as it will be our basic template for the
complicated work that awaits us ;-)
Salam and please let me know quickly about your plans :)
- --
Youcef R. Rahal
Arabeyes.org
http://www.arabeyes.org/~rahal
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)
iD8DBQFAPk35HDRR6Cd0eSYRAqfEAKD6KdjJcJpvH8CupDZ1q5MSZdFJTgCgso4I
YXVq6mmUMFyFHDhMBS9yeek=
=FX5y
-----END PGP SIGNATURE-----
_______________________________________________
Developer mailing list
Developer at arabeyes dot org
http://lists.arabeyes.org/mailman/listinfo/developer
/*
*
* ------------
* Description:
* ------------
* implementation of the Fit Class.
*
*
*
* $Date: 2004/03/03
* $Author: abdalhaq $
*
* this file is licensed under the GPL license.
*
************************************************************************/
using namespace std;
/* headers */
#include "fit.h"
#include <gsl/gsl_fit.h>
Fit::Fit()
{
Clear();
}
Fit::~Fit()
{
}
void Fit::FIT()
{
double c0,c1,cov00,cov01,cov11, chisq;
double * X, * Y;
unsigned n= XY[0].size();
X = new double[n];
Y = new double[n];
for(int i= 0;i< n;i++) {X[i]=XY[0].at(i); Y[i]= XY[1].at(i);} // first x then y
gsl_fit_linear ( X,1,Y,1,n,&c0,&c1,&cov00,&cov01,&cov11,&chisq);
Chi2 = chisq;
C.resize(2);
C[0]= c0;
C[1]= c1;
delete [] X;
delete [] Y;
}
double Fit::GetChi2()
{
return Chi2;
}
void Fit::GetC(vector <double> newC)
{
newC = C;
}
double Fit::GetC(int i)
{
return C.at(i);
}
void Fit::SetData(vector <double> NewXY[2])
{
XY[0] = NewXY[0];
XY[1] = NewXY[1];
}
void Fit::AddData(double X, double Y)
{
XY[0].push_back(X);
XY[1].push_back(Y);
}
void Fit::Clear()
{
XY[0].clear();
XY[1].clear();
}
/* fit.h 2004/03/3 abdakhaq $
*
* ------------
* Description:
* ------------
* Fit Class.
*
* .
*
* -----------------
* Revision Details:
* -----------------
* $Date: 2004/03/03 $
* $Author: abdalahaq $
* $Revision: $
*
* some code is copied and modified from bayani fit by rahal
* this file is licensed under the GPL license.
*
*
************************************************************************/
#ifndef FIT_H
#define FIT_H
/* "Usual" headers */
#include <math.h>
#include <vector>
//! Class for fitting.
/*!
This class fits a function on data.
*/
class Fit
{
protected:
vector <double> C;
vector <double> XY[2];
double Chi2;
public:
Fit ();
~Fit ();
void FIT ();
void SetData (vector <double> NewXY[2]);
void AddData (double, double);
void GetC (vector <double> newC);
double GetC(int i);
double GetChi2 ();
void Clear ();
};
#endif
using namespace std;
#include "fit.h"
#include <iostream>
//#include "gnuplot_i.h"
int main()
{
Fit f;
double x,y,c0,c1;
while( cin >> x >> y) f.AddData(x,y);
f.FIT();
cout << "y="<< f.GetC(0)<<"+"<<f.GetC(1)<<"*x\n";
cout << "chi2 ="<<f.GetChi2()<<"\n";
//gnuplot_ctrl * h ;
// h = gnuplot_init() ;
//gnuplot_setstyle(h, "lines") ;
//gnuplot_cmd (h, "plot y=%f+%f*x", c0,c1);
//gnuplot_close(h) ;
}
using namespace std;
#include <iostream>
double randum(double LB, double UB)
{
return (drand48()*(UB-LB)+LB);
}
/////////////
/* Polar (Box-Mueller) method; See Knuth v2, 3rd ed, p122 */
double ran_gaussian ( const double sigma)
{
double x, y, r2;
do
{
/* choose x,y in uniform square (-1,-1) to (+1,+1) */
x = -1 + 2 * drand48();
y = -1 + 2 * drand48();
/* see if it is in the unit circle */
r2 = x * x + y * y;
}
while (r2 > 1.0 || r2 == 0);
/* Box-Muller transform */
return sigma * y * sqrt (-2.0 * log (r2) / r2);
}
int main()
{
srand48( (unsigned)time( NULL ) );
float e;
e= 1000;
for( float i= 0; i<1000;i++)
cout << i<< " "<<(float)(1+i+randum(-0.5*e,0.5*e))<<"\n";
}
begin:vcard
fn:Baker Abdalhaq
n:Abdalhaq;Baker
org:UAB;Informatica
adr:;;;Bellaterra;;;Spain
email;internet:baker at aows10 dot uab dot es
title:PhD Studient
url:http://www.uab.es
version:2.1
end:vcard