Coder Social home page Coder Social logo

acorns's People

Contributors

deshanadesai avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

acorns's Issues

Differentiating nested `pow` calls

Dear devs,

recently I have been trying to differentiate complicated expressions that eventually result in nested calls to pow. I find that the forward mode derivative for these cases is not taken correctly. Here is the MWE:

c_function = """
function_test(double x){
double x2 = pow(x,2);
double H = pow(x2,2);
}

deriv = acorns.autodiff(c_function, 'H', ['x'], func = 'function_test', output_filename = 'test',
     output_func = 'compute_grad_nested_pow')

This gives as the derivative (pow(pow,(2-1)) * (2 * 0 + pow * 0 * log(pow))) which looks like it's using pow as a variable instead of a function.

Computing directly the derivative of

c_function = """
function_test(double x){
double H = pow(x,4);
}

gives the correct result, (pow(x,(4-1)) * (4 * 1 + x * 0 * log(x))). Unfortunately my expressions are complicated enough that no such simplifications are possible.

Differentiating expressions inside powers

Dear devs,

First, thanks for the useful library! It hits the perfect sweet spot for the problem I am considering.

I have found that differentiating an expression inside a pow call does not work correctly. Here is a MWE:

c_function = "int function_test(double r, double L){ \
    double blah = pow(L+r,0.5); \
    return 0; \
}"

acorns.autodiff(c_function, 'blah', ['r','L'], func = 'function_test', output_filename = 'test_grad_back',
       output_func = 'compute_grad_back')

This gives as the derivatives:

void compute_grad_back(double values[], int num_points, double ders[]){

	for(int i = 0; i < num_points; ++i)
	{
		double r = values[i* 2 + 0 ];
		double L = values[i* 2 + 1 ];
		ders[i*2+0]= (pow((L + r),(0.5-1)) * (0.5 * 0 + (L + r) * 0 * log((L + r)))); // df/(r) 
		ders[i*2+1]= (pow((L + r),(0.5-1)) * (0.5 * 0 + (L + r) * 0 * log((L + r)))); // df/(L) 
	}
}

i.e. zero for both derivatives, which is of course not the correct answer. It appears that the issue is with the ._forward_diff of the base.

Another issues is when the base of the pow call is negative. Then the current implementation gives nan even when the answer should be sensible, e.g. when differentiating pow(pr,4) where pr is -1e-4.

Fix LICENSE

Could you please fix the license?

Copyright (c) [year] [fullname]

It is missing the year and authors.
After that, could you please add the license to be package along with the source distribution?

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.