本文整理汇总了C++中distribution函数的典型用法代码示例。如果您正苦于以下问题:C++ distribution函数的具体用法?C++ distribution怎么用?C++ distribution使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了distribution函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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];
}
}
}
开发者ID:Beautiful-Flowers,项目名称:opencv_localization,代码行数:25,代码来源:particle_filter.cpp
示例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);
}
开发者ID:KoenvanderKeyl,项目名称:Ecosystem,代码行数:24,代码来源:AnimalAIView.cpp
示例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);
}
开发者ID:Menithal,项目名称:hifi,代码行数:15,代码来源:AudioMixerClientData.cpp
示例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);
}
}
开发者ID:dtbinh,项目名称:kinematicEngine,代码行数:36,代码来源:kinematicEngine.cpp
示例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));
}
开发者ID:Anti-Ultimate,项目名称:dolphin,代码行数:24,代码来源:Network.cpp
示例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;
}
}
}
开发者ID:veimox,项目名称:locokit69,代码行数:15,代码来源:ea.cpp
示例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;
}
开发者ID:sudnya,项目名称:video-classifier,代码行数:36,代码来源:test-minerva-visualization.cpp
示例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();
}
开发者ID:CCJY,项目名称:coliru,代码行数:15,代码来源:main.cpp
示例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();
}
}
开发者ID:abhi-agrawal,项目名称:TestAtomProject,代码行数:15,代码来源:randomGen.cpp
示例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;
}
开发者ID:OpenMBIR,项目名称:openmbir,代码行数:51,代码来源:BFReconstructionEngine_Extra.cpp
示例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;
}
开发者ID:itoupeter,项目名称:Computer_Graphics,代码行数:16,代码来源:stratifiedpixelsampler.cpp
示例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]();
}
开发者ID:dmaddalone,项目名称:CrapSim,代码行数:16,代码来源:Die.cpp
示例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);
}
}
}
开发者ID:MarcinCz,项目名称:ealib,代码行数:16,代码来源:NormalMutationOperator.cpp
示例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();
}
开发者ID:XT54321,项目名称:rstudio,代码行数:16,代码来源:Random.hpp
示例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();
}
开发者ID:Barhandar,项目名称:Cataclysm-DDA,代码行数:47,代码来源:npc_class.cpp
示例16: ceilf
void Game::update(sf::Time time) {
if (currentCell.x < 0) currentCell.x = 0;
if (currentCell.y < 0) currentCell.y = 0;
if (currentCell.x >= 10) currentCell.x = 9;
if (currentCell.y >= 10) currentCell.y = 9;
timeLeft = (int) ceilf(gameTime - clock.getElapsedTime().asSeconds());
if (timeLeft == 0) {
lastScore = score;
score = 0;
clock.restart();
}
if (calculate) {
int result = 0;
for (auto cell : selectedCells) {
result += grid[cell.y][cell.x];
}
if (result == 10) {
score += pow(2, selectedCells.size());
for (auto cell : selectedCells) {
grid[cell.y][cell.x] = (short) distribution(generator);
}
soundMatch.play();
}
calculate = false;
selectedCells.clear();
}
if (selection) {
auto found = false;
for (auto cell : selectedCells) {
if (cell.x == currentCell.x &&
cell.y == currentCell.y) {
found = true;
break;
}
}
if (!found) {
selectedCells.push_back(sf::Vector2i(currentCell.x, currentCell.y));
}
}
}
开发者ID:maluramichael,项目名称:match-ten,代码行数:47,代码来源:Game.cpp
示例17: connect
IPC::IPC()
: globalMemory{"qtox-" IPC_PROTOCOL_VERSION}
{
qRegisterMetaType<IPCEventHandler>("IPCEventHandler");
timer.setInterval(EVENT_TIMER_MS);
timer.setSingleShot(true);
connect(&timer, &QTimer::timeout, this, &IPC::processEvents);
// The first started instance gets to manage the shared memory by taking ownership
// Every time it processes events it updates the global shared timestamp "lastProcessed"
// If the timestamp isn't updated, that's a timeout and someone else can take ownership
// This is a safety measure, in case one of the clients crashes
// If the owner exits normally, it can set the timestamp to 0 first to immediately give ownership
std::default_random_engine randEngine((std::random_device())());
std::uniform_int_distribution<uint64_t> distribution;
globalId = distribution(randEngine);
qDebug() << "Our global IPC ID is " << globalId;
if (globalMemory.create(sizeof(IPCMemory)))
{
if (globalMemory.lock())
{
IPCMemory* mem = global();
memset(mem, 0, sizeof(IPCMemory));
mem->globalId = globalId;
mem->lastProcessed = time(0);
globalMemory.unlock();
}
else
{
qWarning() << "Couldn't lock to take ownership";
}
}
else if (globalMemory.attach())
{
qDebug() << "Attaching to the global shared memory";
}
else
{
qDebug() << "Failed to attach to the global shared memory, giving up";
return; // We won't be able to do any IPC without being attached, let's get outta here
}
processEvents();
}
开发者ID:Artom-Kozincev,项目名称:qTox,代码行数:46,代码来源:ipc.cpp
示例18: spline_transform
double *
spline_transform(short *dcts, int bits, int *pnpoints)
{
static double output[HOWMANY*4];
double *p;
int i;
p = output;
for (i = 0; i < HOWMANY; i++) {
distribution(i, dcts, bits, p);
p += 4;
}
*pnpoints = HOWMANY*4;
return (output);
}
开发者ID:CplusHua,项目名称:stegdetect,代码行数:17,代码来源:extraction.c
示例19: randomTest
void randomTest(dbi::LockManager* lm, int thread) {
std::default_random_engine generator;
std::uniform_int_distribution<int> distribution(1,100);
auto rnd = std::bind(distribution, generator);
for (uint64_t i=1; i <= 10000; i++) {
try {
lm->lock(dbi::TupleId(rnd()), thread);
} catch (dbi::AlreadyLockedException e) {
} catch (dbi::DeadlockException e) {
lm->unlockAll(thread);
}
if (i%10 == 0)
lm->unlockAll(thread);
}
lm->unlockAll(thread);
}
开发者ID:swoehrl,项目名称:Gamera-Database,代码行数:17,代码来源:LockManagerTest.cpp
示例20: mk_rbm
// return it, even
rbm mk_rbm(unsigned int nv, unsigned int nh) {
// get the randomly initialized weights
size_t elements = get_number_of_weights(nv, nh);
std::vector<double> weights(elements);
//std::uniform_real_distribution<double> distribution(-1.0f, 1.0f); //Values between -1 and 1
std::normal_distribution<double> distribution(0.0, 1.0);
std::random_device rd; //seed
std::mt19937 engine(rd());
auto generator = std::bind(distribution, engine);
std::generate_n(weights.begin(), elements, generator);
std::vector<int> visible = std::vector<int>(nv, 0);
std::vector<int> hidden = std::vector<int>(nh, 0);
rbm res = { nv, nh, visible, hidden, weights };
return res;
}
开发者ID:daydreamt,项目名称:pgm,代码行数:19,代码来源:rbm.cpp
注:本文中的distribution函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论