Giter VIP home page Giter VIP logo

py-cgraph's Introduction

CGraph - symbolic computation in Python

This repository is the result of my efforts to understand symbolic computation of functions factored as expression trees. With the right concepts at hands, a few lines of code are able compute numeric and symbolic gradients of arbitrary functions. Even expression simplification is easily accomplished. While this library is not complete (and will never be) it offers the interested reader some insights on how to perform symbolic computation.

Notebooks on symbolic computation

The code is accompanied by a series of notebooks that explain fundamental concepts for developing your own library that performs symbolic computation:

Foundations

  • Computational Graphs - Introduction view
  • Computational Graphs - Symbolic Computation in Python view

Applications

  • Function Optimization view
  • Signed Distance Functions and Particle Physics view
    This was recently referenced by Donald House co-author of Foundations of Physically Based Modeling & Animation as additional reader supplied material. Signed distance functions are not covered in his book, which makes this contribution a good fit. Most of the math in the notebook used is directly linked with content of the book.

All notebook sources can be found inside the docs folder. There are certainly typos, grammatical errors and all kind of improvements possible. In case you have one for me, I'd be happy to see your pull requests or comments!

CGraph as a library

The code for symbolic computation contained in cgraph.py can be used as follows.

import cgraph as cg

x = cg.Symbol('x')
y = cg.Symbol('y')
z = cg.Symbol('z')

f = (x * y + 3) / (z - 2)

# Evaluate function
cg.value(f, {x:2, y:3, z:3})        # 9.0

# Partial derivatives (numeric)
d = cg.numeric_gradient(f, {x:2, y:3, z:3})
d[x]                                # df/dx 3.0
d[z]                                # df/dz -9.0

# Partial derivatives (symbolic)
d = cg.symbolic_gradient(f)
cg.simplify(d[x])                   # df/dx (y*(1/(z - 2)))
cg.value(d[x], {x:2, y:3, z:3})     # df/dx 3.0

# Higher order derivatives
ddx = cg.symbolic_gradient(d[x])
cg.simplify(ddx[y])                 # ddf/dxdy (1/(z - 2))

Installation

To install CGraph clone this repository and use pip to install from local sources.

pip install -e <path/to/setup.py>

Python 3.5/3.6 and numpy is required.

Continuous Integration

Branch Status
master
develop

License

If not otherwise stated all Material is licensed under BSD license.

py-cgraph's People

Contributors

cheind avatar christophheindl avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.