예제 #1
0
	void MakeChiZeroBuffers(valarray<cl_float> & data, valarray<cl_float> & data_err, valarray<cl_float> & model, valarray<cl_float> & output, unsigned int test_size)
	{
		unsigned int n = 2*test_size;
		// Create buffers
		data.resize(n);
		data_err.resize(n);
		model.resize(n);
		output.resize(n);

		valarray<cl_float2> temp = CModel::GenerateUVSpiral_CL(test_size);

		// Set data = model to produce a zero chi result.
		for(int i = 0; i < test_size; i++)
		{
			data[i] = temp[i].s0;
			data[test_size + i] = temp[i].s1;

			model[i] = temp[i].s0;
			model[test_size + i] = temp[i].s1;

			// 1% error on amplitudes, 10% error on phases
			data_err[i] = amp_err * data[i];
			data_err[test_size + i] = phi_err * data[i];
		}
	}
예제 #2
0
void count_pair_distances::operator()(const SequenceTree& T)
{
  if (not initialized) {
    N = T.n_leaves();
    names = T.get_leaf_labels();
    m1.resize(N*(N-1)/2);
    m2.resize(N*(N-1)/2);
    m1 = 0;
    m2 = 0;
    initialized = true;
  }

  n_samples++;

  // Theoretically, we could do this much faster, I think.
  //  vector<vector<int> > leaf_sets = partition_sets(T);

  int k=0;
  for(int i=0;i<N;i++)
    for(int j=0;j<i;j++,k++) 
    {
      double D = 0;
      if (RF)
	D = T.edges_distance(i,j);
      else
	D = T.distance(i,j);
      m1[k] += D;
      m2[k] += D*D;
    }
}
예제 #3
0
/**
 * generates a random set of n points in X and Y.
 */
void randTest(unsigned n, valarray<double>& X, valarray<double>& Y) {
    X.resize(n);
    Y.resize(n);
    srand(time(NULL));
	for(unsigned i=0;i<n;i++) {
		X[i]=getRand(1.);
		Y[i]=getRand(1.);
	}
}
예제 #4
0
bool spk_sode_model<Scalar>::doDataMean_indPar(valarray<double> &F_eta) const
{	size_t Ni = N_[i_];
	F_eta.resize( Ni * m_ );

	assert( i_ < N_.size() );
	size_t j_start = S_[i_];
	size_t j_end   = j_start + Ni + 1;
	vector< AD<double> > F_ad( Ni );
	vector< AD<double> > alpha_ad = ADvector(alpha_);
	vector< AD<double> > eta_ad   = ADvector(eta_);
	vector< AD<double> > t_ad     = ADvector(t_);
	Independent(eta_ad);
	data_mean(F_ad, t_ad, j_start, j_end, alpha_ad, eta_ad);
	ADFun<double> ad_fun(eta_ad, F_ad);
	vector<double> eta( eta_.size() );
	size_t k;
	for(k = 0; k < eta_.size(); k++)
		eta[k] = Value( eta_[k] );
	vector<double> jacobian = ad_fun.Jacobian(eta);
	bool all_zero = true;
	size_t j;
	for(j = 0; j < Ni; j++)
	{	for(k = 0; k < m_; k++)
		{	F_eta[j + k * Ni] = jacobian[j * m_ + k]; 
			all_zero &= (0. == F_eta[j + k * Ni]);
		}
	}
	return ! all_zero;
}
예제 #5
0
/**
 * generates a set of 8 points (actually the vertices of two rectangles)
 * which lineup horizontally.  The expected hull are the lower-left and
 * top-left corners of the left rectangle and the top-right/lower-right
 * corners of the right rectangle.
 */
void tworects(valarray<double>& X, valarray<double>& Y, Hull& expectedHull) {
    const unsigned n=8;
    X.resize(n);
    Y.resize(n);
    X[0]=330.011898, Y[0]=203.250425;
    X[1]=330.011898, Y[1]=237.250425;
    X[2]=276.011898, Y[2]=237.250425;
    X[3]=276.011898, Y[3]=203.250425;
    X[4]=459.998300, Y[4]=203.250425;
    X[5]=459.998300, Y[5]=237.250425;
    X[6]=405.998300, Y[6]=237.250425;
    X[7]=405.998300, Y[7]=203.250425;
    unsigned hull[]={3,4,5,2};
    unsigned m=sizeof(hull)/sizeof(unsigned);
    expectedHull.resize(m);
    copy(hull,hull+m,expectedHull.begin());
}
예제 #6
0
    void doDataMean( valarray<double>& ret ) const
    {
      //
      // f(alpha, b) = [ alp(2) + b(2) ]
      //               [ alp(2) + b(2) ]
      //
      ret.resize(_nYi);
      ret[0] = _a[1] + _b[1];
      ret[1] = _a[1] + _b[1];

    }
예제 #7
0
 void doIndParVarianceInv( valarray<double>& ret ) const
 {
   //
   // Dinv = [ alp(1)^-1      0     ]
   //        [     0      alp(1)^-1 ]
   //
   ret.resize(_nB * _nB);
   ret[0] = 1.0 / _a[0];
   ret[1] = 0.0;
   ret[2] = 0.0;
   ret[3] = 1.0 / _a[0];
 }
예제 #8
0
void spk_sode_model<Scalar>::doDataVariance(valarray<Scalar> &R) const
{	size_t Ni = N_[i_];
	R.resize(Ni * Ni);

	size_t j1, j2;
	for(j1 = 0; j1 < Ni; j1++)
	{	for(j2 = 0; j2 < Ni; j2++)
			R[j1 + j2 * Ni] = 0.;
		R[j1 + j1 * Ni] = exp( alpha_[ell_-1] );
	}
	return;
}
예제 #9
0
 void doDataVariance( valarray<double>& ret ) const
 {
   //
   // R(alp, b) = [ b(1)  0   ]
   //             [  0   b(1) ]
   //
   ret.resize(_nYi * _nYi);
   ret[0] = _b[0];
   ret[1] =  0.0;
   ret[2] =  0.0;
   ret[3] = _b[0];
 }
예제 #10
0
    void doDataMean( valarray<double>& ret ) const
    {
      //
      // h(x) = [ x(3) ]
      //        [ x(3) ]
      //
      ret.resize(_nY);
      const double *pX = _b.data();

      ret[0] = 1.0 * pX[2];
      ret[1] = 1.0 * pX[2];
    }
예제 #11
0
 void doIndParVariance( valarray<double>& ret ) const
 {
   //
   // D = [alp(1)   0   ]
   //     [   0   alp(1)]
   //
   ret.resize(_nB * _nB);
   ret[0] = _a[0];
   ret[1] = 0.0;
   ret[2] = 0.0;
   ret[3] = _a[0];
 }
예제 #12
0
 void doDataVarianceInv( valarray<double>& ret ) const
 {
   //
   // R(alp, b)^-1 = [ 1 / b(1)      0   ]
   //                [  0       1 / b(1) ]
   //
   ret.resize(_nYi * _nYi);
   ret[0] = 1.0 / _b[0];
   ret[1] =  0.0;
   ret[2] =  0.0;
   ret[3] = 1.0 / _b[0];
 }
예제 #13
0
 bool doDataMean_indPar( valarray<double>& ret ) const
 {
   //
   // f_b   = [ 0  1 ]
   //         [ 0  1 ]
   //
   ret.resize(_nYi * _nB);
   ret[0] = 0.0;
   ret[1] = 0.0;
   ret[2] = 1.0;
   ret[3] = 1.0;
   return true;
 }
예제 #14
0
void spk_sode_model<Scalar>::doDataMean(valarray<Scalar> &F) const
{	size_t Ni = N_[i_];
	F.resize(Ni);
	assert( i_ < N_.size() );
	vector<Scalar> F_vec( Ni );
	size_t j_start = S_[i_];
	size_t j_end   = j_start + Ni + 1;
	data_mean(F_vec, t_, j_start, j_end, alpha_, eta_);
	size_t j;
	for(j = 0; j < Ni; j++)
		F[j] = F_vec[j];
	return;
}
예제 #15
0
 bool doDataVarianceInv_popPar( valarray<double>& ret ) const
 {
   //
   // R^(-1)_alp = [ 0  0 ]
   //              [ 0  0 ]
   //              [ 0  0 ]
   //              [ 0  0 ]
   //
   ret.resize(_nYi * _nYi * _nA);
   for( int i=0; i<_nYi*_nYi*_nA; i++ )
     ret[i] = 0.0;
   return false;
 }
예제 #16
0
    void doDataVarianceInv( valarray<double>& ret ) const
    {
      //
      // Q(x)^-1 = [ 1.0 / (2.0*x(1)),   0.0        ]
      //           [ 0.0                 1.0 / x(2) ]
      //
      ret.resize(_nY * _nY);
      const double *x = _b.data();

      ret[0] = 1.0 / (2.0 * x[0]);
      ret[1] = 0.0;
      ret[2] = 0.0;
      ret[3] = 1.0 / x[1];
    }
예제 #17
0
bool spk_sode_model<Scalar>::doDataVariance_indPar(valarray<double> &R_eta) const
{	size_t Ni = N_[i_];
	R_eta.resize( Ni * Ni * m_ );

	size_t j1, j2, k;
	for(j1 = 0; j1 < Ni; j1++)
	{	for(j2 = 0; j2 < Ni; j2++)
		{	for(k = 0; k < m_; k ++)
				R_eta[j2 + j1 * Ni + k * Ni * Ni] = 0.;
		}
	}
	bool non_zero = false;
	return non_zero;
}
예제 #18
0
    bool doDataMean_indPar( valarray<double>& ret ) const 
    {
      //
      // h_x(x) = [ 0 , 0 , 1 ]
      //          [ 0 , 0 , 1 ]
      //
      ret.resize( _nY * _nB );
      for( int i=0; i<_nY*_nB; i++ )
        ret[i] = 0.0;
      ret[4] = 1.0;
      ret[5] = 1.0;

      return true;
    }
예제 #19
0
bool spk_sode_model<Scalar>::doDataVariance_popPar(valarray<double> &R_alpha) const
{	size_t Ni = N_[i_];
	R_alpha.resize( Ni * Ni * ell_ );

	size_t j1, j2, k;
	for(j1 = 0; j1 < Ni; j1++)
	{	for(j2 = 0; j2 < Ni; j2++)
		{	for(k = 0; k < ell_; k ++)
				R_alpha[j2 + j1 * Ni + k * Ni * Ni] = 0.;
		}
		R_alpha[j1 + j1 * Ni + (ell_-1) * Ni * Ni] = exp( Value(alpha_[ell_-1]) );
	}
	bool non_zero = true;
	return non_zero;
}
예제 #20
0
    void doDataVariance( valarray<double>& ret ) const
    {
      //
      // Q(x) = [ 2 * x(1) ,   0   ]
      //        [     0    ,  x(2) ]
      //
      
      ret.resize(_nY * _nY);
      const double *x = _b.data();

      ret[0] = 2.0 * x[0];
      ret[1] = 0.0;
      ret[2] = 0.0;
      ret[3] = x[1];
    }
예제 #21
0
	void MakeChiOneBuffers(valarray<cl_float> & data, valarray<cl_float> & data_err, valarray<cl_float> & model, valarray<cl_float> & output, unsigned int test_size)
	{
		unsigned int n = 2*test_size;
		// Create buffers
		data.resize(n);
		data_err.resize(n);
		model.resize(n);
		output.resize(n);

		valarray<cl_float2> t_data = CModel::GenerateUVSpiral_CL(test_size);

		// Generate test data.
		for(int i = 0; i < test_size; i++)
		{
			complex<float> c_data(t_data[i].s0, t_data[i].s1);

			// Data are stored as amplitude and phase.
			data[i] = abs(c_data);
			data[test_size + i] = arg(c_data);

			// Avoid any cases where the data yield chi=0.
			if(fabs(data[i]) < amp_err)
				model[i] = amp_err;
			else
				model[i] = abs(c_data) * (1 + amp_err);

			if(fabs(data[test_size + i]) < phi_err)
				model[test_size + i] = copysign(phi_err, data[test_size + i]);
			else
				model[test_size + i] = arg(c_data) * (1 + phi_err);

			// Set the errors, avoid zero error
			data_err[i] = max(fabs(amp_err * data[i]), amp_err);
			data_err[test_size + i] = max(fabs(phi_err * data[test_size + i]), phi_err);
		}
	}
예제 #22
0
 bool doIndParVariance_popPar( valarray<double>& ret ) const
 {
   //
   // D_alp = [ 1  0 ]
   //         [ 0  0 ]
   //         [ 0  0 ]
   //         [ 1  0 ]
   //
   ret.resize(_nB * _nB * _nA);
   for( int i=0; i<_nB*_nB*_nA; i++ )
     ret[i] = 0.0;
   ret[0] = 1.0;
   ret[3] = 1.0;
   return true;
 }
예제 #23
0
 bool doIndParVarianceInv_popPar( valarray<double>& ret ) const
 {
   //
   // Dinv_alp = [ -1.0 / alp(1)^2  0 ]
   //            [ 0                0 ]
   //            [ 0                0 ]
   //            [ -1.0 / alp(1)^2  0 ]
   //
   ret.resize(_nB * _nB * _nA);
   for( int i=0; i<_nB*_nB*_nA; i++ )
     ret[i] = 0.0;
   ret[0] = -1.0 / (_a[0] * _a[0]);
   ret[3] = -1.0 / (_a[0] * _a[0]);
   return true;
 }
예제 #24
0
    bool doDataVarianceInv_indPar( valarray<double>& ret ) const
    {
      //
      // R^(-1)_b(alp,b) = [ -1.0 / b(1)^2   0 ]
      //                   [ 0               0 ]
      //                   [ 0               0 ]
      //                   [ -1.0 / b(1)^2   0 ]
      //
      ret.resize(_nYi * _nYi * _nB);
      for( int i=0; i<_nYi*_nYi*_nA; i++ )
        ret[i] = 0.0;

      ret[0] = -1.0 / ( _b[0] * _b[0] );
      ret[3] = -1.0 / ( _b[0] * _b[0] );
      return true;
    }
예제 #25
0
    bool doDataVariance_indPar( valarray<double>& ret ) const
    {
      //
      // R_b   = [ 1  0 ]
      //         [ 0  0 ]
      //         [ 0  0 ]
      //         [ 1  0 ]
      //
      ret.resize(_nYi *_nYi * _nB);
      for( int i=0; i<_nYi*_nYi*_nA; i++ )
        ret[i] = 0.0;

      ret[0] = 1.0;
      ret[3] = 1.0;
      return true;
    }  
예제 #26
0
/// CPU-bound implementation.  Computes the norm of the visibilities.
void CRoutine_FTtoV2::FTtoV2(valarray<cl_float2> & ft_input, valarray<cl_uint> & uv_ref, valarray<cl_float> & cpu_output, unsigned int n_v2)
{
	// Reset and resize the output array:
	cpu_output.resize(n_v2);

	// Make a couple of assertations about the input data
	assert(cpu_output.size() <= ft_input.size());
	assert(cpu_output.size() <= uv_ref.size());

	// Square the visibility, save it to the output array:
	unsigned int uv_index = 0;
	for(size_t i = 0; i < n_v2; i++)
	{
		uv_index = uv_ref[i];
		cpu_output[i] = ft_input[uv_index].s[0] * ft_input[uv_index].s[0] + ft_input[uv_index].s[1] * ft_input[uv_index].s[1];
	}
}
예제 #27
0
    bool doDataVariance_indPar( valarray<double>& ret ) const
    {
      //
      // Q_x(x) = [ 2 , 0 , 0 ]
      //          [ 0 , 0 , 0 ]
      //          [ 0 , 0 , 0 ]
      //          [ 0 , 1 , 0 ]
      //
      ret.resize( _nY*_nY * _nB );
      for( int i=0; i<_nY*_nY*_nB; i++ )
        ret[i] = 0.0;

      ret[0] = 2.0;
      ret[7] = 1.0;

      return true;
    }
예제 #28
0
    bool doDataVarianceInv_indPar( valarray<double>& ret ) const
    {
      //
      // Q^-1_x(x) = [ -1.0 / (2.0 * x(1))^2  0.0             0.0    ]
      //             [ 0.0                    0.0             0.0    ]
      //             [ 0.0                    0.0             0.0    ]
      //             [ 0.0                    -1.0 / x(2)^2   0.0    ]
      //
      ret.resize(_nY*_nY*_nB);
      const double * x = _b.data();
      for( int i=0; i<_nY*_nY*_nB; i++ )
        ret[i] = 0.0;

      ret[0] = -1.0 / ( (2.0 * x[0])*(2.0 * x[0]) );
      ret[7] = -1.0 / (x[1] * x[1]);
      return true;
    }
예제 #29
0
void spk_sode_model<Scalar>::doIndParVariance(valarray<Scalar> &Omega) const
{	size_t Ni = N_[0];
	assert( m_ == (Ni + 1) );
	Omega.resize(m_ * m_);
	assert( alpha_.size() == ell_);
	assert(  ell_ == 6 );
	size_t k1, k2;
	// initialize as zero
	for(k1 = 0; k1 < m_; k1++)
	{	for(k2 = 0; k2 < m_; k2++)
			Omega[k1 + k2 * m_] = 0.;
	}
	// set the diagonal
	Omega[0 + 0 * m_] = exp( alpha_[2] );
	Omega[1 + 1 * m_] = exp( alpha_[3] );
	for(k1 = 2; k1 < m_; k1++)
		Omega[k1 + k1 * m_] = exp( alpha_[4] );
	return;
}
예제 #30
0
bool spk_sode_model<Scalar>::doIndParVariance_popPar
	(valarray<double> &Omega_alpha) const
{	size_t Ni = N_[i_];
	size_t m_sq = m_ * m_;
	Omega_alpha.resize(m_sq * ell_);

	size_t k1, k2, k;
	for(k1 = 0; k1 < m_; k1++)
	{	for(k2 = 0; k2 < m_; k2++)
		{	for(k = 0; k < ell_; k ++)
				Omega_alpha[k2 + k1 * m_ + k * m_sq] = 0.;
		}
	}
	Omega_alpha[0 + 0 * m_ + 0 * m_sq] = exp( Value( alpha_[2] ) ); 
	Omega_alpha[1 + 1 * m_ + 1 * m_sq] = exp( Value( alpha_[3] ) ); 
	for(k1 = 2; k1 < m_; k1++)
		Omega_alpha[k1 + k1 * m_ + k1 * m_sq] = exp( Value(alpha_[5]) );
	
	bool non_zero = true;
	return non_zero;
}