示例#1
0
bool Weights::operator==(const Weights& ws) const
{
    return (mHeight        == ws.height()        &&
            mWidth         == ws.width()         &&
            mPolynomeOrder == ws.polynomeOrder() &&
            mTwoDim        == ws.twoDim());
}
示例#2
0
            ReturnCode computeMeanSigma(Result &mean, Result &sigma, const Values &values, const Weights &weights)
            {
                MSS_BEGIN(ReturnCode);
                MSS(!values.empty());
                MSS(values.size() == weights.size());

                //Compute mean and the sum of the weights
                mean = 0.0;
                Result sumW = 0.0;
                typename Values::const_iterator value = values.begin();
                for (auto weight: weights)
                {
                    mean += *(value++)*weight;
                    sumW += weight;
                }
                mean /= sumW;

                //Compute sigma
                sigma = 0.0;
                typename Weights::const_iterator weight = weights.begin();
                for (auto value: values)
                    sigma += *(weight++)*(value-mean)*(value-mean);
                sigma = ::sqrt(sigma/sumW);

                MSS_END();
            }
void GeneticPopulation::crossover(
	const Weights& parent1,
	const Weights& parent2,
	Weights& child1,
	Weights& child2) const {

	assert(parent1.size() == parent2.size());

	if (randomReal(0, 1) > crossoverRate || parent1 == parent2) {
		child1 = parent1;
		child2 = parent2;
		return;
	}

	unsigned crossoverPoint = static_cast<unsigned>(randomInt(0, parent1.size()));

	child1.clear();
	child2.clear();

	//create the offspring
	for (unsigned i = 0; i < crossoverPoint; ++i) {
		child1.push_back(parent1[i]);
		child2.push_back(parent2[i]);
	}

	for (unsigned i = crossoverPoint; i < parent1.size(); ++i) {
		child1.push_back(parent2[i]);
		child2.push_back(parent1[i]);
	}
}
    RealMassDecomposer::RealMassDecomposer(const Weights & weights) :
      weights_(weights)
    {

      rounding_errors_ = std::make_pair(weights.getMinRoundingError(), weights.getMaxRoundingError());
      precision_ = weights.getPrecision();
      decomposer_ = std::shared_ptr<integer_decomposer_type>(
        new integer_decomposer_type(weights));
    }
示例#5
0
void GameManager::controlCar() {
	Weights outputs = callNeuralNetwork();
	assert(outputs.size() == 3);

	Car& car = model.getCar();

	float throttleOutput = clamp((2.f/3.f)*outputs[0] + (2.f/3.f), 0.f, 1.f);
	float brakeOutput = clamp((2.f/3.f)*outputs[1] + (1.f/3.f), 0.f, 1.f);
	float turnLevelOutput = outputs[2];

	car.setThrottle(throttleOutput);
	car.setBrake(brakeOutput);
	car.setTurnLevel(turnLevelOutput);
}
示例#6
0
文件: main.cpp 项目: GeneralMayo/rnn
Forward_Prop_Data forward_propegation(std::vector<int> &x, Weights &weights){
	int T = x.size();
	MatrixXd s = MatrixXd::Zero(T,HIDDEN_DIM);
	MatrixXd o = MatrixXd::Zero(T,WORD_DIM);
	for(int t = 0; t<T; t++){
		if(t==0){
			for(int i = 0; i<HIDDEN_DIM; i++){
				s(t,i) = tanh(weights.U(i,x[t]));
			}
		} else {
			MatrixXd step(HIDDEN_DIM,1);
			step = step.cast<double>();
			step = weights.U.col(x[t]) + weights.W*(s.row(t-1).transpose());
			for(int i = 0; i<HIDDEN_DIM; i++){
				s(t,i) = tanh(step(i));
			}
		}
		MatrixXd step(WORD_DIM,1);
		step = step.cast<double>();
		step = weights.V*(s.row(t).transpose());
		step = exp(step.array());
		o.row(t) = (step/step.sum()).transpose();
	}

	struct Forward_Prop_Data fpd;
	fpd.S = s;
	fpd.O = o;
	return fpd;
}
示例#7
0
void printHeader(const Alphabet& alphabet, const Weights& weights, Options::Mode mode) {
	cout <<
		"# " PROGRAM_NAME " " PROGRAM_VERSION "\n"
		"# Copyright 2006 Informatics for Mass Spectrometry group\n"
		"#                at Bielefeld University\n"
		"#\n"
		"# http://BiBiServ.TechFak.Uni-Bielefeld.DE/decomp/\n"
		"#\n"
		"# alphabet (character, weight):\n";
	for (Weights::size_type i = 0; i < weights.size(); ++i) {
		cout
			<< "#\t" << alphabet.getName(i) << "\t"
			<< weights[i] << '\n';
	}
	cout << "#\n# Problem to solve: ";
	switch (mode) {
		case Options::GETNUMBER:
			cout << "Get number of decompositions";
			break;
		case Options::FINDALL:
			cout << "Find all decompositions";
			break;
		case Options::FINDONE:
			cout << "Find one decomposition";
			break;
		case Options::ISDECOMPOSABLE:
			cout << "Is decomposable";
			break;
	}
	cout << "\n#\n";
}
void Player::CalcLeagueScore(const Weights& weights)
{
    // The Weights object supplies the values for w1, w2, ... , w11
    double score = 0.0;
    
    // For each of the Player's stats
    for (size_t i = 0; i < NUM_STATS; ++i)
    {
        double weight = weights.GetWeight(static_cast<StatName>(i));
        double stat = GetStat(static_cast<StatName>(i));
        score += weight * stat;
    }
    
    leagueScore = score;
}
示例#9
0
 ReturnCode computeMean(Mean &mean, const Values &values, const Weights &weights)
 {
     MSS_BEGIN(ReturnCode);
     MSS(!values.empty());
     MSS(values.size() == weights.size());
     mean = 0.0;
     Mean sumW = 0.0;
     typename Values::const_iterator value = values.begin();
     for (auto weight: weights)
     {
         mean += *(value++)*weight;
         sumW += weight;
     }
     mean /= sumW;
     MSS_END();
 }
示例#10
0
  void reweight(Weight& wt, Util::Random01& rng) const {
    double cost = wt.getValue();
    double newcost = cost;
    maybeSet(newcost);
    if (!weights.empty()) {
      if (!IsFeatureWeight<Weight>::value)
        SDL_THROW_LOG(Hypergraph.Reweight, ConfigException,
                      "supplied (unusable) feature weights for non-feature hypergraph");
      double weighted = FeatureDotProduct<Weight, double>::dotProduct(wt, weights);
      if (weightsAdd)
        newcost += weighted;
      else
        newcost = weighted;
    }
    postSet(newcost, rng);

    if (clearFeatures)
      wt = Weight((typename Weight::FloatT)newcost);
    else
      wt.value_ = newcost;
  }
示例#11
0
int random_weighted_choice(const Weights& w)
{
    using T = typename Weights::value_type;

    auto n = w.size();
    TBLIS_ASSERT(n > 0);

    T s = 0;
    for (unsigned i = 0;i < n;i++)
    {
        TBLIS_ASSERT(w[i] >= 0);
        s += w[i];
    }

    T c = random_number(s);
    for (unsigned i = 0;i < n;i++)
    {
        if (c < w[i]) return i;
        c -= w[i];
    }

    return n-1;
}
示例#12
0
  // test equality of copy and ptr
  ABORT_IF(ptr->size()!=copy.size())

  for(Size i = 0 ; i < ptr->size() ; ++i)
  {
    TEST_EQUAL(ptr->getAlphabetMass(i), copy.getAlphabetMass(i))
    TEST_EQUAL(ptr->getWeight(i), copy.getWeight(i))
    TEST_EQUAL((*ptr)[i], copy[i])
  }
}
END_SECTION

START_SECTION((Weights& operator=(const Weights &weights_)))
{
  Weights copy;
  copy = *ptr;
  TEST_NOT_EQUAL(&copy, null_ptr)

  // test equality of copy and ptr
  ABORT_IF(ptr->size()!=copy.size())

  for(Size i = 0 ; i < ptr->size() ; ++i)
  {
    TEST_EQUAL(ptr->getAlphabetMass(i), copy.getAlphabetMass(i))
    TEST_EQUAL(ptr->getWeight(i), copy.getWeight(i))
    TEST_EQUAL((*ptr)[i], copy[i])
  }
}
END_SECTION
示例#13
0
template<typename EXAMPLE> Weights ExamplePtrs<EXAMPLE>::current_weight() const {
	Weights w;
	for (typename ExamplePtrs<EXAMPLE>::const_iterator e = this->begin(); e != this->end(); e++)
		w.add((*e)->weight(), (*e)->is_correct());
	return w;
}
示例#14
0
template<typename EXAMPLE> Weights Examples<EXAMPLE>::initial_weight() const {
	Weights w;
	for (typename Examples<EXAMPLE>::const_iterator e = this->begin(); e != this->end(); e++)
		w.add(e->initial_weight(), e->is_correct());
	return w;
}
示例#15
0
 bool trivial() const {
   return is_null(set) && is_null(random_add) && is_null(add) && is_null(scale) && !clearFeatures
          && !fsm_normalize && !head_normalize && weights.empty();
 }
示例#16
0
文件: Demo.cpp 项目: treeman/7days
void Demo::Draw()
{
    Tree::clear_window( Tree::Color::black );

    str.SetText( boost::lexical_cast<std::string>( t.GetTime() ) );
    str.SetPosition( 100, 5 );
    Tree::draw( str );

    str.SetText( boost::lexical_cast<std::string>( st.GetTime() ) );
    str.SetPosition( 100, 15 );
    Tree::draw( str );

    str.SetText( boost::lexical_cast<std::string>( cd.GetTime() ) );
    str.SetPosition( 200, 5 );
    Tree::draw( str );

    if( cd.IsDone() ) {
        str.SetText( "done" );
    }
    else {
        str.SetText( "not done" );
    }
    str.SetPosition( 200, 15 );
    Tree::draw( str );

    // Draw shuffle bag's contents
    int n = 1;
    const float h = 10;
    for( Ints::iterator it = bagged.begin(); it != bagged.end(); ++it, ++n )
    {
        str.SetPosition( 10, 30 + h * n );
        str.SetText( boost::lexical_cast<std::string>( *it ) );
        Tree::draw( str );
    }

    n = 1;
    for( Ints::iterator it = rest.begin(); it != rest.end(); ++it, ++n )
    {
        str.SetPosition( 30, 30 + h * n );
        str.SetText( boost::lexical_cast<std::string>( *it ) );
        Tree::draw( str );
    }

    Vec2i mpos = Tree::get_mouse_pos();
    Vec2i l1 = point - mpos;
    Tree::clip( l1, 0, 50 );

    Tree::draw( sf::Shape::Line( point, point - l1, 1.0, Tree::Color( 0xff557733)));

    Vec2i p2( point.x, point.y - 50 );
    Vec2i l2 = point - p2;
    Tree::clip( l2, 0, 50 );

    Tree::draw( sf::Shape::Line( point, point - l2, 1.0, Tree::Color( 0xff775533)));

    float rad = angle( l1, l2 );

    str.SetPosition( point.x + 20, point.y - 30 );
    str.SetText( boost::lexical_cast<std::string>( rad ) );
    Tree::draw( str );

    float degree = Tree::rad2deg( rad );

    str.SetPosition( point.x + 20, point.y - 20 );
    str.SetText( boost::lexical_cast<std::string>( degree ) );
    Tree::draw( str );

    // Check neighbours
    str.SetPosition( 250, 350 );
    str.SetText( "neighbours" );
    Tree::draw( str );

    typedef std::vector<Vec2i> Points;
    Points ps = Tree::generate_neighbours( point );
    n = 1;
    for( Points::iterator it = ps.begin(); it < ps.end(); ++it, ++n ) {
        str.SetPosition( 250, 350 + h * n );
        str.SetText( boost::lexical_cast<std::string>( *it ) );
        Tree::draw( str );
    }

    str.SetPosition( 320, 350 );
    str.SetText( "corners" );
    Tree::draw( str );

    ps = Tree::generate_corners( point );
    n = 1;
    for( Points::iterator it = ps.begin(); it < ps.end(); ++it, ++n ) {
        str.SetPosition( 320, 350 + h * n );
        str.SetText( boost::lexical_cast<std::string>( *it ) );
        Tree::draw( str );
    }

    str.SetPosition( 400, 350 );
    str.SetText( "both" );
    Tree::draw( str );

    ps = Tree::generate_surroundings( point );
    n = 1;
    for( Points::iterator it = ps.begin(); it < ps.end(); ++it, ++n ) {
        str.SetPosition( 400, 350 + h * n );
        str.SetText( boost::lexical_cast<std::string>( *it ) );
        Tree::draw( str );
    }

    // Draw weight bag's selections
    typedef std::vector<std::string> Vals;
    typedef std::vector<float> Weights;

    Vals vals = weight_bag.GetVals();
    Weights weights = weight_bag.GetWeights();

    std::stringstream ss;
    ss.precision( 2 );

    n = 1;
    for( Weights::iterator it = weights.begin(); it < weights.end(); ++it, ++n ) {
        str.SetPosition( 60, 30 + h * n );
        ss.str("");
        ss << *it;
        //str.SetText( boost::lexical_cast<std::string>( *it ) );
        str.SetText( ss.str() );
        Tree::draw( str );
    }

    n = 1;
    for( Vals::iterator it = vals.begin(); it < vals.end(); ++it, ++n ) {
        str.SetPosition( 85, 30 + h * n );
        str.SetText( boost::lexical_cast<std::string>( *it ) );
        Tree::draw( str );
    }

    str.SetPosition( 170, 40 );
    ss.str("");
    ss << "0.2: " << apples << " " << (float)apples / (float)total_weight
        << " Apples";
    str.SetText( ss.str() );
    Tree::draw( str );

    str.SetPosition( 170, 50 );
    ss.str("");
    ss << "0.2: " << oranges << " " << (float)oranges / (float)total_weight
        << " Oranges";
    str.SetText( ss.str() );
    Tree::draw( str );

    str.SetPosition( 170, 60 );
    ss.str("");
    ss << "0.6: " << strawberries << " " <<
        (float)strawberries / (float)total_weight << " Strawberries";
    str.SetText( ss.str() );
    Tree::draw( str );

    str.SetPosition( 170, 70 );
    str.SetText( "last: " + curr_weight );
    Tree::draw( str );

    // Draw shapes
    Tree::draw_line( 500, 200, 520, 220, Tree::Color::white );
    Tree::draw_line( 520, 220, 540, 180, Tree::Color::yellow, 2.0 );
    Tree::draw_line( Vec2i( 540, 180 ), Vec2i( 560, 200 ),
        Tree::Color::magenta, 2.0, Tree::Color::cyan, 1.0 );

    Tree::draw_rect( 600, 100, 640, 140, Tree::Color::blue );
    Tree::draw_rect( 600, 200, 640, 240, Tree::Color::green,
        Tree::Color::red, 1.0 );

    Tree::draw_circle( 700, 250, 40, Tree::Color::white );

    Tree::draw_triangle( 610, 300, 600, 320, 620, 320, Tree::Color::white );
    Tree::draw_triangle( 610, 360, 600, 340, 620, 340, Tree::Color::white,
        Tree::Color::red, 2.0 );

    // Draw statusbar
    float perc = st.GetTime() - (int)(st.GetTime() / 2.0) * 2.0;
    Tree::draw_bar( 700, 580, 790, 590, perc, Tree::Color( 0xff333333 ),
        Tree::Color( 0xffaaaaaa ), Tree::Color::white, 1.0 );

    // Draw indexed sprites
    for( size_t i = 0; i < sprites.size(); ++i ) {
        sf::Sprite &spr = sprites[i];
        spr.SetPosition( 40 + i * 32, 530 );
        Tree::draw( spr );
    }

    // Draw regular sprite
    aspr.SetPosition( 50, 200 );
    if( perc > 1.0 ) perc = 1.0;
    Tree::set_alpha( aspr, Tree::enbyten( perc ) );
    Tree::draw( aspr );
}
示例#17
0
 Wt& axiomWt(StateId s) {
   assert(isAxiom(s));
   StateId i = s - axiomsStart;
   if (weights.is_null(i)) return weights[i] = StateWtFn::operator()(i);
   return weights[i];
 }
示例#18
0
 void init(StateId axiomsStart_, StateId axiomsEnd) {
   axiomsStart = axiomsStart_;
   weights.clear();
   weights.resize(axiomsEnd-axiomsStart);
 }