Giter Club home page Giter Club logo

cdstar's Introduction

CD*

CD* is an expression compiler written in C++ that generates C code of functions that contain derivatives computation. For example, the following code:

    auto xArg = std::make_shared<DoubleArgument>("x");
    auto x = xArg->GetExpr();
    auto xSq = x * x;
    auto xCu = xSq * x;
    // y = 2x^3 + 3x^2 + 4x + 5
    auto y = 2.0 * xCu + 3.0 * xSq + 4.0 * x + 5.0; 
    auto dydx = std::make_shared<NamedAssignment>("dydx", 0, Derivatives({{y, x}})[0]);
    EmitFunction({xArg}, {dydx}, "derv", std::cout);

Generates the following C code in standard output

void derv(const double x, double dydx[1]) {
    double t[7];
    t[0] = x * x;
    t[1] = 2.000000 * t[0];
    t[2] = 2.000000 * x;
    t[3] = 3.000000 + t[2];
    t[4] = t[3] * t[2];
    t[5] = t[1] + t[4];
    t[6] = 4.000000 + t[5];
    dydx[0] = t[6];
}

It is possible to generate higher-order derivatives or mixed derivatives by mixing the calls of the Derivatives function. See test.cpp for more examples.

CD* implements the D* algorithm to efficiently compute the derivatives of a function. The algorithm is efficient for small-to-medium dimensional (say, <100) functions because it performs costly path-finding algorithm on the expression graph. If you need to generate the code of the Jacobian or Hessian of a function with 10000 variables, you should also take a look at the following libraries: CasADi, theano, CppADCode

This project is still in its very early stage, the interface may change significantly in future development.

More to come.

cdstar's People

Contributors

bachili avatar jgillis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

jgillis bssrdf

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.