locked
Error compiling model in 2.6 RRS feed

  • Question

  • I've a model (a variant of the Chess TS model) which compiled under Infer.net 2.5 but now gives error messages compiling under 2.6. The full model code is:

        class TrainModel
        {
            public int[][][] AllPlayers;
            public int nPlayers;
            public int nYears;
            public Range player;
            public InferenceEngine engine;
            public VariableArray<VariableArray<double>, double[][]> skill;
            public Variable<double> performancePrecision;
            public Variable<double> skillChangePrecision;
            public VariableArray<int> firstYear;
            public TrainModel(int[][] Player1Data, int[][]Player2Data, int[] firstYears)
            {
                engine = new InferenceEngine();
                //engine.Compiler.UseSerialSchedules = true;
                //engine.Compiler.ShowProgress = true;
                //engine.Compiler.FreeMemory = false;
                engine.Compiler.UseParallelForLoops = true;
    
                AllPlayers = new int[2][][];
                AllPlayers[0] = Player1Data;
                AllPlayers[1] = Player2Data;
                nPlayers = (from array in AllPlayers from arr in array from value in arr select value).Distinct().Count();
                nYears = Player1Data.Length;
                Rand.Restart(1);
    
                var skillPrior = new Gaussian(2000, 800 * 800);
                var performancePrecisionPrior = Gamma.FromShapeAndRate(2, 800 * 800);
                var skillChangePrecisionPrior = Gamma.FromShapeAndRate(2, 26 * 26);
    
                performancePrecision = Variable.Random(performancePrecisionPrior).Named("performancePrecision");
                skillChangePrecision = Variable.Random(skillChangePrecisionPrior).Named("skillChangePrecision");
    
                player = new Range(nPlayers).Named("player");
                Range year = new Range(nYears).Named("year");
    
                skill = Variable.Array(Variable.Array<double>(player), year).Named("skill");
                firstYear = Variable.Array<int>(player).Named("firstYear");
                //firstYear.SetTo(firstYears);
    
                using (var yearBlock = Variable.ForEach(year))
                {
                    var y = yearBlock.Index;
                    using (Variable.If(y == 0))
                    {
                        skill[year][player] = Variable.Random(skillPrior).ForEach(player);
                    }
                    using (Variable.If(y > 0))
                    {
                        using (Variable.ForEach(player))
                        {
                            Variable<bool> isFirstYear = (firstYear[player] >= y).Named("isFirstYear");
                            using (Variable.If(isFirstYear))
                            {
                                skill[year][player] = Variable.Random(skillPrior);
                            }
                            using (Variable.IfNot(isFirstYear))
                            {
                                skill[year][player] = Variable.GaussianFromMeanAndPrecision(skill[y - 1][player], skillChangePrecision);
                            }
                        }
                    }
                }
    
                // Learn the skills from the data
                firstYear.ObservedValue = Util.ArrayInit(nPlayers, i => firstYears[i]);
                int[] nGamesData = Util.ArrayInit(nYears, y => Player1Data[y].Length);
                var nGames = Variable.Observed(nGamesData, year).Named("nGames");
                Range game = new Range(nGames[year]).Named("game");
                var whitePlayer = Variable.Observed(Player1Data, year, game).Named("whitePlayer");
                var blackPlayer = Variable.Observed(Player2Data, year, game).Named("blackPlayer");
                using (Variable.ForEach(year))
                {
                    using (Variable.ForEach(game))
                    {
                        var w = whitePlayer[year][game];
                        var b = blackPlayer[year][game];
                        Variable<double> white_performance = Variable.GaussianFromMeanAndPrecision(skill[year][w], performancePrecision);
                        Variable<double> black_performance = Variable.GaussianFromMeanAndPrecision(skill[year][b], performancePrecision);
                        Variable<double> white_delta = white_performance - black_performance;
                        Variable.ConstrainTrue(white_delta > 0);
                    }
                }
    
                engine.NumberOfIterations = 100;
            }
            public Gaussian[][] InferSkills() 
            {
                var SkillsPosterior = engine.Infer<Gaussian[][]>(skill);
                return SkillsPosterior;
            }
        }

    When I come to call the InferSkills function (which triggers model compilation) the following error message is generated:

    SchedulingTransform failed with 1 error(s) and 0 warning(s):

    Error 0: Internal error: Invalid init schedule.  Offending statement: for(int year = 0; year<143; year++) {

    for(int game = 0; game<nGames[year]; game++) {

    performancePrecision_rep2_rep_B[year][game] = GaussianOp.PrecisionAverageConditional(vdouble22_use_B[year][game], skill_itemblackPlayer_year__game__F[year][game], performancePrecision_rep2_rep_F[year][game]);

    }

    }



    for(int year = 0; year<143; year++) {

    for(int game = 0; game<nGames[year]; game++) {

    performancePrecision_rep_rep_B[year][game] = GaussianOp.PrecisionAverageConditional(vdouble20_use_B[year][game], skill_itemwhitePlayer_year__game__F[year][game], performancePrecision_rep_rep_F[year][game]);

    }

    }

     in

    {

    while (true)

    {

    for(int year = 143-1; year>=0; year--) {

    performancePrecision_rep_rep_B_toDef[year] = ReplicateOp_Divide.ToDef<Gamma>(performancePrecision_rep_rep_B[year], performancePrecision_rep_rep_B_toDef[year]);

    }

    for(int year = 143-1; year>=0; year--) {

    for(int game = 0; game<nGames[year]; game++) {

    performancePrecision_rep_rep_B[year][game] = GaussianOp.PrecisionAverageConditional(vdouble20_use_B[year][game], skill_itemwhitePlayer_year__game__F[year][game], performancePrecision_rep_rep_F[year][game]);

    }

    }

    for(int year = 143-1; year>=0; year--) {

    for(int game = 0; game<nGames[year]; game++) {

    skill_itemwhitePlayer_year__game__F[year][game] = GetItemsOp<double>.ItemsAverageConditional<DistributionStructArray<Gaussian,double>,Gaussian>(skill_itemwhitePlayer_year__game__B[year][game], skill_depth1_uses_F[year][0], skill_depth1_uses_F_year__0__marginal[year], whitePlayer[year], game, skill_itemwhitePlayer_year__game__F[year][game]);

    }

    }

    for(int year = 143-1; year>=0; year--) {

    skill_depth1_uses_F_year__0__marginal[year] = GetItemsOp<double>.Marginal<DistributionStructArray<Gaussian,double>,Gaussian>(skill_depth1_uses_F[year][0], skill_itemwhitePlayer_year__game__B[year], whitePlayer[year], skill_depth1_uses_F_year__0__marginal[year]);

    }

    for(int year = 143-1; year>=0; year--) {

    skill_depth1_uses_F[year][0] = ReplicateOp_Divide.UsesAverageConditional<DistributionStructArray<Gaussian,double>>(skill_depth1_uses_B[year][0], skill_depth1_uses_F_year__marginal[year], 0, skill_depth1_uses_F[year][0]);

    }

    for(int year = 143-1; year>=0; year--) {

    skill_depth1_uses_F_year__marginal[year] = ReplicateOp_Divide.Marginal<DistributionStructArray<Gaussian,double>>(skill_depth1_uses_B_year__toDef[year], skill_depth1_F[year], skill_depth1_uses_F_year__marginal[year]);

    }

    for(int year = 143-1; year>=0; year--) {

    for(int player = 0; player<14536; player++) {

    skill_depth1_F[year][player] = ArrayHelper.SetTo<Gaussian>(skill_depth1_F[year][player], skill_uses_F[year][player][1]);

    }

    }

    for(int year = 143-1; year>=0; year--) {

    if (year==0) {

    for(int player = 0; player<14536; player++) {

    skill_uses_F[0][player][1] = ReplicateOp_Divide.UsesAverageConditional<Gaussian>(skill_uses_B[0][player][1], skill_uses_F_0__player__marginal[year][player], 1, skill_uses_F[0][player][1]);

    }

    }

    }

    for(int year = 143-1; year>=0; year--) {

    if (year==0) {

    for(int player = 0; player<14536; player++) {

    skill_uses_F_0__player__marginal[year][player] = ReplicateOp_Divide.Marginal<Gaussian>(skill_uses_B_0__player__toDef[year][player], vGaussian2, skill_uses_F_0__player__marginal[year][player]);

    }

    }

    }

    for(int year = 143-1; year>=0; year--) {

    if (year==0) {

    for(int player = 0; player<14536; player++) {

    skill_uses_B_0__player__toDef[year][player] = ReplicateOp_Divide.ToDef<Gaussian>(skill_uses_B[0][player], skill_uses_B_0__player__toDef[year][player]);

    }

    }

    }

    for(int year = 143-1; year>=0; year--) {

    if (year>0) {

    for(int player = 0; player<14536; player++) {

    skill_uses_F[year][player][1] = ReplicateOp_Divide.UsesAverageConditional<Gaussian>(skill_depth1_uses_B_year__toDef[year][player], skill_uses_F_year__player__marginal[year][player], 1, skill_uses_F[year][player][1]);

    }

    }

    }

    for(int year = 143-1; year>=0; year--) {

    if (year>0) {

    for(int player = 0; player<14536; player++) {

    skill_uses_F_year__player__marginal[year][player] = ReplicateOp_Divide.Marginal<Gaussian>(skill_uses_B_year__player__toDef[year][player], skill_year_player_0__F[year][player], skill_uses_F_year__player__marginal[year][player]);

    }

    }

    }

    for(int year = 143-1; year>=0; year--) {

    if (year>0) {

    for(int player = 0; player<14536; player++) {

    // FactorManager.Any(skill_year_player_0__F[year][player], skill_year_player_0__F[year][player]) is now updated in all contexts

    }

    }

    }

    for(int year = 143-1; year>=0; year--) {

    if (year>0) {

    for(int player = 0; player<14536; player++) {

    if (!isFirstYear[year][player]) {

    skill_year_player_0__F[year][player] = ArrayHelper.SetTo<Gaussian>(skill_year_player_0__F[year][player], skill_year_player_0__player_1__F[year][player]);

    }

    }

    }

    }

    for(int year = 143-1; year>=0; year--) {

    if (year>0) {

    for(int player = 0; player<14536; player++) {

    if (!isFirstYear[year][player]) {

    skill_year_player_0__player_1__F[year][player] = GaussianOp.SampleAverageConditional(skill_uses_B_year__player__toDef[year][player], skill_uses_F[year-1][player][0], skillChangePrecision_0__rep_F[year][player], skillChangePrecision_0__1__B[year][player]);

    }

    }

    }

    }

    for(int year = 143-1; year>=0; year--) {

    if (year>0) {

    for(int player = 0; player<14536; player++) {

    skillChangePrecision_0__rep_F[year][player] = ReplicateOp_Divide.UsesAverageConditional<Gamma>(skillChangePrecision_0__rep_B[year][player], skillChangePrecision_0__rep_F_marginal[year], player, skillChangePrecision_0__rep_F[year][player]);

    }

    }

    }

    for(int year = 143-1; year>=0; year--) {

    if (year>0) {

    skillChangePrecision_0__rep_F_marginal[year] = ReplicateOp_Divide.Marginal<Gamma>(skillChangePrecision_0__rep_B_toDef[year], skillChangePrecision_rep_F[year], skillChangePrecision_0__rep_F_marginal[year]);

    }

    }

    for(int year = 143-1; year>=0; year--) {

    if (year>0) {

    skillChangePrecision_0__rep_B_toDef[year] = ReplicateOp_Divide.ToDef<Gamma>(skillChangePrecision_0__rep_B[year], skillChangePrecision_0__rep_B_toDef[year]);

    }

    }

    for(int year = 143-1; year>=0; year--) {

    if (year>0) {

    for(int player = 0; player<14536; player++) {

    if (!isFirstYear[year][player]) {

    skillChangePrecision_0__rep_B[year][player] = ArrayHelper.SetTo<Gamma>(skillChangePrecision_0__rep_B[year][player], skillChangePrecision_0__1__B[year][player]);

    }

    }

    }

    }

    for(int year = 143-1; year>=0; year--) {

    if (year>0) {

    for(int player = 0; player<14536; player++) {

    if (!isFirstYear[year][player]) {

    skillChangePrecision_0__1__B[year][player] = GaussianOp.PrecisionAverageConditional(skill_uses_B_year__player__toDef[year][player], skill_uses_F[year-1][player][0], skillChangePrecision_0__rep_F[year][player]);

    }

    }

    }

    }

    for(int year = 143-1; year>=0; year--) {

    if (year>0) {

    for(int player = 0; player<14536; player++) {

    skill_uses_B_year__player__toDef[year][player] = ReplicateOp_Divide.ToDef<Gaussian>(skill_uses_B[year][player], skill_uses_B_year__player__toDef[year][player]);

    }

    }

    }

    for(int year = 143-1; year>=0; year--) {

    for(int player = 0; player<14536; player++) {

    skill_uses_B[year][player][1] = ArrayHelper.SetTo<Gaussian>(skill_uses_B[year][player][1], skill_depth1_uses_B_year__toDef[year][player]);

    }

    }

    for(int year = 143-1; year>=0; year--) {

    skill_depth1_uses_B_year__toDef[year] = ReplicateOp_Divide.ToDef<DistributionStructArray<Gaussian,double>>(skill_depth1_uses_B[year], skill_depth1_uses_B_year__toDef[year]);

    }

    for(int year = 143-1; year>=0; year--) {

    skill_depth1_uses_B[year][1] = GetItemsOp<double>.ArrayAverageConditional<Gaussian,DistributionStructArray<Gaussian,double>>(skill_itemblackPlayer_year__game__B[year], blackPlayer[year], skill_depth1_uses_B[year][1]);

    }

    for(int year = 143-1; year>=0; year--) {

    skill_depth1_uses_B[year][0] = GetItemsOp<double>.ArrayAverageConditional<Gaussian,DistributionStructArray<Gaussian,double>>(skill_itemwhitePlayer_year__game__B[year], whitePlayer[year], skill_depth1_uses_B[year][0]);

    }

    for(int year = 143-1; year>=0; year--) {

    for(int game = 0; game<nGames[year]; game++) {

    skill_itemwhitePlayer_year__game__B[year][game] = GaussianOp.MeanAverageConditional(vdouble20_use_B[year][game], skill_itemwhitePlayer_year__game__F[year][game], performancePrecision_rep_rep_F[year][game], performancePrecision_rep_rep_B[year][game]);

    }

    }

    for(int year = 143-1; year>=0; year--) {

    for(int game = 0; game<nGames[year]; game++) {

    vdouble20_use_B[year][game] = DoublePlusOp.SumAverageConditional(vdouble23_B[year][game], vdouble22_F[year][game]);

    }

    }

    for(int year = 143-1; year>=0; year--) {

    for(int game = 0; game<nGames[year]; game++) {

    vdouble22_F[year][game] = GaussianOp.SampleAverageConditional(vdouble22_use_B[year][game], skill_itemblackPlayer_year__game__F[year][game], performancePrecision_rep2_rep_F[year][game], performancePrecision_rep2_rep_B[year][game]);

    }

    }

    for(int year = 143-1; year>=0; year--) {

    for(int game = 0; game<nGames[year]; game++) {

    skill_itemblackPlayer_year__game__F[year][game] = GetItemsOp<double>.ItemsAverageConditional<DistributionStructArray<Gaussian,double>,Gaussian>(skill_itemblackPlayer_year__game__B[year][game], skill_depth1_uses_F[year][1], skill_depth1_uses_F_year__1__marginal[year], blackPlayer[year], game, skill_itemblackPlayer_year__game__F[year][game]);

    }

    }

    for(int year = 143-1; year>=0; year--) {

    skill_depth1_uses_F_year__1__marginal[year] = GetItemsOp<double>.Marginal<DistributionStructArray<Gaussian,double>,Gaussian>(skill_depth1_uses_F[year][1], skill_itemblackPlayer_year__game__B[year], blackPlayer[year], skill_depth1_uses_F_year__1__marginal[year]);

    }

    for(int year = 143


    What do I need to change to this model to make it Infer.net 2.6 compatible?

    Tuesday, December 2, 2014 3:44 PM

Answers

  • This is a bug.  You can work around it with:

    engine.Compiler.UseSerialSchedules = false;

    • Marked as answer by MarkG87 Monday, December 8, 2014 5:24 PM
    Thursday, December 4, 2014 10:45 PM
    Owner

All replies

  • This is a bug.  You can work around it with:

    engine.Compiler.UseSerialSchedules = false;

    • Marked as answer by MarkG87 Monday, December 8, 2014 5:24 PM
    Thursday, December 4, 2014 10:45 PM
    Owner
  • Tom,

    Is there another way to structure my code to work around this problem without resorting to setting UseSerialSchedules to false? I've found that setting UseSerialSchedules to false causes significant deterioration in the predictive performance of my models compared to the same model in 2.5 with it set to the default value of true.

    Wednesday, January 14, 2015 7:01 PM