locked
Exception: items.Count != indices.Count (Migrated from community.research.microsoft.com) RRS feed

  • Question

  • nbeckman posted on 07-01-2010 9:06 AM

    Hello,

     

    I am getting an AssertionFailedException from Infer.NET when I try to infer results and I was wondering if someone could help me track down the source.

     

    Basically I have a program that creates a number of very large VariableArrays and initializes them with constant values. When I call InferenceEngine.InferAll(...) on these variable arrays, my program is able to compile the model, but during the initialization phase it throws the following exception:

    Unhandled Exception: MicrosoftResearch.Infer.Utils.AssertFailedException: items.Count != indices.Count

       at MicrosoftResearch.Infer.Factors.GetItemsOp`1.ItemsAverageConditional[DistributionType,ArrayType,ResultType](IList`1 items, ArrayType array, IList`1 indices, ResultType result) in C:\infernetBuilds\12-11-2009_17-18\Runtime\Factors\GetItems.cs:line 155

       at MicrosoftResearch.Infer.Models.User.Model_EP.Initialise()

       at MicrosoftResearch.Infer.CompiledAlgorithm.Initialise() in C:\infernetBuilds\12-11-2009_17-18\Compiler\Infer\Algorithms\CompiledAlgorithm.cs:line 261

       at MicrosoftResearch.Infer.CompiledAlgorithm.Execute() in C:\infernetBuilds\12-11-2009_17-18\Compiler\Infer\Algorithms\CompiledAlgorithm.cs:line 70

       at MicrosoftResearch.Infer.InferenceEngine.InferAll(Boolean inferOnlySpecifiedVars, IEnumerable`1 vars) in C:\infernetBuilds\12-11-2009_17-18\Compiler\Infer\InferenceEngine.cs:line 348

       at MicrosoftResearch.Infer.InferenceEngine.InferAll(IEnumerable`1 vars) in C:\infernetBuilds\12-11-2009_17-18\Compiler\Infer\InferenceEngine.cs:line 340

       at Anek.ProbConstraints.inferGlobal(graph g, FSharpList`1 constraints, FSharpMap`2 cnstr_params) in c:\Documents and Settings\nbeckman\working\nbeckman\anek\src\GraphLoader\GraphLoader\ProbConstraints.fs:line 1328

       at Program.Main(String[] arg) in c:\Documents and Settings\nbeckman\working\nbeckman\anek\src\GraphLoader\GraphLoader\Program.fs:line 58

    I have some suspicions about what the issue might be. In several places in my program I use the GetItems() method on a VariableArray to create an array that is a sub-array of a larger array. Then I use ranges to apply various constraints on those sub-arrays. If the size of my range does not match the size of my sub-array, would this lead to the exception I am getting?
    Thanks!
    Nels

    Friday, June 3, 2011 5:53 PM

Answers

  • nbeckman replied on 07-02-2010 9:13 AM

    Great. Thank-you minka.

     

     I think that I have tracked down the range that is too small. I fixed it, and the exception is no longer thrown.

     

    It seems like if the range is too large, an exception is thrown right at the point in my code where it is used, however, if the range is too small, then it's not thrown until the generated code starts to run.

     

    Thanks,

    Nels

    Friday, June 3, 2011 5:53 PM

All replies

  • minka replied on 07-02-2010 3:21 AM

    Yes, this exception is thrown by GetItems.  It means that the number of indices on the right-hand side doesn't match the size of the array on the left-hand side.  For example:  b = Variable.GetItems(a,indices) requires that the length of b matches the length of indices.

    Friday, June 3, 2011 5:53 PM
  • nbeckman replied on 07-02-2010 9:13 AM

    Great. Thank-you minka.

     

     I think that I have tracked down the range that is too small. I fixed it, and the exception is no longer thrown.

     

    It seems like if the range is too large, an exception is thrown right at the point in my code where it is used, however, if the range is too small, then it's not thrown until the generated code starts to run.

     

    Thanks,

    Nels

    Friday, June 3, 2011 5:53 PM