void MCI::doStepMRT2(bool * flagacc)
{
    // propose a new position x
    this->computeNewX();

    // find the corresponding sampling function value
    this->computeNewSamplingFunction();

    //determine if the proposed x is accepted or not
    *flagacc = false;
    if ( this->computeAcceptance() > _rd(_rgen) ) *flagacc=true;

    //update some values according to the acceptance of the mrt2 step
    if ( *flagacc )
    {
        //accepted
        _acc++;
        //update the walker position x
        this->updateX();
        //update the sampling function values pdfx
        this->updateSamplingFunction();
    } else
    {
        //rejected
        _rej++;
    }
}
ssize_t SharedBufferClient::dequeue()
{
    SharedBufferStack& stack( *mSharedStack );

    if (stack.head == tail && stack.available == mNumBuffers) {
        LOGW("dequeue: tail=%d, head=%d, avail=%d, queued=%d",
                tail, stack.head, stack.available, stack.queued);
    }

    RWLock::AutoRLock _rd(mLock);

    const nsecs_t dequeueTime = systemTime(SYSTEM_TIME_THREAD);

    //LOGD("[%d] about to dequeue a buffer",
    //        mSharedStack->identity);
    DequeueCondition condition(this);
    status_t err = waitForCondition(condition);
    if (err != NO_ERROR)
        return ssize_t(err);

    DequeueUpdate update(this);
    updateCondition( update );

    int dequeued = stack.index[tail];
    tail = ((tail+1 >= mNumBuffers) ? 0 : tail+1);
    LOGD_IF(DEBUG_ATOMICS, "dequeued=%d, tail++=%d, %s",
            dequeued, tail, dump("").string());

    mDequeueTime[dequeued] = dequeueTime; 

    return dequeued;
}
Beispiel #3
0
int GameLayer::generateRandomDigit()
{
    int ret = 0;
    while (ret == 0 || ret == 5 || ret == 2 || ret == 1)
        ret = _rd() % 200;
    return ret;
}
void MCI::computeNewX()
{
    for (int i=0; i<_ndim; ++i)
    {
        *(_xnew+i) = *(_xold+i) + (*(_mrt2step+i)) * (_rd(_rgen)-0.5);
    }
    applyPBC(_xnew);
}
status_t SharedBufferClient::lock(int buf)
{
    RWLock::AutoRLock _rd(mLock);

    SharedBufferStack& stack( *mSharedStack );
    LockCondition condition(this, buf);
    status_t err = waitForCondition(condition);
    return err;
}
void MCI::newRandomX()
{
    //generate a new random x (within the irange)
    for (int i=0; i<_ndim; ++i)
    {
        *(_xold+i) = *(*(_irange+i)) + ( *(*(_irange+i)+1) - *(*(_irange+i)) ) * _rd(_rgen);
    }
    //move automatically accepted
    _acc++;
}
Beispiel #7
0
 SporadicLabeler(void):
     _gen(_rd()),
     _probability(0.0)
 {
     this->setupInput(0);
     this->setupOutput(0, "", this->uid()); //unique domain because of buffer forwarding
     this->registerCall(this, POTHOS_FCN_TUPLE(SporadicLabeler, setProbability));
     this->registerCall(this, POTHOS_FCN_TUPLE(SporadicLabeler, getProbability));
     this->registerCall(this, POTHOS_FCN_TUPLE(SporadicLabeler, setIdList));
     this->registerCall(this, POTHOS_FCN_TUPLE(SporadicLabeler, getIdList));
 }
status_t SharedBufferClient::cancel(int buf)
{
    RWLock::AutoRLock _rd(mLock);

    // calculate the new position of the tail index (essentially tail--)
    int localTail = (tail + mNumBuffers - 1) % mNumBuffers;
    CancelUpdate update(this, localTail, buf);
    status_t err = updateCondition( update );
    if (err == NO_ERROR) {
        tail = localTail;
    }
    return err;
}
NNRay::NNRay(NNLayer * nnl)
{
   _rgen = std::mt19937_64(_rdev());
   _rd = std::uniform_real_distribution<double>(-3.,3.);

   for (int i=0; i<nnl->getNUnits(); ++i)
   {
      _source.push_back(nnl->getUnit(i));
      _intensity.push_back(_rd(_rgen));
   }

   _intensity_id.clear();
}
status_t SharedBufferClient::queue(int buf)
{
    RWLock::AutoRLock _rd(mLock);

    SharedBufferStack& stack( *mSharedStack );

    queued_head = (queued_head + 1) % mNumBuffers;
    stack.index[queued_head] = buf;

    QueueUpdate update(this);
    status_t err = updateCondition( update );
    LOGD_IF(DEBUG_ATOMICS, "queued=%d, %s", buf, dump("").string());

    const nsecs_t now = systemTime(SYSTEM_TIME_THREAD);
    stack.stats.totalTime = ns2us(now - mDequeueTime[buf]);
    return err;
}
Gracz3::Gracz3() : _gen( _rd() ), _dis( 0, 2 ) {
	moje_ruchy.push_back( Papier );
		wygr.ja = 0;
		wygr.on = 0;
}