locked
Error:Attempt to redefine index variable at depth 1. (Migrated from community.research.microsoft.com) RRS feed

  • Question

  • shakey posted on 12-08-2009 5:36 AM

    When Compiling the model , I get this error 'Attempt to redefine index variable at depth 1. ' from infer.net when calling the engine.infer method. I search in the docs and find no helps. I cant find any index redefinition in my code.

    Does anyone know how could this happen?

     

    Friday, June 3, 2011 5:28 PM

Answers

  • minka replied on 12-12-2009 12:54 PM

    The problem is this line:

      ru[UserSize][Zu[UserSize][word1]][word1]=eta[Zu[UserSize][word1]]

    Since Zu is a random variable, it means that you are assigning to a random element of the array 'ru'.  This is not allowed.  You need to provide a definition for every element of the array 'ru', not just a few of the elements.  We will fix the error message to be more clear.

    Friday, June 3, 2011 5:29 PM

All replies

  • minka replied on 12-08-2009 6:33 AM

    This is an internal error of the model compiler which means that Infer.NET somehow got confused by your model definition.   Can you send us the model so that we can fix the problem?

    Friday, June 3, 2011 5:29 PM
  • shakey replied on 12-08-2009 10:54 PM

    i try to model the relation between two kinds of doc in my corpus through inner product of  their respective latent variable Z_u and Z_v, the variable R is observed respond. Since inner product in infer.net does't support dirichlet vector, i accumulate the sum by use of temp varaible ru,rv,ru2,rv2。 Then the error come up  when calling the engine.infer method

     

    the main part of the code :


    uVar = Variable.Observed[int](users, RespondSize).Named("uVar")
    mVar = Variable.Observed[int](movies, RespondSize).Named("mVar")
    ru = Variable.Array[float](Variable.Array[float](Variable.Array[float](word1),TopicsNum), UserSize).Named("ru")
    rv = Variable.Array[float](Variable.Array[float](Variable.Array[float](word2),TopicsNum), MovieSize).Named("rv")
    ru2 = Variable.Array[float](Variable.Array[float](TopicsNum), UserSize).Named("ru2")
    rv2 = Variable.Array[float](Variable.Array[float](TopicsNum), MovieSize).Named("rv2")
    x= Variable.Array[float](Variable.Array[float](TopicsNum), RespondSize).Named("x")

    #the first kind of docs
    with (Variable.ForEach(UserSize)) as forBlock :
        with (Variable.ForEach(word1)) as forBlock :
            Zu[UserSize][word1] = Variable.Discrete(u[UserSize]).Attrib( ValueRange(TopicsNum))
            with (Variable.Switch(Zu[UserSize][word1])) as swBlock :
                Wu[UserSize][word1] = Variable.Discrete(phi[Zu[UserSize][word1]])
                ru[UserSize][Zu[UserSize][word1]][word1]=eta[Zu[UserSize][word1]]
        with (Variable.ForEach(TopicsNum)) as forBlock :       
            ru2[UserSize][TopicsNum]=Variable.Sum(ru[UserSize][TopicsNum])
     #the second kind of doc      
    with (Variable.ForEach(MovieSize)) as forBlock :
        with (Variable.ForEach(word2)) as forBlock :
            Zv[MovieSize][word2] = Variable.Discrete(v[MovieSize]).Attrib( ValueRange(TopicsNum))
            with (Variable.Switch(Zv[MovieSize][word2])) as swBlock :
                Wv[MovieSize][word2] = Variable.Discrete(phi[Zv[MovieSize][word2]])
                rv[MovieSize][Zv[MovieSize][word2]][word2]=eta[Zv[MovieSize][word2]]
        with (Variable.ForEach(TopicsNum)) as forBlock :       
            rv2[MovieSize][TopicsNum]=Variable.Sum(rv[MovieSize][TopicsNum])
    #the respond variable R, model the interaction between two kinds of doc above
    with (Variable.ForEach(RespondSize)) as forBlock : 
        with (Variable.ForEach(TopicsNum)) as forBlock :
            x[RespondSize][TopicsNum]=ru2[uVar[RespondSize]][TopicsNum]*rv2[mVar[RespondSize]][TopicsNum]
        R[RespondSize]=Variable.Sum(x[RespondSize])

    Wu.ObservedValue = docs1
    Wv.ObservedValue = docs2
    R.ObservedValue =Respond

    Friday, June 3, 2011 5:29 PM
  • minka replied on 12-12-2009 12:54 PM

    The problem is this line:

      ru[UserSize][Zu[UserSize][word1]][word1]=eta[Zu[UserSize][word1]]

    Since Zu is a random variable, it means that you are assigning to a random element of the array 'ru'.  This is not allowed.  You need to provide a definition for every element of the array 'ru', not just a few of the elements.  We will fix the error message to be more clear.

    Friday, June 3, 2011 5:29 PM