本文整理汇总了C++中SparseVector::size方法的典型用法代码示例。如果您正苦于以下问题:C++ SparseVector::size方法的具体用法?C++ SparseVector::size怎么用?C++ SparseVector::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SparseVector
的用法示例。
在下文中一共展示了SparseVector::size方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: report_multiplication_error
void report_multiplication_error(const SparseKalmanMatrix *T,
const SparseVector &Z,
bool new_time,
double fraction_in_initial_period,
const VEC &v) {
ostringstream err;
int state_dim = T->nrow();
err << "incompatible sizes in AccumulatorTransitionMatrix multiplication"
<< endl
<< "T.nrow() = " << state_dim << endl
<< "Z.size() = " << Z.size() << endl
<< "v.size() = " << v.size() << endl
<< "The first two should match. The last should be two more "
<< "than the others" << endl;
report_error(err.str());
}
示例2: RQR_Multiply
Vec RQR_Multiply(const VECTOR &v,
const SparseKalmanMatrix &RQR,
const SparseVector &Z,
double H) {
int state_dim = Z.size();
if(v.size() != state_dim + 2) {
report_error("wrong sizes in RQR_Multiply");
}
// Partition v = [eta, epsilon, 0]
ConstVectorView eta(v, 0, state_dim);
double epsilon = v[state_dim];
// Partition this
Vec RQRZ = RQR * Z.dense();
double ZRQRZ_plus_H = Z.dot(RQRZ) + H;
Vec ans(v.size());
VectorView(ans, 0, state_dim) = (RQR * eta).axpy(RQRZ, epsilon);
ans[state_dim] = RQRZ.dot(eta) + ZRQRZ_plus_H * epsilon;
return ans;
}
示例3: resize
{
TEST_EQUAL(sv2.size(), 8)
}
END_SECTION
START_SECTION((void resize(size_type newsize)))
{
sv2.resize(10);
TEST_EQUAL(sv2.size(),10)
}
END_SECTION
START_SECTION((SparseVector& operator=(const SparseVector &source)))
{
sv2=sv;
TEST_EQUAL(sv2.size(), 8)
}
END_SECTION
START_SECTION((bool operator==(const SparseVector &rhs) const ))
{
SparseVector<double> sv3(sv);
TEST_EQUAL((sv3==sv), true)
}
END_SECTION
START_SECTION((bool operator<(const SparseVector &rhs) const ))
{
SparseVector<double> sv3(sv);
sv3[0]=-1.23;
示例4: updateProbabilitiesBeforeAction
void SoftmaxPolicyPlayout::updateProbabilitiesBeforeAction(const Go::Board *board, Color player) {
// check the last move
size_t historySize = board->getHistoryCount();
const Board::MoveChangeEntry *lastMove = board->getHistory(historySize-1); // enemy's move
const Board::MoveChangeEntry *secondLastMove = board->getHistory(historySize-2); // last my move
const Board::MoveChangeEntry *thirdLastMove = board->getHistory(historySize-3);
double *table = NULL;
SparseVector *featureTable = NULL;
if (player == BLACK) {
table = m_probTableBlack;
featureTable = m_featureTableBlack;
} else {
table = m_probTableWhite;
featureTable = m_featureTableWhite;
}
if (lastMove && lastMove->m_putPos != PASS) table[lastMove->m_putPos] = 0;
if (secondLastMove && secondLastMove->m_putPos != PASS) table[secondLastMove->m_putPos] = 0;
PointSet updatedMoves;
// reset static features which are set in the last time of player
PointSet &previousSetMoves = player == BLACK ? m_toResetStaticFeaturesMovesBlack : m_toResetStaticFeaturesMovesWhite;
for (size_t i=0; i<previousSetMoves.size(); i++) {
//cerr << previousSetMoves[i] << ":" << featureTable[previousSetMoves[i]].toString() << endl;
Point p = previousSetMoves[i];
StandardFeatureExtractor::clearStaticFeatures(featureTable[p]);
if (board->isColor(p, FREE) &&
(board->getNeighborEmptyCount(p) >= 1 || board->checkLegalHand(p, player, Board::flipColor(player)) == Board::PUT_LEGAL)) {
updatedMoves.insert(p,p);
}
}
previousSetMoves.clear();
// enumerate pattern update moves
PointSet patternUpdateMoves;
enumerateMovesOfPatternChanged(patternUpdateMoves, board, player, lastMove, secondLastMove, false);
// enumerate moves that their status will change
PointSet toBeLegal, toBeIllegal;
PointSet legalMovesSet;
toBeLegal.clear(); toBeIllegal.clear();
enumerateToBeLegalAndIllegalMoves(board, table, player, toBeLegal, toBeIllegal, legalMovesSet, false);
PointSet &staticFeatureUpdateMoves = previousSetMoves;
if (lastMove == NULL) return; // no further old moves
// update static features
m_featureExtractor.updateStaticFeaturesForAllMovesWithoutClearOldFeatures(board, player, legalMovesSet, featureTable, staticFeatureUpdateMoves);
// update patterns
PointSet::ListConstIterator it, end = patternUpdateMoves.end();
for (it = patternUpdateMoves.begin(); it!=end; it++) {
SparseVector &targetFeatures = featureTable[*it];
assert (board->isColor(*it, FREE));
m_featureExtractor.updatePatternFeature(targetFeatures, board, *it, player);
//if (board->checkLegalHand(*it, player, Board::flipColor(player)) == Board::PUT_LEGAL) {
if ((!toBeIllegal.contains(*it) && table[*it] != 0) || toBeLegal.contains(*it)) {
updatedMoves.insert(*it,*it);
}
}
end = toBeLegal.end();
for (it = toBeLegal.begin(); it!=end; it++) {
updatedMoves.insert(*it,*it);
// check capturing, atari features
}
end = staticFeatureUpdateMoves.end();
for (it=staticFeatureUpdateMoves.begin(); it!=end; it++) {
//table[*it] = m_expFeatureWeights.multiplyAll(featureTable[*it]);
updatedMoves.insert(*it,*it);
}
end = updatedMoves.end();
for (it=updatedMoves.begin(); it!=end; it++) {
//table[*it] = m_expFeatureWeights.multiplyAll(featureTable[*it]);
table[*it] = fmath::expd(m_featureWeights.dot(featureTable[*it]));
//table[*it] = exp(m_featureWeights.dot(featureTable[*it]));
}
end = toBeIllegal.end();
for (it = toBeIllegal.begin(); it!=end; it++) {
table[*it] = 0;
StandardFeatureExtractor::clearStaticFeatures(featureTable[*it]);
}
#ifdef STRICT_CHECK
for (int y=0; y<board->getSize(); y++) {
for (int x=0; x<board->getSize(); x++) {
Point p = board->xyToPoint(x,y);
Board::PutType err = board->checkLegalHand(p, player, Board::flipColor(player));
assert (!(err == Board::PUT_LEGAL && table[p] == 0) &&
!(err != Board::PUT_LEGAL && table[p] != 0));
if (err == Board::PUT_LEGAL) {
double v = m_expFeatureWeights.multiplyAll(featureTable[p]);
if (fabs(v-table[p]) >= 0.001) {
cerr << "v = " << v << endl;
//.........这里部分代码省略.........