Skip to content

Commit 761e74d

Browse files
authored
Learn changes for Constraints.jl (#20)
* temp save * Typo in string evaluation * Typo in string evaluation 2/? * Typo in string evaluation 3/? * Typo in string evaluation 4/? * Typo in string evaluation 5/?
1 parent 363f28b commit 761e74d

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "CompositionalNetworks"
22
uuid = "4b67e4b5-442d-4ef5-b760-3f5df3a57537"
33
authors = ["Jean-François Baffier"]
4-
version = "0.1.1"
4+
version = "0.1.2"
55

66
[deps]
77
ConstraintDomains = "5800fd60-8556-4464-8d61-84ebf7a0bedb"

src/learn.jl

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
function _partial_search_space(domains, concept; sol_number=100)
1+
function _partial_search_space(domains, concept, param=nothing; sol_number=100)
22
solutions = Set{Vector{Int}}()
33
non_sltns = Set{Vector{Int}}()
44

55
while length(solutions) < 100 || length(non_sltns) < 100
66
config = map(_draw, domains)
7-
c = concept(config)
7+
c = concept(config; param = param)
88
c && length(solutions) < 100 && push!(solutions, config)
99
!c && length(non_sltns) < 100 && push!(non_sltns, config)
1010
end
1111
return solutions, non_sltns
1212
end
1313

14-
function _complete_search_space(domains, concept)
14+
function _complete_search_space(domains, concept, param=nothing)
1515
solutions = Set{Vector{Int}}()
1616
non_sltns = Set{Vector{Int}}()
1717

@@ -24,8 +24,10 @@ function _complete_search_space(domains, concept)
2424
@warn message space_size
2525
end
2626

27+
f = isnothing(param) ? ((x; param = p) -> concept(x)) : concept
28+
2729
configurations = product(map(d -> _get_domain(d), domains)...)
28-
foreach(c -> (cv = collect(c); push!(concept(cv) ? solutions : non_sltns, cv)), configurations)
30+
foreach(c -> (cv = collect(c); push!(f(cv; param=param) ? solutions : non_sltns, cv)), configurations)
2931

3032
return solutions, non_sltns
3133
end
@@ -54,7 +56,7 @@ function explore_learn_compose(concept; domains, param=nothing,
5456
)
5557
dom_size = maximum(_length, domains)
5658
if search == :complete
57-
X_sols, X = _complete_search_space(domains, concept)
59+
X_sols, X = _complete_search_space(domains, concept, param)
5860
union!(X, X_sols)
5961
return learn_compose(X, X_sols, dom_size, param;
6062
local_iter=local_iter, global_iter=global_iter, action=action)
@@ -72,7 +74,9 @@ function _compose_to_string(symbols, name)
7274
co = _reduce_symbols(symbols[4], ", ", false; prefix=CN * "_co_")
7375

7476
julia_string = """
75-
$name = x -> fill(x, $tr_length) .|> $tr |> $ar |> $ag |> $co
77+
function $name(x; param=nothing, dom_size)
78+
fill(x, $tr_length) .|> map(f -> (y -> f(y; param=param)), $tr) |> $ar |> $ag |> (y -> $co(y; param=param, dom_size=dom_size, nvars=length(x)))
79+
end
7680
"""
7781

7882
return julia_string

0 commit comments

Comments
 (0)