Comments (6)
I have been able to reproduce the problem; see
https://github.com/coin-or/CppAD/blob/master/bug/pow.sh
Thanks.
from cppad.
I believe the change to include/cppad/local/pow_op.hpp in
2196bce#diff-bc3c06208a0f4bedde79191e991128d9
fixes this problem.
Please test it and if you agree, close this bug.
from cppad.
This this seems to work for a simple pow(x,0.3).
But if I multiply two pow as in my example above, I still get a (0,0) and no error.
Adapted pow.sh:
#! /bin/bash -e
# vim: set expandtab:
# -----------------------------------------------------------------------------
# CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-18 Bradley M. Bell
#
# CppAD is distributed under the terms of the
# Eclipse Public License Version 2.0.
#
# This Source Code may also be made available under the following
# Secondary License when the conditions for such availability set forth
# in the Eclipse Public License, Version 2.0 are satisfied:
# GNU General Public License, Version 2.0 or later.
# -----------------------------------------------------------------------------
name=`echo $0 | sed -e 's|^bug/||' -e 's|\.sh$||'`
if [ "$0" != "bug/$name.sh" ]
then
echo 'usage: bug/pow.sh'
exit 1
fi
# -----------------------------------------------------------------------------
if [ -e build/bug ]
then
rm -r build/bug
fi
mkdir -p build/bug
cd build/bug
# cmake ../..
# -----------------------------------------------------------------------------
cat << EOF
Issue 43:
f(x) = x_0^0.5 and differentiate at x = (0,0).
Expect some NaN or Inf in the Jacobian or some error,
but get a jac = {0, 0}.
EOF
cat << EOF > $name.cpp
# include <cstdio>
# include "cppad/cppad.hpp"
int main(int argc, char** argv)
{ bool ok = true;
using std::cout;
using CppAD::AD;
using CppAD::vector;
//
vector< double> x(2), y(1), w(1), dw(2);
vector< AD<double> > ax(2), ay(1);
//
ax[0] = 0.0;
ax[1] = 0.0;
//
CppAD::Independent(ax);
ay[0] = pow(ax[0], 0.5) * pow(ax[1], 0.5);
CppAD::ADFun<double> f(ax, ay);
//
x[0] = 0.0;
x[1] = 0.0;
y = f.Forward(0, x);
w[0] = 1.0;
dw = f.Reverse(1, w);
//
cout << "dw[0] = " << dw << "\n";
//
ok &= y[0] == 0.0;
ok &= ! std::isfinite( dw[0] );
ok &= ! std::isfinite( dw[1] );
//
if( ! ok )
return 1;
return 0;
}
EOF
cxx_flags='-Wall -pedantic-errors -std=c++11 -Wshadow -Wconversion -g -O0'
eigen_dir="$HOME/prefix/eigen/include"
echo "g++ -I../../include -isystem $eigen_dir $cxx_flags $name.cpp -o $name"
g++ -I../../include -isystem $eigen_dir $cxx_flags $name.cpp -o $name
#
echo "build/bug/$name"
if ! ./$name
then
echo
echo "build/bug/$name: Error"
exit 1
fi
echo
# -----------------------------------------------------------------------------
echo "bug/$name.sh: OK"
exit 0
from cppad.
Now we have a real problem, in the multiplication
pow(ax[0], 0.5) * pow(ax[1], 0.5);
the left term is zero and the right term is zero
Here is the issue, during reverse mode, zero for a partial derivative has a speical meaning of variable selection, instead of the normal meaning of just zero. This enables computing partial derivatives where the partial w.r.t one viable is a number and w.r.t. another variable is a nan. The problem is the double use of zero both for selection and for the value zero; see
http://coin-or.github.io/CppAD/doc/azmul.htm
What is really needed here is a different floating point value that is equal to absolute zero and different from normal zero (so that one does not need an extra boolean for every floating point value).
I am going to have to think about this. In the meantime, keep this issue open.
from cppad.
I have committed a modified version of your test that also gives an unexpected zero for the derivative of
f(x) = pow(x, .5) * pow(x, .5) = x
In addition, I have fixed the higher order version of the previous change and added more comments about what is going on here; see
75fca6f
from cppad.
I am moving this issue to discussion #83
from cppad.
Related Issues (20)
- Discrete coefficient sets for polynomial vary as a function of dependent variable HOT 16
- How to write the `.lp` file of a Ipopt model? HOT 6
- Linking error "undefined reference to `CppAD::local::temp_file()'" HOT 4
- solution vector is empty HOT 10
- Undefined reference to temp_file HOT 2
- ipopt and cppad tests HOT 11
- Problem to Link with CppAD and Ipopt HOT 16
- CppAD::cg::CGException: what(): GreaterThanZero cannot be called for non-parameters HOT 5
- Compiler warnings from use of bitwise '|' and '&' for bool arguments HOT 5
- Potential build mistake in third party tool in use of NDEBUG flag - CppAD compiled in Release HOT 13
- Static library for non-windows builds HOT 2
- User's Guide URL on README.md 404s HOT 8
- bin/get_colpack.sh Script Error HOT 6
- Exception thrown in val_graph optimizer HOT 3
- Name of function is cleared after val_graph optimization
- License question about the meaning of EPL-2.0 OR GPL-2.0-or-later HOT 3
- CppAD exception while running parallel loop HOT 13
- About Eigen. I can't store the scalar result of a matrix operation at the index location of another std::vector or Eigen::Vector. HOT 5
- Could NOT find GOOGLEHASH (missing: GOOGLEHASH_COMPILE) HOT 4
- make check_cppad_ipopt Failure HOT 14
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cppad.