SharedVariable indexing RRS feed

  • Question

  • Dear InferNET community and creators:

    Thanks for creating a great tool!

    I have run into a problem trying to perform inference on a large graph. Before I display the code below, I just wanted to summarize the task: I have a fairly large graph of "users" (each user is a gaussian r.v.) and "competitions" (each competition is an observed boolean r.v) from a database. A subset (a very sparse one) of all pairs of "users" connect to a subset of "competition" variables through a BernoulliFromLogOdds factor. There are too many variables to load all in one, so I intend to separate subsets of the "users" and "competitions" into separate models, and share those variables that have edges crossing between groups. The graph has high modularity, so I naturally split the models according to the modules in the graph. This is the code that I want to write ( but cannot, since indexing sharedvariable arrays is not possible), so that makes me think that this approach is wrong from the start:

    namespace ConsoleApplication12 { using GaussianArray=DistributionStructArray<Gaussian,double>; class Program { private static GaussianArray CreateGaussianArray(int len) { Gaussian[] result = new Gaussian[len]; for (int i=0; i<len; i++) { result[i] = Gaussian.FromMeanAndPrecision(0.0, 1.0); } return (GaussianArray)Distribution<double>.Array<Gaussian>(result); } static void Main(string[] args) { // Define the users --- appr 10^5 users Range user = new Range(10); SharedVariableArray<double> users = SharedVariable<double>.Random(user, CreateGaussianArray(user.SizeAsInt)); // Define groups of users that are compared (observed) --- appr 10^6 observations Range obs = new Range(5); var users_obs_group_A = Variable.Array<int>(obs); var users_obs_group_B = Variable.Array<int>(obs); users_obs_group_A.ObservedValue = new int[] {1,4,2,3,3}; users_obs_group_B.ObservedValue = new int[] {3,1,4,5,6}; // observations of pairwise results VariableArray<bool> z = Variable.Array<bool>(obs); // each user is partitioned into a "module" (from modularity detection in graph), // appr 100 modules, each corresponding to a Model var modules = Variable.Array<int>(obs); modules.ObservedValue = new int[] {0,1,2,3,4}; // Array of models -- must be as many as modules in the graph Model[] models = new Model[obs.SizeAsInt]; for (int i = 0; i < models.Count(); i++) { models[i] = new Model(1); } // finish initializing models. This code below doesn't actually work, but that's how I would

    // have wanted to write it. using (Variable.ForEach(obs)) { var module = modules[obs]; var model = models[module.ObservedValue]; var user_of_obs_group_A_index = users_obs_group_A[obs]; var user_of_obs_group_B_index = users_obs_group_B[obs]; var user_of_obs_group_A = users[user_of_obs_group_A_index].getCopyFor(model); var user_of_obs_group_B = users[user_of_obs_group_B_index].getCopyFor(model); z[obs] = Variable.BernoulliFromLogOdds(user_of_obs_group_A - user_of_obs_group_B); }

    Note that the last part doesn't workbecause I can't index the SharedVariableArray like I can index the regular VariableArray. 

    Do you think I am going about this incorrectly?

    Thank you so much for your help!

    Wednesday, April 16, 2014 3:10 AM


  • Please nevermind my question --- I posted it while not exploring the straightforward approach of putting all the variables into standard c# arrays, rather than using the infer.net VariableArray types. I was making it more complicated than it needed to be. Also this was immensely helpful - http://research.microsoft.com/en-us/um/cambridge/projects/infernet/docs/how%20to%20represent%20large%20irregular%20graphs.aspx.


    • Marked as answer by IgorNeletov Monday, April 21, 2014 11:41 PM
    Wednesday, April 16, 2014 8:00 AM