本文整理汇总了C++中sampler函数的典型用法代码示例。如果您正苦于以下问题:C++ sampler函数的具体用法?C++ sampler怎么用?C++ sampler使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sampler函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: get_simulation_particle_indexes
void MolecularDynamics::assign_velocities(Float temperature) {
ParticleIndexes ips = get_simulation_particle_indexes();
setup_degrees_of_freedom(ips);
ParticlesTemp ps = IMP::internal::get_particle(get_model(), ips);
boost::normal_distribution<Float> mrng(0., 1.);
boost::variate_generator<RandomNumberGenerator &,
boost::normal_distribution<Float> >
sampler(random_number_generator, mrng);
for (ParticlesTemp::iterator iter = ps.begin(); iter != ps.end();
++iter) {
Particle *p = *iter;
LinearVelocity(p).set_velocity(algebra::Vector3D(sampler(), sampler(),
sampler()));
}
Float rescale =
sqrt(temperature / get_kinetic_temperature(get_kinetic_energy()));
for (ParticlesTemp::iterator iter = ps.begin(); iter != ps.end();
++iter) {
Particle *p = *iter;
LinearVelocity v(p);
algebra::Vector3D velocity = v.get_velocity();
velocity *= rescale;
v.set_velocity(velocity);
}
}
示例2: setup_degrees_of_freedom
void MolecularDynamics::assign_velocities(Float temperature)
{
ParticleIndexes ips=get_simulation_particle_indexes();
setup_degrees_of_freedom(ips);
ParticlesTemp ps= IMP::internal::get_particle(get_model(), ips);
boost::normal_distribution<Float> mrng(0., 1.);
boost::variate_generator<RandomNumberGenerator&,
boost::normal_distribution<Float> >
sampler(random_number_generator, mrng);
for (ParticlesTemp::iterator iter = ps.begin();
iter != ps.end(); ++iter) {
Particle *p = *iter;
for (int i = 0; i < 3; ++i) {
p->set_value(vs_[i], sampler());
}
}
Float rescale = sqrt(temperature/
get_kinetic_temperature(get_kinetic_energy()));
for (ParticlesTemp::iterator iter = ps.begin();
iter != ps.end(); ++iter) {
Particle *p = *iter;
for (int i = 0; i < 3; ++i) {
Float velocity = p->get_value(vs_[i]);
velocity *= rescale;
p->set_value(vs_[i], velocity);
}
}
}
示例3: sample_chisq
inline float sample_chisq (rng_t & rng, float nu)
{
// HACK <float> appears to be broken in libstdc++ 4.6
//typedef std::chi_squared_distribution<float> chi_squared_distribution_t;
typedef std::chi_squared_distribution<double> chi_squared_distribution_t;
chi_squared_distribution_t sampler(nu);
return sampler(rng);
}
示例4: sample_gamma
inline float sample_gamma (
rng_t & rng,
float alpha,
float beta = 1.f)
{
// HACK <float> appears to be broken in libstdc++ 4.6
//typedef std::gamma_distribution<float> gamma_distribution_t;
typedef std::gamma_distribution<double> gamma_distribution_t;
gamma_distribution_t sampler(alpha, beta);
return sampler(rng);
}
示例5: cdf_estimator
int Cosisim::full_ik( RandomPath begin, RandomPath end,
Progress_notifier* progress_notifier ) {
typedef FullIK_cdf_estimator< geostat_utils::CoKrigingConstraints,
geostat_utils::CoKrigingCombiner,
MarkovBayesCovariance > FullIkEstimator;
FullIkEstimator cdf_estimator( marginal_->p_begin(),marginal_->p_end(),
covariances_.begin(), covariances_.end(),
combiners_.begin(), combiners_.end(),
*kconstraints_ );
// set up the sampler
Random_number_generator gen;
Monte_carlo_sampler_t< Random_number_generator > sampler( gen );
// this vector will contain the indicies of the indicators to be estimated
// at a given grid node
std::vector< unsigned int > unestimated_indicators;
for( ; begin != end ; ++begin ) {
if( !progress_notifier->notify() ) return 1;
get_current_local_cdf( *begin, unestimated_indicators );
if( unestimated_indicators.empty() ) {
sampler( *begin, *ccdf_ );
continue;
}
geostat_utils::NeighborhoodVector neighborhoods =
full_ik_find_neighbors( *begin, unestimated_indicators );
DEBUG_PRINT_LOCATION( "center", begin->location() );
DEBUG_PRINT_NEIGHBORHOOD( "hard1", &neighborhoods[0] );
DEBUG_PRINT_NEIGHBORHOOD( "soft1", &neighborhoods[1] );
DEBUG_PRINT_NEIGHBORHOOD( "hard2", &neighborhoods[2] );
DEBUG_PRINT_NEIGHBORHOOD( "soft2", &neighborhoods[3] );
GsTLPoint watch( 52, 95, 13 );
if( begin->location() == watch ) {
std::cout << "found" << std::endl;
}
clear_ccdf();
int status = cdf_estimator( *begin,
neighborhoods.begin(), neighborhoods.end(),
*ccdf_ );
sampler( *begin, *ccdf_ );
code_into_indicators( *begin );
}
return 0;
}
示例6: unif
void pdf::generate_sample(int size, long double theta) {
static unsigned int calls = 0; // use as seed for generator
calls++; // ensures unique seed in every call
sample.clear();
boost::uniform_real<> unif(theta, theta * theta);
boost::random::mt19937 gen(calls);
boost::variate_generator< boost::random::mt19937&, boost::uniform_real<> > sampler(gen, unif);
for(int i=0;i<size;i++) {
sample.push_back(sampler());
}
}
示例7: rng
double ProfileNormal::getSample() {
// Create a Mersenne twister random number generator
// that is seeded once with #seconds since 1970
static boost::mt19937 rng(static_cast<unsigned> (std::time(0)));
// select Normal probability distribution
boost::normal_distribution<double> dist(boost::math::mean(profile), sqrt(boost::math::variance(profile)));
// bind random number generator to distribution, forming a function
boost::variate_generator<boost::mt19937&, boost::normal_distribution<double> > sampler(rng, dist);
// sample from the distribution
return sampler();
}
示例8: sampler
void MotionSample::recalculate(Pose end_pose, std::array<double, 4> params) {
// pfcpp::VelocityMotionModelSampler sampler(std::move(params));
pfcpp::OdometryMotionModelSampler sampler(params);
m_moves.clear();
m_moves.push_back(std::make_shared<Pose>(*m_startPose));
m_moves.push_back(std::make_shared<Pose>(end_pose));
m_samples.clear();
for (int i = 0; i < 400; ++i) {
auto p = sampler(*m_startPose, end_pose);
m_samples.push_back(std::make_shared<Pose>(p));
}
}
示例9: sampler
/**
* Computes the curvature of the image and the force of the ACWE
* @param {vector<cl::Event>} The events that this kernel depends on
* @param {bool} Indicates if we need to use all the bands of the image (by computing the avg)
*/
cl::Event ActiveContours::compCurvAndF(vector<cl::Event> vecEvPrev, bool useAllBands) {
cl::Event evCurvF;
if (WRITE) {
cout << endl << " ----------------- Computing Curvature and F ---------" << endl;
}
try {
cl::Context* context = clMan.getContext();
cl::CommandQueue* queue = clMan.getQueue();
cl::Program* program = clMan.getProgram();
cl::Sampler sampler(*context, CL_FALSE,
CL_ADDRESS_REPEAT, CL_FILTER_NEAREST, &err);
cl::Kernel kernelCurvAndF(*program, (char*) "CurvatureAndF");
kernelCurvAndF.setArg(0, img_phi);
kernelCurvAndF.setArg(1, img_in);
kernelCurvAndF.setArg(2, img_curv_F);
kernelCurvAndF.setArg(3, sampler);
kernelCurvAndF.setArg(4, buf_avg_in_out);
kernelCurvAndF.setArg(5, (int)useAllBands);
queue->enqueueNDRangeKernel(
kernelCurvAndF,
cl::NullRange,
cl::NDRange((size_t) width, (size_t) height),
cl::NDRange((size_t) grp_size_x, (size_t) grp_size_y),
&vecEvPrev,
&evCurvF);
} catch (cl::Error ex) {
clMan.printError(ex);
}
return evCurvF;
}
示例10: TEST
TEST(McmcNutsBaseNuts, transition) {
rng_t base_rng(0);
int model_size = 1;
double init_momentum = 1.5;
stan::mcmc::ps_point z_init(model_size);
z_init.q(0) = 0;
z_init.p(0) = init_momentum;
stan::mcmc::mock_model model(model_size);
stan::mcmc::mock_nuts sampler(model, base_rng);
sampler.set_nominal_stepsize(1);
sampler.set_stepsize_jitter(0);
sampler.sample_stepsize();
sampler.z() = z_init;
std::stringstream output_stream;
stan::interface_callbacks::writer::stream_writer writer(output_stream);
std::stringstream error_stream;
stan::interface_callbacks::writer::stream_writer error_writer(error_stream);
stan::mcmc::sample init_sample(z_init.q, 0, 0);
stan::mcmc::sample s = sampler.transition(init_sample, writer, error_writer);
EXPECT_EQ(31.5, s.cont_params()(0));
EXPECT_EQ(0, s.log_prob());
EXPECT_EQ(1, s.accept_stat());
EXPECT_EQ("", output_stream.str());
EXPECT_EQ("", error_stream.str());
}
示例11: lock
void mFakeMonkey::spike(){
boost::mutex::scoped_lock lock(monkey_lock);
boost::exponential_distribution<double> dist = boost::exponential_distribution<double>(spiking_rate->getValue().getFloat() / 1000000);
variate_generator<boost::mt19937&, boost::exponential_distribution<double> > sampler = variate_generator<boost::mt19937&, boost::exponential_distribution<double> >(rng,dist);
if(spike_node != NULL){
spike_node->cancel();
}
if(spike_var != 0) {
*spike_var = 1;
}
float delay = sampler();
spike_node = scheduler->scheduleUS(FILELINE,
delay,
0,
1,
&fake_monkey_spike,
(void *)this,
M_DEFAULT_IODEVICE_PRIORITY,
M_DEFAULT_IODEVICE_WARN_SLOP_US,
M_DEFAULT_IODEVICE_FAIL_SLOP_US,
M_MISSED_EXECUTION_CATCH_UP);
}
示例12: sampler
sk_sp<GrTextureProxy> GrTextureProducer::refTextureProxy(GrMipMapped willNeedMips,
SkColorSpace* dstColorSpace,
sk_sp<SkColorSpace>* proxyColorSpace) {
GrSamplerState::Filter filter =
GrMipMapped::kNo == willNeedMips ? GrSamplerState::Filter::kNearest
: GrSamplerState::Filter::kMipMap;
GrSamplerState sampler(GrSamplerState::WrapMode::kClamp, filter);
int mipCount = SkMipMap::ComputeLevelCount(this->width(), this->height());
bool willBeMipped = GrSamplerState::Filter::kMipMap == sampler.filter() && mipCount &&
fContext->contextPriv().caps()->mipMapSupport();
auto result =
this->onRefTextureProxyForParams(sampler, dstColorSpace, proxyColorSpace,
willBeMipped, nullptr);
// Check to make sure that if we say the texture willBeMipped that the returned texture has mip
// maps, unless the config is not copyable.
SkASSERT(!result || !willBeMipped || result->mipMapped() == GrMipMapped::kYes ||
!fContext->contextPriv().caps()->isConfigCopyable(result->config()));
// Check that no scaling occured and we returned a proxy of the same size as the producer.
SkASSERT(!result || (result->width() == this->width() && result->height() == this->height()));
return result;
}
示例13: guess_EBV_profile
void guess_EBV_profile(TMCMCOptions &options, TLOSMCMCParams ¶ms, unsigned int N_regions) {
TNullLogger logger;
unsigned int N_steps = options.steps / 8;
if(N_steps < 40) { N_steps = 40; }
unsigned int N_samplers = options.samplers;
unsigned int N_threads = options.N_threads;
unsigned int ndim = N_regions + 1;
TAffineSampler<TLOSMCMCParams, TNullLogger>::pdf_t f_pdf = &lnp_los_extinction;
TAffineSampler<TLOSMCMCParams, TNullLogger>::rand_state_t f_rand_state = &gen_rand_los_extinction;
std::cout << "Generating Guess ..." << std::endl;
TParallelAffineSampler<TLOSMCMCParams, TNullLogger> sampler(f_pdf, f_rand_state, ndim, N_samplers*ndim, params, logger, N_threads);
sampler.set_scale(1.05);
sampler.set_replacement_bandwidth(0.75);
sampler.step(int(N_steps*30./100.), true, 0., 0.5, 0.);
sampler.step(int(N_steps*20./100), true, 0., 1., 0., true);
sampler.step(int(N_steps*30./100.), true, 0., 0.5, 0.);
sampler.step(int(N_steps*20./100), true, 0., 1., 0., true);
sampler.print_stats();
std::cout << std::endl << std::endl;
sampler.get_chain().get_best(params.EBV_prof_guess);
for(size_t i=0; i<ndim; i++) {
//params.EBV_prof_guess[i] = log(params.EBV_prof_guess[i]);
std::cout << "\t" << params.EBV_prof_guess[i] << std::endl;
}
std::cout << std::endl;
}
示例14: glGenTextures
TexOGL * TexOGL::CreateTexWidthImage( Image * _pImage,bool _mipmap )
{
GLint error;
TexOGL * pTex = new TexOGL;
pTex->m_desc.ePixelFormat = PIXEL_FORMAT_RGBA8888;
pTex->m_desc.eTexClass = TEX_CLASS_STATIC_RAW;
pTex->m_desc.size.width = _pImage->nWidth;
pTex->m_desc.size.height = _pImage->nHeight;
glGenTextures(1,&pTex->m_texture);
error = glGetError();
glBindTexture(GL_TEXTURE_2D,pTex->m_texture);
glTexImage2D(GL_TEXTURE_2D, 0,GL_RGBA, _pImage->nWidth, _pImage->nHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, _pImage->pData);
if(_mipmap)
{
glGenerateMipmap(GL_TEXTURE_2D);
}
// 新版api的创建方式
//glTexStorage2D(GL_TEXTURE_2D,4,GL_RGBA8,64,64);
//glTexSubImage2D(GL_TEXTURE_2D,0,0,0,64,64,GL_RGBA,GL_UNSIGNED_BYTE,bitmap);
error = glGetError();
SamplerOGL sampler(_mipmap);
pTex->ApplySamplerState(&sampler);
assert(GL_NO_ERROR == error);
return pTex;
}
示例15: TEST
TEST(McmcStaticBaseStaticHMC, set_nominal_stepsize_and_L) {
rng_t base_rng(0);
std::vector<double> q(5, 1.0);
std::vector<int> r(2, 2);
stan::mcmc::mock_model model(q.size());
stan::mcmc::mock_static_hmc sampler(model, base_rng);
double old_epsilon = 1.0;
int old_L = 10;
sampler.set_nominal_stepsize_and_L(old_epsilon, old_L);
EXPECT_EQ(old_epsilon, sampler.get_nominal_stepsize());
EXPECT_EQ(old_L, sampler.get_L());
EXPECT_EQ(true, sampler.get_T() > 0);
sampler.set_nominal_stepsize_and_L(-0.1, 5);
EXPECT_EQ(old_epsilon, sampler.get_nominal_stepsize());
EXPECT_EQ(old_L, sampler.get_L());
sampler.set_nominal_stepsize_and_T(5.0, -1);
EXPECT_EQ(old_epsilon, sampler.get_nominal_stepsize());
EXPECT_EQ(old_L, sampler.get_L());
}