本文整理汇总了C++中distribution函数的典型用法代码示例。如果您正苦于以下问题:C++ distribution函数的具体用法?C++ distribution怎么用?C++ distribution使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了distribution函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: resample
// Stochastic universal resampling
void resample() {
double variance = ras::variance(particle_weight);
std::copy(particle_state.begin(), particle_state.end(), particle_state_aux.begin());
std::copy(particle_weight.begin(), particle_weight.end(), particle_weight_aux.begin());
// TODO normalize goes here??
ras::normalize(particle_weight);
// TODO what is resample_variance
if (variance >= resample_variance) {
ras::cumsum(particle_weight, cdf_aux);
std::uniform_real_distribution<double> distribution(0.0, 1.0 / (double) P);
double r0 = distribution(generator);
for (int m = 0; m < P; m++) {
double cdf_thre = r0 + (double) m / P;
//Resampling condition
int j;
for (j = 0; cdf_aux[j] < cdf_thre && j < P; j++);
particle_state[m].x = particle_state_aux[j].x;
particle_state[m].y = particle_state_aux[j].y;
particle_state[m].theta = particle_state_aux[j].theta;
particle_weight[m] = particle_weight_aux[j];
}
}
}
示例2: distribution
void AnimalAIView::update(int timeStep)
{
Vector<double> position = controllingAnimal.getPosition();
target.x += distribution(generator)*30;
target.y += distribution(generator)*30;
target.normalize();
target.x *= radius;
target.y *= radius;
Vector<double> targetLocal = target;
Vector<double> worldLocation;
worldLocation.x = position.x + targetLocal.x;
worldLocation.y = position.y + targetLocal.y;
Vector<double> direction(worldLocation);
direction.x -= position.x;
direction.y -= position.y;
controllingAnimal.setSpeed(50);
controllingAnimal.setDirection(direction);
}
示例3: NodeData
AudioMixerClientData::AudioMixerClientData(const QUuid& nodeID, Node::LocalID nodeLocalID) :
NodeData(nodeID, nodeLocalID),
audioLimiter(AudioConstants::SAMPLE_RATE, AudioConstants::STEREO),
_outgoingMixedAudioSequenceNumber(0),
_downstreamAudioStreamStats()
{
// of the ~94 blocks in a second of audio sent from the AudioMixer, pick a random one to send out a stats packet on
// this ensures we send out stats to this client around every second
// but do not send all of the stats packets out at the same time
std::random_device randomDevice;
std::mt19937 numberGenerator { randomDevice() };
std::uniform_int_distribution<> distribution { 1, (int) ceil(1.0f / AudioConstants::NETWORK_FRAME_SECS) };
_frameToSendStats = distribution(numberGenerator);
}
示例4: distribution
void KinematicEngine::fillTreeWithValues(KinematicTree &tree,
kinematics::MotorValuesMap values,
kinematics::MotorValuesMap speeds,
bool addNoise)
{
std::uniform_real_distribution<double> distribution(-m_valueNoise, m_valueNoise);
for (std::pair<const MotorID, double>& value : values) {
double noise = 0.;
if (addNoise) {
noise = distribution(generator);
}
value.second += noise;
}
for (std::pair<const kinematics::NodeID, KinematicNode*> nodeP : tree.getNodes()) {
KinematicNode * node = nodeP.second;
kinematics::MotorIDs const& motors = node->getMotors();
kinematics::MotorValuesMap valuesForNode;
kinematics::MotorValuesMap valueDerivativesForNode;
for (MotorID const& id : motors) {
if (values.find(id) != values.end()) {
// this motor is accessible for inverse kinematics
valuesForNode[id] = values.at(id);
}
if (speeds.find(id) != speeds.end()) {
valueDerivativesForNode[id] = speeds.at(id);
}
}
node->setValues(valuesForNode);
node->setValueDerivatives(valueDerivativesForNode);
}
}
示例5: GenerateMacAddress
void GenerateMacAddress(const MACConsumer type, u8* mac)
{
memset(mac, 0, MAC_ADDRESS_SIZE);
u8 const oui_bba[] = {0x00, 0x09, 0xbf};
u8 const oui_ios[] = {0x00, 0x17, 0xab};
switch (type)
{
case MACConsumer::BBA:
memcpy(mac, oui_bba, 3);
break;
case MACConsumer::IOS:
memcpy(mac, oui_ios, 3);
break;
}
// Generate the 24-bit NIC-specific portion of the MAC address.
std::default_random_engine generator(Common::Timer::GetTimeMs());
std::uniform_int_distribution<int> distribution(0x00, 0xFF);
mac[3] = static_cast<u8>(distribution(generator));
mac[4] = static_cast<u8>(distribution(generator));
mac[5] = static_cast<u8>(distribution(generator));
}
示例6: distribution
void Chromosome<T>::gaussianMutation(double mutation_rate)
{
double probability;
std::normal_distribution<double> distribution = std::normal_distribution<double>((lower_boundary + upper_boundary) / 2, lower_boundary / 2 + upper_boundary);
for (unsigned int i = 0; i < size; i++) {
probability = std::generate_canonical<double, std::numeric_limits<double>::digits>(generator);
if (probability < mutation_rate) {
chromosome_values[i] += distribution(generator);
if (chromosome_values[i] > upper_boundary)
chromosome_values[i] = upper_boundary;
else if (chromosome_values[i] < lower_boundary)
chromosome_values[i] = lower_boundary;
}
}
}
示例7: addRandomNoiseToImage
static Image addRandomNoiseToImage(const Image& image, float noiseMagnitude,
std::default_random_engine& engine)
{
Image copy = image;
size_t xPixels = image.x();
size_t yPixels = image.y();
size_t colors = image.colorComponents();
std::uniform_real_distribution<float> distribution(-noiseMagnitude, noiseMagnitude);
for(size_t y = 0; y != yPixels; ++y)
{
for(size_t x = 0; x != xPixels; ++x)
{
for(size_t c = 0; c != colors; ++c)
{
float value = distribution(engine) + image.getStandardizedComponentAt(x, y, c);
if(value < -1.0f)
{
value = -1.0f;
}
if(value > 1.0f)
{
value = 1.0f;
}
copy.setStandardizedComponentAt(x, y, c, value);
}
}
}
return copy;
}
示例8: main
int main()
{
async_task<int(int)> async_d6{[&](std::size_t seed) -> int {
std::mt19937 generator{seed};
std::uniform_int_distribution<int> distribution{1, 6};
auto r = distribution(generator);
std::this_thread::sleep_for(std::chrono::seconds(r));
std::cout << "Slept for " << r << " seconds.\n"; // race on purpose
return r;
}};
std::random_device rng;
auto die1 = async_d6(rng());
auto die2 = async_d6(rng());
std::cout << "Total is: " << die1.get() + die2.get();
}
示例9: randomGenWithSeed
void randomGenWithSeed( const Vector2 range, const int limit, VectorLong& output, const int seed )
{
// generator type defined and initialized by a seed value
generator_type generator( seed );
// define uniform random number distribution which produces type double values
// between [min,max) for each orbital element. For more details please refer to
// the following web link:
// http://www.boost.org/doc/libs/1_60_0/libs/random/example/random_demo.cpp
boost::uniform_real<> distribution( range[ 0 ], range[ 1 ] );
boost::variate_generator<generator_type&, boost::uniform_real<> > uniform(generator, distribution);
for(int i = 0; i < limit; i++)
{
output[ i ] = uniform();
}
}
示例10: distribution
// -----------------------------------------------------------------------------
//Function to generate a randomized list from a given input list
// -----------------------------------------------------------------------------
VoxelUpdateList::Pointer BFReconstructionEngine::GenRandList(VoxelUpdateList::Pointer InpList)
{
VoxelUpdateList::Pointer OpList;
const uint32_t rangeMin = 0;
const uint32_t rangeMax = std::numeric_limits<uint32_t>::max();
typedef boost::uniform_int<uint32_t> NumberDistribution;
typedef boost::mt19937 RandomNumberGenerator;
typedef boost::variate_generator<RandomNumberGenerator&, NumberDistribution> Generator;
NumberDistribution distribution(rangeMin, rangeMax);
RandomNumberGenerator generator;
Generator numberGenerator(generator, distribution);
boost::uint32_t arg = static_cast<boost::uint32_t>(EIMTOMO_getMilliSeconds());
generator.seed(arg); // seed with the current time
int32_t ArraySize = InpList.NumElts;
OpList.NumElts = ArraySize;
OpList.Array = (struct ImgIdx*)(malloc(ArraySize * sizeof(struct ImgIdx)));
size_t dims[3] =
{ ArraySize, 0, 0};
Int32ArrayType::Pointer Counter = Int32ArrayType::New(dims, "Counter");
for (int32_t j_new = 0; j_new < ArraySize; j_new++)
{
Counter->d[j_new] = j_new;
}
for(int32_t test_iter = 0; test_iter < InpList.NumElts; test_iter++)
{
int32_t Index = numberGenerator() % ArraySize;
OpList.Array[test_iter] = InpList.Array[Counter->d[Index]];
Counter->d[Index] = Counter->d[ArraySize - 1];
ArraySize--;
}
#ifdef DEBUG
if(getVerbose()) { std::cout << "Input" << std::endl; }
maxList(InpList);
if(getVerbose()) { std::cout << "Output" << std::endl; }
maxList(OpList);
#endif //Debug
return OpList;
}
示例11: a
QList<glm::vec2> StratifiedPixelSampler::GetSamples(int x, int y)
{
QList<glm::vec2> result;
float a( x - .5f );
float b( y - .5f );
float c( 1.f / samples_sqrt );
for( int i = 0; i < samples_sqrt; ++i ){
for( int j = 0; j < samples_sqrt; ++j ){
result.push_back( glm::vec2( a + c * i + c * distribution( generator ), b + c * i + c * distribution( generator ) ) );
}
}
return result;
}
示例12: defined
Die::Die(int nFaces)
{
#if defined(_WIN32)
static unsigned seed = std::chrono::high_resolution_clock::now().time_since_epoch().count();
++seed;
std::mt19937 generator{seed};
#else
std::random_device rdev{};
std::mt19937 generator{rdev()};
#endif // defined
std::uniform_int_distribution<int> distribution(1, nFaces);
rollDie = std::bind(distribution, generator);
m_nFaces = nFaces;
m_pnDieRollValues = new int[m_nFaces]();
}
示例13: distribution
void NormalMutationOperatorCPU::doMutation(Population& _population)
{
vector<IndividualPtr> individuals = _population.getIndividuals();
int representation_size = _population.getRepresentationSize();
for(IndividualPtr ind: individuals)
{
RepresentationPtr representation = ind->getRepresentation();
for(int i = 0; i < representation_size; ++i)
{
if(prob_distribution(generator) <= probability)
representation->at(i) += distribution(generator);
}
}
}
示例14: uniformRandomInteger
T uniformRandomInteger()
{
// setup generator and distribution
typedef boost::mt19937 GeneratorType;
typedef boost::uniform_int<T> DistributionType;
GeneratorType generator(std::time(NULL));
DistributionType distribution(std::numeric_limits<T>::min(),
std::numeric_limits<T>::max());
// create variate generator
boost::variate_generator<GeneratorType, DistributionType> vg(generator,
distribution);
// return random number
return vg();
}
示例15: load_distribution
distribution load_distribution( JsonObject &jo )
{
if( jo.has_float( "constant" ) ) {
return distribution::constant( jo.get_float( "constant" ) );
}
if( jo.has_float( "one_in" ) ) {
return distribution::one_in( jo.get_float( "one_in" ) );
}
if( jo.has_array( "dice" ) ) {
JsonArray jarr = jo.get_array( "dice" );
return distribution::dice_roll( jarr.get_int( 0 ), jarr.get_int( 1 ) );
}
if( jo.has_array( "rng" ) ) {
JsonArray jarr = jo.get_array( "rng" );
return distribution::rng_roll( jarr.get_int( 0 ), jarr.get_int( 1 ) );
}
if( jo.has_array( "sum" ) ) {
JsonArray jarr = jo.get_array( "sum" );
JsonObject obj = jarr.next_object();
distribution ret = load_distribution( obj );
while( jarr.has_more() ) {
obj = jarr.next_object();
ret = ret + load_distribution( obj );
}
return ret;
}
if( jo.has_array( "mul" ) ) {
JsonArray jarr = jo.get_array( "mul" );
JsonObject obj = jarr.next_object();
distribution ret = load_distribution( obj );
while( jarr.has_more() ) {
obj = jarr.next_object();
ret = ret * load_distribution( obj );
}
return ret;
}
jo.throw_error( "Invalid distribution" );
return distribution();
}