public void CalculateMarginal()
    {
        for (int i = 0; i < n; i ++)
        {
            double sum_py = 0.0;
            for (int y = 0; y < num_label; y ++)
            {
              //  System.out.println(var_node[i].state_factor[y]);
                var_node[i].marginal[y] = var_node[i].state_factor[y];
                for (int t = 0; t < var_node[i].neighbor.size(); t ++)
                {
                    var_node[i].marginal[y] *= ((double[])var_node[i].belief.get(t))[y];
                   // System.out.println(((double[])var_node[i].belief.get(t))[y]);
                }
                sum_py += var_node[i].marginal[y];
            }
          //  System.out.println(sum_py);
            for (int y = 0; y < num_label; y ++)
            {
                var_node[i].marginal[y] /= sum_py;
            }
        }

        for (int i = 0; i < m; i ++)
        {
            double sump = 0.0;
            for (int a = 0; a < num_label; a ++)
                for (int b = 0; b < num_label; b ++)
                {
                    factor_node[i].marginal[a][b] +=
                    		((double[])factor_node[i].belief.get(0))[a]
                          * ((double[])factor_node[i].belief.get(1))[b]
                          * factor_node[i].func.GetValue(a, b);
                    sump += factor_node[i].marginal[a][b];
                }
            for (int a = 0; a < num_label; a ++)
                for (int b = 0; b < num_label; b ++)
                    factor_node[i].marginal[a][b] /= sump;
        }
    }