Hello,
I am looking for some help for the following scenario. I have a 2-D integer array(named "Choices") and every element can have one of two integer values: 0 and 1 and I want to sum the array for every value of dimension-1(i.e G). Below is the relevant portion
of my model along with the definitions:
// variable declarations
protected VariableArray<VariableArray<int>, int[][]> Choices;
protected VariableArray<int> History;
protected Variable<int> NumAgents;
//Ranges
G = new Range(NumGames).Named("G");
H = new Range(HistoryLength).Named("H");
S = new Range(NumStrategies).Named("S");
C = new Range(NumAgents).Named("C");
//Model
Choices = Variable.Array(Variable.Array<int>(C), G).Named("Choices");
using (Variable.ForEach(G))
{
History[G] = Variable<int>.Random(HistoryDis);
using (Variable.ForEach(C))
{
Variable<int> Agent = null;
Agent = Variable.Discrete(ADist[History[G], C]).Named("Agent");
Agent.SetValueRange(S);
using (Variable.Switch(Agent))
{
Choices[G][C] = Variable.Discrete(Phi[History[G], Agent]);
}
}
}
Now, I am looking for a piece of infer.Net code that will allow me to do the following: for each "G" I want to sum "Choices" over all values of "C" and If this sum is less than "NumAgents/2" then I want to define a new "Variable<int> Result" whose
value would be 0. i.e.
Using(Variable.ForEach(G))
{
If (sum(Choices[G][*])>NumAgents/2)
Result=0;
else
Result=1;
}
Sorry for the poor pseudo code.I would appreciate any help I can get.Thanks