本文整理汇总了C++中IncidentTieIterator::valid方法的典型用法代码示例。如果您正苦于以下问题:C++ IncidentTieIterator::valid方法的具体用法?C++ IncidentTieIterator::valid怎么用?C++ IncidentTieIterator::valid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IncidentTieIterator
的用法示例。
在下文中一共展示了IncidentTieIterator::valid方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: primarySetting
/**
* Create primary setting based on a network
*/
std::vector<int> * primarySetting(const Network * pNetwork, int ego)
{
std::vector<int> *setting = new std::vector<int>;
std::set<int> neighbors;
for (IncidentTieIterator iter = pNetwork->outTies(ego);
iter.valid();
iter.next())
{
neighbors.insert(iter.actor());
}
for (IncidentTieIterator iter = pNetwork->inTies(ego);
iter.valid();
iter.next())
{
neighbors.insert(iter.actor());
}
neighbors.insert(ego);
// when finished (not all done here) copy to the vector
for (std::set<int>::const_iterator iter1 = neighbors.begin();
iter1 != neighbors.end(); iter1++)
{
setting->push_back(*iter1);
}
return setting;
}
示例2: preprocessEgo
/**
* Does the necessary preprocessing work for calculating the tie flip
* contributions for a specific ego. This method must be invoked before
* calling NetworkEffect::calculateTieFlipContribution(...).
*/
void TwoNetworkDependentBehaviorEffect::preprocessEgo(int ego)
{
// set up the covariate based on current values of the network and behavior
const Network * pFirstNetwork = this->pFirstNetwork();
for (int i = 0; i < pFirstNetwork->n(); i++)
{
this->lfirstTotalAlterValues[i] = 0;
if (pFirstNetwork->outDegree(i) > 0)
{
for (IncidentTieIterator iter = pFirstNetwork->outTies(i);
iter.valid();
iter.next())
{
int j = iter.actor();
this->lfirstTotalAlterValues[i] += this->centeredValue(j);
// Rprintf("%d %f %d %d %d %d\n",
// j,
// this->centeredValue(j),
// this->period(),
}
}
else
{
this->lfirstTotalAlterValues[i] = 0;
}
// Rprintf("%d %f\n", i,this->ltotalAlterValues[i]);
}
for (int i = 0; i < pFirstNetwork->m(); i++)
{
this->lfirstTotalInAlterValues[i] = 0;
if (pFirstNetwork->inDegree(i) > 0)
{
for (IncidentTieIterator iter = pFirstNetwork->inTies(i);
iter.valid();
iter.next())
{
int j = iter.actor();
this->lfirstTotalInAlterValues[i] += this->centeredValue(j);
}
}
else
{
this->lfirstTotalInAlterValues[i] = 0;
}
}
}
示例3: value
/**
* Returns the value of this function for the given alter. It is assumed
* that the function has been initialized before and pre-processed with
* respect to a certain ego.
*/
double DifferentCovariateOutStarFunction::value(int alter)
{
int statistic = 0;
if (!(this->lexcludeMissing && this->missing(alter)))
{
const Network * pNetwork = this->pNetwork();
// Iterate over incoming ties in network W
for (IncidentTieIterator iter =
pNetwork->inTies(this->ego());
iter.valid();
iter.next())
{
// Get the sender of the incoming tie.
int h = iter.actor();
// in-2-stars:
if (!(this->lexcludeMissing && this->missing(h)))
{
if ((fabs(this->CovariateNetworkAlterFunction::value(h)
- this->CovariateNetworkAlterFunction::value(this->ego()))
> EPSILON) &&
((lnotBothDifferent) || (fabs(this->CovariateNetworkAlterFunction::value(h)
- this->CovariateNetworkAlterFunction::value(alter))
> EPSILON)) &&
(pNetwork->tieValue(alter, h) >= 1))
{
statistic++ ;
}
}
}
}
return statistic;
}
示例4: egoStatistic
/**
* Returns the statistic corresponding to the given ego with respect to the
* given values of the behavior variable.
*/
double AltersCovariateAvAltEffect::egoStatistic(int ego, double * currentValues)
{
double statistic = 0;
const Network * pNetwork = this->pNetwork();
int neighborCount = 0;
for (IncidentTieIterator iter = pNetwork->outTies(ego);
iter.valid();
iter.next())
{
int j = iter.actor();
if (!this->missing(this->period(), j) &&
!this->missing(this->period() + 1, j) &&
!this->missingCovariate(j,this->period()))
{
statistic += currentValues[j] * this->covariateValue(j);
neighborCount++;
}
}
if ((neighborCount > 0) && (this->ldivide))
{
statistic *= currentValues[ego] / neighborCount;
}
return statistic;
}
示例5: calculateChangeContribution
/**
* Calculates the change in the statistic corresponding to this effect if
* the given actor would change his behavior by the given amount.
*/
double SimilarityEffect::calculateChangeContribution(int actor,
int difference)
{
double contribution = 0;
const Network * pNetwork = this->pNetwork();
if (pNetwork->outDegree(actor) > 0)
{
// The formula for the average similarity effect:
// s_i(x) = avg(sim(v_i, v_j) - centeringConstant) over all neighbors
// j of i.
// sim(v_i, v_j) = 1.0 - |v_i - v_j| / observedRange
// We need to calculate the change delta in s_i(x), if we changed
// v_i to v_i + d (d being the given amount of change in v_i).
// To this end, we can disregard the centering constant and
// compute the average change in similarity, namely,
// avg(sim(v_i + d, v_j) - sim(v_i, v_j)) =
// avg(1 - |v_i+d-v_j|/range - 1 + |v_i-v_j|/range) =
// avg(|v_i-v_j| - |v_i+d-v_j|) / range,
// the average being taken over all neighbors of i.
// The reasoning for avg. similarity x popularity alter effect is
// similar.
// This is what is calculated below.
int oldValue = this->value(actor);
int newValue = oldValue + difference;
int totalChange = 0;
for (IncidentTieIterator iter = pNetwork->outTies(actor);
iter.valid();
iter.next())
{
int j = iter.actor();
int alterValue = this->value(j);
int change =
std::abs(oldValue - alterValue) - std::abs(newValue - alterValue);
if (this->lalterPopularity)
{
change *= pNetwork->inDegree(j);
}
totalChange += change;
}
contribution = ((double) totalChange) / this->range();
if (this->laverage)
{
contribution /= pNetwork->outDegree(actor);
}
if (this->legoPopularity)
{
contribution *= pNetwork->inDegree(actor);
}
}
return contribution;
}
示例6: calculateChangeContribution
/**
* Calculates the change in the statistic corresponding to this effect if
* the given actor would change his behavior by the given amount.
*/
double AltersCovariateAvAltEffect::calculateChangeContribution(int actor,
int difference)
{
double contribution = 0;
const Network * pNetwork = this->pNetwork();
if (pNetwork->outDegree(actor) > 0)
{
double totalAlterValue = 0;
for (IncidentTieIterator iter = pNetwork->outTies(actor);
iter.valid();
iter.next())
{
int j = iter.actor(); // identifies alter
double alterValue = this->centeredValue(j) * this->covariateValue(j);
totalAlterValue += alterValue;
}
if (this->ldivide)
{
contribution = difference * totalAlterValue /
pNetwork->outDegree(actor);
}
else
{
contribution = difference * totalAlterValue;
}
}
return contribution;
}
示例7: egoEndowmentStatistic
/**
* Returns the statistic corresponding to the given ego as part of
* the endowment function with respect to the initial values of a
* behavior variable and the current values.
*/
double AltersCovariateAvAltEffect::egoEndowmentStatistic(int ego,
const int * difference,
double * currentValues)
{
double statistic = 0;
const Network * pNetwork = this->pNetwork();
if (difference[ego] > 0 && !this->missingDummy(ego) && (pNetwork->outDegree(ego) > 0)) // otherwise, nothing to calculate...
{
double totalAlterValue = 0;
for (IncidentTieIterator iter = pNetwork->outTies(ego);
iter.valid();
iter.next())
{
int j = iter.actor(); // identifies alter
double alterValue = this->centeredValue(j) * this->covariateValue(j);
totalAlterValue += alterValue;
}
if (this->ldivide)
{
statistic -= difference[ego] * totalAlterValue /
pNetwork->outDegree(ego);
}
else
{
statistic -= difference[ego] * totalAlterValue;
}
}
return statistic;
}
示例8:
/**
* Returns the statistic corresponding to the given ego with respect to the
* currentValues given for the behavior variable.
*/
double AverageAlterDist2Effect::egoStatistic(int i, double * currentValues)
{
double statistic = 0;
const Network * pNetwork = this->pNetwork();
int neighborCount = 0;
for (IncidentTieIterator iter = pNetwork->outTies(i);
iter.valid();
iter.next())
{
int j = iter.actor();
double alterValue = 0;
int tieToi = 0;
for (IncidentTieIterator iteri = pNetwork->outTies(j);
iteri.valid();
iteri.next())
{
if (i != iteri.actor())
{
alterValue += currentValues[iteri.actor()];
}
else
{
tieToi = 1;
}
}
// tieToi = this->pNetwork()->tieValue(iter.actor(), i);
if ((pNetwork->outDegree(j) > tieToi) & (this->ldivide2))
{
alterValue /= (pNetwork->outDegree(j) - tieToi);
}
statistic += alterValue;
neighborCount++;
}
if (neighborCount > 0)
{
statistic *= currentValues[i];
if (this->ldivide1)
{
statistic /= neighborCount;
}
}
return statistic;
}
示例9:
/**
* Returns the statistic corresponding to the given ego with respect to the
* currentValues given for the behavior variable.
*/
double AverageAlterInDist2Effect::egoStatistic(int i, double * currentValues)
{
double statistic = 0;
const Network * pNetwork = this->pNetwork();
int neighborCount = 0;
for (IncidentTieIterator iter = pNetwork->outTies(i);
iter.valid();
iter.next())
{
int j = iter.actor();
double alterValue = 0;
for (IncidentTieIterator iteri = pNetwork->inTies(j);
iteri.valid();
iteri.next())
{
if (i != iteri.actor())
{
alterValue += currentValues[iteri.actor()];
}
}
// tieFromi = this->pNetwork()->tieValue(i, iter.actor());
if ((pNetwork->inDegree(j) > 1) & (this->ldivide2))
{
alterValue /= (pNetwork->inDegree(j) - 1);
// there always is a tie i -> iteri.actor()
}
statistic += alterValue;
neighborCount++;
}
if (neighborCount > 0)
{
statistic *= currentValues[i];
if (this->ldivide1)
{
statistic /= neighborCount;
}
}
return statistic;
}
示例10:
/**
* Modifies the two-path count given the case the observed network is a
* two mode network.
* @param[in] rNetwork The observed network
* @param[in] ego The ego of the modified tie
* @param[in] alter The alter of the modified tie
* @param[in[ val The magnitude of modification
*/
void DistanceTwoLayer::modify2PathCountTwoMode(const Network& rNetwork, int ego,
int alter, int val) {
// in a two mode network the exist no triangles, therefore it is
// sufficient to iterate over all incoming ties of alter
for (IncidentTieIterator iter = rNetwork.inTies(alter); iter.valid();
iter.next()) {
if (iter.actor() != ego) {
modifyTieValue(ego, iter.actor(), val);
}
}
}
示例11: initializeTwoMode
/**
* Initializes the layer given the reference network is a two mode
* network.
*/
void DistanceTwoLayer::initializeTwoMode(const Network& rNetwork) {
// this is a two mode network so we do not need to check for loops
// nor do we have to store the reciever two paths.
for (int i = 0; i < rNetwork.m(); ++i) {
// construct all pairs
for (IncidentTieIterator outerIter = rNetwork.inTies(i);
outerIter.valid(); outerIter.next()) {
int outerActor = outerIter.actor();
// copy the iterator
IncidentTieIterator innerIter(outerIter);
// move to the next position
innerIter.next();
for (; innerIter.valid(); innerIter.next()) {
modifyTieValue(outerActor, innerIter.actor(), 1);
}
}
}
}
示例12: egoStatistic
/**
* Returns the statistic corresponding to the given ego with respect to the
* given values of the behavior variable.
*/
double SimilarityEffect::egoStatistic(int ego,
double * currentValues)
{
const Network * pNetwork = this->pNetwork();
double statistic = 0;
int neighborCount = 0;
for (IncidentTieIterator iter = pNetwork->outTies(ego);
iter.valid();
iter.next())
{
int j = iter.actor();
if (!this->missing(this->period(), j) &&
!this->missing(this->period() + 1, j))
{
double tieStatistic =
this->similarity(currentValues[ego], currentValues[j]);
if (this->lalterPopularity)
{
tieStatistic *= pNetwork->inDegree(j);
}
statistic += tieStatistic;
neighborCount++;
}
}
if (this->laverage && neighborCount > 0)
{
statistic /= neighborCount;
}
if (this->legoPopularity)
{
statistic *= pNetwork->inDegree(ego);
}
return statistic;
}