Compiler error "consume excess memory due to the indexing expression"

Jingwen Pan 1 Reputation point
2022-01-04T04:24:48.78+00:00

Hi, I am trying to construct a Bayesian network that contains 8 parents(which are iKorean, iOthrserv, iMay, dYrsserv, iSept80, iVietnam and iFeb55) pointing to 1 child(which is iRvetserv), and while compiling, I got the error like this:

" [1] This model will consume excess memory due to the indexing expression CPTiRvetserv[iKorean[N]][iOthrserv[N]][iMay[N]][iWWll[N]][dYrsserv[N]][iSept80[N]][iVietnam[N]][iFeb55[N]] since iVietnam[N] and iFeb55[N] have larger depth than the compiler can handle.
[2] This model will consume excess memory due to the indexing expression CPTiRvetserv[iKorean[N]][iOthrserv[N]][iMay[N]][iWWll[N]][dYrsserv[N]][iSept80[N]][iVietnam[N]] since iSept80[N] and iVietnam[N] have larger depth than the compiler can handle.
[3] This model will consume excess memory due to the indexing expression CPTiRvetserv[iKorean[N]][iOthrserv[N]][iMay[N]][iWWll[N]][dYrsserv[N]][iSept80[N]] since dYrsserv[N] and iSept80[N] have larger depth than the compiler can handle.
[4] This model will consume excess memory due to the indexing expression CPTiRvetserv[iKorean[N]][iOthrserv[N]][iMay[N]][iWWll[N]][dYrsserv[N]] since iWWll[N] and dYrsserv[N] have larger depth than the compiler can handle.
[5] This model will consume excess memory due to the indexing expression CPTiRvetserv[iKorean[N]][iOthrserv[N]][iMay[N]][iWWll[N]] since iMay[N] and iWWll[N] have larger depth than the compiler can handle."

And here is my code:

using System;
using Microsoft.ML.Probabilistic.Models; //For modelling Bernoulli distribution
using Microsoft.ML.Probabilistic.Math;
using Microsoft.ML.Probabilistic.Distributions;
using Range = Microsoft.ML.Probabilistic.Models.Range;
using System.Linq;

namespace learningdotnet
{
public class BN2model
{
// Primary random variables
public Variable<int> NumberOfExamples;
public VariableArray<int> iKorean;
public VariableArray<int> iOthrserv;
public VariableArray<int> iMay;
public VariableArray<int> iWWll;
public VariableArray<int> dYrsserv;
public VariableArray<int> iSept80;
public VariableArray<int> iVietnam;
public VariableArray<int> iFeb55;
public VariableArray<int> iRvetserv;

    //parents
    public Variable<Vector> ProbiKorean;
    public Variable<Vector> ProbiOthrserv;
    public Variable<Vector> ProbiMay;
    public Variable<Vector> ProbiWWll;
    public Variable<Vector> ProbdYrsserv;
    public Variable<Vector> ProbiSept80;
    public Variable<Vector> ProbiVietnam;
    public Variable<Vector> ProbiFeb55;
    //child
    public VariableArray<VariableArray<VariableArray<VariableArray<VariableArray<VariableArray<VariableArray<VariableArray<Vector>, Vector[][]>, Vector[][][]>, Vector[][][][]>, Vector[][][][][]>, Vector[][][][][][]>, Vector[][][][][][][]>, Vector[][][][][][][][]> CPTiRvetserv;

    public Variable<Dirichlet> ProbiKoreanPrior;
    public Variable<Dirichlet> ProbiOthrservPrior;
    public Variable<Dirichlet> ProbiMayPrior;
    public Variable<Dirichlet> ProbiWWllPrior;
    public Variable<Dirichlet> ProbdYrsservPrior;
    public Variable<Dirichlet> ProbiSept80Prior;
    public Variable<Dirichlet> ProbiVietnamPrior;
    public Variable<Dirichlet> ProbiFeb55Prior;
    public VariableArray<VariableArray<VariableArray<VariableArray<VariableArray<VariableArray<VariableArray<VariableArray<Dirichlet>, Dirichlet[][]>, Dirichlet[][][]>, Dirichlet[][][][]>, Dirichlet[][][][][]>, Dirichlet[][][][][][]>, Dirichlet[][][][][][][]>, Dirichlet[][][][][][][][]> CPTiRvetservPrior;

    //parameters to be learnt
    public Dirichlet ProbiKoreanPosterior;
    public Dirichlet ProbiOthrservPosterior;
    public Dirichlet ProbiMayPosterior;
    public Dirichlet ProbiWWllPosterior;
    public Dirichlet ProbdYrsservPosterior;
    public Dirichlet ProbiSept80Posterior;
    public Dirichlet ProbiVietnamPosterior;
    public Dirichlet ProbiFeb55Posterior;
    public Dirichlet[][][][][][][][] CPTiRvetservPosterior;

    public InferenceEngine Engine = new InferenceEngine();

    public BN2model()
    {
        // Set up the ranges
        NumberOfExamples = Variable.New<int>().Named("NofE");
        Range N = new Range(NumberOfExamples).Named("N");

        // Variables have just 2 states (go to this attribute/not go to this attribute)
        Range R1 = new Range(2).Named("R1"); //iKorean
        Range R2 = new Range(2).Named("R2"); //iOthrserv
        Range R3 = new Range(2).Named("R3"); //iMay
        Range R4 = new Range(2).Named("R4"); //iWWll
        Range R5 = new Range(2).Named("R5"); //dYrsserv
        Range R6 = new Range(2).Named("R6"); //iSept80
        Range R7 = new Range(2).Named("R7"); //iVietnam
        Range R8 = new Range(2).Named("R8"); //iFeb55
        Range R9 = new Range(8).Named("R9"); //iRvetserv
        // Define the priors and the parameters
        ProbiKoreanPrior = Variable.New<Dirichlet>().Named("ProbiKoreanPrior");
        ProbiKorean = Variable<Vector>.Random(ProbiKoreanPrior).Named("ProbiKorean");
        ProbiKorean.SetValueRange(R1);

        ProbiOthrservPrior = Variable.New<Dirichlet>().Named("ProbiOthrservPrior");
        ProbiOthrserv = Variable<Vector>.Random(ProbiOthrservPrior).Named("ProbiOthrserv");
        ProbiOthrserv.SetValueRange(R2);

        ProbiMayPrior = Variable.New<Dirichlet>().Named("ProbiMayPrior");
        ProbiMay = Variable<Vector>.Random(ProbiMayPrior).Named("ProbiMay");
        ProbiMay.SetValueRange(R3);

        ProbiWWllPrior = Variable.New<Dirichlet>().Named("ProbiWWllPrior");
        ProbiWWll = Variable<Vector>.Random(ProbiWWllPrior).Named("ProbiWWll");
        ProbiWWll.SetValueRange(R4);

        ProbdYrsservPrior = Variable.New<Dirichlet>().Named("ProbdYrsservPrior");
        ProbdYrsserv = Variable<Vector>.Random(ProbdYrsservPrior).Named("ProbdYrsserv");
        ProbdYrsserv.SetValueRange(R5);

        ProbiSept80Prior = Variable.New<Dirichlet>().Named("ProbiSept80Prior");
        ProbiSept80 = Variable<Vector>.Random(ProbiSept80Prior).Named("ProbiSept80");
        ProbiSept80.SetValueRange(R6);

        ProbiVietnamPrior = Variable.New<Dirichlet>().Named("ProbiVietnamPrior");
        ProbiVietnam = Variable<Vector>.Random(ProbiVietnamPrior).Named("ProbiVietnam");
        ProbiVietnam.SetValueRange(R7);

        ProbiFeb55Prior = Variable.New<Dirichlet>().Named("ProbiFeb55Prior");
        ProbiFeb55 = Variable<Vector>.Random(ProbiFeb55Prior).Named("ProbiFeb55");
        ProbiFeb55.SetValueRange(R8);

        // iRvetserv probability table conditioned on iKorean,iOthrserv,iMay,iWWll,dYrsserv,iSept80,iVietnam,iFeb55
        CPTiRvetservPrior = Variable.Array(Variable.Array(Variable.Array(Variable.Array(Variable.Array(Variable.Array(Variable.Array(Variable.Array<Dirichlet>(R8), R7), R6), R5), R4), R3), R2), R1).Named("CPTiRvetservPrior");
        CPTiRvetserv = Variable.Array(Variable.Array(Variable.Array(Variable.Array(Variable.Array(Variable.Array(Variable.Array(Variable.Array<Vector>(R8), R7), R6), R5), R4), R3), R2), R1).Named("CPTiRvetserv");
        CPTiRvetserv[R1][R2][R3][R4][R5][R6][R7][R8] = Variable<Vector>.Random(CPTiRvetservPrior[R1][R2][R3][R4][R5][R6][R7][R8]);
        //[R8][R7][R6][R5][R4][R3][R2][R1]
        CPTiRvetserv.SetValueRange(R9);

        // define Bayesian network structure
        iKorean = Variable.Array<int>(N).Named("iKorean");
        iKorean[N] = Variable.Discrete(ProbiKorean).ForEach(N);

        iOthrserv = Variable.Array<int>(N).Named("iOthrserv");
        iOthrserv[N] = Variable.Discrete(ProbiOthrserv).ForEach(N);

        iMay = Variable.Array<int>(N).Named("iMay");
        iMay[N] = Variable.Discrete(ProbiMay).ForEach(N);

        iWWll = Variable.Array<int>(N).Named("iWWll");
        iWWll[N] = Variable.Discrete(ProbiWWll).ForEach(N);

        dYrsserv = Variable.Array<int>(N).Named("dYrsserv");
        dYrsserv[N] = Variable.Discrete(ProbdYrsserv).ForEach(N);

        iSept80 = Variable.Array<int>(N).Named("iSept80");
        iSept80[N] = Variable.Discrete(ProbiSept80).ForEach(N);

        iVietnam = Variable.Array<int>(N).Named("iVietnam");
        iVietnam[N] = Variable.Discrete(ProbiVietnam).ForEach(N);

        iFeb55 = Variable.Array<int>(N).Named("iFeb55");
        iFeb55[N] = Variable.Discrete(ProbiFeb55).ForEach(N);

        iRvetserv = AddChildFromEightParents(iKorean, iOthrserv, iMay, iWWll, dYrsserv, iSept80, iVietnam, iFeb55, CPTiRvetserv);

    }

    public static VariableArray<int> AddChildFromEightParents(
        VariableArray<int> p1,
        VariableArray<int> p2,
        VariableArray<int> p3,
        VariableArray<int> p4,
        VariableArray<int> p5,
        VariableArray<int> p6,
        VariableArray<int> p7,
        VariableArray<int> p8,
        VariableArray<VariableArray<VariableArray<VariableArray<VariableArray<VariableArray<VariableArray<VariableArray<Vector>, Vector[][]>, Vector[][][]>, Vector[][][][]>, Vector[][][][][]>, Vector[][][][][][]>, Vector[][][][][][][]>, Vector[][][][][][][][]> cpt)
    {
        var n = p1.Range;
        var child = Variable.Array<int>(n);

        using (Variable.ForEach(n))
        using (Variable.Switch(p1[n]))
        using (Variable.Switch(p2[n]))
        using (Variable.Switch(p3[n]))
        using (Variable.Switch(p4[n]))
        using (Variable.Switch(p5[n]))
        using (Variable.Switch(p6[n]))
        using (Variable.Switch(p7[n]))
        using (Variable.Switch(p8[n]))
            child[n] = Variable.Discrete(cpt[p1[n]][p2[n]][p3[n]][p4[n]][p5[n]][p6[n]][p7[n]][p8[n]]); 
        return child;
    }

    public void LearnParameters(
        int[] ikorean,
        int[] iothrserv,
        int[] imay,
        int[] iwwll,
        int[] dyrsserv,
        int[] isept80,
        int[] ivietnam,
        int[] ifeb55,
        Dirichlet probikoreanPrior,
        Dirichlet probiothrservPrior,
        Dirichlet probimayPrior,
        Dirichlet probiwwllPrior,
        Dirichlet probdyrsservPrior,
        Dirichlet probisept80Prior,
        Dirichlet probivietnamPrior,
        Dirichlet probifeb55Prior,
        Dirichlet[][][][][][][][] cpt)
    {
        NumberOfExamples.ObservedValue = ikorean.Length;
        iKorean.ObservedValue = ikorean;
        iOthrserv.ObservedValue = iothrserv;
        iMay.ObservedValue = imay;
        iWWll.ObservedValue = iwwll;
        dYrsserv.ObservedValue = dyrsserv;
        iSept80.ObservedValue = isept80;
        iVietnam.ObservedValue = ivietnam;
        iFeb55.ObservedValue = ifeb55;

        ProbiKoreanPrior.ObservedValue = probikoreanPrior;
        ProbiOthrservPrior.ObservedValue = probiothrservPrior;
        ProbiMayPrior.ObservedValue = probimayPrior;
        ProbiWWllPrior.ObservedValue = probiwwllPrior;
        ProbdYrsservPrior.ObservedValue = probdyrsservPrior;
        ProbiSept80Prior.ObservedValue = probisept80Prior;
        ProbiVietnamPrior.ObservedValue = probivietnamPrior;
        ProbiFeb55Prior.ObservedValue = probifeb55Prior;
        CPTiRvetservPrior.ObservedValue = cpt;

        // Inference
        ProbiKoreanPosterior = Engine.Infer<Dirichlet>(ProbiKorean);
        ProbiOthrservPosterior = Engine.Infer<Dirichlet>(ProbiOthrserv);
        ProbiMayPosterior = Engine.Infer<Dirichlet>(ProbiMay);
        ProbiWWllPosterior = Engine.Infer<Dirichlet>(ProbiWWll);
        ProbdYrsservPosterior = Engine.Infer<Dirichlet>(ProbdYrsserv);
        ProbiSept80Posterior = Engine.Infer<Dirichlet>(ProbiSept80);
        ProbiVietnamPosterior = Engine.Infer<Dirichlet>(ProbiVietnam);
        ProbiFeb55Posterior = Engine.Infer<Dirichlet>(ProbiFeb55);

        CPTiRvetservPosterior = Engine.Infer<Dirichlet[][][][][][][][]>(CPTiRvetserv);
    }

    public void LearnParameters(
        int[] ikorean,
        int[] iothrserv,
        int[] imay,
        int[] iwwll,
        int[] dyrsserv,
        int[] isept80,
        int[] ivietnam,
        int[] ifeb55)
    {
        // Set all priors to uniform
        Dirichlet probikoreanPrior = Dirichlet.Uniform(2);
        Dirichlet probiothrservPrior = Dirichlet.Uniform(2);
        Dirichlet probimayPrior = Dirichlet.Uniform(2);
        Dirichlet probiwwllPrior = Dirichlet.Uniform(2);
        Dirichlet probdyrsservPrior = Dirichlet.Uniform(2);
        Dirichlet probisept80Prior = Dirichlet.Uniform(2);
        Dirichlet probivietnamPrior = Dirichlet.Uniform(2);
        Dirichlet probifeb55Prior = Dirichlet.Uniform(2);

        Dirichlet[] arr1 = Enumerable.Repeat(Dirichlet.Uniform(2), 2).ToArray();
        Dirichlet[][] arr2 = Enumerable.Repeat(arr1, 2).ToArray();
        Dirichlet[][][] arr3 = Enumerable.Repeat(arr2, 2).ToArray();
        Dirichlet[][][][] arr4 = Enumerable.Repeat(arr3, 2).ToArray();
        Dirichlet[][][][][] arr5 = Enumerable.Repeat(arr4, 2).ToArray();
        Dirichlet[][][][][][] arr6 = Enumerable.Repeat(arr5, 2).ToArray();
        Dirichlet[][][][][][][] arr7 = Enumerable.Repeat(arr6, 2).ToArray();
        Dirichlet[][][][][][][][] cpt = Enumerable.Repeat(arr7, 2).ToArray();

        LearnParameters(ikorean, iothrserv, imay, iwwll, dyrsserv, isept80, ivietnam, ifeb55,
                        probikoreanPrior, probiothrservPrior, probimayPrior, probiwwllPrior,
                        probdyrsservPrior, probisept80Prior, probivietnamPrior, probifeb55Prior, cpt);
    }
}

public class BN2
{
    public static void infer()
    {
        // Set random seed for repeatable example
        Rand.Restart(12347);

        // Create a new model
        BN2model model = new BN2model();
        // Each variable just takes two states - true (index 0) and false (index 1).

        // -------------------------------------------------------------
        // Learn posterior distributions for the parameters
        // -------------------------------------------------------------
        Console.WriteLine("\n*********************************************");
        Console.WriteLine("Learning parameters from data (uniform prior)");
        Console.WriteLine("*********************************************");
        int[] ikorean = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0,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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };

        // Now see if we can recover the parameters from the data - assume uniform priors
        model.LearnParameters(ikorean,iothrserv,imay,iwwll,dyrsserv,isept80,ivietnam,ifeb55);

        // The posteriors are distributions over the probabilities and CPTs. Print out the means of these
        // distributions, and compare with the ground truth
        Console.WriteLine("Prob. iKorean:                               Inferred: {1:0.00}", model.ProbiKoreanPosterior.GetMean()[0]);
        Console.WriteLine("Prob. iOthrserv:                   Inferred: {1:0.00}", model.ProbiOthrservPosterior.GetMean()[0]);
        Console.WriteLine("Prob. iMay:               Inferred: {1:0.00}", model.ProbiMayPosterior.GetMean()[0]);
        Console.WriteLine("Prob. iWWII:                   Inferred: {1:0.00}", model.ProbiWWllPosterior.GetMean()[0]);
        Console.WriteLine("Prob. dYrsserv:               Inferred: {1:0.00}", model.ProbdYrsservPosterior.GetMean()[0]);
        Console.WriteLine("Prob. iSept80:          Inferred: {1:0.00}", model.ProbiSept80Posterior.GetMean()[0]);
        Console.WriteLine("Prob. iVietnam       Inferred: {1:0.00}", model.ProbiVietnamPosterior.GetMean()[0]);
        Console.WriteLine("Prob. iFeb55:      Inferred: {1:0.00}", model.ProbiFeb55Posterior.GetMean()[0]);
        Console.WriteLine("Prob. iRvetserv|iKorean,iOthrserv,iMay,iWWII,dYrsserv,iSept80,iVietnam,iFeb55:  Inferred: {1:0.00}", model.CPTiRvetservPosterior[0][0][0][0][0][0][0][0].GetMean()[0]);

    }
}

}

I wonder how should I fix this error. Thank you so much for help!

Jingwen

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,309 questions
.NET Machine learning
.NET Machine learning
.NET: Microsoft Technologies based on the .NET software framework.Machine learning: A type of artificial intelligence focused on enabling computers to use observed data to evolve new behaviors that have not been explicitly programmed.
150 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Jingwen Pan 1 Reputation point
    2022-01-08T06:25:57.483+00:00

    Solved. The warning didn't cause any problem. The error referred to this line "Console.WriteLine("Prob. iKorean: Inferred: {1:0.00}", model.ProbiKoreanPosterior.GetMean()[0]);" ,which should be "Console.WriteLine("Prob. iKorean: Inferred: {0:0.00}", model.ProbiKoreanPosterior.GetMean()[0]);".

    0 comments No comments