Constraining a VariableArray RRS feed

  • Question

  • Hello,

    I'm trying to constrain a VariableArray such that the sum of all the elements equals zero. How can I do this in Infer.net? The code I've tried (which ends up constraining all the elements individually to zero) is:

    Variable<double> total = Variable.Observed<double>(0);
    Variable<double> element;
    using (Variable.ForEach(index))
        element = Variable.Copy<double>(variablearray[index]);
        total = total + element;
    Variable.ConstrainEqual(0, total);
    Thanks very much!

    Tuesday, August 26, 2014 9:00 AM


  • Use Variable.Sum on the array.
    • Marked as answer by MarkG87 Tuesday, August 26, 2014 10:18 AM
    Tuesday, August 26, 2014 9:50 AM