Ejemplo n.º 1
0
/* lambda reduction (z=Z'*a, Qz=Z'*Q*Z=L'*diag(D)*L) (ref.[1]) ---------------*/
static void reduction(int n, double *L, double *D, double *Z)
{
    int i,j,k;
    double del;
    
    j=n-2; k=n-2;
    while (j>=0) {
        if (j<=k) for (i=j+1;i<n;i++) gauss(n,L,Z,i,j);
        del=D[j]+L[j+1+j*n]*L[j+1+j*n]*D[j+1];
        if (del+1E-6<D[j+1]) { /* compared considering numerical error */
            perm(n,L,D,j,del,Z);
            k=j; j=n-2;
        }
        else j--;
    }
}
Ejemplo n.º 2
0
double gauss() {

static char has_saved;
static double saved;
	if(has_saved){ 
		has_saved = 0;
		return saved;
	}
    double u = ((double) rand() / (RAND_MAX)) * 2 - 1;
    double v = ((double) rand() / (RAND_MAX)) * 2 - 1;
    double r = u * u + v * v;
    if (r == 0 || r > 1) return gauss();
    double c = sqrt(-2 * log(r) / r);
	saved = v*c; has_saved = 1;
    return u * c;
}
Ejemplo n.º 3
0
void gaussian_convolution(float *u, float *v, int width, int height, float sigma)
{

	int ksize;	
	float * kernel;

	ksize = (int)(2.0 * 4.0 * sigma + 1.0);
	kernel = gauss(1,sigma,&ksize);

	int boundary = 1;

	copy(u,v,width*height);
	horizontal_convolution(v, v, width, height, kernel, ksize, boundary);
    vertical_convolution(v, v, width, height,  kernel,  ksize, boundary);
	delete[] kernel; /*memcheck*/
}
Ejemplo n.º 4
0
int main(int argc, char* argv[])
{
  if(argc!=3)
    { printf("Input errato:\n %s (int_righe) (int_colonne)\n", argv[0]); return -1; }
  else 
    if((rows=atoi(argv[1]))<=0 || (cols=atoi(argv[2]))<=0)
      { printf("Valori non ammessi:\n  %s (int_righe) (int_colonne)\n", argv[0]); return -1; }

  float local[rows][cols];
  tab= local[0];
  
  intab();
  gauss(0,0);

  return 0;
}
Ejemplo n.º 5
0
// ######################################################################
int Bayes::classify(const std::vector<double> &fv, double *prob)
{

  //the maximum posterior  (MAP alg):
  itsMaxProb  = -std::numeric_limits<double>::max();
  itsSumProb  = 0.0F;
  itsNormProb = 0.0F;
  int maxCls = -1;
  //double sumClassProb = 0;

  for(uint cls=0; cls<itsNumClasses; cls++)
  {
    LINFO("Class %d of %d - %s",cls,itsNumClasses,itsClassNames[cls].c_str());
    //Find the probability that the fv belongs to this class
    double probVal = 0; ////log(getClassProb(cls)); //the prior probility
    for (uint i=0; i<itsNumFeatures; i++) //get the probilityposterior prob
    {
      if (itsMean[cls][i] > 0)  //only process if mean > 0
      {
        const double g = gauss(fv[i], itsMean[cls][i], itsStdevSq[cls][i]);
        probVal += log(g);

        //LINFO("Val %f Mean %f sigma %f g(%e) %e",
        //      fv[i], itsMean[cls][i], itsStdevSq[cls][i], g, probVal);
      }
    }

    //if (probVal == NAN || probVal == -INFINITY) probVal = 1; //log of 0
    //printf("Class %i %s prob %f\n", cls, getClassName(cls), probVal);

    //sumClassProb += probVal;

    itsSumProb += exp(probVal);
    if (probVal > itsMaxProb){ //we have a new max
      itsMaxProb = probVal;
      maxCls = cls;
    }
  }

  itsMaxProb  = exp(itsMaxProb);
  itsNormProb = itsMaxProb / itsSumProb;

  if (prob != NULL)
    *prob = itsMaxProb; //)/exp(sumClassProb);

  return maxCls;
}
Ejemplo n.º 6
0
void Algorithm< T, Set >::makeInitialStep()
{
    // perform gaussian elimination, find base and rank
    summary.startComputingBasis();
    Matrix<T> f;
    std::vector<size_t> perm;
    gauss( inequalityMatrix, inequalityMatrix.nrows(), f, m_bas, m_rank, perm, m_intArith, m_zerotol );
    summary.endComputingBasis();

    rayFactory = new RayFactory<T, Set>(inequalityMatrix.ncols(), m_intArith,
        m_params.usePlusPlus ? inequalityMatrix.nrows() : 0);
    pivoting.setRayFactory(rayFactory);
    adjacencyChecker.setRank(m_rank);
    // now m_rank rows of f are inequalities (f[i], ray) >= 0 corresponding
    // to simplex facets, vertices of i-th facet are perm[j], j <> i;
    // create rays
    size_t numInequalities = inequalityMatrix.nrows();
    size_t dim = inequalityMatrix.ncols();
    T* coords = new T[dim + inequalityMatrix.nrows()];
    T* disc = coords + dim;
    for (size_t rayIdx = 0; rayIdx < m_rank; ++rayIdx)
    {
        for (size_t i = 0; i < dim; i++)
            coords[i] = f(rayIdx, i);
        if (m_params.usePlusPlus)
            pivoting.computeDiscrepancies(coords, disc);
        Ray* newRay = rayFactory->newRay(coords, disc, numInequalities);
        for( size_t j = 0; j < rayIdx; ++j)
            newRay->cobasis.add(perm[j]);
        for( size_t j = rayIdx + 1; j < m_rank; ++j)
            newRay->cobasis.add(perm[j]);
        extremeRays.push_back(newRay);
    }
    delete [] coords;
    summary.addRays(extremeRays.size());

    // find adjacency information for facets; it is simplex so each facet is
    // adjacent to all others but use common routine for updating adjacency
    adjacencyChecker.computeAdjacency(extremeRays, pivoting.notProcessedInequalities);

    // assign all rays to created facets outside sets
    summary.startPartitioning();
    size_t numInes = inequalityMatrix.nrows();
    for (size_t i = 0; i < numInes; ++i)
        pivoting.assignIne(i, extremeRays);
    summary.endPartitioning();
}
Ejemplo n.º 7
0
DoPiv::DoPiv(PivOptions &options, const IntMap::Pair &imPair, Grid &g)
    : m_num_points(g.size()),
      m_ccfs(m_num_points,
             Mat2<double>(options.winHeight() + 1, options.winWidth() + 1)),
      m_points(m_num_points, PivPoint(-1, -1, options)) {
  // Create a vector of PivPoints when the object is instantiated,
  // give constructor to instantiate CCF at correct size,
  // for now set coordinate to (-1, -1) to indicate that the piv has not yet
  // been done
  //
  //  Once vector points have been initiated loop through each point with
  //  an individual pair of interrogation region coordinates and do the PIV
  //  calculations for each point */

  auto im1Beg = imPair.first->begin();
  auto im2Beg = imPair.second->begin();
  auto imCols = imPair.first->cols();

  // Loop through each grid point and set the point coordinates to the
  // corresponding coordinates from grid.
  for (auto idx = 0; idx < m_num_points; idx++)
    m_points[idx].set_coords(g[idx]);

  // Lambda to calculate cross correlation functions for each vector point.
  auto ccfBatch = [&](int beg, int end) {
    Mat2<double> *ccf = nullptr;
    PivPoint *p = nullptr;
    Peak::PeaksVec *pks = nullptr;

    for (auto idx = beg; idx != end; idx++) {
      ccf = &m_ccfs[idx];
      p = &m_points[idx];
      pks = &p->peaks();

      // Do the cross-correlation, find the peaks and calculate the sub-pixel
      // component of displacement.
      x_corr_n_2(*ccf, imCols, im1Beg, im2Beg, p->i, p->j);
      find_ccf_peaks(*pks, *ccf, 13);
      gauss(*ccf, *pks, p->dispsVec());
    }
  };

  // Run on two threads, splitting the points evenly between the two.
  std::thread t1{ccfBatch, 0, m_num_points / 2};
  ccfBatch(m_num_points / 2, m_num_points);
  t1.join();
}
Ejemplo n.º 8
0
void kernel(mat_GF2& X, const mat_GF2& A)
{
   long m = A.NumRows();
   long n = A.NumCols();

   mat_GF2 M;
   long r;

   transpose(M, A);
   r = gauss(M);

   X.SetDims(m-r, m);
   clear(X);

   long i, j, k;

   vec_long D;
   D.SetLength(m);
   for (j = 0; j < m; j++) D[j] = -1;

   j = -1;
   for (i = 0; i < r; i++) {
      do {
         j++;
      } while (M.get(i, j) == 0);

      D[j] = i;
   }

   for (k = 0; k < m-r; k++) {
      vec_GF2& v = X[k];
      long pos = 0;
      for (j = m-1; j >= 0; j--) {
         if (D[j] == -1) {
            if (pos == k) {
               v[j] = 1;
               // v.put(j, to_GF2(1));
            }
            pos++;
         }
         else {
            v[j] = v*M[D[j]];
            // v.put(j, v*M[D[j]]);
         }
      }
   }
}
Ejemplo n.º 9
0
//Function to compute the current poses likelihood using the sliding window containing past poses 
void compute_likelihood(std::vector<tracking::Candidate> &candidates, std::vector<tracking::Candidate> &all_candidates, double forgetting_factor)
{
	
	std::vector<tracking::Candidate>::iterator it_my_current_candidates = candidates.begin();
      
    
    std::vector<tracking::Candidate>::iterator it_my_all_candidates;
	ros::Time now = ros::Time::now();

	
    while (it_my_current_candidates != candidates.end())
	{
		it_my_current_candidates->likelihood = 0;
		it_my_all_candidates = all_candidates.begin();
		std::vector<tracking::Candidate>::iterator it_my_all_candidates_end = all_candidates.end();
		
		while(it_my_all_candidates != it_my_all_candidates_end)
		{
			ros::Duration my_duration = now - it_my_all_candidates->pose.header.stamp;
			if (my_duration > duration_threshold)
			{
				//erase element
				all_candidates.erase(it_my_all_candidates);
				//refresh end pointer
				it_my_all_candidates_end = all_candidates.end();
			}
			else
			{
				double temp_distance = Dist_Between_Points( it_my_all_candidates->pose.pose.pose.position.x, it_my_all_candidates->pose.pose.pose.position.x, 
									    it_my_all_candidates->pose.pose.pose.position.y, it_my_all_candidates->pose.pose.pose.position.y);
				if(temp_distance > dist_gaussian_threshold)
				{
					break;
				}
				double temp_likelihood = gauss(temp_distance, it_my_all_candidates->pose.pose.covariance[0], 2); 
				double forgetting_element = double(1)/(1+double(forgetting_factor)*((double)my_duration.sec + (double)my_duration.nsec/1000000000));
				it_my_current_candidates->likelihood += temp_likelihood;
			}		
			it_my_all_candidates++;	
		}
		//ROS_INFO("updated_likelihood on candidate number: %d", it_my_current_candidates->counter_debug);			   
		it_my_current_candidates++;
	}

	
}
void main()
{
	int i,j,equ[3][4];
	clrscr();

	printf("Enter the equations:-\t");
	for(i=0;i<3;i++)
	{
		printf("\n\nEnter the equation %d:-\t",i+1);
		for(j=0;j<4;j++)
		{
			scanf("%d",&equ[i][j]);
		}
	}
	gauss(equ);
	getch();
}
Ejemplo n.º 11
0
void approx2(int n, double *T, double *X,
            double *a0, double *a1, double *a2)
{
 double st=0, st2=0, st3=0, st4=0, sx=0, stx=0, st2x=0;
 double a[9], b[3], r[3];
 for(int i=0;i<n;i++) {
   double t,t2,t3,t4,x;
   t=T[i]; t2=t*t; t3=t2*t; t4=t3*t;
   x=X[i];
   st+=t; st2+=t2; st3+=t3; st4+=t4; sx+=x; stx+=t*x; st2x+=t2*x;
 }
 a[0]=n;   a[1]=st;  a[2]=st2;  b[0]=sx;
 a[3]=st;  a[4]=st2; a[5]=st3;  b[1]=stx;
 a[6]=st2; a[7]=st3; a[8]=st4;  b[2]=st2x;
 gauss(3,a,b,r);
 *a0=r[0]; *a1=r[1]; *a2=r[2];
}
Ejemplo n.º 12
0
// Bi-variated Gaussian distribution.
inline
double
gauss(const double rho, const double theta, const double sigma2_rho, const double sigma2_theta, const double sigma_rho_theta)
{
	/* Leandro A. F. Fernandes, Manuel M. Oliveira
	 * Real-time line detection through an improved Hough transform voting scheme
	 * Pattern Recognition (PR), Elsevier, 41:1, 2008, 299-314.
	 *
	 * Equation 15
	 */

	const double sigma_rho_sigma_theta = sqrt( sigma2_rho ) * sqrt( sigma2_theta );
	const double r = (sigma_rho_theta / sigma_rho_sigma_theta), two_r = 2.0 * r;
	const double a = 1.0 / (2.0 * pi * sigma_rho_sigma_theta * sqrt( 1.0 - (r * r) ));
	const double b = 1.0 / (2.0 * (1.0 - (r * r)));
	return gauss( rho, theta, sigma2_rho, sigma2_theta, sigma_rho_sigma_theta, two_r, a, b );
}
Ejemplo n.º 13
0
int
main(int argc, char **argv) {

    struct cmdlineInfo cmdline;
    struct pam pam;
    int row;
    double normalizer;
    tuplen * tuplerown;
    
    pnm_init(&argc, argv);
   
    parseCommandLine(argc, argv, &cmdline);

    pam.size        = sizeof(pam);
    pam.len         = PAM_STRUCT_SIZE(tuple_type);
    pam.file        = stdout;
    pam.format      = PAM_FORMAT;
    pam.plainformat = 0;
    pam.width       = cmdline.width;
    pam.height      = cmdline.height;
    pam.depth       = 1;
    pam.maxval      = cmdline.maxval;
    strcpy(pam.tuple_type, cmdline.tupletype);

    normalizer = imageNormalizer(&pam, cmdline.sigma);
    
    pnm_writepaminit(&pam);
   
    tuplerown = pnm_allocpamrown(&pam);

    for (row = 0; row < pam.height; ++row) {
        int col;
        for (col = 0; col < pam.width; ++col) {
            double const gauss1 = gauss(distFromCenter(&pam, col, row),
                                        cmdline.sigma);

            tuplerown[col][0] = gauss1 * normalizer;
        }
        pnm_writepamrown(&pam, tuplerown);
    }
    
    pnm_freepamrown(tuplerown);

    return 0;
}
int main()
{
    int i,f,num,x;
//    freopen("D:\\in.txt","r",stdin);
    scanf("%d",&num);
    for(i=0;i<num;i++)
    {
        chu();
        scanf("%d",&m);
        for(f=0;f<m;f++)
        {
            scanf("%d",&x);
            fen(f,x);
        }
        printf("%d\n",gauss());
    }
    return 0;
}
Ejemplo n.º 15
0
//runs under 3s with:
//time cperf
int main(void){
int k = 2, d=20,  m = 3; 
int x[4] = {0, 20, 30, 40}; 
int L[4] = {0, 12, 15, 20}; 
int U[4] = {0, 30, 40, 70};
double f[4] ={0, 100, 60, 40};
printf("Revenue = %f\n", OnlineR(k,d,m,x,L,U,f));

int scens = 100, i,j,l;
for(i=m; i>0; i--) scens += U[i]-L[i];
for(i=0; i< 2000*50; i++){ 
		for(l=0;l<m;l++) gauss();
		for(j=0;j<scens;j++){ 
			k = rand()%m+1;
			OnlineR(k,d,m,x,L,U,f);
		}
}
}
Ejemplo n.º 16
0
ring_elem DetComputation::bareiss_det()
{
  // Computes the determinant of the p by p matrix D. (dense form).
  int sign = 1;
  size_t pivot_col;

  ring_elem pivot = R->from_long(0);
  ring_elem lastpivot = R->from_long(0);

  for (size_t r=p-1; r>=1; --r)
    {
      R->remove(lastpivot);
      lastpivot = pivot;
      if (!get_pivot(D, r, pivot, pivot_col)) // sets pivot_col and pivot
        {
          // Remove the rest of D.
          for (size_t i=0; i<=r; i++)
            for (size_t j=0; j<=r; j++)
              R->remove(D[i][j]);
          R->remove(lastpivot);
          return R->from_long(0);
        }
      for (size_t i=0; i<r; i++)
        gauss(D,i,r,pivot_col,lastpivot);

      if (((r + pivot_col) % 2) == 1)
        sign = -sign;  // MES: do I need to rethink this logic?

      for (size_t c=0; c<=r; c++)
        if (c != pivot_col)
          R->remove(D[r][c]);
        else
          D[r][c] = ZERO_RINGELEM;
    }

  R->remove(pivot);
  R->remove(lastpivot);
  ring_elem r = D[0][0];
  D[0][0] = ZERO_RINGELEM;

  if (sign < 0) R->negate_to(r);

  return r;
}
Ejemplo n.º 17
0
int main(int argc, char *argv[])
{
    setIO("sample");
    n = gi,m = gi, lim = gi;CLEAR(d,0);
    num = 0;
    for(int i = 1;i<=n;++i){
     tp[i] = gi;if(tp[i]) p[i] = ++num;
    }
    for(int i = 1;i<=m;++i) g[i].a=gi,g[i].b = gi,++d[g[i].a],++d[g[i].b];
    CLEAR(w,0);
    for(int i = 1;i<=n;++i) w[i][i] = w[i][i+n] = 1;
    for(int i = 1;i<=m;++i){
     if(!tp[g[i].a])
      w[g[i].b][g[i].a] -= 1.0/double(d[g[i].a]);
     if(!tp[g[i].b])
      w[g[i].a][g[i].b] -= 1.0/double(d[g[i].b]);
    }
    gauss();CLEAR(f,0);CLEAR(b,0);
    for(int i = 1;i<=n;++i)
     if(!tp[i])
      for(int j = 1;j<=n;++j) f[i][j] = w[j][i+n];
     else
      f[i][i] = 1;
    for(int i = 1;i<=m;++i){
     if(tp[g[i].a]){
      for(int j = 1;j<=n;++j)
       if(p[j])
        b[p[j]][p[g[i].a]]+=f[g[i].b][j]/double(d[g[i].a]);
        }
     if(tp[g[i].b]){
      for(int j = 1;j<=n;++j)
       if(p[j])
        b[p[j]][p[g[i].b]]+=f[g[i].a][j]/double(d[g[i].b]); 
      }
    }
    mpw(lim-2);
    ans = 0;
    for(int i = 1;i<=n;++i)
     if(p[i])
      ans += a[num][p[i]]*f[1][i];
    printf("%.9lf\n",ans);
    closeIO();
    return EXIT_SUCCESS;
}
Ejemplo n.º 18
0
int main(int argc, char **argv) {
  /* Timing variables */
  struct timeval etstart, etstop;  /* Elapsed times using gettimeofday() */
  struct timezone tzdummy;
  clock_t etstart2, etstop2;  /* Elapsed times using times() */
  unsigned long long usecstart, usecstop;
  struct tms cputstart, cputstop;  /* CPU times for my processes */

  ID = argv[argc-1];
  argc--;

  /* Process program parameters */
  parameters(argc, argv);

  /* Initialize A and B */
  initialize_inputs();

  /* Print input matrices */
  print_inputs();

  /* Start Clock */
  printf("\nStarting clock.\n");
  gettimeofday(&etstart, &tzdummy);
  etstart2 = times(&cputstart);

  /* Gaussian Elimination */
  gauss();

  /* Stop Clock */
  gettimeofday(&etstop, &tzdummy);
  etstop2 = times(&cputstop);
  printf("Stopped clock.\n");
  usecstart = (unsigned long long)etstart.tv_sec * 1000000 + etstart.tv_usec;
  usecstop = (unsigned long long)etstop.tv_sec * 1000000 + etstop.tv_usec;

  /* Display output */
  print_X();

  /* Display timing results */
  printf("\nElapsed time = %g ms.\n",
	 (float)(usecstop - usecstart)/(float)1000);


}
Ejemplo n.º 19
0
double RadialInterpolatePoint( const AcGePoint3dArray& datas, const AcGePoint3d& pt )
{
    MQ<double>          rbf; // RBF as kernel we can use : MQ, IMQ, GAU, TPS, POT
    Polinomio<double>   pol;
    double              c;
    Matrix<double>      A;
    Vector<double>      x, y, f, b, lambda;
    Vector<double>      x_new, y_new, f_new;
    int                 n, m;

    //define the number of nodes
    n = 10;

    //define the shape parameter for MQ kernel
    c = 1.0;

    //make the 2d data, see 2d-comun.hpp
    make_data( datas, x, y, f );
    n = x.GetSize();

    //configure the associate polynomial
    // pol.make( data_dimension, degree_pol)
    pol.make( 2, rbf.get_degree_pol() );

    //get the number of elements in the polynomial base
    m = pol.get_M();

    //make aditional data for:  Ax=b
    b.Reallocate( n + m );
    b = 0.0;

    //fill the expanded vector b = [f 0]
    for( int i = 0;  i < n;  i++ )
        b( i ) = f( i );

    //fill the Gramm matrix
    fill_gram( rbf, pol, c, x, y, A );

    //solve the linear system by LU factorization
    lambda = gauss( A, b );

    //interpolate the data
    return interpolate( rbf, pol, c, lambda, x, y, pt.x, pt.y );
}
Ejemplo n.º 20
0
int main(int argc, char **argv) {
    ID = argv[argc-1];
    argc--;
    
    MPI_Init(&argc, &argv);
    MPI_Comm_rank(MPI_COMM_WORLD, &myid);
    MPI_Comm_size(MPI_COMM_WORLD, &procs);
    printf("\nProcess number %d", myid);
    /* Process program parameters */
    parameters(argc, argv);
    
    //alocate memory
    A = (float*)malloc(N*N*sizeof(float));
    B = (float*)malloc(N*sizeof(float));
    X = (float*)malloc(N*sizeof(float));
    
    /* Initialize A and B */
    if (myid == 0) {
        initialize_inputs();
        
        /* Print input matrices */
        print_inputs();
    }
    /* Gaussian Elimination */
    gauss();
    /* Back substitution */
    if (myid == 0) {
        int row, col;
        for (row = N - 1; row >= 0; row--) {
            X[row] = B[row];
            for (col = N-1; col > row; col--) {
                X[row] -= A[row*N + col] * X[col];
            }
            X[row] /= A[row * N + row];
        }
        /* Display output */
        print_X();
    }
    free(A);
    free(B);
    free(X);
    MPI_Finalize();
    return 0;
}
Ejemplo n.º 21
0
void* threadedInverse(void* args) {
    ARGS* pargs = (ARGS*) args;
    Matrix* self = pargs->self;
    Matrix* inv = pargs->inv;
    int ncurr = pargs->ncurr;
    int nthrd = pargs->nthrd;
    int n = pargs->self->size();
    int begin = ncurr * (n / nthrd);
    int end = ncurr == nthrd - 1 ? n : (ncurr + 1) * (n / nthrd);
    double* temp = new double[2 * n];
    double* qtemp = new double[2 * n];
    string s, c;
    if (ncurr == 0)
        cout << "\tQR decomposition:" << endl;
    static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
    for (int i = 0; i < n - 1; ++i) {
        if (ncurr == 0 )
            cout << '\t' << '[' + s.assign(50 * i / (n - 1), '#') + c.assign(50 - 50 * i / (n - 1), ' ') + ']' +
                 ' ' + to_string(((1 + i) * 100) / (n - 1)) + '%' + '\r' << flush;
        pthread_mutex_lock (&mutex);
        if (self->flags[i] == 0) {
            self->flags[i] = 1;
            pthread_mutex_unlock (&mutex);
            for (int j = i + 1; j < n; ++j) {
                self->request(i, j, ncurr, nthrd);
                self->rotate(i, j, *inv, temp, qtemp);
                self->report(j);
            }
        } else {
            pthread_mutex_unlock (&mutex);
        }
    }
    self->awake();
    synchronize(nthrd, &self->condvar);
    if (ncurr == 0) {
        cout << '\t' << '[' + s.assign(50, '#') + ']' << endl;
        cout << "\tReverse Gauss: " << endl;
    }
    delete[] temp;
    delete[] qtemp;
    synchronize(nthrd, NULL);
    gauss(*self, *inv, begin, end, nthrd);
    return 0;
}
Ejemplo n.º 22
0
/**
 * \brief perform a gauss experiment with n x n matrix
 *
 * \param n	dimension of the matrix the inverse
 */
void	experiment(int n) {
	/* create a system to solve */
	a = random_matrix(n, 2 * n);

	/* display the matrix */
	if (n <= 10) {
		display_matrix(stdout, a, n, 2 * n);
	}

	/* perform the Gauss algorithm */
	gauss();

	/* display the matrix */
	if (n <= 10) {
		display_matrix(stdout, a, n, 2 * n);
	}

	free(a);
}
Ejemplo n.º 23
0
int		main(int argc, char **argv)
{
  int		tab[5];

  if (argc < 2) {
    printf("\033[01;06;33mUSAGE: n (positive) [start] [end] ");
    printf("[subdivision (strict positive)] [precision (positive)]\n");
    printf("If an error occur, start will be a 0, end at 5000, ");
    printf("subdivision at 10000 and precision at 10\n\033[0m");
    exit(EXIT_FAILURE); }
  else if ((tab[0] = atoi(argv[1])) < 0) {
    printf("You must enter a positive value for 'n' (arg 1)\n"); exit(EXIT_FAILURE); }
  fill_tab(tab, argv);
  rectangle(tab);
  trapeze(tab);
  simpson(tab);
  gauss(tab);
  return (0);
}
Ejemplo n.º 24
0
double *xtract_init_window(const int N, const int type)
{
    double *window;

    window = malloc(N * sizeof(double));

    switch (type)
    {
    case XTRACT_GAUSS:
        gauss(window, N, 0.4);
        break;
    case XTRACT_HAMMING:
        hamming(window, N);
        break;
    case XTRACT_HANN:
        hann(window, N);
        break;
    case XTRACT_BARTLETT:
        bartlett(window, N);
        break;
    case XTRACT_TRIANGULAR:
        triangular(window, N);
        break;
    case XTRACT_BARTLETT_HANN:
        bartlett_hann(window, N);
        break;
    case XTRACT_BLACKMAN:
        blackman(window, N);
        break;
    case XTRACT_KAISER:
        kaiser(window, N, 3 * PI);
        break;
    case XTRACT_BLACKMAN_HARRIS:
        blackman_harris(window, N);
        break;
    default:
        hann(window, N);
        break;
    }

    return window;
}
Ejemplo n.º 25
0
void CLAMBDA::reduction(int n, std::vector< std::vector<double> >& L, std::vector<double> &D, std::vector< std::vector<double> > &Z)
{
	int i,j,k;
	double del;
	j=n-2; k=n-2;
	while (j>=0) 
	{
		if (j<=k) 
			for (i=j+1;i<n;i++) 
				gauss(n,L,Z,i,j);
		del=D[j]+L[j][j+1]*L[j][j+1]*D[j+1];
		if (del+1E-6<D[j+1]) 			/* compared considering numerical error */
		{ 
			perm(n,L,D,j,del,Z);
			k=j; 
			j=n-2;
		}
		else j--;
	}
}
Ejemplo n.º 26
0
void rootexpo (float vf[], int n)
{
	int k;
	float temp_exp[1];
	float temp_gauss[1];
	double x1, x2, y;
	double choice[1];
	
	for(k=0; k<n; k++)
	{	
		ranlxd(choice, 1);
		gauss(temp_gauss,1);
		expo(temp_exp,1);
		x1 = (double)temp_gauss[0];
		x2 = (double)temp_exp[0];
		y = pow(x1,2) + x2;
		
		vf[k] = (float)y;
	}
}
int sinrank2(size_t n, const double * xin, double * out, void * args)
{
    struct sinrank2_opts * opts = args;

    double x,y;
    for (size_t ii = 0; ii < n; ii++){
       x = xin[ii*2+0];
       y = xin[ii*2+1];
       out[ii] = sin(10.0* x  + 0.25)*(y+1.0);
       out[ii] = out[ii] + gauss(x,y);
    
       if (opts->sv != NULL){
           double pt[2]; pt[0] = x; pt[1] = y;
           opts->sv->nEvals+= 1;
           PushVal(&(opts->sv->head),2, pt, out[ii]);
       }
    }

    return 0;
}
Ejemplo n.º 28
0
// ######################################################################
std::vector<Bayes::ClassInfo> Bayes::classifyRange(std::vector<double> &fv,
                                                   int &retCls, const bool sortit)
{

  std::vector<ClassInfo> classInfoRet;

  //the maximum posterior  (MAP alg):
  itsMaxProb  = -std::numeric_limits<double>::max();
  itsSumProb  = 0.0F;
  itsNormProb = 0.0F;
  int maxCls = -1;

  for(uint cls=0; cls<itsNumClasses; cls++)
  {
    //Find the probability that the fv belongs to this class
    double probVal = 0; //log(getClassProb(cls)); //the prior probility
    for (uint i=0; i<itsNumFeatures; i++) //get the posterior prob
    {
      if (itsMean[cls][i] > 0)  //only process if mean > 0
      {
        const double g = gauss(fv[i], itsMean[cls][i], itsStdevSq[cls][i]);
        probVal += log(g);
      }
    }

    itsSumProb += exp(probVal);
    if (probVal > itsMaxProb){ //we have a new max
      itsMaxProb = probVal;
      maxCls = cls;
    }
    classInfoRet.push_back(ClassInfo(cls, probVal, getStatSig(fv, cls)));
  }

  itsMaxProb  = exp(itsMaxProb);
  itsNormProb = itsMaxProb / itsSumProb;

  retCls = maxCls;
  if (sortit)
    std::sort(classInfoRet.begin(), classInfoRet.end(), lessClassInfo());
  return classInfoRet;
}
Ejemplo n.º 29
0
Archivo: numfcns.c Proyecto: FHe/tdl
/******************************************************************************
* convolve_pad()
* Simple gaussian convolution (padded)
*
* - x array of length num
* - y array of length num
* - wconv is the convolution width (gaussian fwhm)
*
* Returns
* -------
* - SUCCESS/FAILURE
*
* Returns
* -------
* - SUCCESS/FAILURE
*
* Notes
* -----
* Note y is the input 'data' array and is recomputed to 
* hold the convolution.  ie this overwrites the y data
*
* This routine pads the arrays to get rid of end point probs
* Note this is not normalized like the above one,
* Therefore it adds wierd stuff!  (NEEDS WORK) 
*
* Have to add normalization stuff to loop as did above
* and should work ok.  Should really be doing this with fft!
*
******************************************************************************/
int convolve_pad(double *x, double *y, int num, double wconv){
    double  *yp,*xp,*ypp, *temp, del, xcen;
    int j, k, np;

    np = 3*num - 2;
    xp = new_array(np, double);
    yp = new_array(np, double);
    ypp = new_array(np, double);
    temp = new_array(num, double);
    del = fabs(x[num-1] - x[0])/(num-1);

    for (j=0;j<np;j++){
        if (j < num - 1){
            xp[j] = x[0] - del*(num-1) + del*j;
            yp[j] = y[0] ;
        } else if (j > 2*(num - 1) ) {
            xp[j] = x[num-1] + del*( j - 2*(num - 1) );
            yp[j] = y[num-1] ;
        } else {
            xp[j] = x[j-num + 1];
            yp[j] = y[j-num + 1];
        }
    }

    for (j=0;j<num;j++){
        xcen = x[j];
        for (k=0;k<np;k++){
            ypp[k] = yp[k]*gauss(xp[k], xcen, wconv, 1.0);
        }
        temp[j] = trapz_int(xp,ypp,np);
    }
    for (j=0;j<num;j++){
        y[j] = temp[j];
    }
    free(xp);
    free(yp);
    free(ypp);
    free(temp);
    return(SUCCESS);
}
Ejemplo n.º 30
0
int main (void)
{
	int n;
	double tol = 1e-14;
	double **A, *b;

	for (n = 1; n <= 15; n++)
	{
		A = GMH (n);
		b = GV1 (n, A);

		gauss (n, A, b, tol);
		trisup (n, A, b, tol);

		printf ("%3d:\t%.30le\n", n, Norm (n, b)-1);

		FM (A, n, n);
		FV (b, n);
	}

	return 0;
}