Exemplo n.º 1
0
void MichaelDeque::push_back( int& data) {
    
    Node* node = new Node();
    node->data = data;
    
    while (1) {
        Anchor a = m_Anchor.load(std::memory_order::memory_order_acquire);
        if (a.idxRight == c_nEmptyIndex) {
            if (m_Anchor.compare_exchange_weak(a, Anchor((int) node | c_nEmptyIndex, (int) node | c_nEmptyIndex), std::memory_order::memory_order_release, std::memory_order::memory_order_relaxed))
                break;
        } else if ( Stable == status(a)) {
            node->m_Links.store(Anchor(a.idxRight, c_nEmptyIndex), std::memory_order::memory_order_release);
            Anchor aNew(a.idxLeft, (int) node | c_nFlagMask);
            if (m_Anchor.compare_exchange_weak(a, aNew, std::memory_order::memory_order_release, std::memory_order::memory_order_relaxed)) {
                stabilize_back(aNew);
                break;
            }
        } else {
            stabilize(a);
        }
    }
}
Exemplo n.º 2
0
double BaseFreqs::change(void) {
	
	/* set all of the flags */
	modelPtr->setAllUpdateCls( true );
	modelPtr->setAllUpdateTis( true );
	modelPtr->flipAllActiveCls();
	modelPtr->flipAllActiveTis();
	
	/* change the state */
	MbVector<double> bfNew(numStates);
	MbVector<double> bfOld(numStates);
	MbVector<double> aNew(numStates);
	MbVector<double> aOld(numStates);
	for (int i=0; i<numStates; i++)
		{
		aNew[i] = freqs[i] * alpha0;
		bfOld[i] = freqs[i];
		}
	ranPtr->dirichletRv(aNew, bfNew);
	double sum = 0.0;
	for (int i=0; i<numStates; i++)
		{
		if (bfNew[i] < 0.001)
			bfNew[i] = 0.001;
		sum += bfNew[i];
		}
	for (int i=0; i<numStates; i++)
		bfNew[i] /= sum;
	for (int i=0; i<numStates; i++)
		{
		aOld[i] = bfNew[i] * alpha0;
		freqs[i] = bfNew[i];
		}
	return ranPtr->lnDirichletPdf(aNew, bfNew) - ranPtr->lnDirichletPdf(aOld, bfOld);
	
}
Exemplo n.º 3
0
lab1_4::LamVec* lab1_4::system::getResult()
{
    LamVec *str = new LamVec;
    std::vector<double> *res = new std::vector<double>(this->size, 0);
    

    std::vector<std::vector<std::vector<double> >*> vecU;

    double exz = 1000;

    std::vector<std::vector<double> > aNew((*(this->a)));
    while (exz > this->eps)
    {
        std::vector<std::vector<double> > aCopy(aNew);

        std::vector<std::vector<double> > *u = new std::vector<std::vector<double> >(this->size, std::vector<double>(size, 0));
        for (int i = 0; i < this->size; ++i)
            (*(u))[i][i] = 1;
    
        double max = aCopy[0][1];
        int iMax = 0;
        int jMax = 1;
        for (int i = 0; i < this->size; ++i)
        {
            for (int j = 0; j < this->size; ++j)
            {
                if (i == j)
                    continue;
                if (max < fabs(aCopy[i][j]))
                {
                    max = fabs(aCopy[i][j]);
                    iMax = i;
                    jMax = j;
                }
            }
        }
        (*(u))[iMax][jMax] = -sin(0.5 * atan(2 * aCopy[iMax][jMax] / (aCopy[iMax][iMax] - aCopy[jMax][jMax])));
        (*(u))[jMax][iMax] = sin(0.5 * atan(2 * aCopy[iMax][jMax] / (aCopy[iMax][iMax] - aCopy[jMax][jMax])));
        (*(u))[iMax][iMax] = cos(0.5 * atan(2 * aCopy[iMax][jMax] / (aCopy[iMax][iMax] - aCopy[jMax][jMax])));
        (*(u))[jMax][jMax] = cos(0.5 * atan(2 * aCopy[iMax][jMax] / (aCopy[iMax][iMax] - aCopy[jMax][jMax])));

        /*for (int i = 0; i < this->size; ++i)
        {
            for (int j = 0; j < this->size; ++j)
            {
                std::cout << (*(u))[i][j] << " ";
            }
            std::cout << "\n";
        }
        std::cout << iMax << " " << jMax << "\n";*/

        std::vector<std::vector<double> > tmpA(aCopy);
        for (int i = 0; i < this->size; ++i)
        {
            for (int j = 0; j < this->size; ++j)
            {
                double tmp = 0;
                for (int z = 0; z < this->size; ++z)
                {
                    tmp += (*(u))[z][i] * aCopy[z][j];
                }
                tmpA[i][j] = tmp;
            }
        }
        for (int i = 0; i < this->size; ++i)
        {
            for (int j = 0; j < this->size; ++j)
            {
                double tmp = 0;
                for (int z = 0; z < this->size; ++z)
                {
                    tmp += tmpA[i][z] * (*(u))[z][j];
                }
                aNew[i][j] = tmp;
            }
        }
        exz = 0;
        for (int i = 0; i < this->size; ++i)
        {
            for (int j = 0; j < i; ++j)
            {
                exz += pow(aNew[i][j], 2);
            }
        }
        exz = pow(exz, 0.5);
        std::cout << exz << " -exz\n";

        /*for (int i = 0; i < this->size; ++i)
        {
            for (int j = 0; j < this->size; ++j)
            {
                std::cout << aNew[i][j] << " ";
            }
            std::cout << "\n";
        }

        std::cout << "\n";
        std::cout << "=============\n";
        std::cout << "\n";
        _sleep(1000);*/

        vecU.push_back(u);
    }
    
    str->vec = new std::vector<std::vector<double> >((*(vecU[0])));
    for (int k = 1; k < vecU.size(); ++k)
    {
        std::vector<std::vector<double> > tmpV((*(str->vec)));
        for (int i = 0; i < this->size; ++i)
        {
            for (int j = 0; j < this->size; ++j)
            {
                double tmp = 0;
                for (int z = 0; z < this->size; ++z)
                {
                    tmp += tmpV[i][z] * (*(vecU[k]))[z][j];
                }
                (*(str->vec))[i][j] = tmp;
            }
        }
    }
    for (int i = 0; i < vecU.size(); ++i)
    {
        delete vecU[i];
    }

    for (int i = 0; i < this->size; ++i)
    {
        (*(res))[i] = aNew[i][i];
    }
    str->lambda = res;
    return str;
}