ab::Coin ab::DefaultCoinGenerator::GetCoin(const double field_radius, const double coin_radius)
{
    assert(coin_radius < field_radius);
    const double max_radius = field_radius - coin_radius;
    std::uniform_real_distribution<double> radius_distribution(0, max_radius);
    std::uniform_real_distribution<double> alpha_distribution(0, pi() * 2.0);

    const double radius = radius_distribution(generator_);
    const double alpha = alpha_distribution(generator_);
    ab::Coin coin;
    coin.value = 1.0;
    coin.radius = coin_radius;
    coin.center.x = radius * std::cos(alpha);
    coin.center.y = radius * std::sin(alpha);

    return coin;
}
Esempio n. 2
0
void CharacterData::divide(int _train_size)
{
    mt19937_64 generator(random());
    uniform_int_distribution<> alpha_distribution(0, 25);

    test_data.clear();
    train_data.clear();
    train_size = 0;

    test_data.insert(data.begin(), data.end());

    set<int> not_accesible_characters;

    for (int i = 0; i < _train_size; i++)
    {
        if (not_accesible_characters.size() == test_data.size()) break;

        int alpha_index = alpha_distribution(generator);
        char x = alphabet.at(alpha_index);

        if (!test_data.count(x) || test_data[x].size() == 1)
        {
            i--;
            not_accesible_characters.insert(alpha_index);
            continue;
        }

        uniform_int_distribution<> data_distribution(0, (int) test_data[x].size()-1);
        int data_index = data_distribution(generator);

        train_data[x].push_back(test_data[x][data_index]);
        test_data[x].erase(test_data[x].begin() + data_index);
        train_size++;
    }
    
    test_size = data_size - train_size;
    CharacterData::calculateStats();
}