Module programinduction::pcfg
[−]
[src]
(representation) Probabilistic context-free grammar without bound variables or polymorphism.
Examples
use programinduction::pcfg::{task_by_evaluation, Grammar, Rule}; fn evaluator(name: &str, inps: &[i32]) -> i32 { match name { "0" => 0, "1" => 1, "plus" => inps[0] + inps[1], _ => unreachable!(), } } let g = Grammar::new( tp!(EXPR), vec![ Rule::new("0", tp!(EXPR), 1.0), Rule::new("1", tp!(EXPR), 1.0), Rule::new("plus", tp!(@arrow[tp!(EXPR), tp!(EXPR), tp!(EXPR)]), 1.0), ], ); // task: the number 4 let task = task_by_evaluation(&evaluator, &4, tp!(EXPR)); // solution: let expr = g.parse("plus(1, plus(1, plus(1,1)))").unwrap(); assert!((task.oracle)(&g, &expr).is_finite())
Structs
AppliedRule |
Identifies a rule by its location in |
EstimationParams |
Parameters for PCFG parameter estimation. |
GeneticParams |
Parameters for PCFG genetic programming ( |
Grammar |
(representation) Probabilistic context-free grammar. Currently cannot handle bound variables or polymorphism. |
Rule |
A PCFG rule specifies a production that can happen for a particular nonterminal. |
Enums
ParseError |
Functions
task_by_evaluation |
Create a task based on evaluating a PCFG sentence and comparing its output against data. |