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]);
	}
}
示例#2
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";
}
示例#3
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();
            }
示例#4
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);
}
示例#5
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();
 }
示例#6
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;
}
示例#7
0
  {
    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

START_SECTION((size_type size() const ))
{
  TEST_EQUAL(ptr->size(), 5)
  Weights w;
  TEST_EQUAL(w.size(),0)