# Data # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def make_data(size=options.datasize): return [FunctionData(input=[], output={'h e s': size, 'm e s': size, 'm e g': size, 'h e g': size, 'm e n': size, 'h e m': size, 'm e k': size, 'k e s': size, 'h e k': size, 'k e N': size, 'k e g': size, 'h e n': size, 'm e N': size, 'k e n': size, 'h e N': size, 'f e N': size, 'g e N': size, 'n e N': size, 'n e s': size, 'f e n': size, 'g e n': size, 'g e m': size, 'f e m': size, 'g e k': size, 'f e k': size, 'f e g': size, 'f e s': size, 'n e g': size, 'k e m': size, 'n e m': size, 'g e s': size, 'n e k': size})] import LOTlib.Miscellaneous from LOTlib.Grammar import Grammar from LOTlib.Miscellaneous import q from LOTlib.Eval import register_primitive register_primitive(LOTlib.Miscellaneous.flatten2str) # # # # # # # # # # # # # # # # # # # # # # # # # # # # # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # Grammar # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ TERMINAL_WEIGHT = 15 grammar = Grammar() # flattern2str lives at the top, and it takes a cons, cdr, car structure and projects it to a string grammar.add_rule('START', 'flatten2str', ['EXPR'], 1.0) grammar.add_rule('EXPR', 'sample_', ['SET'], 1.)
from LOTlib.Eval import register_primitive from LOTlib.Miscellaneous import flatten2str, logsumexp, qq from LOTlib.TopN import TopN from Model.Hypothesis import MyHypothesis from Language import * from mpi4py import MPI comm = MPI.COMM_WORLD size = comm.Get_size() rank = comm.Get_rank() fff = sys.stdout.flush from copy import deepcopy from LOTlib.Projects.FormalLanguageTheory.Model.Grammar import base_grammar # passed in as kwargs register_primitive(flatten2str) global prefix global suffix prefix = "" suffix = "" LARGE_SAMPLE = 10000 # sample this many and then re-normalize to fractional counts from math import log from LOTlib.Miscellaneous import attrmem from Levenshtein import distance from LOTlib.Hypotheses.RecursiveLOTHypothesis import RecursiveLOTHypothesis, RecursionDepthException from LOTlib.Hypotheses.Proposers.Sandbox.InverseInlineProposer import InverseInlineProposer from LOTlib.Hypotheses.Proposers.InsertDeleteProposal import InsertDeleteProposal from LOTlib.Hypotheses.Likelihoods.StochasticLikelihood import StochasticLikelihood
'D N V N': size, 'D N V D N': size }) ] # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # Grammar # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ import LOTlib.Miscellaneous from LOTlib.Grammar import Grammar from LOTlib.Miscellaneous import q from LOTlib.Eval import register_primitive register_primitive(LOTlib.Miscellaneous.flatten2str) # # # # # # # # # # # # # # # # # # # # # # # # # # # # TERMINAL_WEIGHT = 2. grammar = Grammar() # flattern2str lives at the top, and it takes a cons, cdr, car structure and projects it to a string grammar.add_rule('START', 'flatten2str', ['EXPR'], 1.0) grammar.add_rule('BOOL', 'and_', ['BOOL', 'BOOL'], 1.) grammar.add_rule('BOOL', 'or_', ['BOOL', 'BOOL'], 1.) grammar.add_rule('BOOL', 'not_', ['BOOL'], 1.) grammar.add_rule('EXPR', 'if_', ['BOOL', 'EXPR', 'EXPR'], 1.)
from LOTlib.Inference.Samplers.MetropolisHastings import MHSampler from LOTlib.Eval import register_primitive from LOTlib.Miscellaneous import flatten2str, logsumexp, qq from LOTlib.TopN import TopN from Model.Hypothesis import MyHypothesis from Language import * from mpi4py import MPI comm = MPI.COMM_WORLD size = comm.Get_size() rank = comm.Get_rank() fff = sys.stdout.flush from copy import deepcopy from LOTlib.Projects.FormalLanguageTheory.Model.Grammar import base_grammar # passed in as kwargs register_primitive(flatten2str) global prefix global suffix prefix = "" suffix = "" LARGE_SAMPLE = 100000 # sample this many and then re-normalize to fractional counts def run(options, ndata): """ This out on the DATA_RANGE amounts of data and returns all hypotheses in top count """ if LOTlib.SIG_INTERRUPTED: return set()
# Math rules (30-40 of these) # --------------------------- # Odd numbers mix_grammar.add_rule('EXPR', 'plus_', ['ODD', str(1)], 1.) mix_grammar.add_rule('ODD', 'times_', ['X', str(2)], 1.) # Primes mix_grammar.add_rule('EXPR', 'isprime_', ['X'], 1.) # Squares, cubes mix_grammar.add_rule('EXPR', 'ipowf_', ['X', str(2)], 1.) mix_grammar.add_rule('EXPR', 'ipowf_', ['X', str(3)], 1.) # { 2^n - 32 } register_primitive(lambda x: x if x in (2, 4, 8, 16, 64) else 0, name='pow2n_d32_') mix_grammar.add_rule('EXPR', 'pow2n_d32_', ['X'], 1.) # { 2^n & 37 } register_primitive(lambda x: x if x in (2, 4, 8, 16, 32, 37, 64) else 0, name='pow2n_u37_') mix_grammar.add_rule('EXPR', 'pow2n_u37_', ['X'], 1.) # [2,12] * n for i in range(2, 13): mix_grammar.add_rule('EXPR', 'times_', ['X', str(i)], 1.) # [2,10] ^ m for i in range(2, 11): mix_grammar.add_rule('EXPR', 'ipowf_', [str(i), 'X'], 1.) # Ends in [0,9] for i in range(0, 10):