示例#1
0
#napsPrimitives.py
from dreamcoder.program import Primitive, prettyProgram
from dreamcoder.grammar import Grammar
from dreamcoder.type import tlist, tint, arrow, baseType  #, t0, t1, t2

#from functools import reduce

#types
PROGRAM = baseType("PROGRAM")

RECORD = baseType("RECORD")
FUNC = baseType("FUNC")

VAR = baseType("VAR")
STMT = baseType("STMT")
EXPR = baseType("EXPR")
ASSIGN = baseType("ASSIGN")
LHS = baseType("LHS")
IF = baseType("IF")
FOREACH = baseType("FOREACH")
WHILE = baseType("WHILE")
BREAK = baseType("BREAK")
CONTINUE = baseType("CONTINUE")
RETURN = baseType("RETURN")
NOOP = baseType("NOOP")
FIELD = baseType("FIELD")
CONSTANT = baseType("CONSTANT")
INVOKE = baseType("INVOKE")
TERNARY = baseType("TERNARY")
CAST = baseType("CAST")
TYPE = baseType("TYPE")
示例#2
0
delim_dict = {disallowed[c]: c for c in delimiters}

types = {}
types["Number"] = r'\d+'
types["Word"] = r'\w+'
types["Alphanum"] = r'\w'
types["PropCase"] = r'[A-Z][a-z]+'
types["AllCaps"] = r'[A-Z]'
types["Lower"] = r'[a-z]'
types["Digit"] = r'\d'
types["Char"] = r'.'

regexes = {name: re.escape(val) for name, val in delim_dict.items()}
regexes = {**regexes, **types}

tposition = baseType("position")
tindex = baseType("index")
tcharacter = baseType("character")
tboundary = baseType("boundary")
tregex = baseType("regex")
tsubstr = baseType("substr")
texpression = baseType("expression")
tprogram = baseType("program")
tnesting = baseType("nesting")
ttype = baseType("type")
tdelimiter = baseType("delimiter")


def _substr(k1):
    return lambda k2: lambda string: string[k1:k2]  #i think this is fine
示例#3
0
from dreamcoder.program import Primitive, Program
from dreamcoder.grammar import Grammar
from dreamcoder.type import tlist, arrow, baseType #, t0, t1, t2

#from functools import reduce


#Internal TYPES:
# NUMBER
# BOOLEAN
# NOTFUNCTYPE
# Type
# ANYTYPE

#types
tsymbol = baseType("symbol")
#PROGRAM = SYMBOL = constant | argument | function_call | function | lambda
tconstant = baseType("constant")
tfunction = baseType("function")

f = dict([("|||","triple_or"),
("reduce","reduce"),
("+","+"),
("len","len"),
("map","map"),
("filter","filter"),
("-","-"),
("*","*"),
("partial0","partial0"),
("if","if"),
("lambda1","lambda1"),
示例#4
0
    import bin.binutil  # alt import if called as module

from bin.rational import RandomParameterization
from dreamcoder.domains.arithmetic.arithmeticPrimitives import (
    f0, f1, fpi, real_power, real_subtraction, real_addition, real_division,
    real_multiplication)
from dreamcoder.domains.list.listPrimitives import bootstrapTarget
from dreamcoder.dreamcoder import explorationCompression, commandlineArguments
from dreamcoder.grammar import Grammar
from dreamcoder.program import Program
from dreamcoder.recognition import RecurrentFeatureExtractor, DummyFeatureExtractor
from dreamcoder.task import DifferentiableTask, squaredErrorLoss
from dreamcoder.type import baseType, tlist, arrow
from dreamcoder.utilities import eprint, numberOfCPUs

tvector = baseType("vector")
treal = baseType("real")
tpositive = baseType("positive")


def makeTrainingData(
        request,
        law,
        # Number of examples
        N=10,
        # Vector dimensionality
        D=2,
        # Maximum absolute value of a random number
        S=20.):
    from random import random, randint
示例#5
0
from dreamcoder.program import Primitive, prettyProgram
from dreamcoder.grammar import Grammar
from dreamcoder.type import tlist, tint, arrow, baseType  #, t0, t1, t2

#from functools import reduce

#todo
int_to_int = baseType("int_to_int")
int_to_bool = baseType("int_to_bool")
int_to_int_to_int = baseType("int_to_int_to_int")

#deepcoderPrimitives
Null = 300  #or perhaps something else, like "an integer outside the working range"?


def _head(xs):
    return xs[0] if len(xs) > 0 else Null


def _tail(xs):
    return xs[-1] if len(xs) > 0 else Null


def _take(n):
    return lambda xs: xs[:n]


def _drop(n):
    return lambda xs: xs[n:]

示例#6
0
from dreamcoder.grammar import Grammar
from dreamcoder.type import baseType, arrow

from matplotlib import patches
from matplotlib.collections import PatchCollection
import matplotlib.pyplot as plt
from matplotlib import transforms
import matplotlib
import math
import numpy as np

NBINS = 10  # for discretizing continious params
XYLIM = 5.  # size of canvas.

# ========== base types
tdummy = baseType("tdummy")
taxes = baseType("taxes")
tartist = baseType("tartist")
tangle = baseType("tangle")
tscale = baseType("tscale")
tdist = baseType("tdist")
ttrorder = baseType("ttorder")

# -- for repeats
tartistfun = baseType("tartistfun")
ttransform = baseType("ttransform")
trep = baseType("trep")
# tintrep = baseType("tintrep") # number for repeat

# ========== Primitives
示例#7
0
from dreamcoder.program import Primitive, Program
from dreamcoder.type import arrow, baseType, tint

turtle = baseType("turtle")
tstate = baseType("tstate")
tangle = baseType("tangle")
tlength = baseType("tlength")

primitives = [
    Primitive("logo_UA", tangle, ""),
    Primitive("logo_UL", tlength, ""),
    Primitive("logo_ZA", tangle, ""),
    Primitive("logo_ZL", tlength, ""),
    Primitive("logo_DIVA", arrow(tangle, tint, tangle), ""),
    Primitive("logo_MULA", arrow(tangle, tint, tangle), ""),
    Primitive("logo_DIVL", arrow(tlength, tint, tlength), ""),
    Primitive("logo_MULL", arrow(tlength, tint, tlength), ""),
    Primitive("logo_ADDA", arrow(tangle, tangle, tangle), ""),
    Primitive("logo_SUBA", arrow(tangle, tangle, tangle), ""),
    # Primitive("logo_ADDL",  arrow(tlength,tlength,tlength), ""),
    # Primitive("logo_SUBL",  arrow(tlength,tlength,tlength), ""),

    # Primitive("logo_PU",  arrow(turtle,turtle), ""),
    # Primitive("logo_PD",  arrow(turtle,turtle), ""),
    Primitive("logo_PT", arrow(arrow(turtle, turtle), arrow(turtle, turtle)),
              None),
    Primitive("logo_FWRT", arrow(tlength, tangle, turtle, turtle), ""),
    Primitive("logo_GETSET", arrow(arrow(turtle, turtle), turtle, turtle), "")
] + [
    Primitive("logo_IFTY", tint, ""),
    Primitive("logo_epsA", tangle, ""),