0

DISCLAIMER: I'm new to bayesian Networks and Adjacency Matrix

hey guys,

So I'm making this very simple Bayesian network and I am trying to represent it using an Adjacency Matrix. enter image description here. So above is a graphical representation of the problem. We see that we have a cycle between node A, B, and C. And I want to prevent that. Now here is how I am trying to represent my graph in code (using an Adjacency Matrix or double loop).

enter image description here

I'm writing this method called checkDag(int[][] AdjacencyMatrixInput)

it takes an AM and check if the DAG constraint is violated or not. i've started some code but keep getting stuck. Really would appreciate the help! (pseudocode or actual code would be great).

public void checkDag(Node[][] AM)
    {
        for(int i = 0; i < AM.length; i++)
        {
            for(int j = 0; j < AM[i].length; j++)
            {
                if(AM[i][i].value == 1)
                {
                    //getting stuck on how to check parents.
                }
            }
        }
    }
TheQ
  • 1,949
  • 10
  • 38
  • 63
  • Your represantation is wrong for both graphes ( the one with a cycle and the "correct" one). If you want to show us a graph with a cycle, you have to set the 1 not from A-C, but from C-A. If you want to show us the correct one, remove the 1 from A-C – Supahupe May 16 '16 at 12:57
  • To detect cycles in a graph, refer to wikipedia first and try to implement one of the algorithms: https://en.wikipedia.org/wiki/Cycle_detection. It also may be helpful to take a look here: http://stackoverflow.com/questions/261573/best-algorithm-for-detecting-cycles-in-a-directed-graph – Supahupe May 16 '16 at 12:59
  • @Supahupe Sorry, I'll update that image, I forgot to put the arrow in there. But thanks for the links. I'll def. look into it right now! – TheQ May 16 '16 at 13:04

0 Answers0