/** Default constructor generates new Genome of randomized values. */ Genome::Genome(int i) { Rand r; // random number generating utility ostringstream temp; // temp place to house the string version of the rand // id temp << i; genes["id"] = temp.str(); // PERIOD temp << r.randfloat(1.8, 2.0); genes["period"] = temp.str(); // DESCENDING LENGTH temp << r.randfloat(1.8, 2.0); genes["decending_length"] = temp.str(); // EFFECTOR DELAY temp << r.randfloat(1.8, 2.0); genes["effector_delay"] = temp.str(); // PRC SLOPE temp << r.randfloat(1.8, 2.0); genes["prc_slope"] = temp.str(); genes["channel"] = "0"; genes["sample"] = "peeper.wav"; }
int main() { int i=0; Rand * rnd = new Rand; cout << "[*] Generating 100 seeds...\t\tseeds.txt" << endl; ofstream fseed ("seeds.txt"); for (i=0; i<100; i++) fseed << rnd->genSeed() << endl; fseed.close(); cout << "[*] Generating " << LOOPCNT << " chars...\t\tchars.txt" << endl; ofstream fchar ("chars.txt"); for (i=0; i<LOOPCNT; i++) fchar << rnd->getChar(); fchar.close(); cout << "[*] Generating " << LOOPCNT << " letters...\tletters.txt" << endl; ofstream fletter ("letters.txt"); for (i=0; i<LOOPCNT; i++) fletter << rnd->getLetter(); fletter.close(); delete rnd; cout << endl << endl << "[I] Now you can run these tools:" << endl << "[I] $> cntchar letters.txt" << endl << "[I] $> derandom chars.txt 1000" << endl << endl << "[I] Those tools are part of the jr-tools project:" << endl << "[I] $> git clone https://code.haibane.org/tools/jr-tools" << endl; return 0; }
//************************************************************************* void BeatDetectorApp::NextFile() { roto = 0; if(mTrack && mTrack->isPlaying()) { mTrack->enablePcmBuffering(false); mTrack->stop(); } #ifdef WIN32 time_t now; time(&now); int time_int = (int)now; #else timeval now; gettimeofday(&now, NULL); int time_int = now.tv_sec; #endif Rand r; r.seed(time_int); int rand_file = r.nextInt(m_FileList.size()); path my_path = m_FileList[rand_file].path(); m_CurrentFile = my_path.string(); if(!write_frames) { mAudioSource = audio::load(m_CurrentFile); mTrack = audio::Output::addTrack(mAudioSource, false); mTrack->enablePcmBuffering(true); mTrack->play(); } //rot_inc = r.nextFloat(1.5f, 30.0f); }
void DaemonState::start(bool forceFullScan, bool isReindex) { // Disable implicit flushing after a change WorkerThread::immediateFlush(false); // Do full scans ? if (forceFullScan == true) { m_fullScan = true; } else { Rand randomStuff; guint32 randomArray[5]; randomStuff.set_seed(randomArray[2]); gint32 randomNum = randomStuff.get_int_range(0, 10); if (randomNum >= 7) { m_fullScan = true; } #ifdef DEBUG cout << "DaemonState::start: picked " << randomNum << endl; #endif } m_isReindex = isReindex; // Fire up the disk monitor thread if (m_pDiskHandler == NULL) { OnDiskHandler *pDiskHandler = new OnDiskHandler(); pDiskHandler->getFileFoundSignal().connect(sigc::mem_fun(*this, &DaemonState::on_message_filefound)); m_pDiskHandler = pDiskHandler; } MonitorThread *pDiskMonitorThread = new MonitorThread(m_pDiskMonitor, m_pDiskHandler); start_thread(pDiskMonitorThread, true); for (set<PinotSettings::IndexableLocation>::const_iterator locationIter = PinotSettings::getInstance().m_indexableLocations.begin(); locationIter != PinotSettings::getInstance().m_indexableLocations.end(); ++locationIter) { m_crawlQueue.push(*locationIter); } #ifdef DEBUG cout << "DaemonState::start: " << m_crawlQueue.size() << " locations to crawl" << endl; #endif if (m_fullScan == true) { CrawlHistory crawlHistory(PinotSettings::getInstance().getHistoryDatabaseName()); // Update all items status so that we can get rid of files from deleted sources crawlHistory.updateItemsStatus(CrawlHistory::CRAWLING, CrawlHistory::TO_CRAWL, 0, true); crawlHistory.updateItemsStatus(CrawlHistory::CRAWLED, CrawlHistory::TO_CRAWL, 0, true); crawlHistory.updateItemsStatus(CrawlHistory::CRAWL_ERROR, CrawlHistory::TO_CRAWL, 0, true); } // Initiate crawling start_crawling(); }
Particle::Particle( const Vec2f& origin, Rand& r ) : position( origin ), lifespan( 1.0f ), velocity( r.nextFloat( -1.0f, 1.0f ), r.nextFloat( -1.0f, 1.0f ) ), acceleration( 0.0f, r.nextFloat( 0.01f, 0.03f ) ), aging( r.nextFloat( ( 1.0f / 64 ), ( 1.0f / 128 ) ) ), sizeRadius( r.nextFloat( 3.0f, 9.0f ) ) { }
virtual int ready() { if(slotA->ready() + slotB->ready() == 2){ val = op(slotA->val, slotB->val); delete slotA; delete slotB; return 1; } else return 0; }
void loseScore(Vec2f impact, int num) { vel -= impact; closestPlanet = 0; for(int i = 0; i < num; i++) losing.push_back(new Particle(pos, Vec2f(rand->nextFloat(20.5f), rand->nextFloat(20.5f)), 5.0f, color)); }
void RandomPolicy::act(const Observation &in, Action *out) const { out->v.resize(min_.size()); Rand *rand = RandGen::instance(); for (size_t ii=0; ii < min_.size(); ++ii) (*out)[ii] = rand->getUniform(min_[ii], max_[ii]); out->type = atExploratory; }
Particle(vector<Tile*> *_tiles, Tile *_tile, Vec2f _pos, float _lifetime, Rand* _r) { tiles = _tiles; tile = _tile; lifetime = _lifetime; pos = _pos; expired = .0f; rand = _r; vel = Vec2f(rand->nextFloat(-PSPEED, PSPEED), rand->nextFloat(-PSPEED, PSPEED)); }
void Vocabulary::initWordVectors(){ this->scoreVector = MatD::Zero(this->scoreDim, this->contextStr.size()-2); this->scoreBias = MatD::Zero(1, this->contextStr.size()-2); Rand rnd; double r = 1.0/this->wordDim; this->nounVector = MatD(this->wordDim, this->nounStr.size()); this->contextVector = MatD(this->wordDim, this->contextStr.size()); rnd.gauss(this->nounVector, r); rnd.gauss(this->contextVector, r); }
void CristalWaveApp::setup() { float sizeW = getWindowWidth() * 0.5f; float sizeH = getWindowHeight() * 0.5f; float x = 0.0f, z = 0.0f, y = 0.0f; ///////////////////////////////////////////////// int numRows = PARAM_WAVE_NB_ROWS; int gap = PARAM_WAVE_GAP + getWindowWidth() / 2000; int numLines = getWindowWidth() / gap + 1; ///////////////////////////////////////////////// mOpacity = 0.0f; mOffsetCameratH = 60; // Global amplitude // Init BackgroundLayer mBackground.setup(getWindowWidth(), getWindowHeight(), mOffsetCameratH); // Init Wave Model mWave.setup(getWindowWidth(), getWindowHeight(), numRows, numLines, -mOffsetCameratH); // set a random offset Rand rnd; rnd.seed((unsigned long)GetTickCount()); mOffsetTime = rnd.nextFloat(0.0f, 100.0f); // Set the Shader program mFresnelShader.load(); mpWaveShader = &mFresnelShader; mWave.setShader(mpWaveShader); // -------------------------------------------------------- // Set Particule manager int nbParticule = PARAM_NB_PARTICULES; mEmitter.radius = PARAM_EMITTER_RADIUS; mParticuleInTheWindManager.attrPosition = Vec3f::zero(); mParticuleInTheWindManager.attrFactor = PARAM_FORCE_FACTOR; ParticuleManager::PARTICULE_LIFE particule_life; particule_life.minTTL = 0.5f; particule_life.maxTTL = 3.5f; particule_life.minTTH = 1.0f; particule_life.minTTH = 4.0f; mParticuleInTheWindManager.init(nbParticule, particule_life, getWindowWidth()); }
int choose(Rand& rand) const { const size_t v = rand.get(totalRatio); for (size_t i = 0; i < TYPE_MAX; i++) { if (v < ratio[i]) return i; } throw cybozu::Exception("must not reach here."); }
size_t sample_discrete(const double* cumsum, const size_t m, int level, Rand& rng) { size_t a = 0; size_t b = m - 1; size_t c; double z = cumsum[b]; double r = rng.rand_01() * z; // bisection search while (level > 0){ c = (a + b) / 2; if (r < cumsum[c]){ b = c; } else { a = c + 1; } --level; } // linear search for (size_t i = a; i <= b; ++i){ if (r < cumsum[i]){ return i; } } throw std::logic_error("sample_discrete reached end"); }
void Layer::init(Rand& rand) { double dev = std::max(0.3, 1.0 / m_weights.cols()); for(size_t i = 0; i < m_weights.rows(); i++) { vector<double>& row = m_weights[i]; for(size_t j = 0; j < m_weights.cols(); j++) { row[j] = dev * rand.normal(); } } for(size_t j = 0; j < m_weights.rows(); j++) { m_bias[j] = dev * rand.normal(); } }
virtual int ready() { if(slotA->ready()){ val = op(slotA->val); delete slotA; return 1; } else return 0; }
void Matrix::shuffleRows(Rand& r, Matrix* pBuddy) { if(pBuddy) { for(size_t n = rows(); n > 0; n--) { size_t i = (size_t)r.next(n); std::swap(m_data[i], m_data[n - 1]); std::swap((*pBuddy)[i], (*pBuddy)[n - 1]); } } else { for(size_t n = rows(); n > 0; n--) std::swap(m_data[(size_t)r.next(n)], m_data[n - 1]); } }
void DaemonState::start(bool forceFullScan) { // Disable implicit flushing after a change WorkerThread::immediateFlush(false); // Do full scans ? if (forceFullScan == true) { m_fullScan = true; } else { Rand randomStuff; guint32 randomArray[5]; randomStuff.set_seed(randomArray[2]); int randomNum = randomStuff.get_int_range(0, 10); if (randomNum >= 7) { m_fullScan = true; } #ifdef DEBUG cout << "DaemonState::start: picked " << randomNum << endl; #endif } // Fire up the mail monitor thread now m_pMailHandler = new MboxHandler(); MonitorThread *pMailMonitorThread = new MonitorThread(m_pMailMonitor, m_pMailHandler); pMailMonitorThread->getDirectoryFoundSignal().connect(SigC::slot(*this, &DaemonState::on_message_filefound)); start_thread(pMailMonitorThread, true); // Same for the disk monitor thread m_pDiskHandler = new OnDiskHandler(); MonitorThread *pDiskMonitorThread = new MonitorThread(m_pDiskMonitor, m_pDiskHandler); pDiskMonitorThread->getDirectoryFoundSignal().connect(SigC::slot(*this, &DaemonState::on_message_filefound)); start_thread(pDiskMonitorThread, true); set<PinotSettings::IndexableLocation>::const_iterator locationIter = PinotSettings::getInstance().m_indexableLocations.begin(); if (locationIter != PinotSettings::getInstance().m_indexableLocations.end()) { // Crawl this now crawlLocation(locationIter->m_name, true, locationIter->m_monitor); } }
void EditorState::keyDown(ci::app::KeyEvent event) { // XXX duplicate raycast Vec2f pos = GG.mouse.getPos(); Vec3f planeHit = GG.hexRender.raycastHexPlane(pos.x, pos.y); HexCoord selectedHex = GG.hexGrid.WorldToHex(planeHit); int keycode = event.getCode(); Vec3f& cameraTo = GG.hexRender.getCameraTo(); if (keycode == app::KeyEvent::KEY_ESCAPE) { mManager.setActiveState("title"); } else if (keycode == app::KeyEvent::KEY_UP) { cameraTo += Vec3f(0, 2.0f, 0); } else if (keycode == app::KeyEvent::KEY_DOWN) { cameraTo += Vec3f(0, -2.0f, 0); } else if (keycode == app::KeyEvent::KEY_LEFT) { cameraTo += Vec3f(-2.0f, 0, 0); } else if (keycode == app::KeyEvent::KEY_RIGHT) { cameraTo += Vec3f(2.0f, 0, 0); } else if (keycode == app::KeyEvent::KEY_g) { // Generate hex colors Vec2i mapSize = GG.hexMap.getSize(); for (int iy=0; iy < mapSize.y; ++iy) { for (int ix=0; ix < mapSize.x; ++ix) { HexCell& cell = GG.hexMap.at(HexCoord(ix, iy)); if (cell.getLand()) { int playerID = random.nextInt(0, 5); cell.setOwner(playerID); cell.setColor(GG.warGame.getPlayers()[playerID].getColor()); } } } } else if (keycode == app::KeyEvent::KEY_DELETE) { GG.hexMap.at(selectedHex).setLand(0); } else if (keycode == app::KeyEvent::KEY_SPACE) { mManager.setActiveState(string("game")); } else if (keycode == app::KeyEvent::KEY_c) { vector<HexCoord> connected = GG.hexMap.connected(selectedHex); for (vector<HexCoord>::iterator it = connected.begin(); it != connected.end(); ++it) { HexCell& cell = GG.hexMap.at(*it); Color cellColor = cell.getColor(); cellColor.r = 0.5f * cellColor.r; cellColor.g = 0.5f * cellColor.g; cellColor.b = 0.5f * cellColor.b; cell.setColor(cellColor); } } }
void setRandomData(AlignedArray& buf, Rand& rand) { size_t off = 0; while (off < buf.size()) { const size_t size = std::min<size_t>(buf.size() - off, 16); rand.fill(buf.data() + off, size); off += 512; } }
void Example4App::setup() { gl::clear( Color( 1, 1, 1 ) ); gl::enableAlphaBlending(); generator_.seed(randInt()); app::setWindowSize(600, 200); mean_ = getWindowWidth() / 2; }
void update(float dt) { Vec2f newpos = pos + vel; if(insidePolygon(newpos - tile->pos, (*tile->hex))) { pos = newpos; } else { Vec2f newpos2 = pos + vel * 15.0f; Vec2f exitdir = newpos2 - tile->pos; bool wander = false; vector<Tile*>::iterator tileit; int idx = Tile::getIndexForAngle(math<float>::atan2(exitdir.x, exitdir.y)); console() << idx << endl; for(tileit = tiles->begin(); tileit < tiles->end(); tileit++) { if(insidePolygon(newpos2 - (*tileit)->pos, *(*tileit)->hex) && tile->connections[idx] && !tile->state[idx] && !(*tileit)->state[(idx+3) % 6]) { pos = newpos; wander = true; tile = tile->connections[idx]; } } if(!wander) { Rand r; vel = Vec2f(rand->nextFloat(-PSPEED, PSPEED), rand->nextFloat(-PSPEED, PSPEED)); } } expired += dt; }
void Prior::sample_tau2(Model* model, Rand& rng) { const std::vector<DataModel::ef_t>& x_types = model->x_types; const VectorView& beta = model->beta; double alpha2_sigma2 = alpha2_ * model->sigma2; if (use_individual_tau2){ for (size_t i = m_e; i < beta.length(); ++i){ double nu = nu_tau2[x_types[i]] + 1.0; double s2 = (nus2_tau2[x_types[i]] + beta(i) * beta(i) / alpha2_sigma2) / nu; model->inv_tau2_alpha2(i) = 1.0 / (alpha2_ * rng.rand_sinvchi2(nu, s2)); assert(model->inv_tau2_alpha2(i) > 0); } } else { size_t m = beta.length(); double beta2sum[] = {0.0, 0.0, 0.0, 0.0}; size_t m_types[] = {0, 0, 0, 0}; for (size_t i = m_e; i < m; ++i){ beta2sum[x_types[i]] += beta(i) * beta(i); ++m_types[x_types[i]]; } for (size_t t = 0; t < 4; ++t){ if (allow_terms[t]){ double nu = nu_tau2[t] + m_types[t]; double s2 = (nus2_tau2[t] + beta2sum[t] / alpha2_sigma2) / nu; assert(std::isfinite(s2)); inv_tau2_alpha2[t] = 1.0 / (alpha2_ * rng.rand_sinvchi2(nu, s2)); assert(inv_tau2_alpha2[t] > 0); } } for (size_t i = m_e; i < m; ++i){ model->inv_tau2_alpha2(i) = inv_tau2_alpha2[x_types[i]]; } } model->mu_beta_computed = false; }
int createPath(const RTScene& scene, Rand& rand, int maxVerts, const float3& initialAlpha, const Ray& initialRay, bool includeLightIntersections, PathVertex vertices[]) { int numVerts = 0; Ray ray = initialRay; float3 alpha = initialAlpha; for(int i = 0; i < maxVerts; i++) { float3 woWorld = -ray.dir; IntersectionQuery query(ray); Intersection isect; Intersection lightIsect; intersectScene(scene, query, &isect, &lightIsect); if(hitLightFirst(isect, lightIsect)) { if(includeLightIntersections) { vertices[i] = PathVertex(lightIsect.normal, woWorld, lightIsect.position, lightIsect.material, alpha); return numVerts + 1; } else { return numVerts; } } if(!isect.hit) break; else numVerts++; vertices[i] = PathVertex(isect.normal, woWorld, isect.position, isect.material, alpha); if(i == (maxVerts - 1)) break; ShadingCS isectShadingCS(isect.normal); float3 wi; float3 weight; isect.material->sample(isectShadingCS.local(woWorld), rand.next01f2(), &wi, &weight); if(isBlack(weight)) { break; } float3 wiWorld = isectShadingCS.world(wi); ray.origin = isect.position; ray.dir = wiWorld; alpha *= weight; } return numVerts; }
void RendererTestApp::setup() { mRenderFunctions = { { "Batch 2d", [=](){ mRenderer2dStrip.update(); mRenderer2dStrip.render(); } }, { "VBO 2d", [=](){ mRenderer2dStripVbo.update(); mRenderer2dStripVbo.render(); } }, { "Simple", [=](){ mSimpleRenderer.render(); } }, { "Batch 2d (no updates)", [=](){ mRenderer2dStrip.render(); } }, { "VBO 2d (no updates)", [=](){ mRenderer2dStripVbo.render(); } }, }; mRenderFn = mRenderFunctions.begin(); gl::enableVerticalSync(); Rand r; for( auto &box : mBoxes ) { box.setColor( ColorA{ CM_HSV, r.nextFloat( 1.0f ), 0.9f, 0.9f, 1.0f } ); box.setPos( Vec2f{ r.nextFloat(getWindowWidth()), r.nextFloat(getWindowHeight()) } ); box.setRotation( r.nextFloat( M_PI * 2 ) ); mRenderer2dStrip.add( &box ); mSimpleRenderer.add( &box ); mRenderer2dStripVbo.add( &box ); } // We perform the cast since we know what type of things we stored in each renderer // A type-safe way could be to assign y to each objects layer and then sort by layer Vec2f center = getWindowCenter(); auto vortex_simple = [center]( const SimpleRenderer::Renderable *lhs, const SimpleRenderer::Renderable *rhs ) { return static_cast<const Box*>( lhs )->getPos().distance(center) < static_cast<const Box*>( rhs )->getPos().distance(center); }; auto vortex_triangle = [center]( const BatchRenderer2d::Renderable *lhs, const BatchRenderer2d::Renderable *rhs ) { return static_cast<const Box*>( lhs )->getPos().distance(center) < static_cast<const Box*>( rhs )->getPos().distance(center); }; mSimpleRenderer.sort( vortex_simple ); mRenderer2dStrip.sort( vortex_triangle ); mRenderer2dStripVbo.sort( vortex_triangle ); getWindow()->getSignalKeyUp().connect( [this](KeyEvent &event){ if( event.getCode() == KeyEvent::KEY_SPACE ){ swapRenderer(); } } ); getWindow()->getSignalTouchesEnded().connect( [this](TouchEvent &event){ swapRenderer(); } ); }
double SpeedTest (pfHash hash, uint32_t seed, const int trials, const int blocksize, const int align) { Rand r (seed); uint8_t *buf = new uint8_t[blocksize + 512]; uint64_t t1 = reinterpret_cast < uint64_t > (buf); t1 = (t1 + 255) & BIG_CONSTANT (0xFFFFFFFFFFFFFF00); t1 += align; uint8_t *block = reinterpret_cast < uint8_t * >(t1); r.rand_p (block, blocksize); //---------- std::vector < double >times; times.reserve (trials); for (int itrial = 0; itrial < trials; itrial++) { r.rand_p (block, blocksize); double t = (double) timehash (hash, block, blocksize, itrial); if (t > 0) times.push_back (t); } //---------- std::sort (times.begin (), times.end ()); FilterOutliers (times); delete[]buf; return CalcMean (times); }
void MPEBouncingBallApp::mpeReset() { console() << "RESETTING\n"; // Set the random seed to a known value so all of the clients are using the same rand values. mRand.seed(1); // Clear out the previous state mServerFramesProcessed = 0; mBalls.clear(); // Add the first ball ivec2 sizeMaster = mClient->getMasterSize(); addBallAtPosition(vec2(mRand.nextFloat(sizeMaster.x), mRand.nextFloat(sizeMaster.y))); if (mClient->isAsynchronousClient()) { send3DSettings(); } }
double sortTime(int method, int numSize, int repeat) { Rand r; Timer t; double res = 0.0; for (int j = 0; j < repeat; j++) { auto vec = r.getRandIntVec(numSize); t.startTime(); if (method == 0) MergeSort::sort(vec); else if (method == 1) InsertionSort::sort(vec); else if (method == 2) HybridSort::sort(vec); else if (method == 3) MergeBU::sort(vec); t.endTime(); res += t.elapsedSeconds(); assert(isSorted(vec)); } return res / repeat; }
void P_2_1_3_01App::draw() { // clear out the window with black gl::clear( Color( 1, 1, 1 ) ); gl::color(0, 0, 0, 0.5f); mRand.seed(mRandomSeed); gl::pushMatrices(); gl::translate(mTileWidth / 2.0f, mTileHeight / 2.0f); mCircleCount = mMousePos.x / 30.0f + 1.0f; mEndSize = lmap(float(mMousePos.x), 0.0f, float(getWindowWidth()), mTileWidth / 2.0f, 0.0f); mEndOffset = lmap(float(mMousePos.y), 0.0f, float(getWindowHeight()), 0.0f, (mTileWidth - mEndSize)/2.0f); for (int gridY = 0; gridY <= mTileCountY; gridY++) { for (int gridX = 0; gridX <= mTileCountX; gridX++) { gl::pushMatrices(); gl::translate(mTileWidth * gridX, mTileHeight * gridY); gl::scale(Vec2f(1.0f, mTileHeight / mTileWidth)); int toggle = mRand.nextInt(4); if (toggle == 0) gl::rotate(-90.0f); if (toggle == 1) gl::rotate(0.0f); if (toggle == 2) gl::rotate(90.0f); if (toggle == 3) gl::rotate(180.0f); for (int i = 0; i < mCircleCount; i++) { float diameter = lmap(float(i), 0.0f, mCircleCount - 1.0f, mTileWidth, mEndSize); float offset = lmap(float(i), 0.0f, mCircleCount - 1.0f, 0.0f, mEndOffset); gl::drawStrokedCircle(Vec2f(offset, 0.0f), diameter / 2.0f); } gl::popMatrices(); } } gl::popMatrices(); }
int sample_discrete_naive(const double *cumsum, const int m, Rand &rng){ double z = cumsum[m - 1]; double r = rng.rand_01() * z; for (int i = 0; i < m; ++i){ if (r < cumsum[i]){ return i; } } throw std::logic_error("sample_discrete_naive reached end, exiting"); }
double Prior::sample_alpha(Model* model, const VectorView& y, Rand& rng) { // then use full conditional of alpha to update it size_t nterms = (model->beta).length() - m_e; double a = alpha_; do { // disallow exact zero value if (nterms > 0){ // propose switching sign of alpha and eta (sign of eta has no effect as long // as we actually sample beta; note that eta has symmetric zero mean // distribution); this is metropolis move with deterministic // proposal; no effect is mu_alpha is zero (might as well skip...) if ((a <= 0.0) || log(rng.rand_01()) <= -2.0 * mu_alpha * a){ a = -a; } Vector xb(n); Vector eb(n); xb.set_to_product((model->x).columnblock(m_e, nterms), (model->beta).block(m_e, nterms), false); eb.set_to_product((model->x).columnblock(0, m_e), (model->beta).block(0, m_e), false); eb -= y; // note: this is E * b - y, hence there is minus below in mu formul. double alpha_sigma2 = a * model->sigma2; double var = 1.0 / (1.0 + VectorView::dotproduct(xb, xb) / (a * alpha_sigma2)); double mu = var * (mu_alpha - VectorView::dotproduct(eb, xb) / alpha_sigma2); a = sqrt(var) * rng.rand_normal() + mu; } else { // sample from prior a = rng.rand_normal() + mu_alpha; } } while (a == 0 || a * a == 0); model->mu_beta_computed = false; return a; }