Skip to content
Merged
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
4 changes: 3 additions & 1 deletion pycona/active_algorithms/genacq.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def learn(self, instance: ProblemInstance, oracle: Oracle = UserOracle(), verbos
if self.env.verbose >= 1:
print(f"\nLearned {self.env.metrics.cl} constraints in "
f"{self.env.metrics.total_queries} queries.")
self.env.instance.bias = []
return self.env.instance

self.env.metrics.increase_generation_time(gen_end - gen_start)
Expand Down Expand Up @@ -108,7 +109,7 @@ def generalize(self, r, c):
for var in scope_vars:
var_types = []
for type_group in self._types:
if var.name in type_group:
if var in type_group:
var_types.append(type_group)
type_sequences.append(var_types)

Expand Down Expand Up @@ -139,6 +140,7 @@ def generalize(self, r, c):
all_type_sequences.sort(key=lambda seq: len(set().union(*seq)))

while len(all_type_sequences) > 0 and gq_counter < self._qg_max:

Y = all_type_sequences.pop(0)

# Instead of getting constraints from bias, generate them for this type sequence
Expand Down
15 changes: 12 additions & 3 deletions pycona/active_algorithms/growacq.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,23 @@ def learn(self, instance: ProblemInstance, oracle: Oracle = UserOracle(), verbos
self.inner_algorithm.env = copy.copy(self.env)

Y = []
init_bias = list(self.env.instance.bias)
init_bias_provided = len(init_bias) > 0

n_vars = len(X)
for x in X:
# we 'grow' the inner bias by adding one extra variable at a time
# we 'grow' the considered part of the problem by adding one extra variable at a time
Y.append(x)
# add the constraints involving x and other added variables
if len(self.env.instance.bias) == 0:
# Add candidate constraints for the new frontier.
# - If an initial bias is provided, only reveal newly visible constraints
# - Otherwise, generate constraints incrementally from the language
if init_bias_provided:
visible_now = set(get_con_subset(init_bias, Y))
self.env.instance.bias = list(visible_now)
init_bias = set(init_bias) - visible_now
else:
self.env.instance.construct_bias_for_vars(x, Y)

if verbose >= 3:
print(f"Added variable {x} in GrowAcq")
print("size of B in growacq: ", len(self.env.instance.bias))
Expand Down
4 changes: 4 additions & 0 deletions pycona/ca_environment/active_ca.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ def init_state(self, instance, oracle, verbose, metrics=None):
self.find_scope.ca = self
self.findc.ca = self

# Reset optional query-generator internal state between independent runs
if hasattr(self.qgen, "reset_partial") and callable(self.qgen.reset_partial):
self.qgen.reset_partial()

def run_query_generation(self, Y=None):
""" Run the query generation process. """
Y = self.qgen.generate(Y)
Expand Down
2 changes: 1 addition & 1 deletion pycona/find_scope/findscope.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def run(self, Y):
:return: The scope of the partial example.
"""
assert self.ca is not None
scope = self._find_scope(set(), Y, do_ask=False)
scope = self._find_scope(set(), list(Y), do_ask=False)
return scope

def _find_scope(self, R, Y, do_ask):
Expand Down
2 changes: 1 addition & 1 deletion pycona/find_scope/findscope2.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def _find_scope(self, R, Y):

# Create Y1, Y2 -------------------------
proba = self.ca.bias_proba if hasattr(self.ca, 'bias_proba') else []
Y1, Y2 = self.split_func(Y=Y, R=R, kappaB=kappaBRY, P_c=proba)
Y1, Y2 = self.split_func(Y=Y, R=R, kappaB=kappaBRY, P_c=proba, time_limit=self.time_limit)

S1 = set()
S2 = set()
Expand Down
4 changes: 3 additions & 1 deletion pycona/find_scope/findscope_obj.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ def split_proba(Y, R, kappaB, P_c, **kwargs):
if len(kappaB) > 10000:
return split_half(Y)

time_limit = kwargs.get('time_limit', 1)

hashY = [hash(y) for y in Y]
hashR = [hash(r) for r in R]

Expand All @@ -50,7 +52,7 @@ def split_proba(Y, R, kappaB, P_c, **kwargs):

model.maximize(constraints_Y1)

model.solve(time_limit=1)
model.solve(time_limit=time_limit)

Y1 = [Y[i] for i in range(len(Y)) if x[i].value()]
Y2 = list(set(Y) - set(Y1))
Expand Down
2 changes: 1 addition & 1 deletion pycona/predictor/feature_representation.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def featurize_constraint(self, c):
features.append(dimj_diff)
else:
features.append(True)
for _ in range(4):
for _ in range(3):
features.append(0)
features.append(0.0)

Expand Down
Loading