コード例 #1
0
ファイル: sync.cpp プロジェクト: Gudui/pyclustering
void sync_network::initialization(const double weight_factor, const double frequency_factor, const initial_type initial_phases) {
    weight = weight_factor;

    m_callback_solver = &sync_network::adapter_phase_kuramoto;

    std::random_device                      device;
    std::default_random_engine              generator(device());
    std::uniform_real_distribution<double>	phase_distribution(0.0, 2.0 * pi());
    std::uniform_real_distribution<double>	frequency_distribution(0.0, 1.0);

    for (unsigned int index = 0; index < size(); index++) {
        sync_oscillator & oscillator_context = m_oscillators[index];

        switch (initial_phases) {
        case initial_type::RANDOM_GAUSSIAN:
            oscillator_context.phase = phase_distribution(generator);
            break;
        case initial_type::EQUIPARTITION:
            oscillator_context.phase = (pi() / size() * index);
            break;
        default:
            throw std::runtime_error("Unknown type of initialization");
        }

        oscillator_context.frequency = frequency_distribution(generator) * frequency_factor;
    }
}
コード例 #2
0
ファイル: generator.cpp プロジェクト: sifaserdarozen/DDGen
SingleToneGeneratorType::SingleToneGeneratorType()
{
    // form a seed
    unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
    
    // introduce generator
    std::minstd_rand generator(seed);
    
    // generate amplitude between 0.2 to 0.8
    std::uniform_real_distribution<float> amplitude_distribution(0.2, 0.8);
    m_amplitude = amplitude_distribution(generator);
    
    // generate phase between -PI to PI
    std::uniform_real_distribution<float> phase_distribution(-PI, PI);
    m_phase = phase_distribution(generator);
    
    // generate frequency between 0.2PI to 0.8PI
    std::uniform_real_distribution<float> frequency_distribution(0.2*PI, 0.8*PI);
    m_frequency = frequency_distribution(generator);
    
    std::cout << __FILE__ << " " << __LINE__ << " Single tone generator with A: " << m_amplitude << " F: " << m_frequency << " P: " << m_phase << std::endl;
}