[Rsiena-commits] r215 - pkg/RSienaTest/src/model/effects

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue May 22 03:25:13 CEST 2012


Author: tomsnijders
Date: 2012-05-22 03:25:12 +0200 (Tue, 22 May 2012)
New Revision: 215

Added:
   pkg/RSienaTest/src/model/effects/SameCovariateTransitiveTripletsEffect.cpp
   pkg/RSienaTest/src/model/effects/SameCovariateTransitiveTripletsEffect.h
   pkg/RSienaTest/src/model/effects/SimilarityTransitiveTripletsEffect.cpp
   pkg/RSienaTest/src/model/effects/SimilarityTransitiveTripletsEffect.h
   pkg/RSienaTest/src/model/effects/TransitiveReciprocatedTripletsEffect.cpp
   pkg/RSienaTest/src/model/effects/TransitiveReciprocatedTripletsEffect.h
Log:
Six files that were forgotten in the previous commit.

Added: pkg/RSienaTest/src/model/effects/SameCovariateTransitiveTripletsEffect.cpp
===================================================================
--- pkg/RSienaTest/src/model/effects/SameCovariateTransitiveTripletsEffect.cpp	                        (rev 0)
+++ pkg/RSienaTest/src/model/effects/SameCovariateTransitiveTripletsEffect.cpp	2012-05-22 01:25:12 UTC (rev 215)
@@ -0,0 +1,98 @@
+/******************************************************************************
+ * SIENA: Simulation Investigation for Empirical Network Analysis
+ *
+ * Web: http://www.stats.ox.ac.uk/~snijders/siena/
+ *
+ * File: SameCovariateTransitiveTripletsEffect.cpp
+ *
+ * Description: This file contains the implementation of the class
+ * SameCovariateTransitiveTripletsEffect.
+ *****************************************************************************/
+#include <cmath>
+
+#include "SameCovariateTransitiveTripletsEffect.h"
+#include "utils/Utils.h"
+#include "network/Network.h"
+#include "network/IncidentTieIterator.h"
+#include "network/CommonNeighborIterator.h"
+#include "network/OneModeNetwork.h"
+#include "network/TieIterator.h"
+#include "model/variables/NetworkVariable.h"
+#include "model/tables/ConfigurationTable.h"
+
+namespace siena
+{
+
+/**
+ * Constructor.
+ */
+
+SameCovariateTransitiveTripletsEffect::SameCovariateTransitiveTripletsEffect(
+									const EffectInfo * pEffectInfo, bool reciprocal) :
+	CovariateDependentNetworkEffect(pEffectInfo)
+{
+// currently not used:
+	{
+		this->lreciprocal = reciprocal;
+	}
+}
+
+/**
+ * Calculates the contribution of a tie flip to the given actor.
+ */
+double SameCovariateTransitiveTripletsEffect::calculateContribution(
+                                              int alter) const
+{
+	// If we are introducing a tie from the ego i to the alter j, then each
+	// two-path from i to j with v_i = v_j contributes one unit;
+   // in addition, each in-star i -> h <- j with v_i = v_h 
+   // also contributes one unit.
+   // This number is not stored in a table and is calculated from scratch.
+
+	int contribution1 = 0;
+	const Network * pNetwork = this->pNetwork();
+
+	if (fabs(this->value(alter) - this->value(this->ego())) < EPSILON)
+	{
+		contribution1 = this->pTwoPathTable()->get(alter);
+	}
+
+	// The following probably can be done more efficiently 
+	// using CommonNeighborIterator.
+	// Iterate over ego's outgoing ties
+	for (IncidentTieIterator iter = pNetwork->outTies(this->ego());
+		iter.valid();
+		iter.next())
+	{
+		// Get the receiver of the outgoing tie.
+		int h = iter.actor();
+		if (fabs(this->value(h) - this->value(this->ego())) < EPSILON &&
+            pNetwork->tieValue(h, alter) >= 1)
+		{
+		 contribution1++ ;
+		}
+	}
+	return contribution1;
+}
+
+
+/**
+ * The contribution of the tie from the implicit ego to the given alter
+ * to the statistic. It is assumed that preprocessEgo(ego) has been
+ * called before.
+ */
+double SameCovariateTransitiveTripletsEffect::tieStatistic(int alter)
+{
+	
+	double statistic = 0;
+
+	if (!this->missing(this->ego()) && !this->missing(alter) &&
+		fabs(this->value(alter) - this->value(this->ego())) < EPSILON)
+	{
+		statistic = this->pTwoPathTable()->get(alter);
+	}
+	
+	return statistic;
+}
+
+}

Added: pkg/RSienaTest/src/model/effects/SameCovariateTransitiveTripletsEffect.h
===================================================================
--- pkg/RSienaTest/src/model/effects/SameCovariateTransitiveTripletsEffect.h	                        (rev 0)
+++ pkg/RSienaTest/src/model/effects/SameCovariateTransitiveTripletsEffect.h	2012-05-22 01:25:12 UTC (rev 215)
@@ -0,0 +1,42 @@
+/******************************************************************************
+ * SIENA: Simulation Investigation for Empirical Network Analysis
+ *
+ * Web: http://www.stats.ox.ac.uk/~snijders/siena/
+ *
+ * File: SameCovariateTransitiveTripletsEffect.h
+ *
+ * Description: This file contains the declaration of the class
+ * SameCovariateTransitiveTripletsEffect.
+ *****************************************************************************/
+
+#ifndef SAMECOVARIATETRANSITIVETRIPLETSEFFECT_H_
+#define SAMECOVARIATETRANSITIVETRIPLETSEFFECT_H_
+
+#include "model/effects/NetworkEffect.h"
+#include "CovariateDependentNetworkEffect.h"
+
+namespace siena
+{
+
+class SameCovariateTransitiveTripletsEffect : 
+                   public CovariateDependentNetworkEffect
+{
+public:
+	SameCovariateTransitiveTripletsEffect(
+                   const EffectInfo * pEffectInfo, bool reciprocal);
+	virtual double calculateContribution(int alter) const;
+
+protected:
+	virtual double tieStatistic(int alter);
+
+private:
+	// Indicates if the reciprocal version of the 
+   // same covariate transitive triplets effect is required;
+   // currently not implemented.
+
+	bool lreciprocal;
+};
+
+}
+
+#endif /*SAMECOVARIATETRANSITIVETRIPLETSEFFECT_H_*/

Added: pkg/RSienaTest/src/model/effects/SimilarityTransitiveTripletsEffect.cpp
===================================================================
--- pkg/RSienaTest/src/model/effects/SimilarityTransitiveTripletsEffect.cpp	                        (rev 0)
+++ pkg/RSienaTest/src/model/effects/SimilarityTransitiveTripletsEffect.cpp	2012-05-22 01:25:12 UTC (rev 215)
@@ -0,0 +1,93 @@
+/******************************************************************************
+ * SIENA: Simulation Investigation for Empirical Network Analysis
+ *
+ * Web: http://www.stats.ox.ac.uk/~snijders/siena/
+ *
+ * File: SimilarityTransitiveTripletsEffect.cpp
+ *
+ * Description: This file contains the implementation of the class
+ * SimilarityTransitiveTripletsEffect.
+ *****************************************************************************/
+
+#include "SimilarityTransitiveTripletsEffect.h"
+#include "network/OneModeNetwork.h"
+#include "network/TieIterator.h"
+#include "model/variables/NetworkVariable.h"
+#include "model/tables/ConfigurationTable.h"
+#include "network/Network.h"
+#include "network/IncidentTieIterator.h"
+#include "network/CommonNeighborIterator.h"
+
+namespace siena
+{
+
+/**
+ * Constructor.
+ */
+SimilarityTransitiveTripletsEffect::SimilarityTransitiveTripletsEffect(
+	const EffectInfo * pEffectInfo,
+	bool reciprocal) : CovariateDependentNetworkEffect(pEffectInfo)
+{
+	// currently not used:
+	{
+		this->lreciprocal = reciprocal;
+	}
+}
+
+/**
+ * Calculates the contribution of a tie flip to the given actor.
+ */
+double SimilarityTransitiveTripletsEffect::calculateContribution(int alter) const
+{
+	// If we are introducing a tie from the ego i to the alter j, then each
+	// two-path from i to j with v_i = v_j contributes the similarity i-j;
+   // in addition, each in-star i -> h <- j also contributes 
+   // the similarity i-h.
+   // This number is not stored in a table and is calculated from scratch.
+
+	double contribution1 = 0;
+	const Network * pNetwork = this->pNetwork();
+
+	{
+		contribution1 = this->similarity(this->ego(), alter) *
+								this->pTwoPathTable()->get(alter);
+	}
+
+
+	// The following probably can be done more efficiently 
+	// using CommonNeighborIterator.
+	// Iterate over ego's outgoing ties
+	for (IncidentTieIterator iter = pNetwork->outTies(this->ego());
+		iter.valid();
+		iter.next())
+	{
+		// Get the receiver of the outgoing tie.
+		int h = iter.actor();
+		if (pNetwork->tieValue(h, alter) >= 1)
+		{
+		 contribution1 = contribution1 + this->similarity(this->ego(), h) ;
+		}
+	}
+
+	return contribution1;
+}
+
+/**
+ * The contribution of the tie from the implicit ego to the given alter
+ * to the statistic. It is assumed that preprocessEgo(ego) has been
+ * called before.
+ */
+double SimilarityTransitiveTripletsEffect::tieStatistic(int alter)
+{
+	double statistic = 0;
+
+	if (!this->missing(this->ego()) && !this->missing(alter))
+	{
+		statistic = this->similarity(this->ego(), alter) *
+						 this->pTwoPathTable()->get(alter);
+	}
+
+	return statistic;
+}
+
+}

Added: pkg/RSienaTest/src/model/effects/SimilarityTransitiveTripletsEffect.h
===================================================================
--- pkg/RSienaTest/src/model/effects/SimilarityTransitiveTripletsEffect.h	                        (rev 0)
+++ pkg/RSienaTest/src/model/effects/SimilarityTransitiveTripletsEffect.h	2012-05-22 01:25:12 UTC (rev 215)
@@ -0,0 +1,44 @@
+/******************************************************************************
+ * SIENA: Simulation Investigation for Empirical Network Analysis
+ *
+ * Web: http://www.stats.ox.ac.uk/~snijders/siena/
+ *
+ * File: SimilarityTransitiveTripletsEffect.h
+ *
+ * Description: This file contains the declaration of the class
+ * SimilarityTransitiveTripletsEffect.
+ *****************************************************************************/
+
+#ifndef SIMILARITYTRANSITIVETRIPLETSEFFECT_H_
+#define SIMILARITYTRANSITIVETRIPLETSEFFECT_H_
+
+#include "model/effects/NetworkEffect.h"
+#include "CovariateDependentNetworkEffect.h"
+
+namespace siena
+{
+
+/**
+ * This class defines the transitive triplets effect for non-symmetric
+ * networks.
+ */
+class SimilarityTransitiveTripletsEffect : public CovariateDependentNetworkEffect
+{
+public:
+	SimilarityTransitiveTripletsEffect(const EffectInfo * pEffectInfo, bool reciprocal);
+
+	virtual double calculateContribution(int alter) const;
+
+protected:
+	virtual double tieStatistic(int alter);
+
+private:
+	// Indicates if the reciprocal version of the similarity transitive 
+	// triplets effect is required; currently not implemented.
+
+	bool lreciprocal;
+};
+
+}
+
+#endif /*SIMILARITYTRANSITIVETRIPLETSEFFECT_H_*/

Added: pkg/RSienaTest/src/model/effects/TransitiveReciprocatedTripletsEffect.cpp
===================================================================
--- pkg/RSienaTest/src/model/effects/TransitiveReciprocatedTripletsEffect.cpp	                        (rev 0)
+++ pkg/RSienaTest/src/model/effects/TransitiveReciprocatedTripletsEffect.cpp	2012-05-22 01:25:12 UTC (rev 215)
@@ -0,0 +1,71 @@
+/******************************************************************************
+ * SIENA: Simulation Investigation for Empirical Network Analysis
+ *
+ * Web: http://www.stats.ox.ac.uk/~snijders/siena/
+ *
+ * File: TransitiveReciprocatedTripletsEffect.cpp
+ *
+ * Description: This file contains the implementation of the class
+ * TransitiveReciprocatedTripletsEffect.
+ *****************************************************************************/
+
+#include "TransitiveReciprocatedTripletsEffect.h"
+#include "network/OneModeNetwork.h"
+#include "network/TieIterator.h"
+#include "network/IncidentTieIterator.h"
+#include "model/variables/NetworkVariable.h"
+#include "model/tables/ConfigurationTable.h"
+
+namespace siena
+{
+
+/**
+ * Constructor.
+ */
+TransitiveReciprocatedTripletsEffect::TransitiveReciprocatedTripletsEffect(
+	const EffectInfo * pEffectInfo) : NetworkEffect(pEffectInfo)
+{
+}
+
+
+/**
+ * Calculates the contribution of a tie flip to the given actor.
+ */
+double TransitiveReciprocatedTripletsEffect::calculateContribution(int alter) const
+{
+	// If we are introducing a tie from the ego i to the alter j, then each
+	// two-path from i to j with an existing tie from j to i 
+   // contributes one unit;
+   // in addition, each configuration i <-> h <- j also contributes one unit;
+   // the number of such configurations is stored in pRBTable.
+
+	double contribution1 = 0;
+
+	if (this->inTieExists(alter))
+	{
+		contribution1 = this->pTwoPathTable()->get(alter);
+	}
+
+	return contribution1 + this->pRBTable()->get(alter);
+}
+
+
+/**
+ * The contribution of the tie from the implicit ego to the given alter
+ * to the statistic. It is assumed that preprocessEgo(ego) has been
+ * called before if there is a tie from alter to ego.
+ */
+double TransitiveReciprocatedTripletsEffect::tieStatistic(int alter)
+{
+
+	int statistic = 0;
+
+	if (this->inTieExists(alter))
+	{
+		statistic = this->pTwoPathTable()->get(alter);
+	}
+
+	return statistic;
+}
+
+}

Added: pkg/RSienaTest/src/model/effects/TransitiveReciprocatedTripletsEffect.h
===================================================================
--- pkg/RSienaTest/src/model/effects/TransitiveReciprocatedTripletsEffect.h	                        (rev 0)
+++ pkg/RSienaTest/src/model/effects/TransitiveReciprocatedTripletsEffect.h	2012-05-22 01:25:12 UTC (rev 215)
@@ -0,0 +1,37 @@
+/******************************************************************************
+ * SIENA: Simulation Investigation for Empirical Network Analysis
+ *
+ * Web: http://www.stats.ox.ac.uk/~snijders/siena/
+ *
+ * File: TransitiveReciprocatedTripletsEffect.h
+ *
+ * Description: This file contains the declaration of the class
+ * TransitiveReciprocatedTripletsEffect.
+ *****************************************************************************/
+
+#ifndef TRANSITIVERECIPROCATEDTRIPLETSEFFECT_H_
+#define TRANSITIVERECIPROCATEDTRIPLETSEFFECT_H_
+
+#include "model/effects/NetworkEffect.h"
+
+namespace siena
+{
+
+/**
+ * This class defines the reciprocated transitive triplets effect for non-symmetric
+ * networks.
+ */
+class TransitiveReciprocatedTripletsEffect : public NetworkEffect
+{
+public:
+	TransitiveReciprocatedTripletsEffect(const EffectInfo * pEffectInfo);
+
+	virtual double calculateContribution(int alter) const;
+
+protected:
+	virtual double tieStatistic(int alter);
+};
+
+}
+
+#endif /*TRANSITIVERECIPROCATEDTRIPLETSEFFECT_H_*/



More information about the Rsiena-commits mailing list