-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathrunOracleRCD.py
More file actions
executable file
·66 lines (53 loc) · 2.11 KB
/
runOracleRCD.py
File metadata and controls
executable file
·66 lines (53 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import pdb
import random
import logging
import numpy as np
from causality.citest.CITest import Oracle
from causality.learning import ModelEvaluation
from causality.learning.RCD import RCD
from causality.learning.sRCD import sRCD
from causality.learning.RelFCI import RelFCI
from causality.model.Schema import Schema
from causality.model.Model import Model
from causality.modelspace import ModelGenerator
from causality.modelspace import SchemaGenerator
from causality.graph.GraphUtil import isPossibleParent, isPossibleAncestor
logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)
rseed = 123
random.seed(rseed)
np.random.seed(rseed)
# Parameters
numEntities = 3
numRelationships = 2
numDependencies = 4
numFeedbackLoops = 1
hopThreshold = 4
maxNumParents = rcdDepth = 3
# Parameters
# schema = SchemaGenerator.generateSchema(numEntities, numRelationships, allowCycles=True, oneRelationshipPerPair=True)
# logger.info(schema)
# model = ModelGenerator.generateModel(schema, hopThreshold, numDependencies, numFeedbackLoops, maxNumParents=maxNumParents)
# Self Loop example
schema = Schema()
schema.addEntity('A')
schema.addAttribute('A', 'X1')
schema.addEntity('B')
schema.addAttribute('B', 'Y1')
schema.addRelationship('AB', ('A', Schema.MANY), ('B', Schema.MANY))
model = Model(schema, ['[A, AB, B, AB, A].X1 -> [A].X1', '[A, AB, B].Y1 -> [A].X1'])
logger.info('Model: %s', model.dependencies)
oracle = Oracle(model, 2*hopThreshold, sep='sigma')
# Run RCD algorithm and collect statistics on learned model
rcd = RCD(schema, oracle, hopThreshold, depth=rcdDepth)
rcd.identifyUndirectedDependencies()
rcd.orientDependencies()
trueAggs = RCD.constructTrueAggsFromDependencies(schema, model.dependencies, hopThreshold)
# p, r, f1 = ModelEvaluation.parentalQuery(trueAggs, rcd.perspectiveToAgg, isPossibleParent)
# print("isPossibleParent: P:%.2lf, R:%.2lf, F1:%.2lf" % (p, r, f1))
p, r, f1 = ModelEvaluation.parentalQuery(trueAggs, rcd.perspectiveToAgg, isPossibleAncestor)
print("isPossibleAncestor: P:%.2lf, R:%.2lf, F1:%.2lf" % (p, r, f1))
print()
print(trueAggs['A'].edges())
print()
print(rcd.perspectiveToAgg['A'].edges())