HerbSearch.jl Documentation
HerbSearch.AbstractBFSIterator
— TypeAbstractBFSIterator <: TopDownIterator
This is the supertype for all breadth-first search iterators. It inherits all stop-criteria and traversal mechanisms from TopDownIterator
.
HerbSearch.AbstractDFSIterator
— TypeAbstractDFSIterator <: TopDownIterator
This is the supertype for all depth-first search iterators. It inherits all stop-criteria and from TopDownIterator
, but the traversal mechanism is implemented to perform a depth-first search.
HerbSearch.AbstractMHSearchIterator
— TypeAbstractMHSearchIterator <: StochasticSearchIterator
This is the supertype for all Metropolis Hastings (MH) search iterators. It inherits all behaviour from StochasticSearchIterator
.
HerbSearch.AbstractSASearchIterator
— TypeAbstractSASearchIterator <: StochasticSearchIterator
This is the supertype for all SA search iterators.
HerbSearch.AbstractVLSNSearchIterator
— TypeAbstractVLSNSearchIterator <: StochasticSearchIterator
This is the supertype for all VLSN search iterators.
HerbSearch.BFSIterator
— Type@programiterator BFSIterator() <: TopDownIterator
Creates a breadth-first search iterator for traversing given a grammar, starting from the given symbol. The iterator returns trees in the grammar in increasing order of size.
HerbSearch.DFSIterator
— Type@programiterator DFSIterator() <: AbstractDFSIterator
Creates a depth-first search iterator for traversing a given a grammar, starting from a given symbol. The iterator returns trees in the grammar in decreasing order of size.
HerbSearch.ExpandFailureReason
— Type@enum ExpandFailureReason limit_reached=1 already_complete=2
Representation of the different reasons why expanding a partial tree failed. Currently, there are two possible causes of the expansion failing:
limit_reached
: The depth limit or the size limit of the partial tree would be violated by the expansionalready_complete
: There is no hole left in the tree, so nothing can be expanded.
HerbSearch.GeneticSearchIterator
— TypeGeneticSearchIterator{FitnessFunction,CrossOverFunction,MutationFunction,SelectParentsFunction,EvaluationFunction} <: ProgramIterator
Defines an ProgramIterator
using genetic search.
Consists of:
examples::Vector{<:IOExample}
: a collection of examples defining the specificationevaluation_function::EvaluationFunction
: interpreter to evaluate the individual programspopulation_size::Int64
: number of inviduals in the populationmutation_probability::Float64
: probability of mutation for each individualmaximum_initial_population_depth::Int64
: maximum depth of trees when population is initialized
end
HerbSearch.MHSearchIterator
— TypeMHSearchIterator(examples::AbstractArray{<:IOExample}, cost_function::Function, evaluation_function::Function=HerbInterpret.execute_on_input)
The MHSearchIterator
generates programs using the Metropolis-Hastings algorithm. The search behaviour has the following characteristics:
- It uses
random_fill_propose
for thepropose
function. - The
accept function is
probabilistic`. - The
temperature
of the algorithm remains constant over time, ensuring a stable acceptance probability.
Arguments
examples::AbstractArray{<:IOExample}
: An array of input-output examples used to guide the search.cost_function::Function
: A function to evaluate the cost of the proposed programs.evaluation_function::Function=HerbInterpret.execute_on_input
: A function that evaluates the generated program generated and produces an output. Defaults toHerbInterpret.execute_on_input
.
Returns
An iterator to generate programs according to the Metropolis Hastings algorithm.
HerbSearch.MLFSIterator
— Type@programiterator MLFSIterator() <: TopDownIterator
Iterator that enumerates expressions in the grammar in decreasing order of probability (Only use this iterator with probabilistic grammars). Inherits all stop-criteria from TopDownIterator.
HerbSearch.ProgramIterator
— Typeabstract type ProgramIterator
Generic iterator for all possible search strategies. All iterators are expected to have the following fields:
grammar::ContextSensitiveGrammar
: the grammar to search oversym::Symbol
: defines the start symbol from which the search should be startedmax_depth::Int
: maximum depth of program treesmax_size::Int
: maximum number ofAbstractRuleNode
s of program treesmax_time::Int
: maximum time the iterator may takemax_enumerations::Int
: maximum number of enumerations
HerbSearch.RandomIterator
— Type@programiterator RandomIterator() <: TopDownIterator
Iterates trees in the grammar in a random order.
HerbSearch.SASearchIterator
— TypeSASearchIterator(spec, cost_function, initial_temperature=1, temperature_decreasing_factor = 0.99, evaluation_function::Function=HerbInterpret.execute_on_input)
Returns an enumerator that runs according to the Simulated Annealing Search algorithm.
spec
: array of examplescost_function
: cost function to evaluate the programs proposedinitial_temperature
: the starting temperature of the algorithmtemperature_decreasing_factor
: the decreasing factor of the temperature of the timeevaluation_function
: evaluation function that evaluates the program generated and produces an output
The propose function is random_fill_propose
(the same as for Metropolis Hastings). The accept function is probabilistic but takes into account the tempeerature too.
HerbSearch.StochasticSearchIterator
— Type abstract type StochasticSearchIterator <: ProgramIterator
A unified abstract type for the stochastic search algorithms Metropolis Hastings, Very Large Scale Neighbourhood and Simulated Annealing. Iterators are customisable by overloading the followign functions:
neighbourhood
propose
temperature
accept
.
Fields
examples::Vector{IOExample}
example used to check the programcost_function::Function
. Returns the cost of the current program. It receives a list of tuples for (expected, found) and gives back a cost.initial_temperature::Real
= 1evaluation_function
::Function that evaluates the julia expressions
An iterator over all possible expressions of a grammar up to maxdepth with start symbol sym. Also inherits all stop criteria like `maxdepthfrom
ProgramIterator`.
HerbSearch.SynthResult
— Type@enum SynthResult optimal_program=1 suboptimal_program=2
Representation of the possible results of the synth procedure. At the moment there are two possible outcomes:
optimal_program
: The synthesized program satisfies the entire program specification.suboptimal_program
: The synthesized program does not satisfy the entire program specification, but got the best score from the evaluator.
HerbSearch.TopDownIterator
— Typemutable struct TopDownIterator <: ProgramIterator
Enumerates a context-free grammar starting at Symbol
sym
with respect to the grammar up to a given depth and a given size. The exploration is done using the given priority function for derivations, and the expand function for discovered nodes. Concrete iterators may overload the following methods:
- priority_function
- derivation_heuristic
- hole_heuristic
HerbSearch.UniformIterator
— Typemutable struct UniformIterator
Inner iterator that enumerates all candidate programs of a uniform tree.
solver
: the uniform solver.outeriter
: outer iterator that is responsible for producing uniform trees. This field is used to dispatch on thederivation_heuristic
.unvisited_branches
: for each search-node from the root to the current search-node, a list of unviisted branches.nsolutions
: number of solutions found so far.
HerbSearch.UniformIterator
— MethodUniformIterator(solver::UniformSolver, outeriter::ProgramIterator)
Constructs a new UniformIterator that traverses solutions of the UniformSolver
and is an inner iterator of an outer ProgramIterator
.
HerbSearch.VLSNSearchIterator
— TypeVLSNSearchIterator(spec, cost_function, enumeration_depth = 2, evaluation_function::Function=HerbInterpret.execute_on_input) = StochasticSearchIterator(
Returns an iterator that runs according to the Very Large Scale Neighbourhood Search algorithm.
spec
: array of examplescost_function
: cost function to evaluate the proposed programsvlsn_neighbourhood_depth
: the enumeration depth to search for a best program at a timeevaluation_function
: evaluation function that evaluates the program generated and produces an output
The propose function consists of all possible programs of the given enumeration_depth
. The accept function accepts the program with the lowest cost according to the cost_function
. The temperature value of the algorithm remains constant over time.
HerbSearch.@programiterator
— Macro@programiterator
Canonical way of creating a program iterator. The macro automatically declares the expected fields listed in the ProgramIterator
documentation. Syntax accepted by the macro is as follows (anything enclosed in square brackets is optional): @programiterator [mutable] <IteratorName>( <arg₁>, ..., <argₙ> ) [<: <SupertypeIterator>]
Note that the macro emits an assertion that the SupertypeIterator
is a subtype of ProgramIterator
which otherwise throws an ArgumentError. If no supertype is given, the new iterator extends ProgramIterator
directly. Each <argᵢ> may be (almost) any expression valid in a struct declaration, and they must be comma separated. One known exception is that an inner constructor must always be given using the extended function <name>(...) ... end
syntax. The mutable
keyword determines whether the declared struct is mutable.
Base.collect
— Methodfunction Base.collect(iter::TopDownIterator)
Return an array of all programs in the TopDownIterator.
This requires deepcopying programs from type StateHole to type RuleNode. If it is not needed to save all programs, iterate over the iterator manually.
Base.iterate
— MethodBase.iterate(iter::GeneticSearchIterator, current_state::GeneticIteratorState)
Iterates the search space using a genetic algorithm. Takes the iterator and the current state to mutate and crossover random inviduals. Returns the best program-so-far and the state of the iterator.
Base.iterate
— MethodBase.iterate(iter::GeneticSearchIterator)
Iterates the search space using a genetic algorithm. First generates a population sampling random programs. Returns the best program-so-far, and the state of the iterator.
Base.iterate
— MethodBase.iterate(iter::StochasticSearchIterator, current_state::IteratorState)
The algorithm that constructs the iterator of StochasticSearchIterator. It has the following structure:
- get a random node location -> location,dict = neighbourhood(current_program)
- call propose on the current program getting a list of full programs
- iterate through all the proposals and check if the proposed program is "better" than the previous one
- "accept" the new program by calling the
accept
- return the new next_program
Base.iterate
— MethodBase.iterate(iter::TopDownIterator, pq::DataStructures.PriorityQueue)
Describes the iteration for a given TopDownIterator
and a PriorityQueue
over the grammar without enqueueing new items to the priority queue. Recursively returns the result for the priority queue.
Base.iterate
— MethodBase.iterate(iter::TopDownIterator)
Describes the iteration for a given TopDownIterator
over the grammar. The iteration constructs a PriorityQueue
first and then prunes it propagating the active constraints. Recursively returns the result for the priority queue.
Base.length
— MethodBase.length(iter::ProgramIterator)
Counts and returns the number of possible programs without storing all the programs. !!! warning: modifies and exhausts the iterator
Base.length
— MethodBase.length(iter::UniformIterator)
Counts and returns the number of programs without storing all the programs. !!! warning: modifies and exhausts the iterator
Base.rand
— Functionrand(::Type{RuleNode}, grammar::AbstractGrammar, max_depth::Int=10)
Generates a random RuleNode
of arbitrary type and maximum depth max_depth.
Base.rand
— Functionrand(::Type{RuleNode}, grammar::AbstractGrammar, typ::Symbol, max_depth::Int=10)
Generates a random RuleNode
of return type typ and maximum depth max_depth.
Base.rand
— Functionrand(::Type{RuleNode}, grammar::AbstractGrammar, typ::Symbol, dmap::AbstractVector{Int}, max_depth::Int=10)
Generates a random RuleNode
, i.e. an expression tree, of root type typ and maximum depth max_depth guided by a depth map dmap if possible.
HerbSearch._calculate_cost
— Method_calculate_cost(program::RuleNode, cost_function::Function, spec::AbstractVector{IOExample}, grammar::AbstractGrammar, evaluation_function::Function)
Returns the cost of the program
using the examples and the cost_function
. It first convert the program to an expression and evaluates it on all the examples.
HerbSearch._find_next_complete_tree
— Method_find_next_complete_tree(solver::Solver, pq::PriorityQueue, iter::TopDownIterator)::Union{Tuple{RuleNode, Tuple{Vector{AbstractRuleNode}, PriorityQueue}}, Nothing}
Takes a priority queue and returns the smallest AST from the grammar it can obtain from the queue or by (repeatedly) expanding trees that are in the queue. Returns nothing
if there are no trees left within the depth limit.
HerbSearch.accept
— Methodaccept(::StochasticSearchIterator, current_cost::Real, next_cost::Real, temperature::Real)
Based on the current program and possible cost and temperature a program is accepted or not. Usually we would always want to accept better programs but we might get stuck if we do so. That is why some implementations of the accept
function accept with a probability costs that are worse. cost
means how different are the outcomes of the program compared to the correct outcomes. The lower the cost
the better the program performs on the examples. The cost
is provided by the cost_function
HerbSearch.best_accept
— Methodbest_accept(current_cost::Real, next_cost::Real, temperature::Real)
Returns true if the cost of the proposed program is smaller than the cost of the current program. Otherwise, returns false.
Arguments
current_cost::Real
: the cost of the current program.next_cost::Real
: the cost of the proposed program.temperature::Real
: the temperature; not used.
HerbSearch.calculate_cost
— Methodcalculate_cost(iter::T, program::Union{RuleNode, StateHole}) where T <: StochasticSearchIterator
Wrapper around _calculate_cost
.
HerbSearch.const_temperature
— Methodconst_temperature(current_temperature::Real)
Returns the temperature unchanged. This function is used by Metropolis Hastings and Very Large Neighbourhood Search algorithms.
Arguments
current_temperature::Real
: the current temperature of the search.
HerbSearch.constructNeighbourhood
— MethodconstructNeighbourhood(current_program::RuleNode, grammar::AbstractGrammar)
The neighbourhood node location is chosen at random. The dictionary is nothing.
Arguments
current_program::RuleNode
: the current program.grammar::AbstractGrammar
: the grammar.
HerbSearch.constructNeighbourhoodRuleSubset
— MethodconstructNeighbourhoodRuleSubset(current_program::RuleNode, grammar::AbstractGrammar)
The neighbourhood node location is chosen at random. The dictionary is contains one entry with key "rule_subset" and value of type Vector{Any} being a random subset of grammar rules.
Arguments
current_program::RuleNode
: the current program.grammar::AbstractGrammar
: the grammar.
HerbSearch.cross_over
— Methodcross_over(::GeneticSearchIterator, parent_1::RuleNode, parent_2::RuleNode)
Combines the program from two parent individuals to create one or more offspring individuals.
HerbSearch.crossover_swap_children_1
— Methodcrossover_swap_children_1(parent_1::RuleNode, parent_2::RuleNode)
Performs a random crossover of two parents of type RuleNode
. The subprograms are swapped and only one altered parent program is returned.
HerbSearch.crossover_swap_children_2
— Methodcrossover_swap_children_2(parent_1::RuleNode, parent_2::RuleNode)
Performs a random crossover of two parents of type RuleNode
. The subprograms are swapped and both altered parent programs are returned.
HerbSearch.decreasing_temperature
— Methoddecreasing_temperature(percentage::Real)
Returns a function that produces a temperature decreased by percentage
%. This function is used by the Simmulated Annealing algorithm.
Arguments
percentage::Real
: the percentage to decrease the temperature by.
HerbSearch.default_fitness
— Methoddefault_fitness(program, results)
Defines the default fitness function taking the program and its results. Results are a vector of tuples, where each tuple is in the form Tuple{expected_output, actual_output}
. As we are looking for individuals with the highest fitness function, the error is inverted.
HerbSearch.derivation_heuristic
— Methodderivation_heuristic(iter::MLFSIterator, domain::Vector{Int})
Defines derivation_heuristic
for the iterator type MLFSIterator
. Sorts the indices within a domain, that is grammar rules, by decreasing log_probabilities.
This will invert the enumeration order if probabilities are equal.
HerbSearch.derivation_heuristic
— Methodfunction derivation_heuristic(::RandomIterator, indices::Vector{Int})
Randomly shuffles the rules.
HerbSearch.derivation_heuristic
— Methodfunction derivation_heuristic(::TopDownIterator, indices::Vector{Int})
Returns a sorted sublist of the indices
, based on which rules are most promising to fill a hole. The underlying solver can change the order within a Hole's domain. We sort the domain to make the enumeration order explicit and more predictable.
HerbSearch.enumerate_neighbours_propose
— Methodenumerate_neighbours_propose(enumeration_depth::Int64)
The return function is a function that produces a list with all the subprograms with depth at most enumeration_depth
.
HerbSearch.evaluate
— Methodevaluate(problem::Problem{Vector{IOExample}}, expr::Any, tab::SymbolTable; allow_evaluation_errors::Bool=false)
Evaluate the expression on the examples.
Optional parameters:
- `shortcircuit` - Whether to stop evaluating after finding single example fails, to speed up the [synth](@ref) procedure. If true, the returned score is an underapproximation of the actual score.
- `allow_evaluation_errors` - Whether the search should continue if an exception is thrown in the evaluation or throw the error
Returns a score in the interval [0, 1]
HerbSearch.extract_name_from_argument
— Methodextract_name_from_argument(ex)
Extracts the name of a field declaration, otherwise throws an ArgumentError
. A field declaration is either a simple field name with possible a type attached to it or a keyword argument.
Example
x::Int -> x hello -> hello x = 4 -> x x::Int = 3 -> x
HerbSearch.fitness
— Methodfitness(::GeneticSearchIterator, program, results)
Assigns a numerical value (fitness score) to each individual based on how closely it meets the desired objective.
HerbSearch.generate_branches
— MethodReturns a vector of disjoint branches to expand the search tree at its current state. Example:
# pseudo code
Hole(domain=[2, 4, 5], children=[
Hole(domain=[1, 6]),
Hole(domain=[1, 6])
])
If we split on the first hole, this function will create three branches.
(firsthole, 2)
(firsthole, 4)
(firsthole, 5)
HerbSearch.get_best_program
— Methodget_best_program(population::Array{RuleNode}, iter::GeneticSearchIterator)::RuleNode
Returns the best program within the population with respect to the fitness function.
HerbSearch.heuristic_leftmost
— Methodheuristic_leftmost(node::AbstractRuleNode, max_depth::Int)::Union{ExpandFailureReason, HoleReference}
Defines a heuristic over holes, where the left-most hole always gets considered first. Returns a HoleReference
once a hole is found. This is the default option for enumerators.
HerbSearch.heuristic_random
— Methodheuristic_random(node::AbstractRuleNode, max_depth::Int)::Union{ExpandFailureReason, HoleReference}
Defines a heuristic over holes, where random holes get chosen randomly using random exploration. Returns a HoleReference
once a hole is found.
HerbSearch.heuristic_rightmost
— Methodheuristic_rightmost(node::AbstractRuleNode, max_depth::Int)::Union{ExpandFailureReason, HoleReference}
Defines a heuristic over holes, where the right-most hole always gets considered first. Returns a HoleReference
once a hole is found.
HerbSearch.heuristic_smallest_domain
— Methodheuristic_smallest_domain(node::AbstractRuleNode, max_depth::Int)::Union{ExpandFailureReason, HoleReference}
Defines a heuristic over all available holes in the unfinished AST, by considering the size of their respective domains. A domain here describes the number of possible derivations with respect to the constraints. Returns a HoleReference
once a hole is found.
HerbSearch.hole_heuristic
— Methodhole_heuristic(::TopDownIterator, node::AbstractRuleNode, max_depth::Int)::Union{ExpandFailureReason, HoleReference}
Defines a heuristic over variable shaped holes. Returns a HoleReference
once a hole is found.
HerbSearch.is_field_decl
— Methodis_field_decl(ex)
Check if extractname(ex)
returns a name.
HerbSearch.is_kwdef
— Methodis_kwdeg(ex)
Checks if a field declaration is a keyword argument or not. This is called when filtering if the user arguments to the program iteartor are keyword arguments or not.
HerbSearch.mean_squared_error
— Methodmean_squared_error(results::AbstractVector{Tuple{<:Number,<:Number}})
Returns the mean squared error of results
.
Arguments
results<:AbstractVector{<:Tuple{Number,Number}}
: the vector of tuples, where each tuple is in the formTuple{expected_output, actual_output}
.
HerbSearch.misclassification
— Methodmisclassification(results::AbstractVector{Tuple{<:Number,<:Number}})
Returns the amount of misclassified examples, i.e. how many tuples with non-matching entries are there in results
.
Arguments
results<:AbstractVector{<:Tuple{Number,Number}}
: the vector of tuples, where each tuple is in the formTuple{expected_output, actual_output}
.
HerbSearch.mutate!
— Functionmutate!(::GeneticSearchIterator, program::RuleNode, grammar::AbstractGrammar, max_depth::Int = 2)
Mutates the program of an invididual.
HerbSearch.mutate_random!
— Functionmutate_random!(program::RuleNode, grammar::AbstractGrammar, max_depth::Int64 = 2)
Mutates the given program by inserting a randomly generated sub-program at a random location.
HerbSearch.neighbourhood
— Methodneighbourhood(iter::StochasticSearchIterator, current_program::RuleNode)
Returns a node location from the neighbourhood of the current program.
HerbSearch.next_solution!
— Methodnext_solution!(iter::UniformIterator)::Union{RuleNode, StateHole, Nothing}
Searches for the next unvisited solution. Returns nothing if all solutions have been found already.
HerbSearch.priority_function
— Methodpriority_function(::AbstractDFSIterator, g::AbstractGrammar, tree::AbstractRuleNode, parent_value::Union{Real, Tuple{Vararg{Real}}}, isrequeued::Bool)
Assigns priority such that the search tree is traversed like in a DFS manner.
HerbSearch.priority_function
— Methodpriority_function(::MLFSIterator, grammar::AbstractGrammar, current_program::AbstractRuleNode, parent_value::Union{Real, Tuple{Vararg{Real}}}, isrequeued::Bool)
Calculates the priority function of the MLFSIterator
. The priority value of a tree is then the maxrulenodelog_probability within the represented uniform tree. The value is negated as lower priority values are popped earlier.
HerbSearch.priority_function
— Methodpriority_function(::RandomIterator, g::AbstractGrammar, tree::AbstractRuleNode, parent_value::Union{Real, Tuple{Vararg{Real}}}, isrequeued::Bool)
Assigns a random priority to each state.
HerbSearch.priority_function
— Methodpriority_function(::TopDownIterator, g::AbstractGrammar, tree::AbstractRuleNode, parent_value::Union{Real, Tuple{Vararg{Real}}}, isrequeued::Bool)
Assigns a priority value to a tree
that needs to be considered later in the search. Trees with the lowest priority value are considered first.
- ``: The first argument is a dispatch argument and is only used to dispatch to the correct priority function
g
: The grammar used for enumerationtree
: The tree that is about to be stored in the priority queueparent_value
: The priority value of the parentSolverState
isrequeued
: The same tree shape will be requeued. The next time this tree shape is considered, theUniformSolver
will produce the next complete program deriving from this shape.
HerbSearch.probabilistic_accept
— Methodprobabilistic_accept(current_cost::Real, next_cost::Real, temperature::Real)
Probabilistically decides whether to accept the new program (next) based on the ratio of costs (smaller is better) between the previous and new program. Returns True
if the new program is accepted, False
otherwise.
Arguments
current_cost::Real
: the cost of the current program.next_cost::Real
: the cost of the proposed program.temperature::Real
: the temperature; not used.
HerbSearch.probabilistic_accept_with_temperature
— Methodprobabilistic_accept_with_temperature(current_cost::Real, next_cost::Real, temperature::Real)
Returns true if the cost of the proposed program is smaller than the cost of the current program. Otherwise, returns true with the probability equal to:
\[1 / (1 + exp(delta / temperature))\]
In any other case, returns false.
Arguments
current_cost::Real
: the cost of the current program.next_cost::Real
: the cost of the proposed program.temperature::Real
: the temperature of the search.
HerbSearch.probabilistic_accept_with_temperature_fraction
— Methodprobabilistic_accept_with_temperature_fraction(current_cost::Real, program_to_consider_cost::Real, temperature::Real)
Probabilistically decides whether to accept the new program (next) based on the ratio of costs (smaller is better) between the previous and new program multiplied by the temperature. Returns True
if the new program is accepted, False
otherwise.
Arguments
current_cost::Real
: the cost of the current program.next_cost::Real
: the cost of the proposed program.temperature::Real
: the current temperature
HerbSearch.processkwarg!
— Methodprocesskwarg!(keywords::Vector{Expr}, ex::Union{Expr, Symbol})
Checks if ex
has a default value specified, if so it returns only the field declaration, and pushes ex
to keywords
. Otherwise it returns ex
HerbSearch.propose
— Methodpropose(iter::StochasticSearchIterator, path::Vector{Int}, dict::Union{Nothing,Dict{String,Any}})
Proposes a list of programs to fill in the location provided by path
and the dict
.
HerbSearch.random_fill_propose
— Functionrandom_fill_propose(solver::Solver, path::Vector{Int}, dict::Union{Nothing,Dict{String,Any}}, nr_random=5)
Returns a list with only one proposed, completely random, subprogram.
Arguments
solver::solver
: solverpath::Vector{Int}
: path to the location to be filled.dict::Dict{String, Any}
: the dictionary with additional arguments; not used.nr_random
=1 : the number of random subprograms to be generated.
HerbSearch.select_chromosome
— Methodselect_chromosome(population::Array{RuleNode}, fitness_array::Array{<:Real})::RuleNode
Selects a chromosome (individual) from the population based on a fitness array. The function uses a fitness-proportionate selection strategy, often referred to as "roulette wheel" selection. Assumes fitness_array
to be normalized already.
HerbSearch.select_fitness_proportional_parents
— Methodselect_fitness_proportional_parents(population::Array{RuleNode}, fitness_array::Array{<:Real})::Tuple{RuleNode,RuleNode}
Selects two parent chromosomes (individuals) from a population based on fitness-proportionate selection. The selected parents can be used for genetic crossover in the next steps of the algorithm.
HerbSearch.select_parents
— Methodselect_parents(::GeneticSearchIterator, population::Array{RuleNode}, fitness_array::Array{<:Real})
Selects two parents for the crossover.
HerbSearch.set_stateholes!
— Methodfunction set_stateholes!(iter::UniformIterator, node::Union{StateHole, RuleNode})::Vector{StateHole}
Does a dfs to retrieve all unfilled state holes in the program tree and stores them in the stateholes
vector.
HerbSearch.synth
— Methodsynth(problem::Problem, iterator::ProgramIterator; shortcircuit::Bool=true, allow_evaluation_errors::Bool=false, mod::Module=Main)::Union{Tuple{RuleNode, SynthResult}, Nothing}
Synthesize a program that satisfies the maximum number of examples in the problem. - problem - The problem definition with IO examples - iterator - The iterator that will be used - shortcircuit - Whether to stop evaluating after finding a single example that fails, to speed up the synth procedure. If true, the returned score is an underapproximation of the actual score. - allowevaluationerrors - Whether the search should crash if an exception is thrown in the evaluation - maxtime - Maximum time that the iterator will run - maxenumerations - Maximum number of iterations that the iterator will run - mod - A module containing definitions for the functions in the grammar that do not exist in Main
Returns a tuple of the rulenode representing the solution program and a synthresult that indicates if that program is optimal. synth
uses evaluate
which returns a score in the interval [0, 1] and checks whether that score reaches 1. If not it will return the best program so far, with the proper flag
HerbSearch.temperature
— Methodtemperature(::StochasticSearchIterator, current_temperature::Real)
Returns the new temperature based on the current temperature. A higher temperature means that the algorithm will explore more.
HerbSearch.validate_iterator
— Methodvalidate_iterator(iter)
Validates the parameters of the iterator
StatsBase.sample
— Functionsample(root::RuleNode, typ::Symbol, grammar::AbstractGrammar,
maxdepth::Int=typemax(Int))
Uniformly selects a random node of the given return type typ limited by maxdepth.
StatsBase.sample
— Functionsample(root::RuleNode, typ::Symbol, grammar::AbstractGrammar, maxdepth::Int=typemax(Int))
Uniformly samples a random node from the tree limited to maxdepth.
StatsBase.sample
— Functionsample(::Type{NodeLoc}, root::RuleNode, maxdepth::Int=typemax(Int))
Uniformly selects a random node in the tree no deeper than maxdepth using reservoir sampling. Returns a NodeLoc
that specifies the location using its parent so that the subtree can be replaced.
StatsBase.sample
— FunctionStatsBase.sample(::Type{NodeLoc}, root::RuleNode, typ::Symbol, grammar::AbstractGrammar, maxdepth::Int=typemax(Int))
Uniformly selects a random node in the tree of a given type, specified using its parent such that the subtree can be replaced. Returns a NodeLoc
.
The HerbSearch package takes care of all operations related to searching for the desired program. This includes
- the functionality to sample a certain program given a grammar,
- the implementation of several heuristic functions,
- searching for a program that satisfies the specification, and
- implementations of several search algorithms in terms of how they enumerate the search space
- Breadth-First Search
- Depth-First Search
- Metropolis Hastings
- Very Large Scale Neighbourhood Search
- Simulated Annealing
- Genetic Search
Index
HerbConstraints.AbstractGrammarConstraint
HerbConstraints.AbstractLocalConstraint
HerbConstraints.AbstractStateManager
HerbConstraints.Contains
HerbConstraints.ContainsSubtree
HerbConstraints.DomainRuleNode
HerbConstraints.Forbidden
HerbConstraints.ForbiddenSequence
HerbConstraints.GenericSolver
HerbConstraints.GenericSolver
HerbConstraints.GenericSolver
HerbConstraints.LessThanOrEqualHardFail
HerbConstraints.LessThanOrEqualResult
HerbConstraints.LessThanOrEqualSoftFail
HerbConstraints.LessThanOrEqualSuccess
HerbConstraints.LessThanOrEqualSuccessEquality
HerbConstraints.LessThanOrEqualSuccessLessThan
HerbConstraints.LessThanOrEqualSuccessWithHoles
HerbConstraints.LocalContains
HerbConstraints.LocalContainsSubtree
HerbConstraints.LocalContainsSubtree
HerbConstraints.LocalForbidden
HerbConstraints.LocalForbiddenSequence
HerbConstraints.LocalOrdered
HerbConstraints.LocalUnique
HerbConstraints.MakeEqualHardFail
HerbConstraints.MakeEqualResult
HerbConstraints.MakeEqualSoftFail
HerbConstraints.MakeEqualSuccess
HerbConstraints.Ordered
HerbConstraints.PatternMatchHardFail
HerbConstraints.PatternMatchResult
HerbConstraints.PatternMatchSoftFail
HerbConstraints.PatternMatchSuccess
HerbConstraints.PatternMatchSuccessWhenHoleAssignedTo
HerbConstraints.Solver
HerbConstraints.SolverState
HerbConstraints.SolverStatistics
HerbConstraints.StateHole
HerbConstraints.StateHole
HerbConstraints.StateHole
HerbConstraints.StateInt
HerbConstraints.StateIntBackup
HerbConstraints.StateManager
HerbConstraints.StateSparseSet
HerbConstraints.StateSparseSet
HerbConstraints.StateStack
HerbConstraints.StateStack
HerbConstraints.StateStack
HerbConstraints.UniformSolver
HerbConstraints.UniformSolver
HerbConstraints.Unique
HerbConstraints.VarNode
HerbCore.AbstractConstraint
HerbCore.AbstractGrammar
HerbCore.AbstractHole
HerbCore.AbstractRuleNode
HerbCore.AbstractUniformHole
HerbCore.Hole
HerbCore.HoleReference
HerbCore.RuleNode
HerbCore.RuleNode
HerbCore.RuleNode
HerbCore.UniformHole
HerbGrammar.ContextSensitiveGrammar
HerbGrammar.NodeLoc
HerbGrammar.SymbolTable
HerbSearch.AbstractBFSIterator
HerbSearch.AbstractDFSIterator
HerbSearch.AbstractMHSearchIterator
HerbSearch.AbstractSASearchIterator
HerbSearch.AbstractVLSNSearchIterator
HerbSearch.BFSIterator
HerbSearch.DFSIterator
HerbSearch.ExpandFailureReason
HerbSearch.GeneticSearchIterator
HerbSearch.MHSearchIterator
HerbSearch.MLFSIterator
HerbSearch.ProgramIterator
HerbSearch.RandomIterator
HerbSearch.SASearchIterator
HerbSearch.StochasticSearchIterator
HerbSearch.SynthResult
HerbSearch.TopDownIterator
HerbSearch.UniformIterator
HerbSearch.UniformIterator
HerbSearch.VLSNSearchIterator
HerbSpecification.AbstractDependentTypeSpecification
HerbSpecification.AgdaSpecification
HerbSpecification.IOExample
HerbSpecification.MetricProblem
HerbSpecification.Problem
HerbSpecification.SMTSpecification
HerbSpecification.Trace
Base.collect
Base.collect
Base.findall
Base.findfirst
Base.findlast
Base.get
Base.getindex
Base.getindex
Base.in
Base.in
Base.insert!
Base.isless
Base.iterate
Base.iterate
Base.iterate
Base.iterate
Base.iterate
Base.length
Base.length
Base.length
Base.length
Base.push!
Base.rand
Base.rand
Base.rand
Base.show
Base.size
Base.size
Base.sum
HerbConstraints._contains
HerbConstraints._count_occurrences
HerbConstraints._count_occurrences
HerbConstraints._count_occurrences!
HerbConstraints._exchange_positions!
HerbConstraints._update_bounds_val_removed!
HerbConstraints._update_max_val_removed!
HerbConstraints._update_min_val_removed!
HerbConstraints.annotation2constraint
HerbConstraints.are_disjoint
HerbConstraints.are_disjoint
HerbConstraints.backup!
HerbConstraints.check_tree
HerbConstraints.check_tree
HerbConstraints.check_tree
HerbConstraints.check_tree
HerbConstraints.check_tree
HerbConstraints.check_tree
HerbConstraints.contains_varnode
HerbConstraints.deactivate!
HerbConstraints.deactivate!
HerbConstraints.decrement!
HerbConstraints.fix_point!
HerbConstraints.freeze_state
HerbConstraints.get_grammar
HerbConstraints.get_grammar
HerbConstraints.get_hole_at_location
HerbConstraints.get_hole_at_location
HerbConstraints.get_intersection
HerbConstraints.get_max_depth
HerbConstraints.get_max_size
HerbConstraints.get_nodes
HerbConstraints.get_nodes_on_path
HerbConstraints.get_priority
HerbConstraints.get_starting_symbol
HerbConstraints.get_state
HerbConstraints.get_tree
HerbConstraints.get_tree
HerbConstraints.get_tree_size
HerbConstraints.get_value
HerbConstraints.increment!
HerbConstraints.is_subdomain
HerbConstraints.is_subdomain
HerbConstraints.isfeasible
HerbConstraints.isfeasible
HerbConstraints.load_state!
HerbConstraints.make_equal!
HerbConstraints.make_less_than_or_equal!
HerbConstraints.make_less_than_or_equal!
HerbConstraints.make_less_than_or_equal!
HerbConstraints.new_state!
HerbConstraints.notify_new_node
HerbConstraints.notify_new_nodes
HerbConstraints.notify_new_nodes
HerbConstraints.notify_tree_manipulation
HerbConstraints.notify_tree_manipulation
HerbConstraints.partition
HerbConstraints.pattern_match
HerbConstraints.pattern_match
HerbConstraints.pattern_match
HerbConstraints.pattern_match
HerbConstraints.pattern_match
HerbConstraints.pattern_match
HerbConstraints.post!
HerbConstraints.post!
HerbConstraints.propagate!
HerbConstraints.propagate!
HerbConstraints.propagate!
HerbConstraints.propagate!
HerbConstraints.propagate!
HerbConstraints.propagate!
HerbConstraints.propagate!
HerbConstraints.remove!
HerbConstraints.remove!
HerbConstraints.remove!
HerbConstraints.remove!
HerbConstraints.remove!
HerbConstraints.remove_above!
HerbConstraints.remove_above!
HerbConstraints.remove_above!
HerbConstraints.remove_all_but!
HerbConstraints.remove_all_but!
HerbConstraints.remove_all_but!
HerbConstraints.remove_all_but!
HerbConstraints.remove_below!
HerbConstraints.remove_below!
HerbConstraints.remove_below!
HerbConstraints.remove_node!
HerbConstraints.restore!
HerbConstraints.restore!
HerbConstraints.restore!
HerbConstraints.save_state!
HerbConstraints.save_state!
HerbConstraints.save_state!
HerbConstraints.schedule!
HerbConstraints.set_infeasible!
HerbConstraints.set_infeasible!
HerbConstraints.set_value!
HerbConstraints.shouldschedule
HerbConstraints.shouldschedule
HerbConstraints.simplify_hole!
HerbConstraints.substitute!
HerbCore.contains_hole
HerbCore.contains_hole
HerbCore.contains_index
HerbCore.contains_nonuniform_hole
HerbCore.depth
HerbCore.get_children
HerbCore.get_node_at_location
HerbCore.get_node_at_location
HerbCore.get_node_at_location
HerbCore.get_node_at_location
HerbCore.get_path
HerbCore.get_path
HerbCore.get_path
HerbCore.get_rule
HerbCore.get_rule
HerbCore.get_rulesequence
HerbCore.hasdynamicvalue
HerbCore.have_same_shape
HerbCore.isfilled
HerbCore.isfilled
HerbCore.isuniform
HerbCore.node_depth
HerbCore.number_of_holes
HerbCore.rulesoftype
HerbCore.rulesoftype
HerbCore.rulesonleft
HerbCore.swap_node
HerbCore.swap_node
HerbGrammar.add_rule!
HerbGrammar.add_rule!
HerbGrammar.add_rule!
HerbGrammar.addconstraint!
HerbGrammar.child_types
HerbGrammar.child_types
HerbGrammar.cleanup_removed_rules!
HerbGrammar.clearconstraints!
HerbGrammar.containedin
HerbGrammar.contains_returntype
HerbGrammar.expr2csgrammar
HerbGrammar.expr2pcsgrammar
HerbGrammar.expr2rulenode
HerbGrammar.expr2rulenode
HerbGrammar.expr2rulenode
HerbGrammar.expr2rulenode
HerbGrammar.get_childtypes
HerbGrammar.get_domain
HerbGrammar.get_domain
HerbGrammar.get_rulesequence
HerbGrammar.grammar2symboltable
HerbGrammar.init_probabilities!
HerbGrammar.iscomplete
HerbGrammar.iseval
HerbGrammar.iseval
HerbGrammar.iseval
HerbGrammar.isprobabilistic
HerbGrammar.isterminal
HerbGrammar.isterminal
HerbGrammar.isterminal
HerbGrammar.isvariable
HerbGrammar.isvariable
HerbGrammar.isvariable
HerbGrammar.isvariable
HerbGrammar.log_probability
HerbGrammar.max_arity
HerbGrammar.max_rulenode_log_probability
HerbGrammar.merge_grammars!
HerbGrammar.mindepth
HerbGrammar.mindepth_map
HerbGrammar.nchildren
HerbGrammar.nchildren
HerbGrammar.nonterminals
HerbGrammar.normalize!
HerbGrammar.parse_probabilistic_rule
HerbGrammar.probability
HerbGrammar.read_csg
HerbGrammar.read_pcsg
HerbGrammar.remove_rule!
HerbGrammar.return_type
HerbGrammar.return_type
HerbGrammar.return_type
HerbGrammar.root_node_loc
HerbGrammar.rulenode2expr
HerbGrammar.rulenode_log_probability
HerbGrammar.rulesonleft
HerbGrammar.store_csg
HerbGrammar.subsequenceof
HerbGrammar.swap_node
HerbGrammar.swap_node
HerbInterpret.evaluate_program
HerbInterpret.execute_on_input
HerbInterpret.execute_on_input
HerbInterpret.execute_on_input
HerbInterpret.execute_on_input
HerbInterpret.interpret
HerbInterpret.test_all_examples
HerbInterpret.test_examples
HerbSearch._calculate_cost
HerbSearch._find_next_complete_tree
HerbSearch.accept
HerbSearch.best_accept
HerbSearch.calculate_cost
HerbSearch.const_temperature
HerbSearch.constructNeighbourhood
HerbSearch.constructNeighbourhoodRuleSubset
HerbSearch.cross_over
HerbSearch.crossover_swap_children_1
HerbSearch.crossover_swap_children_2
HerbSearch.decreasing_temperature
HerbSearch.default_fitness
HerbSearch.derivation_heuristic
HerbSearch.derivation_heuristic
HerbSearch.derivation_heuristic
HerbSearch.enumerate_neighbours_propose
HerbSearch.evaluate
HerbSearch.extract_name_from_argument
HerbSearch.fitness
HerbSearch.generate_branches
HerbSearch.get_best_program
HerbSearch.heuristic_leftmost
HerbSearch.heuristic_random
HerbSearch.heuristic_rightmost
HerbSearch.heuristic_smallest_domain
HerbSearch.hole_heuristic
HerbSearch.is_field_decl
HerbSearch.is_kwdef
HerbSearch.mean_squared_error
HerbSearch.misclassification
HerbSearch.mutate!
HerbSearch.mutate_random!
HerbSearch.neighbourhood
HerbSearch.next_solution!
HerbSearch.priority_function
HerbSearch.priority_function
HerbSearch.priority_function
HerbSearch.priority_function
HerbSearch.probabilistic_accept
HerbSearch.probabilistic_accept_with_temperature
HerbSearch.probabilistic_accept_with_temperature_fraction
HerbSearch.processkwarg!
HerbSearch.propose
HerbSearch.random_fill_propose
HerbSearch.select_chromosome
HerbSearch.select_fitness_proportional_parents
HerbSearch.select_parents
HerbSearch.set_stateholes!
HerbSearch.synth
HerbSearch.temperature
HerbSearch.validate_iterator
StatsBase.sample
StatsBase.sample
StatsBase.sample
StatsBase.sample
HerbConstraints.@csgrammar_annotated
HerbCore.@rulenode
HerbGrammar.@cfgrammar
HerbGrammar.@csgrammar
HerbGrammar.@pcsgrammar
HerbSearch.@programiterator