general algo for pred definitions: build graph from matrix