Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lcn/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def make_lcn_random2(
count = 0
while count < c:
child = ordering[np.random.randint(n - p)]
if cpts[child] is True:
if cpts[child]:
continue
cpts[child] = True
num_higher_vars = n - position[child] - 1
Expand All @@ -218,7 +218,7 @@ def make_lcn_random2(

# Add the roots
for i in range(n):
if cpts[i] is False:
if not cpts[i]:
scopes[i] = [i]

# Create extra knowledge: l <= P(x) <= u
Expand Down Expand Up @@ -341,7 +341,7 @@ def make_lcn_dag(
count = 0
while count < c:
child = ordering[np.random.randint(n - p)]
if cpts[child] is True:
if cpts[child]:
continue
cpts[child] = True
num_higher_vars = n - position[child] - 1
Expand All @@ -367,7 +367,7 @@ def make_lcn_dag(

# Add the roots
for i in range(n):
if cpts[i] is False:
if not cpts[i]:
scopes[i] = [i]

# Create extra knowledge: l <= P(x) <= u
Expand Down Expand Up @@ -489,7 +489,7 @@ def make_lcn_polytree(
u = ordering[i]
v = ordering[j]
edge = (u, v)# if np.random.uniform() <= 0.5 else (v, u)
if G.has_edge(edge[0], edge[1]) is False:
if not G.has_edge(edge[0], edge[1]):
UG = nx.to_undirected(G)
paths = list(nx.all_simple_paths(UG, u, v))
assert(len(paths) == 1)
Expand Down
13 changes: 11 additions & 2 deletions lcn/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,13 @@ def __init__(
self.label = label # unique identifier of the formula (is the atom if atomic)
self.input_formula = formula # store the formula
output, atoms = parse_formula(formula) # parse the formula
if output is None or vars is None:
if output is None or atoms is None:
raise ValueError(f"Malformed formula: {formula}")

# Reject empty / whitespace-only formulas that parse as valid but have no content
stripped = formula.strip()
if not stripped:
raise ValueError(f"Empty formula: {formula!r}")

self.parsed_formula = output # parse tree of the formula
self.atoms = atoms # a dict indexed by 'Vi' where i is the i-th variable
Expand Down Expand Up @@ -892,7 +897,11 @@ def parse_sentence(line: str):
tau = False
if ";" in line:
pos = line.find(";")
tau = bool(line[pos+1:].strip())
tau_str = line[pos+1:].strip()
# Parse "tau=true" or "tau=false" correctly — bool() of any
# non-empty string (including "False") returns True, so we
# must split on "=" to get the actual boolean value.
tau = tau_str.split("=")[1].lower() == 'true'
Comment on lines +900 to +904
line = line[:pos]

# Get the lower and upper bounds
Expand Down