Changeset 3495 for trunk/test_more


Ignore:
Timestamp:
Dec 23, 2014 8:16:15 PM (5 years ago)
Author:
bradbell
Message:

Squashed commit of the following:

commit ea33674d009e14c6b8b8479fe08f5fd14efe15ce
Author: Brad Bell <bradbell@…>
Date: Tue Dec 23 17:32:52 2014 -0700

Change CPPAD_HAS_ERROR_FUNCTION -> CPPAD_COMPLIER_HAS_ERF.

commit c81badddaa95ce83d9d74ef5516955fb53be650f
Author: Brad Bell <bradbell@…>
Date: Tue Dec 23 16:31:03 2014 -0700

base_require.hpp: remove command that is not used.
base_adolc.hpp: define erf when it is required.
erf_op.hpp: fix derivative of zero order.
for_jac_sweep.hpp: remove trailing white space, add ErfOp?.
op_code.hpp: fix tracing of ErfOp?
rev_hes_sweep.hpp: add ErfOp?.
rev_jac_sweep.hpp: remove trailing white space, add ErfOp?.
erf.cpp: add more examples and tests.
erf.cpp: change x0 to not be multiply identity.

commit 213c2321cb527d6b913ac627ab631098e643be4f
Author: Brad Bell <bradbell@…>
Date: Tue Dec 23 07:14:56 2014 -0700

Add special routine for erf zero order forward mode.

commit 8cc6ca517ddbe213988e497a100a8ae6465a0a3e
Author: Brad Bell <bradbell@…>
Date: Tue Dec 23 06:54:33 2014 -0700

Implement and test atomic erf in reverse mode.

commit 8611fca3e9fea21ff5cc5d4e8742a01e1f29070f
Author: Brad Bell <bradbell@…>
Date: Tue Dec 23 05:31:47 2014 -0700

tan_reverse.omh: fix typo.

commit f582631d101fdbab721fb283e5284b59bc018015
Author: Brad Bell <bradbell@…>
Date: Tue Dec 23 04:53:39 2014 -0700

Test forward order zero, one, and two both with and without std::erf.

commit 7bba97a757252f279dfe7fc58209d8e55ce8e9f6
Author: Brad Bell <bradbell@…>
Date: Mon Dec 22 21:48:30 2014 -0700

  1. Ignore git_commit.sh (temporary file created by ~/bin/git_commit.sh).
  2. Add base requrements for erf function.
  3. Implement and test forward mode for erf(double).

erf_op.hpp: remove i_x (not used).
forward0sweep.hpp: add ErfOp? case.
undef.hpp: make CPPAD_HAS_ERROR_FUNCTION part of user api.
erf.cpp: comment out parts not yet being tested.

commit 967f6843f9c4133ed3f986371e01115504e20f68
Merge: 3a7a9ea 9edd70a
Author: Brad Bell <bradbell@…>
Date: Mon Dec 22 07:16:00 2014 -0700

Merge branch 'master' into erf

commit 3a7a9ea832d4ab90c80c5c9bbeea5a9f3c9839e7
Author: Brad Bell <bradbell@…>
Date: Sun Dec 21 18:51:58 2014 -0700

op_code.hpp: add ErfOp?.
undef.hpp: add CPPAD_HAS_ERROR_FUNCTION.
makefile.am: add erf_op.hpp.

commit d584798c43e7fe5c5c3d080328fee06ff7ba0fe1
Merge: 5f13ae6 58a292c
Author: Brad Bell <bradbell@…>
Date: Sun Dec 21 09:24:16 2014 -0700

Merge branch 'master' into erf

commit 5f13ae64b979e618188adabad4365ffa6c011215
Author: Brad Bell <bradbell@…>
Date: Sun Dec 21 09:12:11 2014 -0700

erf_op.hpp: only defined operators when compiler has erf.

commit acc16d2b5251250850ef3125a2bdcea11ec18cf8
Author: Brad Bell <bradbell@…>
Date: Sun Dec 21 08:41:35 2014 -0700

Implement erf general forward mode as plan for other changes (not hooked up).

commit 5522393a914a2117bdc149fe16b62c0afff0102e
Author: Brad Bell <bradbell@…>
Date: Sun Dec 21 06:40:27 2014 -0700

Add cppad_has_error_function (true if compiler has error function).

commit da4f1ba378f92e78b17ca1e85c417f86b6946dbf
Author: Brad Bell <bradbell@…>
Date: Sun Dec 21 06:13:52 2014 -0700

erf.hpp: Document planned change in this branch.
erf_forward.omh: fix sqrt{pi}, fix svn Id (messed up by git-svn).
erf_reverse.omh: fix svn Id.

commit 05eebb357f90818f2b4dec8a3e108820fb6c34b2
Merge: 2398fd6 7d9ed8a
Author: Brad Bell <bradbell@…>
Date: Sun Dec 21 05:33:05 2014 -0700

Merge branch 'master' into erf

commit 7d9ed8abddffba666f76f64e28e48766cbc28fb6
Author: Brad Bell <bradbell@…>
Date: Sun Dec 21 05:27:17 2014 -0700

  1. Change size_t_same_unsigned_int to size_t_not_unsigned_int. so that test result variable has same meaning as test.
  2. Fix svn Id property at top if files being commited.

package.sh: Remove check_svn_id.sh from list becuse git-svn messed up Id.

commit 2398fd6ad75d51c436ee1cf9b9cf2f606ef44828
Author: Brad Bell <bradbell@…>
Date: Sat Dec 20 09:02:02 2014 -0700

erf_reverse.omh: theory for for erf reverse mode calculation.

commit fc83d4fe0da0ecc09bbb5a8d0334379756e58c3e
Author: Brad Bell <bradbell@…>
Date: Sat Dec 20 07:43:50 2014 -0700

Start work on makeing erf an atomic operation (when supported by compiler).

erf_forward.omh: forward mode theory for erf.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test_more/erf.cpp

    r3060 r3495  
    2323        using CppAD::exp;
    2424        using CppAD::sqrt;
     25# if CPPAD_COMPILER_HAS_ERF
     26        double eps = 100.0 * std::numeric_limits<double>::epsilon();
     27# endif
     28        // Construct function object corresponding to erf
     29        CPPAD_TESTVECTOR(AD<double>) ax(1);
     30        CPPAD_TESTVECTOR(AD<double>) ay(1);
     31        ax[0] = 0.;
     32        Independent(ax);
     33        ay[0] = erf(ax[0]);
     34        ADFun<double> f(ax, ay);
    2535
    26         // Construct function object corresponding to erf
    27         CPPAD_TESTVECTOR(AD<double>) X(1);
    28         CPPAD_TESTVECTOR(AD<double>) Y(1);
    29         X[0] = 0.;
    30         Independent(X);
    31         Y[0] = erf(X[0]);
    32         ADFun<double> Erf(X, Y);
     36        // Construct function object corresponding to derivative of erf
     37        Independent(ax);
     38        double pi = 4.0 * atan(1.0);
     39        ay[0] = exp( - ax[0] * ax[0] ) * 2.0 / sqrt(pi);
     40        ADFun<double> df(ax, ay);
    3341
    3442        // vectors to use with function object
    35         CPPAD_TESTVECTOR(double) x(1);
    36         CPPAD_TESTVECTOR(double) y(1);
    37         CPPAD_TESTVECTOR(double) dx(1);
    38         CPPAD_TESTVECTOR(double) dy(1);
     43        CPPAD_TESTVECTOR(double) x0(1), y0(1), x1(1), y1(1), check(1);
    3944
    4045        // check value at zero
    41         x[0]  = 0.;
    42         y = Erf.Forward(0, x); 
    43         ok &= NearEqual(0., y[0], 4e-4, 0.);
     46        x0[0]    = 1.5;
     47        y0       = f.Forward(0, x0);   
     48        check[0] = 0.96611;
     49        ok      &= std::fabs(check[0] - y0[0]) <= 4e-4;
    4450
    4551        // check the derivative of error function
    46         dx[0]         = 1.;
    47         double pi     = 4. * atan(1.);
    48         double factor = 2. / sqrt( pi );
    49         int i;
    50         for(i = -10; i <= 10; i++)
    51         {       x[0] = i / 4.;
    52                 y    = Erf.Forward(0, x);       
     52        x1[0] = 1.0;
     53        y1    = f.Forward(1, x1);
     54        check = df.Forward(0, x0);
     55        ok   &= NearEqual(check[0], y1[0], 0., 2e-3);
     56# if CPPAD_COMPILER_HAS_ERF
     57        ok   &= NearEqual(check[0], y1[0], eps, eps);
     58# endif
    5359
    54                 // check derivative
    55                 double derf = factor * exp( - x[0] * x[0] );
    56                 dy          = Erf.Forward(1, dx);
    57                 ok         &= NearEqual(derf, dy[0], 0., 2e-3);
     60        // check second derivative
     61        CPPAD_TESTVECTOR(double) x2(1), y2(1);
     62        x2[0] = 0.0;
     63        y2    = f.Forward(2, x2);
     64        check = df.Forward(1, x1) / 2.0;
     65        ok   &= NearEqual(check[0], y2[0], 0., 2e-3);
     66# if CPPAD_COMPILER_HAS_ERF
     67        ok   &= NearEqual(check[0], y2[0], eps, eps);
     68# endif
    5869
    59                 // test using erf with AD< AD<double> >
    60                 AD< AD<double> > X0 = AD<double>( x[0] );
    61                 AD< AD<double> > Y0 = erf(X0);
     70        // check third derivative
     71        CPPAD_TESTVECTOR(double) x3(1), y3(1);
     72        x3[0] = 0.0;
     73        y3    = f.Forward(3, x3);
     74        check = df.Forward(2, x2) / 3.0;
     75        ok   &= NearEqual(check[0], y3[0], 0., 2e-3);
     76# if CPPAD_COMPILER_HAS_ERF
     77        ok   &= NearEqual(check[0], y3[0], eps, eps);
     78# endif
    6279
    63                 ok &= ( y[0] == Value( Value(Y0) ) );
    64         }
     80        // check 4-th order of reverse mode
     81        CPPAD_TESTVECTOR(double) w(1), dy(4), x4(1), y4(1);
     82        x4[0] = 0.0;
     83        w[0]  = 1.0;
     84        dy    = f.Reverse(4, w);
     85        y4    = f.Forward(4, x4);
     86        //
     87        ok  &= NearEqual(dy[0], y1[0], 0., 2e-3);
     88# if CPPAD_COMPILER_HAS_ERF
     89        ok  &= NearEqual(dy[0], y1[0], eps, eps);
     90# endif
     91        //
     92        ok  &= NearEqual(dy[1], 2.0 * y2[0], 0., 2e-3);
     93# if CPPAD_COMPILER_HAS_ERF
     94        ok  &= NearEqual(dy[1], 2.0 * y2[0], eps, eps);
     95# endif
     96        //
     97        ok  &= NearEqual(dy[2], 3.0 * y3[0], 0., 2e-3);
     98# if CPPAD_COMPILER_HAS_ERF
     99        ok  &= NearEqual(dy[2], 3.0 * y3[0], eps, eps);
     100# endif
     101        //
     102        ok  &= NearEqual(dy[3], 4.0 * y4[0], 0., 2e-3);
     103# if CPPAD_COMPILER_HAS_ERF
     104        ok  &= NearEqual(dy[3], 4.0 * y4[0], eps, eps);
     105# endif
     106
    65107        return ok;
    66108}
Note: See TracChangeset for help on using the changeset viewer.