Skip to main content

Describe and manipulate programs as Meta-Algorithms in Python.

Project description

Meta Algorithm in Python (MetalgPy)

What if we could write a program that generates programs? Inspired by Automated Machine Learning research such as PyGlove.

:warning: Experimental: Contributions are welcome!

Install

pip install metalgpy

Example

A simple but detailed example:

import metalgpy as mpy

# the @mpy.meta decorator transform an original python code 
# into a meta-program. f is now symbolizing the original python code
@mpy.meta
def f(x):
    return x

# program is a symbol representing the call to f (original python code)
# where the input is a symbol representing a variable List (categorical decision variable)
program = f(mpy.List([0,1,2,3,4]))
print("Program: ", program, end="\n\n")

# the choice method returns the variable symbols of the symbolized program
choices = program.choice()
print("Variable Space: ", choices)

# mpy.sample(n, program) generates clones of the symbolized program
for sample_program in mpy.sample(5, program):

    print("\n ** new program **")

    # we iterate over all variables of the variable space and randomly sample each of them
    choice = [v.sample() for v in choices]
    print("choice: ", choice)

    # we freeze the sampled program with a choice for each variable
    sample_program.freeze(choice)
    print("frozen program: ", sample_program)

    # we can now evaluate the program
    res = sample_program.evaluate()
    print("evaluation: ", res)

gives the following output:

Program:  f(List(0, 1, 2, 3, 4))

Variable Space:  [List(0, 1, 2, 3, 4)]

 ** new program **
choice:  [3]
frozen program:  f(3)
evaluation:  3

 ** new program **
choice:  [4]
frozen program:  f(4)
evaluation:  4

 ** new program **
choice:  [3]
frozen program:  f(3)
evaluation:  3

 ** new program **
choice:  [2]
frozen program:  f(2)
evaluation:  2

 ** new program **
choice:  [4]
frozen program:  f(4)
evaluation:  4

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

metalgpy-0.0.1.tar.gz (14.3 kB view details)

Uploaded Source

Built Distribution

metalgpy-0.0.1-py2.py3-none-any.whl (11.1 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file metalgpy-0.0.1.tar.gz.

File metadata

  • Download URL: metalgpy-0.0.1.tar.gz
  • Upload date:
  • Size: 14.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for metalgpy-0.0.1.tar.gz
Algorithm Hash digest
SHA256 8e649fb76a5e91f678e645c151eac09c496be0f919185276a0162c63d3e083a0
MD5 582be2aeeb127e0ffebde272379a8951
BLAKE2b-256 10fd7df83a1e4052c3d025cca5b0c92ca4f82045317f088181c8137a788a9661

See more details on using hashes here.

File details

Details for the file metalgpy-0.0.1-py2.py3-none-any.whl.

File metadata

  • Download URL: metalgpy-0.0.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 11.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for metalgpy-0.0.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 cedc05036743d98f2a38a568b54c97bbd480fa7d198bffaca47ffc96248deb1c
MD5 9f7b55679fbf684475c267218a1e7c11
BLAKE2b-256 e49eb2dc1bcdd101320f7109be53059428e1a663c31a2a12a14d20ce59c101fc

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page