TNode * LeftistHeap::merge(TNode *h1, TNode *h2) { // cout << "Leftist Merge called.\n"; if (h1 == NULL) return h2; if (h2 == NULL) return h1; if (h1->value > h2->value) swap(h1, h2); h1->right = merge(h1->right, h2); // merge to right subtree // swap if leftist tree property is violated if (computeRank(h1->left) < computeRank(h1->right)) swap(h1->left, h1->right); // recompute rank h1->rank = computeRank(h1->right) + 1; return h1; }
void SchreyerFrame::computeRanks(int slanted_degree, int maxlevel) { // Compute all needed ranks to get the minimal Betti numbers in the range // deg <= slanted_degree, lev <=maxlevel. // This means: we need to compute ranks to level maxlevel+1 (or largest that exists) // in degrees <= slanted_degree, EXCEPT we don't need to compute at (slanted_degree,maxlevel+1). int toplevel = (maxlevel < maxLevel() ? maxlevel-1 : mMaxLength); for (int deg=mLoSlantedDegree; deg <=slanted_degree; deg++) for (int lev=1; lev<=toplevel; lev++) computeRank(deg, lev); }
void MainWindow::showCoordinates(float x, float y) { QString str = QString("pos: (%1, %2)").arg(QString::number(x, 'f', 3), 6).arg(QString::number(y, 'f', 3), 6); statusPositionLabel->setText(str); float dbase = m_DFunc(Point(x,y)/(2.*m_spaceSize)); float d = (m_max_density-m_min_density)*dbase+m_min_density; str = QString(" | dens: %1 (%2)").arg(QString::number(float(d), 'e', 2), 6).arg(QString::number(float(dbase), 'f', 2), 4); statusDensityLabel->setText(str); int l = computeLvlMinusHalfRank(d, m_spaceSize, m_sampler->tiling().subdivFactor()); int r = computeRank(d, m_spaceSize, l, m_sampler->tiling().subdivFactor()); str = QString(" | lvl: %1, rank: %2").arg(QString::number(l), 2).arg(QString::number(r), 2); statusLevelsLabel->setText(str); }
void compute( const MatrixXd& A, const int rank_=-1, const double EPSILON=1e-8 ) { NC=A.cols(); NR=A.rows(); #ifdef DEBUG Ainit=A; #endif qrv.compute( A.transpose() ); sotDEBUG(5) << "QR= " <<(MATLAB)qrv.matrixQR() << std::endl; rank = computeRank(rank_,EPSILON); L = qrv.matrixQR().topRows(rank).triangularView<Upper>().transpose(); sotDEBUG(5) << "L = " << (MATLAB)L << std::endl; if( m_computeFullV ) { V.setIdentity(NC,NC); V.applyOnTheRight(qrv.householderQ()); sotDEBUG(5) << "V = " << (MATLAB)V << std::endl; } else if( m_computeThinV ) { V.resize(NC,rank); V.setIdentity(NC,rank); V.applyOnTheLeft(qrv.householderQ()); } if( m_computeFullU || m_computeThinU ) { U = qrv.colsPermutation(); sotDEBUG(5) << "Pi = " << (MATLAB)U << std::endl; } for( int k=rank;k<NR;++k ) leftGivens(k); sotDEBUG(5) << "L = " << (MATLAB)L << std::endl; sotDEBUG(5) << "U = " << (MATLAB)U << std::endl; }
void Rank(int n) { int N, i, k, r; double p_value, product, chi_squared, arg1, p_32, p_31, p_30, R, F_32, F_31, F_30; BitSequence **matrix = create_matrix(32, 32); N = n/(32*32); if ( isZero(N) ) { fprintf(stats[TEST_RANK], "\t\t\t\tRANK TEST\n"); fprintf(stats[TEST_RANK], "\t\tError: Insuffucient # Of Bits To Define An 32x32 (%dx%d) Matrix\n", 32, 32); p_value = 0.00; } else { r = 32; /* COMPUTE PROBABILITIES */ product = 1; for ( i=0; i<=r-1; i++ ) product *= ((1.e0-pow(2, i-32))*(1.e0-pow(2, i-32)))/(1.e0-pow(2, i-r)); p_32 = pow(2, r*(32+32-r)-32*32) * product; r = 31; product = 1; for ( i=0; i<=r-1; i++ ) product *= ((1.e0-pow(2, i-32))*(1.e0-pow(2, i-32)))/(1.e0-pow(2, i-r)); p_31 = pow(2, r*(32+32-r)-32*32) * product; p_30 = 1 - (p_32+p_31); F_32 = 0; F_31 = 0; for ( k=0; k<N; k++ ) { /* FOR EACH 32x32 MATRIX */ def_matrix(32, 32, matrix, k); #if (DISPLAY_MATRICES == 1) display_matrix(32, 32, matrix); #endif R = computeRank(32, 32, matrix); if ( R == 32 ) F_32++; /* DETERMINE FREQUENCIES */ if ( R == 31 ) F_31++; } F_30 = (double)N - (F_32+F_31); chi_squared =(pow(F_32 - N*p_32, 2)/(double)(N*p_32) + pow(F_31 - N*p_31, 2)/(double)(N*p_31) + pow(F_30 - N*p_30, 2)/(double)(N*p_30)); arg1 = -chi_squared/2.e0; fprintf(stats[TEST_RANK], "\t\t\t\tRANK TEST\n"); fprintf(stats[TEST_RANK], "\t\t---------------------------------------------\n"); fprintf(stats[TEST_RANK], "\t\tCOMPUTATIONAL INFORMATION:\n"); fprintf(stats[TEST_RANK], "\t\t---------------------------------------------\n"); fprintf(stats[TEST_RANK], "\t\t(a) Probability P_%d = %f\n", 32,p_32); fprintf(stats[TEST_RANK], "\t\t(b) P_%d = %f\n", 31,p_31); fprintf(stats[TEST_RANK], "\t\t(c) P_%d = %f\n", 30,p_30); fprintf(stats[TEST_RANK], "\t\t(d) Frequency F_%d = %d\n", 32,(int)F_32); fprintf(stats[TEST_RANK], "\t\t(e) F_%d = %d\n", 31,(int)F_31); fprintf(stats[TEST_RANK], "\t\t(f) F_%d = %d\n", 30,(int)F_30); fprintf(stats[TEST_RANK], "\t\t(g) # of matrices = %d\n", N); fprintf(stats[TEST_RANK], "\t\t(h) Chi^2 = %f\n", chi_squared); fprintf(stats[TEST_RANK], "\t\t(i) NOTE: %d BITS WERE DISCARDED.\n", n%(32*32)); fprintf(stats[TEST_RANK], "\t\t---------------------------------------------\n"); p_value = exp(arg1); if ( isNegative(p_value) || isGreaterThanOne(p_value) ) fprintf(stats[TEST_RANK], "WARNING: P_VALUE IS OUT OF RANGE.\n"); for ( i=0; i<32; i++ ) /* DEALLOCATE MATRIX */ free(matrix[i]); free(matrix); } fprintf(stats[TEST_RANK], "%s\t\tp_value = %f\n\n", p_value < ALPHA ? "FAILURE" : "SUCCESS", p_value); fflush(stats[TEST_RANK]); fprintf(results[TEST_RANK], "%f\n", p_value); fflush(results[TEST_RANK]); }
BettiDisplay SchreyerFrame::minimalBettiNumbers( bool stop_after_degree, int top_slanted_degree, int length_limit ) { // The lo degree will be: mLoSlantedDegree. // The highest slanted degree will either be mHiSlantedDegree, or top_slanted_degree (minimum of these two). // The length we need to compute to is either maxLevel(), or length_limit+1. // We set maxlevel to length_limit. We insist that length_limit <= maxLevel() - 2. // Here is what needs to be computed: // lo: . . . . . . . // . . . . . . . /// hi: . . . . . . // Each dot in all rows other than 'hi' needs to have syzygies computed for it. // if hi == mHiSlantedDegree, then we do NOT need to compute syzygies in this last row. // else we need to compute syzygies in these rows, EXCEPT not at level maxlevel+1 computeFrame(); int top_degree; // slanted degree if (stop_after_degree) { top_degree = std::min(top_slanted_degree, mHiSlantedDegree); top_degree = std::max(mLoSlantedDegree, top_degree); } else { top_degree = mHiSlantedDegree; } // First: if length_limit is too low, extend the Frame if (length_limit >= maxLevel()) { std::cout << "WARNING: cannot extend resolution length" << std::endl; length_limit = maxLevel()-1; // Extend the length of the Frame, change mMaxLength, possibly mHiSlantedDegree // increase mComputationStatus if needed, mMinimalBetti, ... // computeFrame() } // What needs to be computed? // lodeg..hideg, level: 0..maxlevel. Note: need to compute at level maxlevel+1 in order to get min betti numbers at // level maxlevel. // Also note: if hideg is the highest degree that occurs in the frame, we do not need to compute any matrices for these. for (int deg=mLoSlantedDegree; deg <= top_degree-1; deg++) for (int lev=1; lev<=length_limit+1; lev++) computeRank(deg, lev); for (int lev=1; lev<=length_limit; lev++) computeRank(top_degree, lev); if (M2_gbTrace >= 1) { showMemoryUsage(); std::cout << "total setPoly: " << poly_constructor::ncalls << std::endl; std::cout << "total setPolyFromArray: " << poly_constructor::ncalls_fromarray << std::endl; std::cout << "total ~poly: " << poly::npoly_destructor << std::endl; std::cout << "total time for make matrix: " << timeMakeMatrix << std::endl; std::cout << "total time for sort matrix: " << timeSortMatrix << std::endl; std::cout << "total time for reorder matrix: " << timeReorderMatrix << std::endl; std::cout << "total time for gauss matrix: " << timeGaussMatrix << std::endl; std::cout << "total time for clear matrix: " << timeClearMatrix << std::endl; std::cout << "total time for reset hash table: " << timeResetHashTable << std::endl; std::cout << "total time for computing ranks: " << timeComputeRanks << std::endl; } BettiDisplay B(mBettiMinimal); // copy B.resize(mLoSlantedDegree, top_degree, length_limit); return B; }
void MainWindow::setRankMax() { m_max_rank = computeRank(m_max_density, m_spaceSize, m_max_level, m_sampler->tiling().subdivFactor()); optionRankMax->setValue(m_max_rank); }