Different ways to define variable matrix RRS feed

  • Question

  • Hi, there are several ways to define variable matrix. For example, there are M*N variables. Variables within each row is correlated, while different rows are (conditional) independent.

    VariableArray<VariableArray<int> > myVar1;
    VariableArray<int>[] myVar2;
    Variable<int[]>[] myVar3;
    Variable<int>[][] myVar4;

    At least "myVar1" and "myVar2" have correct syntax. My question is, are there any different? Is one more suitable for some scenario while another one suitable for another scenario?

    Which one fits the situation I described above best?


    Friday, June 5, 2015 4:09 AM

All replies

  • You keep on mixing C# language components and Infer.NET modelling components (but I understand how confusing this is). Please model factorized matrices and arrays the way these are defined in the Recommender system example:

    var randomMatrix = Variable.Array(Variable.Array<double>(range2), range1);
    var randomArray = Variable.Array<double>(range1);

    You can also use VariableArray2D for matrices, but I rather prefer jagged arrays (as shown above) because they give you extra flexibility. If you want to have operations on arrays which preserve correlation, please use the Infer.NET Vector type as shown in this example. For a more detailed discussion on arrays, please look here and here.

    In general, if you're new to Infer.NET, please firstly read our user guide and go throw the tutorials and examples.


    Friday, June 5, 2015 12:52 PM