Пример #1
0
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

'''
Common hyperbolic functions:
    - (SINH) sineh_op:      math.sinh(x)
    - (COSH) cosineh_op:    math.cosh(x)
    - (TANH) tangenth_op:   math.tanh(x)
    - (CSCH) cosecanth_op:  1 / math.sinh(x)
    - (SECH) secanth_op:    1 / math.cosh(x)
    - (COTH) cotangenth_op: 1 / math.tanh(x)
'''

from pygep.chromosome import symbol
import math


__all__ = 'HYPERBOLIC_ALL', 'HYPERBOLIC_ARITY_1'


sineh_op      = symbol('SINH')(lambda i: math.sinh(i))
cosineh_op    = symbol('COSH')(lambda i: math.cosh(i))
tangenth_op   = symbol('TANH')(lambda i: math.tanh(i))
cosecanth_op  = symbol('CSCH')(lambda i: 1. / math.sinh(i))
secanth_op    = symbol('SECH')(lambda i: 1. / math.cosh(i))
cotangenth_op = symbol('COTH')(lambda i: 1. / math.tanh(i))


HYPERBOLIC_ARITY_1 = sineh_op, cosineh_op, tangenth_op, cosecanth_op, \
                     secanth_op, cotangenth_op
HYPERBOLIC_ALL = HYPERBOLIC_ARITY_1
Пример #2
0
'''
Provides basic comparison non-terminals.  If each is true, it returns
the first value given.  If false, it returns the second.

Common comparison non-terminal functions:
    - (=) equal_op:            i if i == j else j
    - (U) unequal_op:          i if i != j else j
    - (<) less_op:             i if i < j else j
    - (>) greater_op:          i if i > j else j
    - (L) less_or_equal_op:    i if i <= j else j
    - (G) greater_or_equal_op: i if i >= j else j
'''

from pygep.chromosome import symbol


__all__ = 'COMPARISON_ALL', 'COMPARISON_ARITY_2'


equal_op            = symbol('=')(lambda i, j: i if i == j else j)
unequal_op          = symbol('U')(lambda i, j: i if i != j else j)
less_op             = symbol('<')(lambda i, j: i if i < j  else j)
greater_op          = symbol('>')(lambda i, j: i if i > j  else j)
less_or_equal_op    = symbol('L')(lambda i, j: i if i <= j else j)
greater_or_equal_op = symbol('G')(lambda i, j: i if i >= j else j)


COMPARISON_ARITY_2 = equal_op, unequal_op, less_op, greater_op, \
                     less_or_equal_op, greater_or_equal_op
COMPARISON_ALL = COMPARISON_ARITY_2
Пример #3
0
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

'''
Common arithmetical non-terminal functions and symbols:
    - (*) multiply_op: x * y
    - (+) add_op:      x + y
    - (-) subtract_op: x - y
    - (/) divide_op:   x / y
    - (%) modulus_op:  x % y
'''

from pygep.chromosome import symbol


__all__ = 'ARITHMETIC_ALL', 'ARITHMETIC_ARITY_2'


# Functions of Arity 2
add_op      = symbol('+')(lambda i, j: i + j)
subtract_op = symbol('-')(lambda i, j: i - j)
multiply_op = symbol('*')(lambda i, j: i * j)
divide_op   = symbol('/')(lambda i, j: float(i) / j)
modulus_op  = symbol('%')(lambda i, j: i % j)


ARITHMETIC_ARITY_2 = add_op, subtract_op, multiply_op, divide_op, modulus_op
ARITHMETIC_ALL = ARITHMETIC_ARITY_2
Пример #4
0
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
'''
Provides basic comparison non-terminals.  If each is true, it returns
the first value given.  If false, it returns the second.

Common comparison non-terminal functions:
    - (=) equal_op:            i if i == j else j
    - (U) unequal_op:          i if i != j else j
    - (<) less_op:             i if i < j else j
    - (>) greater_op:          i if i > j else j
    - (L) less_or_equal_op:    i if i <= j else j
    - (G) greater_or_equal_op: i if i >= j else j
'''

from pygep.chromosome import symbol

__all__ = 'COMPARISON_ALL', 'COMPARISON_ARITY_2'

equal_op = symbol('=')(lambda i, j: i if i == j else j)
unequal_op = symbol('U')(lambda i, j: i if i != j else j)
less_op = symbol('<')(lambda i, j: i if i < j else j)
greater_op = symbol('>')(lambda i, j: i if i > j else j)
less_or_equal_op = symbol('L')(lambda i, j: i if i <= j else j)
greater_or_equal_op = symbol('G')(lambda i, j: i if i >= j else j)


COMPARISON_ARITY_2 = equal_op, unequal_op, less_op, greater_op, \
                     less_or_equal_op, greater_or_equal_op
COMPARISON_ALL = COMPARISON_ARITY_2
Пример #5
0
    - (^    ) power_op:     x ** y
    - (E^   ) exp_op:       e ** x
    - (10^  ) pow10_op:     10 ** x
    - (^2   ) square_op:    x ** 2
    - (^3   ) cube_op:      x ** 3
    - (Q    ) root_op:      math.sqrt(x)
    - (Q3   ) cube_root_op: x ** (1./3)
    - (^-1  ) inverse_op:   1 / x
'''

from pygep.chromosome import symbol
import math

__all__ = 'POWER_ALL', 'POWER_ARITY_1', 'POWER_ARITY_2'

ln_op = symbol('LN')(lambda i: math.log(i))
log10_op = symbol('LOG10')(lambda i: math.log10(i))
power_op = symbol('^')(lambda i, j: i**j)
exp_op = symbol('E^')(lambda i: math.exp(i))
pow10_op = symbol('10^')(lambda i: 10**i)
square_op = symbol('^2')(lambda i: i**2)
cube_op = symbol('^3')(lambda i: i**3)
root_op = symbol('Q')(lambda i: math.sqrt(i))
cube_root_op = symbol('Q3')(lambda i: i**(1. / 3))
inverse_op = symbol('^-1')(lambda i: 1. / i)


POWER_ARITY_1 = ln_op, log10_op, root_op, exp_op, pow10_op, square_op, \
                cube_op, inverse_op
POWER_ARITY_2 = power_op,
POWER_ALL = POWER_ARITY_1 + POWER_ARITY_2
Пример #6
0
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

'''
Common rounding functions:
    - (FLOOR) floor_op: math.floor(x)
    - (CEIL ) ceil_op:  math.ceil(x)
    - (ROUND) round_op: round(x)
    - (ABS  ) abs_op:   abs(x)
'''

from pygep.chromosome import symbol
import math


__all__ = 'ROUNDING_ALL', 'ROUNDING_ARITY_1'


floor_op = symbol('FLOOR')(lambda i: math.floor(i))
ceil_op  = symbol('CEIL' )(lambda i: math.ceil(i))
round_op = symbol('ROUND')(lambda i: round(i))
abs_op   = symbol('ABS'  )(lambda i: abs(i))


ROUNDING_ARITY_1 = floor_op, ceil_op, round_op, abs_op
ROUNDING_ALL = ROUNDING_ARITY_1
Пример #7
0
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

'''
Common constant functions:
    - (0) zero_op: 0
    - (1) one_op:  1
    - (P) pi_op:   math.pi
    - (E) e_op:    math.e
'''

from pygep.chromosome import symbol
import math


__all__ = 'CONSTANTS_ALL', 'CONSTANTS_ARITY_0'


zero_op = symbol('0')(lambda: 0)
one_op  = symbol('1')(lambda: 1)
pi_op   = symbol('P')(lambda: math.pi)
e_op    = symbol('E')(lambda: math.e)


CONSTANTS_ARITY_0 = zero_op, one_op, pi_op, e_op
CONSTANTS_ALL = CONSTANTS_ARITY_0
Пример #8
0
    - (ASIN) arcsine_op:      math.asin(x)
    - (ACOS) arccosine_op:    math.acos(x)
    - (ATAN) arctangent_op:   math.atan(x)
    - (ACSC) arccosecant_op:  1 / math.asin(x)
    - (ASEC) arcsecant_op:    1 / math.acos(x)
    - (ACOT) arccotangent_op: 1 / math.atan(x)
'''

from pygep.chromosome import symbol
import math


__all__ = 'TRIGONOMETRY_ALL', 'TRIGONOMETRY_ARITY_1'


sine_op         = symbol('SIN' )(lambda i: math.sin(i))
cosine_op       = symbol('COS' )(lambda i: math.cos(i))
tangent_op      = symbol('TAN' )(lambda i: math.tan(i))
cosecant_op     = symbol('CSC' )(lambda i: 1. / math.sin(i))
secant_op       = symbol('SEC' )(lambda i: 1. / math.cos(i))
cotangent_op    = symbol('COT' )(lambda i: 1. / math.tan(i))
arcsine_op      = symbol('ASIN')(lambda i: math.asin(i))
arccosine_op    = symbol('ACOS')(lambda i: math.acos(i))
arctangent_op   = symbol('ATAN')(lambda i: math.atan(i))
arccosecant_op  = symbol('ACSC')(lambda i: 1. / math.asin(i))
arcsecant_op    = symbol('ASEC')(lambda i: 1. / math.acos(i))
arccotangent_op = symbol('ACOT')(lambda i: 1. / math.atan(i))


TRIGONOMETRY_ARITY_1 = sine_op, cosine_op, tangent_op, cosecant_op, \
                       secant_op, cotangent_op, arcsine_op, arccosine_op, \
Пример #9
0
for mission_increment in m.mission_files:
  increment = []
  for mission in mission_increment:
    with open(mission, 'r') as f:
        print "Loading mission from %s" % mission
        mission_xml = f.read()
        increment.append(MalmoPython.MissionSpec(mission_xml, True))
  missions.append(increment)

client_pool = MalmoPython.ClientPool()
client_pool.add( MalmoPython.ClientInfo('127.0.0.1',10000) )
client_pool.add( MalmoPython.ClientInfo('127.0.0.1',10001) )
client_pool.add( MalmoPython.ClientInfo('127.0.0.1',10002) )

iflte_op = symbol('I')(lambda w, x, y, z: y if w == x else z)

class Simulator(Chromosome):
  functions = (iflte_op,)
  terminals = 'F', 'B', 'L', 'R', '0'
  agent = MalmoPython.AgentHost()

  def _fitness(self):
    return run_programming(self)

p = Population(Simulator, popsize, 6, 1, sum_linker)
print("--- Generated Population ---\n")
print p

for _ in xrange(num_generations):
  if p.best.solved:
Пример #10
0
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

'''
Provides basic logical operators: and, or, not, if.  These are same to use
with the mathematics operators as they return either 1, 0 or the types 
passed in to them.

Common logic non-terminal functions:
    - (&) and_op: i if i and j else 0
    - (|) or_op:  i or j or 0
    - (!) not_op: 0 if i else 1
    - (I) if_op:  j if i else k
'''

from pygep.chromosome import symbol


__all__ = 'LOGIC_ALL', 'LOGIC_ARITY_1', 'LOGIC_ARITY_2', 'LOGIC_ARITY_3'


and_op = symbol('&')(lambda i, j: i if i and j else 0)
or_op  = symbol('|')(lambda i, j: i or j or 0)
not_op = symbol('!')(lambda i: 0 if i else 1)
if_op  = symbol('I')(lambda i, j, k: j if i else k)


LOGIC_ARITY_1 = not_op,
LOGIC_ARITY_2 = and_op, or_op
LOGIC_ARITY_3 = if_op,
LOGIC_ALL = LOGIC_ARITY_1 + LOGIC_ARITY_2 + LOGIC_ARITY_3
Пример #11
0
    - (SEC ) secant_op:       1 / math.cos(x)
    - (COT ) cotangent_op:    1 / math.tan(x)
    - (ASIN) arcsine_op:      math.asin(x)
    - (ACOS) arccosine_op:    math.acos(x)
    - (ATAN) arctangent_op:   math.atan(x)
    - (ACSC) arccosecant_op:  1 / math.asin(x)
    - (ASEC) arcsecant_op:    1 / math.acos(x)
    - (ACOT) arccotangent_op: 1 / math.atan(x)
'''

from pygep.chromosome import symbol
import math

__all__ = 'TRIGONOMETRY_ALL', 'TRIGONOMETRY_ARITY_1'

sine_op = symbol('SIN')(lambda i: math.sin(i))
cosine_op = symbol('COS')(lambda i: math.cos(i))
tangent_op = symbol('TAN')(lambda i: math.tan(i))
cosecant_op = symbol('CSC')(lambda i: 1. / math.sin(i))
secant_op = symbol('SEC')(lambda i: 1. / math.cos(i))
cotangent_op = symbol('COT')(lambda i: 1. / math.tan(i))
arcsine_op = symbol('ASIN')(lambda i: math.asin(i))
arccosine_op = symbol('ACOS')(lambda i: math.acos(i))
arctangent_op = symbol('ATAN')(lambda i: math.atan(i))
arccosecant_op = symbol('ACSC')(lambda i: 1. / math.asin(i))
arcsecant_op = symbol('ASEC')(lambda i: 1. / math.acos(i))
arccotangent_op = symbol('ACOT')(lambda i: 1. / math.atan(i))


TRIGONOMETRY_ARITY_1 = sine_op, cosine_op, tangent_op, cosecant_op, \
                       secant_op, cotangent_op, arcsine_op, arccosine_op, \
Пример #12
0
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
'''
Common rounding functions:
    - (FLOOR) floor_op: math.floor(x)
    - (CEIL ) ceil_op:  math.ceil(x)
    - (ROUND) round_op: round(x)
    - (ABS  ) abs_op:   abs(x)
'''

from pygep.chromosome import symbol
import math

__all__ = 'ROUNDING_ALL', 'ROUNDING_ARITY_1'

floor_op = symbol('FLOOR')(lambda i: math.floor(i))
ceil_op = symbol('CEIL')(lambda i: math.ceil(i))
round_op = symbol('ROUND')(lambda i: round(i))
abs_op = symbol('ABS')(lambda i: abs(i))

ROUNDING_ARITY_1 = floor_op, ceil_op, round_op, abs_op
ROUNDING_ALL = ROUNDING_ARITY_1
Пример #13
0
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
'''
Common hyperbolic functions:
    - (SINH) sineh_op:      math.sinh(x)
    - (COSH) cosineh_op:    math.cosh(x)
    - (TANH) tangenth_op:   math.tanh(x)
    - (CSCH) cosecanth_op:  1 / math.sinh(x)
    - (SECH) secanth_op:    1 / math.cosh(x)
    - (COTH) cotangenth_op: 1 / math.tanh(x)
'''

from pygep.chromosome import symbol
import math

__all__ = 'HYPERBOLIC_ALL', 'HYPERBOLIC_ARITY_1'

sineh_op = symbol('SINH')(lambda i: math.sinh(i))
cosineh_op = symbol('COSH')(lambda i: math.cosh(i))
tangenth_op = symbol('TANH')(lambda i: math.tanh(i))
cosecanth_op = symbol('CSCH')(lambda i: 1. / math.sinh(i))
secanth_op = symbol('SECH')(lambda i: 1. / math.cosh(i))
cotangenth_op = symbol('COTH')(lambda i: 1. / math.tanh(i))


HYPERBOLIC_ARITY_1 = sineh_op, cosineh_op, tangenth_op, cosecanth_op, \
                     secanth_op, cotangenth_op
HYPERBOLIC_ALL = HYPERBOLIC_ARITY_1
Пример #14
0
    - (10^  ) pow10_op:     10 ** x
    - (^2   ) square_op:    x ** 2
    - (^3   ) cube_op:      x ** 3
    - (Q    ) root_op:      math.sqrt(x)
    - (Q3   ) cube_root_op: x ** (1./3)
    - (^-1  ) inverse_op:   1 / x
'''

from pygep.chromosome import symbol
import math


__all__ = 'POWER_ALL', 'POWER_ARITY_1', 'POWER_ARITY_2'


ln_op        = symbol('LN'   )(lambda i: math.log(i))
log10_op     = symbol('LOG10')(lambda i: math.log10(i))
power_op     = symbol('^'    )(lambda i, j: i ** j)
exp_op       = symbol('E^'   )(lambda i: math.exp(i))
pow10_op     = symbol('10^'  )(lambda i: 10 ** i)
square_op    = symbol('^2'   )(lambda i: i ** 2)
cube_op      = symbol('^3'   )(lambda i: i ** 3)
root_op      = symbol('Q'    )(lambda i: math.sqrt(i))
cube_root_op = symbol('Q3'   )(lambda i: i ** (1./3))
inverse_op   = symbol('^-1'  )(lambda i: 1. / i)


POWER_ARITY_1 = ln_op, log10_op, root_op, exp_op, pow10_op, square_op, \
                cube_op, inverse_op
POWER_ARITY_2 = power_op,
POWER_ALL = POWER_ARITY_1 + POWER_ARITY_2