Changeset 1470 for trunk/test_more


Ignore:
Timestamp:
Jul 31, 2009 9:06:42 AM (11 years ago)
Author:
bradbell
Message:

trunk: Improve forward and reverse sparse Jacobian calculations.

sparse_vec_ad.cpp: modify test to reflect pattern valid for all x values.
test_more.cpp: change some test names to be same as file names.
for_sparse_jac.cpp: add VecAD to this test.
rev_sparse_jac.cpp: change test name to same as file name.
whats_new_09.omh: user's view of changes, comment on developer documentation.
player.hpp: add member function to return number of VecAD objects.
ad_tape.hpp: remove developer doc for function that no longer exists.
for_jac_sweep.hpp: track dependency of VecAD vectors instead of elements.
for_sparse_jac.hpp: modify user documentation to state valid for all x.
rev_sparse_jac.hpp: modify user documentation to state valid for all x.
rev_jac_sweep.hpp: track dependency of VecAD vectors instead of elements.

Location:
trunk/test_more
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/test_more/for_sparse_jac.cpp

    r1370 r1470  
    11/* $Id$ */
    22/* --------------------------------------------------------------------------
    3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-07 Bradley M. Bell
     3CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-09 Bradley M. Bell
    44
    55CppAD is distributed under multiple licenses. This distribution is under
     
    6868        index++;
    6969
    70 bool ForSparseJac(void)
     70
     71namespace { // Begin empty namespace
     72
     73bool case_one(void)
    7174{       bool ok = true;
    7275        using namespace CppAD;
     
    167170        return ok;
    168171}
     172
     173bool case_two(void)
     174{       bool ok = true;
     175        using namespace CppAD;
     176
     177        // dimension of the domain space
     178        size_t n = 3;
     179
     180        // dimension of the range space
     181        size_t m = 2;
     182
     183        // inialize the vector as zero
     184        CppAD::VecAD<double> Z(n - 1);
     185        size_t k;
     186        for(k = 0; k < n-1; k++)
     187                Z[k] = 0.;
     188
     189        // independent variable vector
     190        CPPAD_TEST_VECTOR< AD<double> > X(n);
     191        X[0] = 0.;
     192        X[1] = 1.;
     193        X[2] = 2.;
     194        Independent(X);
     195
     196        // VecAD vector is going to depend on X[1] and X[2]
     197        Z[ X[0] ] = X[1];
     198        Z[ X[1] ] = X[2];
     199
     200        // dependent variable vector
     201        CPPAD_TEST_VECTOR< AD<double> > Y(m);
     202
     203        // check results vector
     204        CPPAD_TEST_VECTOR< bool >       Check(m * n);
     205
     206        // initialize index into Y
     207        size_t index = 0;
     208
     209        // First component only depends on X[0];
     210        Y[index]             = X[0];
     211        Check[index * n + 0] = true;
     212        Check[index * n + 1] = false;
     213        Check[index * n + 2] = false;
     214        index++;
     215        AD<double> zero(0);
     216        Y[index]             = Z[zero];
     217        Check[index * n + 0] = false;
     218        Check[index * n + 1] = true;
     219        Check[index * n + 2] = true;
     220        index++;
     221
     222        // check final index
     223        assert( index == m );
     224
     225        // create function object F : X -> Y
     226        ADFun<double> F(X, Y);
     227
     228        // dependency matrix for the identity function W(x) = x
     229        CPPAD_TEST_VECTOR< bool > Px(n * n);
     230        size_t i, j;
     231        for(i = 0; i < n; i++)
     232        {       for(j = 0; j < n; j++)
     233                        Px[ i * n + j ] = false;
     234                Px[ i * n + i ] = true;
     235        }
     236
     237        // evaluate the dependency matrix for F(X(x))
     238        CPPAD_TEST_VECTOR< bool > Py(m * n);
     239        Py = F.ForSparseJac(n, Px);
     240
     241        // check values
     242        for(i = 0; i < m; i++)
     243        {       for(j = 0; j < n; j++)
     244                        ok &= (Py[i * n + j] == Check[i * n + j]);
     245        }       
     246
     247        return ok;
     248}
     249
     250} // End empty namespace
     251
     252bool for_sparse_jac(void)
     253{       bool ok = true;
     254        ok &= case_one();
     255        ok &= case_two();
     256        return ok;
     257}
  • trunk/test_more/sparse_vec_ad.cpp

    r1370 r1470  
    11/* $Id$ */
    22/* --------------------------------------------------------------------------
    3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-07 Bradley M. Bell
     3CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-09 Bradley M. Bell
    44
    55CppAD is distributed under multiple licenses. This distribution is under
     
    4141        {       J    = AD<double>(j);
    4242                Z[J] = X[j];
     43
     44                // y[i] depends on x[j] for j <= i
     45                Y[j] = Z[J];
    4346        }
    4447
     
    4750        J = AD<double>(0);
    4851        for(j = 0; j < n; j++)
    49         {       P    = P * Z[J];
    50                 Y[j] = P;
    51                 for(i = 0; i < n; i++)
     52        {       for(i = 0; i < n; i++)
    5253                        Check[ i * n + j ] = (j <= i);
    53                 J = J + X[1];  // X[1] is equal to one
    5454        }
    5555       
  • trunk/test_more/test_more.cpp

    r1469 r1470  
    4242extern bool Exp(void);
    4343extern bool ForHess(void);
    44 extern bool ForSparseJac(void);
     44extern bool for_sparse_jac(void);
    4545extern bool Forward(void);
    4646extern bool FromBase(void);
     
    6161extern bool Reverse(void);
    6262extern bool rev_sparse_hes(void);
    63 extern bool RevSparseJac(void);
     63extern bool rev_sparse_jac(void);
    6464extern bool RevTwo(void);
    6565extern bool RombergOne(void);
     
    135135        ok &= Run( Exp,             "Exp"            );
    136136        ok &= Run( ForHess,         "ForHess"        );
    137         ok &= Run( ForSparseJac,    "ForSparseJac"  );
     137        ok &= Run( for_sparse_jac,  "for_sparse_jac" );
    138138        ok &= Run( Forward,         "Forward"        );
    139139        ok &= Run( FromBase,        "FromBase"       );
     
    154154        ok &= Run( Reverse,         "Reverse"        );
    155155        ok &= Run( rev_sparse_hes,  "rev_sparse_hes" );
    156         ok &= Run( RevSparseJac,    "RevSparseJac"  );
     156        ok &= Run( rev_sparse_jac,  "rev_sparse_jac" );
    157157        ok &= Run( RevTwo,          "RevTwo"         );
    158158        ok &= Run( RombergOne,      "RombergOne"     );
Note: See TracChangeset for help on using the changeset viewer.