[Rsiena-commits] r207 - in pkg: RSiena RSienaTest RSienaTest/src RSienaTest/src/model RSienaTest/src/model/effects RSienaTest/src/model/variables

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Mar 21 15:40:32 CET 2012


Author: cgreenan
Date: 2012-03-21 15:40:31 +0100 (Wed, 21 Mar 2012)
New Revision: 207

Modified:
   pkg/RSiena/DESCRIPTION
   pkg/RSiena/changeLog
   pkg/RSienaTest/DESCRIPTION
   pkg/RSienaTest/changeLog
   pkg/RSienaTest/src/model/StatisticCalculator.cpp
   pkg/RSienaTest/src/model/StatisticCalculator.h
   pkg/RSienaTest/src/model/effects/DiffusionRateEffect.cpp
   pkg/RSienaTest/src/model/effects/DiffusionRateEffect.h
   pkg/RSienaTest/src/model/variables/DependentVariable.cpp
   pkg/RSienaTest/src/model/variables/DependentVariable.h
   pkg/RSienaTest/src/siena07internals.cpp
Log:


Modified: pkg/RSiena/DESCRIPTION
===================================================================
--- pkg/RSiena/DESCRIPTION	2012-03-16 15:18:27 UTC (rev 206)
+++ pkg/RSiena/DESCRIPTION	2012-03-21 14:40:31 UTC (rev 207)
@@ -1,8 +1,8 @@
 Package: RSiena
 Type: Package
 Title: Siena - Simulation Investigation for Empirical Network Analysis
-Version: 1.0.12.206
-Date: 2012-03-16
+Version: 1.0.12.207
+Date: 2012-03-21
 Author: Various
 Depends: R (>= 2.10.0)
 Imports: Matrix

Modified: pkg/RSiena/changeLog
===================================================================
--- pkg/RSiena/changeLog	2012-03-16 15:18:27 UTC (rev 206)
+++ pkg/RSiena/changeLog	2012-03-21 14:40:31 UTC (rev 207)
@@ -1,3 +1,12 @@
+2012-03-21 R-forge revision 207 (RSienaTest only)
+	* siena07internals.cpp, DependentVariable.h,
+	DependentVariable.cpp: changed calculation of scores for diffusion
+	rate effects
+	* StatisticCalculator.h, StatisticCalculator.cpp, DependentVariable.h,
+	DependentVariable.cpp, DiffusionRateEffect.h,
+	DiffusionRateEffect.cpp: added a function to calculate value of
+	a type of diffusion rate effect
+
 2012-03-16 R-forge revision 206 (RSienaTest only)
 
 	* R/effects.R, R/effectsDocumentation.R: added a new behavior rate

Modified: pkg/RSienaTest/DESCRIPTION
===================================================================
--- pkg/RSienaTest/DESCRIPTION	2012-03-16 15:18:27 UTC (rev 206)
+++ pkg/RSienaTest/DESCRIPTION	2012-03-21 14:40:31 UTC (rev 207)
@@ -1,8 +1,8 @@
 Package: RSienaTest
 Type: Package
 Title: Siena - Simulation Investigation for Empirical Network Analysis
-Version: 1.0.12.206
-Date: 2012-03-16
+Version: 1.0.12.207
+Date: 2012-03-21
 Author: Various
 Depends: R (>= 2.10.0)
 Imports: Matrix

Modified: pkg/RSienaTest/changeLog
===================================================================
--- pkg/RSienaTest/changeLog	2012-03-16 15:18:27 UTC (rev 206)
+++ pkg/RSienaTest/changeLog	2012-03-21 14:40:31 UTC (rev 207)
@@ -1,3 +1,12 @@
+2012-03-21 R-forge revision 207 (RSienaTest only)
+	* siena07internals.cpp, DependentVariable.h,
+	DependentVariable.cpp: changed calculation of scores for diffusion
+	rate effects
+	* StatisticCalculator.h, StatisticCalculator.cpp, DependentVariable.h,
+	DependentVariable.cpp, DiffusionRateEffect.h,
+	DiffusionRateEffect.cpp: added a function to calculate value of
+	a type of diffusion rate effect
+
 2012-03-16 R-forge revision 206 (RSienaTest only)
 
 	* R/effects.R, R/effectsDocumentation.R: added a new behavior rate

Modified: pkg/RSienaTest/src/model/StatisticCalculator.cpp
===================================================================
--- pkg/RSienaTest/src/model/StatisticCalculator.cpp	2012-03-16 15:18:27 UTC (rev 206)
+++ pkg/RSienaTest/src/model/StatisticCalculator.cpp	2012-03-21 14:40:31 UTC (rev 207)
@@ -1119,210 +1119,170 @@
 		        pNetworkData(interactionName);
 		    const Network * pStructural =
 		        pNetworkData->pNetworkLessMissingStart(this->lperiod);
-
-		    double statistic = 0;
-		    for (int i = 0; i < pBehaviorData->n(); i++)
-		    {
-		        if (effectName == "avExposure")
+			double statistic = 0;
+			if (interactionName2 == "")
+			{
+				for (int i = 0; i < pBehaviorData->n(); i++)
 				{
-					double totalAlterValue = 0;
-					double averageAlterValue = 0;
-					if (pStructural->outDegree(i) > 0)
+					if (effectName == "avExposure" ||
+						effectName == "susceptAvIn" ||
+						effectName == "totExposure" ||
+						effectName == "infectIn" ||
+						effectName == "infectOut")
 					{
-						for (IncidentTieIterator iter = pStructural->outTies(i);
-							 iter.valid();
-							 iter.next())
-						{
-							double alterValue = pBehaviorData->
-								value(this->lperiod,iter.actor());
-							totalAlterValue += alterValue;
-						}
-						averageAlterValue = totalAlterValue /
-							pStructural->outDegree(i);
+						statistic +=
+							this->calculateDiffusionRateEffect(pBehaviorData,
+								pStructural, i, effectName) *
+							difference[i];
 					}
-
-					statistic += averageAlterValue *
-						difference[i];
+					else
+					{
+						throw domain_error("Unexpected rate effect " +
+							effectName);
+					}
 				}
-				else if (effectName == "susceptAvIn")
-				{
-					double totalAlterValue = 0;
-					double averageAlterValue = 0;
-					if (pStructural->outDegree(i) > 0)
-				    {
-						for (IncidentTieIterator iter = pStructural->outTies(i);
-							 iter.valid();
-							 iter.next())
-						{
-							double alterValue = pBehaviorData->
-								value(this->lperiod,iter.actor());
-							totalAlterValue += alterValue;
-						}
-						averageAlterValue = totalAlterValue /
-							pStructural->outDegree(i);
-				    }
+			}
+			else
+			{
+				ConstantCovariate * pConstantCovariate =
+					this->lpData->pConstantCovariate(interactionName2);
+				ChangingCovariate * pChangingCovariate =
+					this->lpData->pChangingCovariate(interactionName2);
 
-					statistic += averageAlterValue * pStructural->inDegree(i) *
-						difference[i];
-				}
-				else if (effectName == "totExposure")
+				for (int i = 0; i < pBehaviorData->n(); i++)
 				{
-					double totalAlterValue = 0;
-					double averageAlterValue = 0;
-					if (pStructural->outDegree(i) > 0)
-				    {
-						for (IncidentTieIterator iter = pStructural->outTies(i);
-							 iter.valid();
-							 iter.next())
-						{
-							double alterValue = pBehaviorData->
-								value(this->lperiod,iter.actor());
-							totalAlterValue += alterValue;
-						}
-						averageAlterValue = totalAlterValue;
-				    }
-
-					statistic += averageAlterValue *
-						difference[i];
-				}
-				else if (effectName == "susceptAvCovar")
-				{
-					ConstantCovariate * pConstantCovariate =
-						this->lpData->pConstantCovariate(interactionName2);
-					ChangingCovariate * pChangingCovariate =
-						this->lpData->pChangingCovariate(interactionName2);
-					double totalAlterValue = 0;
-					double averageAlterValue = 0;
-					if (pStructural->outDegree(i) > 0)
+					if (effectName == "susceptAvCovar" ||
+						effectName == "infectCovar")
 					{
-					    for (IncidentTieIterator iter = pStructural->outTies(i);
-							 iter.valid();
-							 iter.next())
-						{
-							double alterValue = pBehaviorData->
-								value(this->lperiod,iter.actor());
-							totalAlterValue += alterValue;
-						}
-						averageAlterValue = totalAlterValue /
-							pStructural->outDegree(i);
-					}
-					if (pConstantCovariate)
-					{
-					    statistic += averageAlterValue *
-							pConstantCovariate->value(i) *
-					        difference[i];
-					}
-					else if (pChangingCovariate)
-					{
-					    statistic += averageAlterValue *
-							pChangingCovariate->value(i,this->lperiod) *
+						statistic +=
+							this->calculateDiffusionRateEffect(pBehaviorData,
+								pStructural,
+								pConstantCovariate,
+								pChangingCovariate, i, effectName) *
 							difference[i];
 					}
 					else
 					{
-						throw logic_error(
-							"No individual covariate named '" +
-							interactionName2 +
-							"'.");
+						throw domain_error("Unexpected rate effect " +
+							effectName);
 					}
 				}
-				else if (effectName == "infectIn")
-				{
-					double totalAlterValue = 0;
-					double averageAlterValue = 0;
-					if (pStructural->outDegree(i) > 0)
-				    {
-						for (IncidentTieIterator iter = pStructural->outTies(i);
-							 iter.valid();
-							 iter.next())
-						{
-							double alterValue = pBehaviorData->
-								value(this->lperiod,iter.actor()) *
-								pStructural->inDegree(iter.actor());
-							totalAlterValue += alterValue;
-						}
-						averageAlterValue = totalAlterValue;
-				    }
+			}
+			this->lstatistics[pInfo] = statistic;
+		}
+	}
 
-					statistic += averageAlterValue *
-					    difference[i];
-				}
-				else if (effectName == "infectOut")
-				{
-					double totalAlterValue = 0;
-					double averageAlterValue = 0;
-					if (pStructural->outDegree(i) > 0)
-				    {
-						for (IncidentTieIterator iter = pStructural->outTies(i);
-							 iter.valid();
-							 iter.next())
-						{
-							double alterValue = pBehaviorData->
-								value(this->lperiod,iter.actor()) *
-								pStructural->outDegree(iter.actor());
-							totalAlterValue += alterValue;
-						}
-						averageAlterValue = totalAlterValue;
-				    }
+	delete[] difference;
+	delete[] currentValues;
+}
 
-					statistic += averageAlterValue *
-						difference[i];
-				}
-				else if (effectName == "infectCovar")
-				{
-					ConstantCovariate * pConstantCovariate =
-						this->lpData->pConstantCovariate(interactionName2);
-					ChangingCovariate * pChangingCovariate =
-						this->lpData->pChangingCovariate(interactionName2);
-					double totalAlterValue = 0;
-					double averageAlterValue = 0;
-					if (pStructural->outDegree(i) > 0)
-					{
-					    for (IncidentTieIterator iter = pStructural->outTies(i);
-							 iter.valid();
-							 iter.next())
-						{
-							double alterValue = pBehaviorData->
-								value(this->lperiod,iter.actor());
+/**
+ * Calculates the value of the diffusion rate effect for the given actor.
+ */
+double StatisticCalculator::calculateDiffusionRateEffect(
+	BehaviorLongitudinalData * pBehaviorData, const Network * pStructural,
+	int i, string effectName)
+{
+	double totalAlterValue = 0;
+	double response = 1;
+	if (pStructural->outDegree(i) > 0)
+	{
+		if (effectName == "avExposure")
+		{
+			response /= double(pStructural->outDegree(i));
+		}
+		else if (effectName == "susceptAvIn")
+		{
+			response = double(pStructural->inDegree(i)) /
+				double(pStructural->outDegree(i));
+		}
 
-							if (pConstantCovariate)
-							{
-								alterValue *= pConstantCovariate->
-									value(iter.actor());
-							}
-							else if (pChangingCovariate)
-							{
-								alterValue *= pChangingCovariate->
-									value(iter.actor(), this->lperiod);
-							}
-							else
-							{
-								throw logic_error(
-									"No individual covariate named '" +
-									interactionName2 +
-									"'.");
-							}
-							totalAlterValue += alterValue;
-						}
-						averageAlterValue = totalAlterValue;
-					}
+		for (IncidentTieIterator iter = pStructural->outTies(i);
+			 iter.valid();
+			 iter.next())
+		{
+			double alterValue = pBehaviorData->
+				value(this->lperiod,iter.actor());
 
-					statistic += averageAlterValue *
-						difference[i];
-				}
+			if (effectName == "infectIn")
+			{
+				alterValue *= pStructural->inDegree(iter.actor());
+			}
+			else if (effectName == "infectOut")
+			{
+				alterValue *= pStructural->outDegree(iter.actor());
+			}
 
+			totalAlterValue += alterValue;
+		}
+		totalAlterValue *= response;
+	}
+	return totalAlterValue;
+}
+/**
+ * Calculates the value of the covariate dependent diffusion rate effect for
+ * the given actor.
+ */
+double StatisticCalculator::calculateDiffusionRateEffect(
+	BehaviorLongitudinalData * pBehaviorData, const Network * pStructural,
+	const ConstantCovariate * pConstantCovariate,
+	const ChangingCovariate * pChangingCovariate,
+	int i, string effectName)
+{
+	double totalAlterValue = 0;
+	double response = 1;
+	if (pStructural->outDegree(i) > 0)
+	{
+		if (effectName == "susceptAvCovar")
+		{
+			if (pConstantCovariate)
+			{
+				response = pConstantCovariate->value(i);
+			}
+			else if (pChangingCovariate)
+			{
+				response = pChangingCovariate->value(i, this->lperiod);
+			}
+			else
+			{
+				throw logic_error(
+					"No individual covariate.");
+			}
+			response /= double(pStructural->outDegree(i));
+		}
+
+		for (IncidentTieIterator iter = pStructural->outTies(i);
+			 iter.valid();
+			 iter.next())
+		{
+			double alterValue = pBehaviorData->
+				value(this->lperiod,iter.actor());
+
+			if (effectName == "infectCovar")
+			{
+				if (pConstantCovariate)
+				{
+					alterValue *= pConstantCovariate->value(iter.actor());
+				}
+				else if (pChangingCovariate)
+				{
+					alterValue *= pChangingCovariate->value(iter.actor(),
+						this->lperiod);
+				}
 				else
 				{
-				    throw domain_error("Unexpected rate effect " + effectName);
+					throw logic_error(
+						"No individual covariate.");
 				}
+
 			}
 
-			this->lstatistics[pInfo] = statistic;
+			totalAlterValue += alterValue;
 		}
+		totalAlterValue *= response;
 	}
-
-	delete[] difference;
-	delete[] currentValues;
+	return totalAlterValue;
 }
 
+
 }

Modified: pkg/RSienaTest/src/model/StatisticCalculator.h
===================================================================
--- pkg/RSienaTest/src/model/StatisticCalculator.h	2012-03-16 15:18:27 UTC (rev 206)
+++ pkg/RSienaTest/src/model/StatisticCalculator.h	2012-03-21 14:40:31 UTC (rev 207)
@@ -32,8 +32,9 @@
 class BehaviorLongitudinalData;
 class Network;
 class EffectFactory;
+class ConstantCovariate;
+class ChangingCovariate;
 
-
 // ----------------------------------------------------------------------------
 // Section: StatisticCalculator class
 // ----------------------------------------------------------------------------
@@ -77,6 +78,16 @@
 	void calculateBehaviorStatistics(BehaviorLongitudinalData * pBehaviorData);
 	void calculateBehaviorRateStatistics(BehaviorLongitudinalData * pBehaviorData);
 
+	// Functions to calculate value of diffusion rate effect
+	double calculateDiffusionRateEffect(BehaviorLongitudinalData *
+		pBehaviorData, const Network * pStructural, int i,
+		string effectName);
+	double calculateDiffusionRateEffect(BehaviorLongitudinalData *
+		pBehaviorData, const Network * pStructural,
+	const ConstantCovariate * pConstantCovariate,
+	const ChangingCovariate * pChangingCovariate,
+	int i, string effectName);
+
 	// The data to be used for calculating the statistics
 	const Data * lpData;
 

Modified: pkg/RSienaTest/src/model/effects/DiffusionRateEffect.cpp
===================================================================
--- pkg/RSienaTest/src/model/effects/DiffusionRateEffect.cpp	2012-03-16 15:18:27 UTC (rev 206)
+++ pkg/RSienaTest/src/model/effects/DiffusionRateEffect.cpp	2012-03-21 14:40:31 UTC (rev 207)
@@ -10,6 +10,7 @@
  *****************************************************************************/
 
 #include <cmath>
+#include <cstring>
 #include "DiffusionRateEffect.h"
 #include "utils/Utils.h"
 #include "network/OneModeNetwork.h"
@@ -28,65 +29,44 @@
  * Constructor.
  * @param[in] pVariable the network variable this effect depends on
  * @param[in] pBehaviorVariable the behavior variable this effect depends on
- * @param[in] type the type of this effect
  * @param[in] parameter the statistical parameter of this effect
  */
 
 DiffusionRateEffect::DiffusionRateEffect(const NetworkVariable * pVariable,
 	const BehaviorVariable * pBehaviorVariable,
-	DiffusionRateEffectType type,
+	string effectName,
 	double parameter)
 {
 	this->lpVariable = pVariable;
 	this->lpBehaviorVariable = pBehaviorVariable;
-	this->ltype = type;
-
-	double possibleDegreeNumer = 1;
+	this->leffectName = effectName;
+	double possibleDegreeNumer = this->lpBehaviorVariable->range() *
+		max(this->lpVariable->n(),
+			this->lpVariable->m());
 	double possibleDegreeDenom = 1;
 
-	if (this->ltype == AVERAGE_EXPOSURE_RATE)
+	if (effectName == "avExposure")
 	{
-		possibleDegreeNumer = (this->lpBehaviorVariable->range()) *
-			max(this->lpVariable->n(),
-				this->lpVariable->m());
-		possibleDegreeDenom = max(this->lpVariable->n(),
+   		possibleDegreeDenom = max(this->lpVariable->n(),
 			this->lpVariable->m());
 	}
-	if (this->ltype == SUSCEPT_AVERAGE_INDEGREE_RATE)
+	if (effectName == "susceptAvIn")
 	{
-		possibleDegreeNumer = (this->lpBehaviorVariable->range()) *
-			max(this->lpVariable->n(),
-				this->lpVariable->m()) *
-			max(this->lpVariable->n(),
-				this->lpVariable->m());
+		possibleDegreeNumer *= max(this->lpVariable->n(),
+			this->lpVariable->m());
 		possibleDegreeDenom = max(this->lpVariable->n(),
 			this->lpVariable->m());
 	}
-	if (this->ltype == TOTAL_EXPOSURE_RATE)
+	if (effectName == "infectIn")
 	{
-		possibleDegreeNumer = (this->lpBehaviorVariable->range()) *
-			max(this->lpVariable->n(),
-				this->lpVariable->m());
-		possibleDegreeDenom = 1;
+		possibleDegreeNumer *= max(this->lpVariable->n(),
+			this->lpVariable->m());
 	}
-	if (this->ltype == INFECTION_INDEGREE_RATE)
+	if (effectName == "infectOut")
 	{
-		possibleDegreeNumer = (this->lpBehaviorVariable->range()) *
-			max(this->lpVariable->n(),
-				this->lpVariable->m()) *
-			max(this->lpVariable->n(),
-				this->lpVariable->m());
-		possibleDegreeDenom = 1;
+	   	possibleDegreeNumer *= max(this->lpVariable->n(),
+			this->lpVariable->m());
 	}
-	if (this->ltype == INFECTION_OUTDEGREE_RATE)
-	{
-	   	possibleDegreeNumer = (this->lpBehaviorVariable->range()) *
-			max(this->lpVariable->n(),
-				this->lpVariable->m()) *
-			max(this->lpVariable->n(),
-				this->lpVariable->m());
-		possibleDegreeDenom = 1;
-	}
 	this->lpTable = new DiffusionEffectValueTable(possibleDegreeNumer,
 		possibleDegreeDenom);
 	this->lpTable->parameter(parameter);
@@ -96,19 +76,19 @@
 	const BehaviorVariable * pBehaviorVariable,
 	const ConstantCovariate * pConstantCovariate,
 	const ChangingCovariate * pChangingCovariate,
-	DiffusionRateEffectType type,
+	string effectName,
 	double parameter)
 {
 	this->lpVariable = pVariable;
 	this->lpBehaviorVariable = pBehaviorVariable;
 	this->lpChangingCovariate = pChangingCovariate;
 	this->lpConstantCovariate = pConstantCovariate;
-	this->ltype = type;
+	this->leffectName = effectName;
 
 	double possibleDegreeNumer = 1;
 	double possibleDegreeDenom = 1;
 
-	if (this->ltype == SUSCEPT_AVERAGE_COVARIATE_RATE)
+	if (effectName == "susceptAvCovar")
 	{
 		possibleDegreeNumer = (this->lpBehaviorVariable->range()) *
 			max(this->lpVariable->n(),
@@ -116,11 +96,7 @@
 		possibleDegreeDenom = max(this->lpVariable->n(),
 			this->lpVariable->m());
 	}
-	if (this->ltype == INFECTION_COVARIATE_RATE)
-	{
-		possibleDegreeNumer = 1;
-		possibleDegreeDenom = 1;
-	}
+
 	this->lpTable = new DiffusionEffectValueTable(possibleDegreeNumer,
 		possibleDegreeDenom);
 	this->lpTable->parameter(parameter);
@@ -135,221 +111,131 @@
 	this->lpTable = 0;
 }
 
-
 /**
- * Returns the contribution of this effect for the given actor.
+ * Returns the value of a proximity measure effect, a type of diffusion rate
+ * effect.
  */
-double DiffusionRateEffect::value(int i, int period)
+double DiffusionRateEffect::proximityValue(Network * pNetwork, int i,
+	int egoNumer, int egoDenom)
 {
-	Network * pNetwork = this->lpVariable->pNetwork();
-	switch (this->ltype)
+	int totalAlterValue = 0;
+	if (pNetwork->outDegree(i) > 0)
 	{
-		case AVERAGE_EXPOSURE_RATE:
+		for (IncidentTieIterator iter = pNetwork->outTies(i);
+			 iter.valid();
+			 iter.next())
 		{
-			int totalAlterValue = 0;
-			if (pNetwork->outDegree(i) > 0)
-			{
-				for (IncidentTieIterator iter = pNetwork->outTies(i);
-					 iter.valid();
-					 iter.next())
-				{
-					double alterValue = this->lpBehaviorVariable->
-						value(iter.actor());
-					totalAlterValue += alterValue;
-				}
-			}
+			double alterValue = this->lpBehaviorVariable->
+				value(iter.actor());
 
-			if (totalAlterValue==0)
+			if (this->leffectName == "infectIn")
 			{
-				return 1;
+				alterValue *= pNetwork->inDegree(iter.actor());
 			}
-			if (totalAlterValue>0)
+			else if (this->leffectName == "infectOut")
 			{
-				return this->lpTable->value(totalAlterValue,max(1,
-						pNetwork->outDegree(i)));
+				alterValue *= pNetwork->outDegree(iter.actor());
 			}
+
+			totalAlterValue += alterValue;
 		}
-		case SUSCEPT_AVERAGE_INDEGREE_RATE:
-		{
-			int totalAlterValue = 0;
-			if (pNetwork->outDegree(i) > 0)
-			{
-				for (IncidentTieIterator iter = pNetwork->outTies(i);
-					 iter.valid();
-					 iter.next())
-				{
-					double alterValue = this->lpBehaviorVariable->
-						value(iter.actor());
-					totalAlterValue += alterValue;
-				}
-			}
+	}
 
-			totalAlterValue *= pNetwork->inDegree(i);
+	if (totalAlterValue==0)
+	{
+		return 1;
+	}
+	else
+	{
+		return this->lpTable->value(egoNumer * totalAlterValue, egoDenom);
+	}
+}
 
-			if (totalAlterValue==0)
-			{
-			    return 1;
-			}
-			else
-			{
-			    return this->lpTable->value(totalAlterValue,max(1,
-						pNetwork->outDegree(i)));
-			}
+/**
+ * Returns the contribution of this effect for the given actor.
+ */
+
+double DiffusionRateEffect::value(int i, int period)
+{
+	Network * pNetwork = this->lpVariable->pNetwork();
+
+	if (this->leffectName == "avExposure")
+	{
+		return this->proximityValue(pNetwork, i, 1, max(1,
+				pNetwork->outDegree(i)));
+	}
+	else if (this->leffectName == "susceptAvIn")
+	{
+		return this->proximityValue(pNetwork, i, pNetwork->inDegree(i),
+			max(1, pNetwork->outDegree(i)));
+	}
+	else if (this->leffectName == "totExposure" ||
+		this->leffectName == "infectIn" ||
+		this->leffectName == "infectOut")
+	{
+		return this->proximityValue(pNetwork, i, 1, 1);
+	}
+	else if (this->leffectName == "susceptAvCovar")
+	{
+		if (this->lpConstantCovariate)
+		{
+			return pow(this->proximityValue(pNetwork, i, 1, max(1,
+						pNetwork->outDegree(i))),
+				this->lpConstantCovariate->value(i));
 		}
-		case TOTAL_EXPOSURE_RATE:
+		else if (this->lpChangingCovariate)
 		{
-			int totalAlterValue = 0;
-			if (pNetwork->outDegree(i) > 0)
-			{
-				for (IncidentTieIterator iter = pNetwork->outTies(i);
-					 iter.valid();
-					 iter.next())
-				{
-					double alterValue = this->lpBehaviorVariable->
-						value(iter.actor());
-					totalAlterValue += alterValue;
-				}
-			}
-
-			if (totalAlterValue==0)
-			{
-			    return 1;
-			}
-			else
-			{
-			    return this->lpTable->value(totalAlterValue, 1);
-			}
+			return pow(this->proximityValue(pNetwork, i, 1, max(1,
+						pNetwork->outDegree(i))),
+				this->lpChangingCovariate->value(i,period));
 		}
-		case SUSCEPT_AVERAGE_COVARIATE_RATE:
+		else
+			throw logic_error(
+				"No individual covariate found.");
+	}
+	else if (this->leffectName == "infectCovar")
+	{
+		int totalAlterValue = 0;
+		if (pNetwork->outDegree(i) > 0)
 		{
-			int totalAlterValue = 0;
-			if (pNetwork->outDegree(i) > 0)
+			for (IncidentTieIterator iter = pNetwork->outTies(i);
+				 iter.valid();
+				 iter.next())
 			{
-				for (IncidentTieIterator iter = pNetwork->outTies(i);
-					 iter.valid();
-					 iter.next())
-				{
-					double alterValue = this->lpBehaviorVariable->
-						value(iter.actor());
-					totalAlterValue += alterValue;
-				}
-			}
+				double alterValue = this->lpBehaviorVariable->
+					value(iter.actor());
 
-			if (totalAlterValue==0)
-			{
-			    return 1;
-			}
-			else
-			{
 				if (this->lpConstantCovariate)
 				{
-					return pow(this->lpTable->value(totalAlterValue,max(1,
-								pNetwork->outDegree(i))),
-						this->lpConstantCovariate->value(i));
+					alterValue *=
+						this->lpConstantCovariate->value(iter.actor());
 				}
 				else if (this->lpChangingCovariate)
 				{
-					return pow(this->lpTable->value(totalAlterValue,max(1,
-								pNetwork->outDegree(i))),
-						this->lpChangingCovariate->value(i,period));
+					alterValue *=
+						this->lpChangingCovariate->value(iter.actor(),
+							period);
 				}
-			   	else
+				else
 					throw logic_error(
 						"No individual covariate found.");
-			}
-		}
-		case INFECTION_INDEGREE_RATE:
-		{
-			int totalAlterValue = 0;
-			if (pNetwork->outDegree(i) > 0)
-			{
-				for (IncidentTieIterator iter = pNetwork->outTies(i);
-					 iter.valid();
-					 iter.next())
-				{
-					double alterValue = this->lpBehaviorVariable->
-						value(iter.actor()) *
-						pNetwork->inDegree(iter.actor());
-					totalAlterValue += alterValue;
-				}
-			}
 
-			if (totalAlterValue==0)
-			{
-			    return 1;
+				totalAlterValue += alterValue;
 			}
-			else
-			{
-			    return this->lpTable->value(totalAlterValue,1);
-			}
 		}
-		case INFECTION_OUTDEGREE_RATE:
+		if (totalAlterValue==0)
 		{
-			int totalAlterValue = 0;
-			if (pNetwork->outDegree(i) > 0)
-			{
-				for (IncidentTieIterator iter = pNetwork->outTies(i);
-					 iter.valid();
-					 iter.next())
-				{
-					double alterValue = this->lpBehaviorVariable->
-						value(iter.actor()) *
-						pNetwork->outDegree(iter.actor());
-					totalAlterValue += alterValue;
-				}
-			}
-
-			if (totalAlterValue==0)
-			{
-			    return 1;
-			}
-			else
-			{
-				return this->lpTable->value(totalAlterValue,1);
-			}
+			return 1;
 		}
-		case INFECTION_COVARIATE_RATE:
+		else
 		{
-			int totalAlterValue = 0;
-			if (pNetwork->outDegree(i) > 0)
-			{
-				for (IncidentTieIterator iter = pNetwork->outTies(i);
-					 iter.valid();
-					 iter.next())
-				{
-					double alterValue = this->lpBehaviorVariable->
-						value(iter.actor());
-
-					if (this->lpConstantCovariate)
-					{
-						alterValue *=
-							this->lpConstantCovariate->value(iter.actor());
-					}
-					else if (this->lpChangingCovariate)
-					{
-						alterValue *=
-							this->lpChangingCovariate->value(iter.actor(),
-								period);
-					}
-					else
-						throw logic_error(
-							"No individual covariate found.");
-
-					totalAlterValue += alterValue;
-				}
-			}
-			if (totalAlterValue==0)
-			{
-			    return 1;
-			}
-			else
-			{
-			    return pow(this->lpTable->value(1,1), totalAlterValue);
-			}
+			return pow(this->lpTable->value(1,1), totalAlterValue);
 		}
 	}
-
-	throw new logic_error("Unexpected diffusion rate effect type");
+	else
+	{
+		throw new logic_error("Unexpected diffusion rate effect type");
+	}
 }
 /**
  * Stores the parameter for the diffusion rate effect.

Modified: pkg/RSienaTest/src/model/effects/DiffusionRateEffect.h
===================================================================
--- pkg/RSienaTest/src/model/effects/DiffusionRateEffect.h	2012-03-16 15:18:27 UTC (rev 206)
+++ pkg/RSienaTest/src/model/effects/DiffusionRateEffect.h	2012-03-21 14:40:31 UTC (rev 207)
@@ -12,28 +12,13 @@
 #ifndef DIFFUSIONRATEEFFECT_H_
 #define DIFFUSIONRATEEFFECT_H_
 
-namespace siena
-{
+#include <string>
 
-// ----------------------------------------------------------------------------
-// Section: Enums
-// ----------------------------------------------------------------------------
+using namespace std;
 
-/**
- * Available types of diffusion rate effects.
- */
-enum DiffusionRateEffectType
+namespace siena
 {
-    AVERAGE_EXPOSURE_RATE,
-    SUSCEPT_AVERAGE_INDEGREE_RATE,
-	TOTAL_EXPOSURE_RATE,
-    SUSCEPT_AVERAGE_COVARIATE_RATE,
-    INFECTION_INDEGREE_RATE,
-    INFECTION_OUTDEGREE_RATE,
-    INFECTION_COVARIATE_RATE
-};
 
-
 // ----------------------------------------------------------------------------
 // Section: Forward declarations
 // ----------------------------------------------------------------------------
@@ -43,6 +28,7 @@
 class DiffusionEffectValueTable;
 class ConstantCovariate;
 class ChangingCovariate;
+class Network;
 
 // ----------------------------------------------------------------------------
 // Section: Class definition
@@ -59,18 +45,19 @@
 public:
 	DiffusionRateEffect(const NetworkVariable * pVariable,
 		const BehaviorVariable * pBehaviorVariable,
-		DiffusionRateEffectType type,
+		string effectName,
 		double parameter);
 	DiffusionRateEffect(const NetworkVariable * pVariable,
 		const BehaviorVariable * pBehaviorVariable,
 		const ConstantCovariate * pCovariate,
 		const ChangingCovariate * pChangingCovariate,
-		DiffusionRateEffectType type,
+		string effectName,
 		double parameter);
 
 
 	virtual ~DiffusionRateEffect();
-
+	double proximityValue(Network * pNetwork, int i, int egoNumer,
+		int egoDenom);
 	double value(int i, int period);
 	void parameter(double parameterValue);
 	double parameter() const;
@@ -86,14 +73,12 @@
 	const ConstantCovariate * lpConstantCovariate;
 	const ChangingCovariate * lpChangingCovariate;
 
-	// The type of the effect
-	DiffusionRateEffectType ltype;
-
 	// A table for efficient calculation of contributions. If two actors have
 	// the same effect value, then the table ensures that we don't
 	// calculate the same contribution twice.
 
 	DiffusionEffectValueTable * lpTable;
+	string leffectName;
 
 };
 

Modified: pkg/RSienaTest/src/model/variables/DependentVariable.cpp
===================================================================
--- pkg/RSienaTest/src/model/variables/DependentVariable.cpp	2012-03-16 15:18:27 UTC (rev 206)
+++ pkg/RSienaTest/src/model/variables/DependentVariable.cpp	2012-03-21 14:40:31 UTC (rev 207)
@@ -10,6 +10,7 @@
  *****************************************************************************/
 #include <R_ext/Print.h>
 #include <cmath>
+#include <cstring>
 #include <stdexcept>
 
 #include "BehaviorVariable.h"
@@ -282,20 +283,12 @@
 		}
 		else if (rateType == "diffusion")
 		{
-
 			const NetworkVariable * pVariable;
 			const BehaviorVariable * pBehaviorVariable =
 				dynamic_cast<const BehaviorVariable *>(this);
 
-			if (interactionName == "")
-			{
-				pVariable = dynamic_cast<const NetworkVariable *>(this);
-			}
-			else
-			{
-				pVariable = dynamic_cast<const NetworkVariable *>(
-					this->lpSimulation->pVariable(interactionName));
-			}
+			pVariable = dynamic_cast<const NetworkVariable *>(
+				this->lpSimulation->pVariable(interactionName));
 
 			if (!pVariable)
 			{
@@ -308,7 +301,11 @@
 			}
 			if (interactionName2 == "")
 			{
-				if (effectName == "avExposure")
+				if (effectName == "avExposure" ||
+					effectName == "totExposure" ||
+					effectName == "susceptAvIn" ||
+					effectName == "infectIn" ||
+					effectName == "infectOut")
 				{
 					if (this->lpActorSet != pVariable->pSenders())
 					{
@@ -318,71 +315,9 @@
 					this->ldiffusionRateEffects.push_back(
 						new DiffusionRateEffect(pVariable,
 							pBehaviorVariable,
-							AVERAGE_EXPOSURE_RATE,
+							effectName,
 							parameter));
-					this->laverageExposureScores[pVariable] = 0;
-					this->laverageExposureSumTerm[pVariable] = 0;
 				}
-				else if (effectName == "susceptAvIn")
-				{
-					if (this->lpActorSet != pVariable->pSenders())
-					{
-						throw std::invalid_argument("Mismatch of actor sets");
-					}
-
-					this->ldiffusionRateEffects.push_back(
-						new DiffusionRateEffect(pVariable,
-							pBehaviorVariable,
-							SUSCEPT_AVERAGE_INDEGREE_RATE,
-							parameter));
-					this->lsusceptAverageIndegreeScores[pVariable] = 0;
-					this->lsusceptAverageIndegreeSumTerm[pVariable] = 0;
-				}
-				else if (effectName == "totExposure")
-				{
-					if (this->lpActorSet != pVariable->pSenders())
-					{
-						throw std::invalid_argument("Mismatch of actor sets");
-					}
-
-					this->ldiffusionRateEffects.push_back(
-						new DiffusionRateEffect(pVariable,
-							pBehaviorVariable,
-							TOTAL_EXPOSURE_RATE,
-							parameter));
-					this->ltotalExposureScores[pVariable] = 0;
-					this->ltotalExposureSumTerm[pVariable] = 0;
-				}
-				else if (effectName == "infectIn")
-				{
-					if (this->lpActorSet != pVariable->pSenders())
-					{
-						throw std::invalid_argument("Mismatch of actor sets");
-					}
-
-					this->ldiffusionRateEffects.push_back(
-						new DiffusionRateEffect(pVariable,
-							pBehaviorVariable,
-							INFECTION_INDEGREE_RATE,
-							parameter));
-					this->linfectionIndegreeScores[pVariable] = 0;
-					this->linfectionIndegreeSumTerm[pVariable] = 0;
-				}
-				else if (effectName == "infectOut")
-				{
-					if (this->lpActorSet != pVariable->pSenders())
-					{
-						throw std::invalid_argument("Mismatch of actor sets");
-					}
-
-					this->ldiffusionRateEffects.push_back(
-						new DiffusionRateEffect(pVariable,
-							pBehaviorVariable,
-							INFECTION_OUTDEGREE_RATE,
-							parameter));
-					this->linfectionOutdegreeScores[pVariable] = 0;
-					this->linfectionOutdegreeSumTerm[pVariable] = 0;
-				}
 				else
 				{
 					throw domain_error("Unexpected rate effect " + effectName);
@@ -393,11 +328,14 @@
 				// Covariate-dependent diffusion rate effects
 
 		   		const ConstantCovariate * pConstantCovariate =
-					pData->pConstantCovariate(interactionName2);
+					this->lpSimulation->pData()->
+					pConstantCovariate(interactionName2);
 				const ChangingCovariate * pChangingCovariate =
-					pData->pChangingCovariate(interactionName2);
+					this->lpSimulation->pData()->
+					pChangingCovariate(interactionName2);
 
-				if (effectName == "susceptAvCovar")
+				if (effectName == "susceptAvCovar" ||
+					effectName == "infectCovar")
 				{
 					if (this->lpActorSet != pVariable->pSenders())
 					{
@@ -409,44 +347,14 @@
 							pBehaviorVariable,
 							pConstantCovariate,
 							pChangingCovariate,
-							SUSCEPT_AVERAGE_COVARIATE_RATE,
+							effectName,
 							parameter));
-					this->lsusceptAverageCovariateScores[pVariable] = 0;
-					this->lsusceptAverageCovariateSumTerm[pVariable] = 0;
-					this->lsusceptAverageConstantCovariate
-						[pVariable] = pConstantCovariate;
-					this->lsusceptAverageChangingCovariate
-						[pVariable] = pChangingCovariate;
-
 				}
-				else if (effectName == "infectCovar")
-				{
-					if (this->lpActorSet != pVariable->pSenders())
-					{
-						throw std::invalid_argument("Mismatch of actor sets");
-					}
-
-					this->ldiffusionRateEffects.push_back(
-						new DiffusionRateEffect(pVariable,
-							pBehaviorVariable,
-							pConstantCovariate,
-							pChangingCovariate,
-							INFECTION_COVARIATE_RATE,
-							parameter));
-					this->linfectionCovariateScores[pVariable] = 0;
-					this->linfectionCovariateSumTerm[pVariable] = 0;
-					this->linfectionConstantCovariate
-						[pVariable] = pConstantCovariate;
-					this->linfectionChangingCovariate
-						[pVariable] = pChangingCovariate;
-				}
 				else
 				{
 					throw domain_error("Unexpected rate effect " + effectName);
 				}
-
 			}
-
 		}
 
 	}
@@ -1112,283 +1020,90 @@
 
 	// Update scores for diffusion rate parameters
 
[TRUNCATED]

To get the complete diff run:
    svnlook diff /svnroot/rsiena -r 207


More information about the Rsiena-commits mailing list