Exemple #1
0
bool ReedMullerCoder::MonomDegreeOrder(const std::valarray<bool>& lhs, const std::valarray<bool>& rhs) {
  if (lhs.size() != rhs.size()) {
    return 0;
  }

  if (Weight(lhs) < Weight(rhs)) {
    return 1;
  }

  if (Weight(lhs) > Weight(rhs)) {
    return 0;
  }

  for (int i = rhs.size() - 1; i >= 0; --i) {
    if (lhs[i] > rhs[i]) {
      return 1;
    }

    if (lhs[i] < rhs[i]) {
      return 0;
    }
  }

  return false;
}
Exemple #2
0
Map::point	Map::interPoint(const float x, const float y) const
{
	float	px = x;
	float	py = y;
	float	pz = 0;
	
	float sumVal = 0;
	float sum = 0;
	float distance, weight, value;

	for (std::list<point>::const_iterator ite = this->_pts->begin(), end = this->_pts->end(); ite != end; ++ite)
	{
		distance = point::getDst(point(x, y, 0), *ite);
		weight = distance != 0 ? 1/ (distance * distance) : 1;
		value = weight * ite->z;
		sumVal += value;
		sum += weight;
	}

	sum += Weight(std::min(x, CUBE_SIZE - x));
	sum += Weight(std::min(y, CUBE_SIZE - y));

	pz = sumVal/sum;

	return (point(px, py, pz));
}
Exemple #3
0
// This code has been copied from bp.cpp, except where comments indicate TRWBP-specific behaviour
Prob TRWBP::calcIncomingMessageProduct( size_t I, bool without_i, size_t i ) const {
    Real c_I = Weight(I); // TRWBP: c_I

    Factor Fprod( factor(I) );
    Prob &prod = Fprod.p();
    if( props.logdomain ) {
        prod.takeLog();
        prod /= c_I; // TRWBP
    } else
        prod ^= (1.0 / c_I); // TRWBP

    // Calculate product of incoming messages and factor I
    bforeach( const Neighbor &j, nbF(I) )
        if( !(without_i && (j == i)) ) {
            const Var &v_j = var(j);
            // prod_j will be the product of messages coming into j
            // TRWBP: corresponds to messages n_jI
            Prob prod_j( v_j.states(), props.logdomain ? 0.0 : 1.0 );
            bforeach( const Neighbor &J, nbV(j) ) {
                Real c_J = Weight(J);  // TRWBP
                if( J != I ) { // for all J in nb(j) \ I
                    if( props.logdomain )
                        prod_j += message( j, J.iter ) * c_J;
                    else
                        prod_j *= message( j, J.iter ) ^ c_J;
                } else if( c_J != 1.0 ) { // TRWBP: multiply by m_Ij^(c_I-1)
                    if( props.logdomain )
                        prod_j += message( j, J.iter ) * (c_J - 1.0);
                    else
                        prod_j *= message( j, J.iter ) ^ (c_J - 1.0);
                }
            }

            // multiply prod with prod_j
            if( !DAI_TRWBP_FAST ) {
                // UNOPTIMIZED (SIMPLE TO READ, BUT SLOW) VERSION
                if( props.logdomain )
                    Fprod += Factor( v_j, prod_j );
                else
                    Fprod *= Factor( v_j, prod_j );
            } else {
                // OPTIMIZED VERSION
                size_t _I = j.dual;
                // ind is the precalculated IndexFor(j,I) i.e. to x_I == k corresponds x_j == ind[k]
                const ind_t &ind = index(j, _I);

                for( size_t r = 0; r < prod.size(); ++r )
                    if( props.logdomain )
                        prod.set( r, prod[r] + prod_j[ind[r]] );
                    else
                        prod.set( r, prod[r] * prod_j[ind[r]] );
            }
        }
Exemple #4
0
void snapcmacc(vector cmacc, bodyptr btab, int nbody, int woff)
{
  double wtot, cmtmp[NDIM];
  bodyptr bp;

  wtot = 0.0;
  CLRV(cmtmp);
  for (bp = btab; bp < NthBody(btab, nbody); bp = NextBody(bp)) {
    wtot = wtot + Weight(bp, woff);
    ADDMULVS(cmtmp, Acc(bp), Weight(bp, woff));
  }
  DIVVS(cmacc, cmtmp, wtot);
}
  /// Train by number of iterations or threshold
  void train(unsigned num_iterations, float threshold, bool use_threshold)
  {
    std::cerr << "Estimating model parameters (" << num_iterations << " iterations)" << std::endl;

    // Create parameter updater
    ParameterVector& model_params = this->crf_model.get_parameters();
    ParameterVector summed_model_params(this->crf_model.parameters_count(),Weight(0.0));
    ParameterVector last_params(this->crf_model.parameters_count(),Weight(0.0));
    std::vector<unsigned> last_update(this->crf_model.parameters_count(),0);
    ParamUpdater param_updater(model_params,summed_model_params,last_params,last_update);

    // z will hold the predicted output sequence
    LabelIDSequence z(translated_training_corpus.max_input_length());

    unsigned time_step = 0;
    for (unsigned t = 0; t < num_iterations; ++t) {
      time_t iter_start = clock();
      float loss = 0;
      // Iterate over the training instances
      for (unsigned i = 0; i < translated_training_corpus.size(); ++i) {
        const TranslatedCRFTrainingPair& x_y = translated_training_corpus[i];
        z.resize(x_y.x.size(),0);
        // Determine the currently best sequence for x
        crf_decoder.best_sequence(x_y.x,z);
        // Compare the two sequences
        unsigned num_diffs = 0;
        // Parameter updates are only necessary in case corpus and predicted output sequence differ
        if (x_y.y != z) {
          if (ORDER == 1) num_diffs = first_order_updater(x_y.x,x_y.y,z,param_updater,time_step);
          else            num_diffs = higher_order_updater(x_y.x,x_y.y,z,param_updater,time_step);
        }
        ++time_step;
        loss += num_diffs / float(x_y.y.size());
      } // for i

      std::cerr << "Iteration " << t+1 << ": loss: " << loss
                << ", time: " << ((clock() - iter_start)/float(CLOCKS_PER_SEC))  << "s"  << std::endl;

      // Permute the training corpus
      translated_training_corpus.random_shuffle();
      if (use_threshold && loss <= threshold) 
        break;
    } // for t

    // Now perform the pending parameter updates and divide all parameter values by Num-Iterations * |Corpus|
    average_parameters(summed_model_params,model_params,last_params,last_update, 
                       translated_training_corpus.size() * num_iterations);

    /// Write the averaged parameters back to the model
    this->crf_model.set_parameters(summed_model_params);
  }
Exemple #6
0
// This code has been copied from bp.cpp, except where comments indicate TRWBP-specific behaviour
Real TRWBP::logZ() const {
    Real sum = 0.0;
    for( size_t I = 0; I < nrFactors(); I++ ) {
        sum += (beliefF(I) * factor(I).log(true)).sum();  // TRWBP/FBP
        sum += Weight(I) * beliefF(I).entropy();  // TRWBP/FBP
    }
    for( size_t i = 0; i < nrVars(); ++i ) {
        Real c_i = 0.0;
        bforeach( const Neighbor &I, nbV(i) )
            c_i += Weight(I);
        if( c_i != 1.0 )
            sum += (1.0 - c_i) * beliefV(i).entropy();  // TRWBP/FBP
    }
    return sum;
}
Exemple #7
0
Fichier : map.c Projet : kellyrm/Q1
static int CmpFace (const void *arg1, const void *arg2)
{
	mface_t *f1, *f2;
	int	Cmp;

	f1 = *(mface_t **)arg1;
	f2 = *(mface_t **)arg2;

	Cmp = Weight(f1->plane.normal) - Weight(f2->plane.normal);

	if (Phase1)
		Cmp += (int)(1000 * (f1->plane.dist - f2->plane.dist)); // To get determinism, we need this

	return(Cmp);
}
Exemple #8
0
int32_t InjectErrorsFile (char *src, uint8_t mode) {
	uint8_t err_mask[4] = {0x10, 0x01, 0x18, 0x11};
	uint8_t error_mask;
	uint8_t src_data;

	/* open file to read */
	FILE *fp_s = fopen(src, "rb+");
	int32_t ret = 0;

	/* Upon not successful open return -1 */
	if(!fp_s || mode > 3) {
		return -1;
	}

	/* Read file byte by byte */
	while(fread(&src_data, 1, 1, fp_s)) {
		fseek ( fp_s , -1 , SEEK_CUR );
		error_mask = err_mask[mode]<<(rand()%8);
		/* add to the readed value some random noise */
		fputc(src_data ^ error_mask, fp_s);
		ret+=Weight(error_mask);
		fseek ( fp_s ,  0 , SEEK_CUR );
		memset(&src_data, 0, sizeof(src_data));
	}
	/* Close the file */
	fclose(fp_s);
	return ret;
}
Exemple #9
0
void Show_Cat::Display(std::ostream& os) const
{
    os << "Cat: " << name << endl;
    os << "Breed: " << breed << endl;
    os << "Registration ID: " << registration_id << endl;
    os << "Weight:" << Weight() << endl;
}
 main(){
	 HuffmanTree HT;
     HuffmanCode HC;
	 char s[10000],deco[10000];
	 int n,a;
	 int str1,str2;
	 double rate;
     FILE *fp;
	fp=fopen("When you are old.txt","r");
	if (fp == NULL)
	{
		printf("Can't open this file.\n");
		exit(0);
	}
	 Weight(fp,HC,n);
	 CreateandEncode(HT,HC,n,str2);
     str1=count;
	 rate=(double)str1/(double)(str2*7);
	 fclose(fp);
	 printf("请输入:\n");
	 fgets(s,10000,stdin);
	 for(int i=0;s[i]!='\0';i++){
		 a=s[i]+256;
		 printf("%s",HC[a].code);}
	 printf("\n");

}
        result_type result(Args const &args) const
        {
            float_type threshold = sum_of_weights(args)
                             * ( ( is_same<LeftRight, left>::value ) ? args[quantile_probability] : 1. - args[quantile_probability] );

            std::size_t n = 0;
            Weight sum = Weight(0);

            while (sum < threshold)
            {
                if (n < static_cast<std::size_t>(tail_weights(args).size()))
                {
                    sum += *(tail_weights(args).begin() + n);
                    n++;
                }
                else
                {
                    if (std::numeric_limits<result_type>::has_quiet_NaN)
                    {
                        return std::numeric_limits<result_type>::quiet_NaN();
                    }
                    else
                    {
                        std::ostringstream msg;
                        msg << "index n = " << n << " is not in valid range [0, " << tail(args).size() << ")";
                        boost::throw_exception(std::runtime_error(msg.str()));
                        return Sample(0);
                    }
                }
            }

            // Note that the cached samples of the left are sorted in ascending order,
            // whereas the samples of the right tail are sorted in descending order
            return *(boost::begin(tail(args)) + n - 1);
        }
Exemple #12
0
bool CSPropMaterial::Write2XML(TiXmlNode& root, bool parameterised, bool sparse)
{
	if (CSProperties::Write2XML(root,parameterised,sparse) == false) return false;
	TiXmlElement* prop=root.ToElement();
	if (prop==NULL) return false;

	prop->SetAttribute("Isotropy",bIsotropy);

	/***************   3D - Properties *****************/
	TiXmlElement value("Property");
	WriteVectorTerm(Epsilon,value,"Epsilon",parameterised);
	WriteVectorTerm(Mue,value,"Mue",parameterised);
	WriteVectorTerm(Kappa,value,"Kappa",parameterised);
	WriteVectorTerm(Sigma,value,"Sigma",parameterised);
	/***************   1D - Properties *****************/
	WriteTerm(Density,value,"Density",parameterised);
	prop->InsertEndChild(value);

	/**********   3D - Properties  Weight **************/
	TiXmlElement Weight("Weight");
	WriteVectorTerm(WeightEpsilon,Weight,"Epsilon",parameterised);
	WriteVectorTerm(WeightMue,Weight,"Mue",parameterised);
	WriteVectorTerm(WeightKappa,Weight,"Kappa",parameterised);
	WriteVectorTerm(WeightSigma,Weight,"Sigma",parameterised);
	/**********   1D - Properties  Weight **************/
	WriteTerm(WeightDensity,Weight,"Density",parameterised);
	prop->InsertEndChild(Weight);

	return true;
}
void IndexGraphStarterJoints<Graph>::Init(Segment const & startSegment, Segment const & endSegment)
{
  m_startSegment = startSegment;
  m_endSegment = endSegment;

  m_startPoint = m_graph.GetPoint(m_startSegment, true /* front */);
  m_endPoint = m_graph.GetPoint(m_endSegment, true /* front */);

  if (IsRealSegment(startSegment))
    m_startJoint = CreateInvisibleJoint(startSegment, true /* start */);
  else
    m_startJoint = CreateFakeJoint(m_graph.GetStartSegment(), m_graph.GetStartSegment());

  if (IsRealSegment(endSegment))
    m_endJoint = CreateInvisibleJoint(endSegment, false /* start */);
  else
    m_endJoint = CreateFakeJoint(m_graph.GetFinishSegment(), m_graph.GetFinishSegment());

  m_reconstructedFakeJoints[m_startJoint] = {m_startSegment};
  m_reconstructedFakeJoints[m_endJoint] = {m_endSegment};

  m_startOutEdges = FindFirstJoints(startSegment, true /* fromStart */);
  m_endOutEdges = FindFirstJoints(endSegment, false /* fromStart */);

  m_savedWeight[m_endJoint] = Weight(0.0);
  for (auto const & edge : m_endOutEdges)
    m_savedWeight[edge.GetTarget()] = edge.GetWeight();

  m_init = true;
}
        result_type result(Args const &args) const
        {
            float_type threshold = sum_of_weights(args)
                             * ( ( is_same<LeftRight, left>::value ) ? args[quantile_probability] : 1. - args[quantile_probability] );

            std::size_t n = 0;
            Weight sum = Weight(0);

            while (sum < threshold)
            {
                if (n < static_cast<std::size_t>(tail_weights(args).size()))
                {
                    sum += *(tail_weights(args).begin() + n);
                    n++;
                }
                else
                {
                    if (std::numeric_limits<float_type>::has_quiet_NaN)
                    {
                        std::fill(
                            this->tail_means_.begin()
                          , this->tail_means_.end()
                          , std::numeric_limits<float_type>::quiet_NaN()
                        );
                    }
                    else
                    {
                        std::ostringstream msg;
                        msg << "index n = " << n << " is not in valid range [0, " << tail(args).size() << ")";
                        boost::throw_exception(std::runtime_error(msg.str()));
                    }
                }
            }

            std::size_t num_variates = tail_variate(args).begin()->size();

            this->tail_means_.clear();
            this->tail_means_.resize(num_variates, Sample(0));

            this->tail_means_ = std::inner_product(
                tail_variate(args).begin()
              , tail_variate(args).begin() + n
              , tail_weights(args).begin()
              , this->tail_means_
              , numeric::functional::plus<array_type const, array_type const>()
              , numeric::functional::multiply_and_promote_to_double<VariateType const, Weight const>()
            );

            float_type factor = sum * ( (is_same<Impl, relative>::value) ? non_coherent_weighted_tail_mean(args) : 1. );

            std::transform(
                this->tail_means_.begin()
              , this->tail_means_.end()
              , this->tail_means_.begin()
              , std::bind2nd(numeric::functional::divides<typename array_type::value_type const, float_type const>(), factor)
            );

            return make_iterator_range(this->tail_means_);
        }
Neuron::Neuron(int Number_Of_Connections, int Seed)
{
	// Random Number Generation. - Seed defined in Neuron Class (Private Variable)
	std::mt19937_64 Generate(Seed);
	std::uniform_real_distribution<double> Weight(-0.5, 0.5);
	std::uniform_real_distribution<double> Bias(0, 1);

	// Resize the weight matrix for the number of connection, plus one additional weight that acts as the bias
	Neuron::Weights.resize((Number_Of_Connections + 1), 1);

	// Randomize input weights.
	for (int a = 0; a < Number_Of_Connections; a++) {
		Neuron::Weights(a) = Weight(Generate);
	}

	Neuron::Weights((Number_Of_Connections)) = Bias(Generate); // Randomize neuron bias.
	Neuron::Weight_Update_Old = Eigen::MatrixXd::Constant(Neuron::Weights.cols(), Neuron::Weights.rows(), 0);
}
Exemple #16
0
void SingleSys(Position spp,DdData& dddataPre,DdData& dddataCurr,SdData& lastSdData,ObsEpochData& roverData1,ObsEpochData& baseData1,
						SppCtrl sppctrl,DdCtrl ddctrl, DdAmbInfo& ambinfo,DdAmbInfo& preambinfo,SppInfo sppinfo,SppInfo baseInfo,DdObsInfo ddobsinfo1,
						BroadEphHeader brdephheader,BroadEphData* broadephdata,BroadEphDataGlo* gloeph,int nSate,int nSateGlo,
						ObsHeader obsHeader1,ObsEpochData	epochData1,ObsHeader obsHeader2,ObsEpochData	epochData2,
						double* baseCrd,double* roverCrd,int& nEpoch, int sysidUse,math::matrix<double>* NormEqu)
{
	lastSdData.ZeroElem();roverData1.ZeroElem();	baseData1.ZeroElem();  sppinfo.ZeroElem(); baseInfo.ZeroElem();
	if (sysidUse==1 || sysidUse==3 ||sysidUse==5)
	{
		spp.StandPosition(brdephheader,broadephdata,epochData1,nSate,sppctrl,sppinfo,roverData1);
		spp.baseStn(baseInfo,broadephdata,epochData2,baseData1,nSate,sppctrl);
	}
	else if(sysidUse==2)
	{
		//spp.StandPosition(brdephheader,gloeph,epochData1,nSateGlo,sppctrl,sppinfoGlo,roverData);//Glo
		//spp.baseStn(baseInfoGlo,gloeph,epochData2,baseData,nSateGlo,sppctrl);//glo

	}


	if(Norm(roverCrd,3)>0.0) PtrEqual(roverCrd,sppinfo.recPos,3);
	int refPrn=0;
	ddobsinfo1.ZeroEle();
	int tprn=0;
	refPrn=spp.SelectRefSate(baseInfo,sppinfo,5.0,baseData1,roverData1,lastSdData,ddobsinfo1,0,tprn);
	int refpos;
	refpos=GetPos(lastSdData.prn,refPrn,lastSdData.satnum);

	dddataCurr.ZeroElem(); ambinfo.ZeroElem();
	spp.DoubleDiff(refPrn,refpos,lastSdData,dddataCurr);
	if(dddataCurr.pairNum<4) exit(1);
	//DdData ts=dddataCurr;
	/*	-----------------------------------------end data preparation part	---------------------------------------*/
	dddataCurr=spp.ComObsPhsCod(ddctrl,ddobsinfo1,ambinfo,dddataCurr);
	//if(nEpoch>1) spp.PassPreAmb(preambinfo,ambinfo,ddctrl.PhsTypeNo());
	/* -----------------------------------------end cycle slip---------------------------------------- */

	int obsNum	=ddobsinfo1.SumCod()+ddobsinfo1.SumPhs();//the number of all obs in one system at current epoch
	int phsNum	=ddobsinfo1.SumPhs();
	int ionoNum=dddataCurr.pairNum;
	int ambNum=ambinfo.SumUnfix();
	//if(nEpoch>1)ambNum=preambinfo.SumUnfix();
	if(ambNum==0) ambNum=1;
	/*	equation part	*/
	math::matrix<double> DesMatPos(obsNum,3);
	math::matrix<double> DesMatAmb(obsNum,ambNum);
	math::matrix<double> Weight(obsNum,obsNum);
	math::matrix<double> L(obsNum,1);
	math::matrix<double> DesMatTrop(obsNum,1);
	math::matrix<double> DesMatIono(obsNum,obsNum);

	spp.FormDdErrEq(DesMatPos,DesMatTrop,DesMatIono,DesMatAmb,L,dddataCurr,ddctrl,ambinfo,ddobsinfo1);
	Weight=spp.FormWeightVc(ddctrl,dddataCurr,ddobsinfo1);
	NormEqu[0]=~DesMatPos*Weight*(DesMatPos);		NormEqu[1]=~DesMatPos*Weight*(DesMatAmb);
	NormEqu[2]=~DesMatAmb*Weight*(DesMatAmb);	NormEqu[3]=~DesMatPos*Weight*L;
	NormEqu[4]=~DesMatAmb*Weight*L;
}
Exemple #17
0
/* Calculus 9-3 Ellipse
 * consider  (x^2/a^2)+(y^2)/(b^2)=1
 * where (-a,0),(a,0) is the major axis
 * and
 * where (-b,0),(b,0) is the minor axis
 * ->  a > 0
 * ->  b > 0
 */
int EllipseAverage(
     MAP_REAL8 *average,	/* write-only output average map  */ 
     const MAP_REAL8 *val, 	/* input value map */
     const MAP_REAL8 *xmajor, 	/* input window size map */
     const MAP_REAL8 *yminor, 	/* input window size map */
     const MAP_REAL8 *angle) 	/* input window size map */
{
	int 	r, c, nrRows, nrCols;

	val->SetGetTest(GET_MV_TEST, val);
	xmajor->SetGetTest(GET_MV_TEST, xmajor);
	yminor->SetGetTest(GET_MV_TEST, yminor);
	angle->SetGetTest(GET_MV_TEST,  angle);

	nrRows = val->NrRows(val);
	nrCols = val->NrCols(val);

	for (r = 0; r < nrRows; r++)
	 for (c = 0; c < nrCols; c++)
	{
		REAL8 value, xmajorV,yminorV,angleV;
		if(
		   xmajor->Get(&xmajorV, r, c, xmajor)&&
		   yminor->Get(&yminorV, r, c, yminor)&&
		    angle->Get(&angleV,  r, c, angle) )
		{
			REAL8 count = 0, winTotal = 0;
			int   rWin, cWin, pw; 
			REAL8 bw; /* border weigth */

			BuildCircle(fabs(xmajorV));
			return 0;
			average->PutMV(r, c, average);

			/* Calculate in window */
			for(rWin = -pw; rWin <= pw; rWin++)
			 for(cWin= -pw; cWin <= pw; cWin++)
			 {
				if(val->Get(&value, rWin+r, cWin+c, val))
				{
					REAL8 w = Weight(pw,rWin,cWin,bw);
					winTotal += value*w;
					count    += w;
				}
			 }
			if(count > 0)
			 average->Put(winTotal/count, r, c, average);
			else
			 average->PutMV(r, c, average);
		}
		else
			/* MV or winSize <= 0 */
			average->PutMV(r, c, average);
	}
	return 0;
}
Exemple #18
0
IMPISD_BEGIN_NAMESPACE

WeightMover::WeightMover(Particle *w, double radius)
    : core::MonteCarloMover(w->get_model(), "WeightMover%1%"), radius_(radius) {
  // store decorator. If the particle *w has not been decorated,
  // this line throws and exception
  w_ = Weight(w);
  // initialize oldweights_
  oldweights_ = w_.get_weights();
}
Exemple #19
0
//Magic sequence problem
TEST(CPTest, DISABLED_MagicSeq) {
	SolverOption options;
	options.verbosity = 0;
	auto space = new Space(options);
	extAdd(*space, Disjunction(DEFAULTCONSTRID,{mkPosLit(42)}));

	extAdd(*space, Disjunction(DEFAULTCONSTRID,{mkPosLit(1), mkPosLit(2), mkPosLit(3)}));
	vector<Weight> mult;
	vector<VarID> elemx;
	uint n = 100;
	for(uint i=0; i<n; ++i){
		mult.push_back(Weight(((int)i)-1));
		VarID x = {i};
		extAdd(*space, IntVarRange(DEFAULTCONSTRID,x, Weight(0), Weight(n)));
		elemx.push_back(x);
	}

	vector<Weight> weights;
	weights.resize(elemx.size(),Weight(1));

	for(uint i=0; i<n; ++i){
		extAdd(*space, CPCount(DEFAULTCONSTRID,elemx, Weight((int)i), EqType::EQ, elemx[i]));
	}
	extAdd(*space, Disjunction(DEFAULTCONSTRID,{mkPosLit(4)}));
	extAdd(*space, CPSumWeighted(DEFAULTCONSTRID,mkPosLit(4), vector<Lit>(elemx.size(), mkPosLit(42)), elemx, weights, EqType::EQ, n));

	extAdd(*space, Disjunction(DEFAULTCONSTRID,{mkPosLit(5)}));
	extAdd(*space, CPSumWeighted(DEFAULTCONSTRID,mkPosLit(5),vector<Lit>(elemx.size(), mkPosLit(42)), elemx, mult, EqType::EQ, 0));

	int literalcount = 6;
	for(uint i=0; i<n; ++i){
		for(uint j=0; j<n; ++j){
			extAdd(*space, CPBinaryRel(DEFAULTCONSTRID,mkPosLit(literalcount++), elemx[i], EqType::EQ, Weight((int)j)));
			extAdd(*space, CPBinaryRel(DEFAULTCONSTRID,mkPosLit(literalcount++), elemx[i], EqType::GEQ, Weight((int)j)));
		}
	}

	ModelExpandOptions mxoptions(2, Models::NONE, Models::NONE);
	auto mx = ModelExpand(space, mxoptions, {});
	mx.execute();
	ASSERT_TRUE(mx.isUnsat());
	delete(space);
}
 weighted_peaks_over_threshold_impl(Args const &args)
   : sign_((is_same<LeftRight, left>::value) ? -1 : 1)
   , mu_(sign_ * numeric::average(args[sample | Sample()], (std::size_t)1))
   , sigma2_(numeric::average(args[sample | Sample()], (std::size_t)1))
   , w_sum_(numeric::average(args[weight | Weight()], (std::size_t)1))
   , threshold_(sign_ * args[pot_threshold_value])
   , fit_parameters_(boost::make_tuple(0., 0., 0.))
   , is_dirty_(true)
 {
 }
void BlobMesh::init(int weightCount)
{
    constructVBO();
    for(int i = 0; i < weightCount; i++)
    {
        mWeights.push_back(Weight(ofVec2f(ofRandom( 0.f, mMeshWidth ),
                                        ofRandom( 0.f, mMeshHeight )),
                                  ofVec2f(0,
                                        ofRandom( -0.5f, -2 ))));
    }
}
Exemple #22
0
AMI_err	_LSList::appendField(s32 *entries, s32 numEntries) {
	AMI_err result = AMI_ERROR_NO_ERROR;

	u32 streamLen = _m_baseStream->stream_len();
	_m_baseStream->seek(streamLen);
	_m_baseStream->write_array(entries,numEntries);
	u32 cSize = Weight();
	_m_fields->push_back(cSize+numEntries);

	return result;
}
Exemple #23
0
void _LSList::toLList_t(llist_t* L) {
	ll_init(L,Weight(),numFields());
	L->numFields=numFields();
	for (u32 i=0; i<_m_count(); ++i) {
		_LSListField* cField = fetchField(i);
		for (u32 j=0; j<cField->numEntries();++j) {
			L->data[L->index[i]+j]=cField->at(j);
		}
		L->index[i+1]=L->index[i]+cField->numEntries();
		releaseField(cField);
	}
}
Exemple #24
0
void snaprect(bodyptr btab, int nbody)
{
  matrix qmat, tmpm;
  bodyptr bp;
  vector frame[3], tmpv;
  static vector oldframe[3] =
    { { 1.0, 0.0, 0.0, }, { 0.0, 1.0, 0.0, }, { 0.0, 0.0, 1.0, }, };
  int i;

  snapcenter(btab, nbody, WeightField.offset);
  CLRM(qmat);
  for (bp = btab; bp < NthBody(btab, nbody); bp = NextBody(bp)) {
    OUTVP(tmpm, Pos(bp), Pos(bp));
    MULMS(tmpm, tmpm, Weight(bp));
    ADDM(qmat, qmat, tmpm);
  }
  eigenvect(frame[0], frame[1], frame[2], qmat);
  if (dotvp(oldframe[0], frame[0]) < 0.0)
    MULVS(frame[0], frame[0], -1.0);
  if (dotvp(oldframe[2], frame[2]) < 0.0)
    MULVS(frame[2], frame[2], -1.0);
  CROSSVP(frame[1], frame[2], frame[0]);
  printvect("e_x:", frame[0]);
  printvect("e_y:", frame[1]);
  printvect("e_z:", frame[2]);
  for (bp = btab; bp < NthBody(btab, nbody); bp = NextBody(bp)) {
    if (PosField.offset != BadOffset) {
      for (i = 0; i < NDIM; i++)
	tmpv[i] = dotvp(Pos(bp), frame[i]);
      SETV(Pos(bp), tmpv);
    }
    if (VelField.offset != BadOffset) {
      for (i = 0; i < NDIM; i++)
	tmpv[i] = dotvp(Vel(bp), frame[i]);
      SETV(Vel(bp), tmpv);
    }
    if (AccField.offset != BadOffset) {
      for (i = 0; i < NDIM; i++)
	tmpv[i] = dotvp(Acc(bp), frame[i]);
      SETV(Acc(bp), tmpv);
    }
    if (AuxVecField.offset != BadOffset) {
      for (i = 0; i < NDIM; i++)
	tmpv[i] = dotvp(AuxVec(bp), frame[i]);
      SETV(AuxVec(bp), tmpv);
    }
  }
  for (i = 0; i < NDIM; i++)
    SETV(oldframe[i], frame[i]);
}    
Exemple #25
0
	void ActionBlock::Perform(ArtifactSet &artifacts, ProgressListener &listener)
	{
		size_t nr = 0;
		unsigned totalWeight = Weight();
		for(const_iterator i=begin();i!=end();++i)
		{
			Action *action = *i;
			unsigned weight = action->Weight();
			listener.OnStartTask(*this, nr, totalWeight, action->Description(), weight);
			action->Perform(artifacts, listener);
			listener.OnEndTask(*this);
			nr += weight;
		}
	}
Exemple #26
0
llist_t * _LBList<BTECOLL>::toLList_t() {
	llist_t* P = (llist_t *)lxmalloc(sizeof(llist_t),1);
	ll_init(P,Weight(),numFields());
	for (u32 i=0; i<_count; ++i) {
		// do bulk load. Without any cache.
		_LBListField<BTECOLL>* cField = fetchField(i);
		for (u32 j=0; j<cField->info()->entries;++j) {
			P->data[P->index[i]+j]=cField->el[j];
		}
		P->index[i+1]=P->index[i]+cField->info()->entries;
		releaseField(cField);
	}
	return P;	
}
Exemple #27
0
/**
 * Returns the point corresponding to the pair of parameters (u,v)
 * Assumes that the knots have been set previously
 *
 * Scans the u-direction first, then v-direction
 * @param u the specified u-parameter
 * @param v the specified v-parameter
 * @param Pt a reference to the point defined by the pair (u,v)
*/
void NURBSSurface::GetPoint(double u, double v, CVector &Pt)
{
	CVector V, Vv;
	double wx, weight;

	if(u>=1.0) u=0.99999999999;
	if(v>=1.0) v=0.99999999999;

	weight = 0.0;
	for(int iu=0; iu<FrameSize(); iu++)
	{
		Vv.Set(0.0,0.0,0.0);
		wx = 0.0;
		for(int jv=0; jv<FramePointCount(); jv++)
		{
			cs = SplineBlend(jv, m_ivDegree, v, m_vKnots) * Weight(m_EdgeWeightv, jv, FramePointCount());

			Vv.x += m_pFrame[iu]->m_CtrlPoint[jv].x * cs;
			Vv.y += m_pFrame[iu]->m_CtrlPoint[jv].y * cs;
			Vv.z += m_pFrame[iu]->m_CtrlPoint[jv].z * cs;

			wx += cs;
		}
		bs = SplineBlend(iu, m_iuDegree, u, m_uKnots) * Weight(m_EdgeWeightu, iu, FrameSize());

		V.x += Vv.x * bs;
		V.y += Vv.y * bs;
		V.z += Vv.z * bs;

		weight += wx * bs;
	}

	Pt.x = V.x / weight;
	Pt.y = V.y / weight;
	Pt.z = V.z / weight;
}
void accLooper::doLoop() {
  for (int i = ievent_; i < max_entry; i++) {
    if ((i%(max_entry/10)) == 0) cout << i << " / " << max_entry << endl;
    tree->GetEntry(i);
    //if (nmuons <= 2) {

      Double_t gen_dimuon_pt = gen_dimuon_p4->Pt();
      Double_t gen_dimuon_y = TMath::Abs(gen_dimuon_p4->Rapidity());

      Double_t w = Weight(gen_dimuon_pt,meson_);
      all_y_pt_h.Fill(gen_dimuon_y, gen_dimuon_pt,w);

      if (acceptanceCut(gen_dimuon_p4, gen_muonP_p4, gen_muonN_p4, meson_, barrel_)) {
        pas_y_pt_h.Fill(gen_dimuon_y, gen_dimuon_pt,w);
      }
    //}
  }
}
double WeightRestraint::unprotected_evaluate(DerivativeAccumulator *accum)
    const {
  // retrieve weights
  algebra::VectorKD weight = Weight(w_).get_weights();

  Float dw = 0.;

  for (unsigned i = 0; i < weight.get_dimension(); ++i) {
    if (weight[i] > wmax_)
      dw += (weight[i] - wmax_) * (weight[i] - wmax_);
    else if (weight[i] < wmin_)
      dw += (wmin_ - weight[i]) * (wmin_ - weight[i]);
  }

  if (accum) {
  }

  return 0.5 * kappa_ * dw;
}
Exemple #30
0
void RtkGlo(Position spp,ObsEpochData& baseData1,SppCtrl sppctrl,DdCtrl ddctrl, BroadEphHeader brdephheader,BroadEphData* broadephdata,
					BroadEphDataGlo* gloeph,int nSateGlo, ObsHeader obsHeader1,ObsEpochData	epochData1,ObsHeader obsHeader2,ObsEpochData	epochData2,
					double* baseCrd,double* roverCrd,math::matrix<double>& N11)
{
	DdData dddataCurr;SdData lastSdData; ObsEpochData roverData,baseData;
	DdObsInfo ddobsinfo;SppInfoGlo sppinfo, baseInfoGlo;DdAmbInfo ambinfo;
	spp.StandPosition(brdephheader,gloeph,epochData1,nSateGlo,sppctrl,sppinfo,roverData);
	spp.baseStn(baseInfoGlo,gloeph,epochData2,baseData,nSateGlo,sppctrl);//glo
	roverData.Cycle2MeterGlo(sppinfo.freqNum);
	baseData.Cycle2MeterGlo(baseInfoGlo.freqNum);
	
	if(Norm(roverCrd,3)>0.0) PtrEqual(roverCrd,sppinfo.recPos,3);
	
	int* dNum=new int[max(baseInfoGlo.validnum, sppinfo.validnum)];
	int tprn=0;
	int refPrn= spp.SelectRefSate(baseInfoGlo,sppinfo,5.0,baseData,roverData,lastSdData,ddobsinfo,dNum);
	int refpos=GetPos(lastSdData.prn,refPrn,lastSdData.satnum);
	
	dddataCurr.ZeroElem(); ambinfo.ZeroElem();
	spp.DoubleDiff(refPrn,refpos,lastSdData,dddataCurr);
	if(dddataCurr.pairNum<4) exit(1);
	
	/*	-----------------------------------------end data preparation part	---------------------------------------*/
//	dddataCurr=spp.ComObsPhsCod(ddctrl,ddobsinfo,ambinfo,dddataCurr,sppinfo);// units of obs : m
	/* -----------------------------------------end cycle slip---------------------------------------- */


	int obsNum	=ddobsinfo.SumCod()+ddobsinfo.SumPhs();//the number of all obs in one system at current epoch
	int phsNum	=ddobsinfo.SumPhs();
	int ionoNum=dddataCurr.pairNum;
	int ambNum=ambinfo.SumUnfix();
	//if(nEpoch>1)ambNum=preambinfo.SumUnfix();
	if(ambNum==0) ambNum=1;
	/*	equation part	*/
	math::matrix<double> DesMatPos(obsNum,3);
	math::matrix<double> DesMatAmb(obsNum,ambNum);
	math::matrix<double> Weight(obsNum,obsNum);
	math::matrix<double> L(obsNum,1);
	math::matrix<double> DesMatTrop(obsNum,1);
	math::matrix<double> DesMatIono(obsNum,obsNum);
	spp.FormDdErrEq(DesMatPos,DesMatTrop,DesMatIono,DesMatAmb,L,dddataCurr,ddctrl,ambinfo,ddobsinfo);

}