Changeset 3711


Ignore:
Timestamp:
Aug 20, 2015 10:57:57 AM (5 years ago)
Author:
bradbell
Message:

merge to branch: trunk
from repository: https://github.com/coin-or/CppAD
start hash code: 4fde6db8b832b520a565248126c35d079b2343e0
end hash code: 9068654d6c9e0157639951dd93dad71eb8149e77

commit 9068654d6c9e0157639951dd93dad71eb8149e77
Author: Brad Bell <bradbell@…>
Date: Thu Aug 20 07:56:05 2015 -0700

Remove invisible white space.

commit 9a836c8e18b640c134ab99335a5675a9c5300de4
Author: Brad Bell <bradbell@…>
Date: Thu Aug 20 07:55:36 2015 -0700

  1. Add an example that computes sparsity pattern for subset of variables.
  2. Remove some old index commands that are now redundant.


check_include_omh.sh: add help to error messagew.

Location:
trunk
Files:
1 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/bin/check_include_omh.sh

    r3689 r3711  
    5454        -e 's/$\$//' \
    5555        -e '/^ *$/d' \
    56         -e 's/^[        ]*//' \
     56        -e 's/^[        ]*//' \
    5757        -e 's|\\|/|g'
    5858#
     
    7474if [ $different = "yes" ]
    7575then
    76         echo "Error: nothing should be between the two dashed lines above"
     76        echo "Error: nothing should be between the two dashed lines above."
     77        echo 'Perhaps this file is not and has not yet been added to repository ?'
    7778        exit 1
    7879else
  • trunk/cppad/local/for_sparse_jac.hpp

    r3710 r3711  
    2727        CondExpRel
    2828        optimizer
     29        cpp
    2930$$
    3031
    3132$section Jacobian Sparsity Pattern: Forward Mode$$
    32 
    33 $index ForSparseJac$$
    34 $index forward, sparsity Jacobian$$
    35 $index sparsity, forward Jacobian$$
    36 $index pattern, forward Jacobian$$
    3733
    3834$head Syntax$$
     
    222218contains an example and test of this operation.
    223219It returns true if it succeeds and false otherwise.
     220The file
     221$cref/sparsity_sub.cpp/sparsity_sub.cpp/ForSparseJac/$$
     222contains an example and test of using $code ForSparseJac$$
     223to compute the sparsity pattern for a subset of the Jacobian.
    224224
    225225$end
  • trunk/cppad/local/rev_sparse_hes.hpp

    r3441 r3711  
    44
    55/* --------------------------------------------------------------------------
    6 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-14 Bradley M. Bell
     6CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-15 Bradley M. Bell
    77
    88CppAD is distributed under multiple licenses. This distribution is under
    9 the terms of the 
     9the terms of the
    1010                    Eclipse Public License Version 1.0.
    1111
     
    2828        proportional
    2929        var
     30        cpp
    3031$$
    3132
    32 $section Hessian Sparsity Pattern: Reverse Mode$$
    33 
    34 $index RevSparseHes$$
    35 $index reverse, sparse Hessian$$
    36 $index sparse, reverse Hessian$$
    37 $index pattern, reverse Hessian$$
     33$section Hessian Sparsity Pattern: Reverse Mode$$
    3834
    3935$head Syntax$$
     
    4642We use $latex F : \B{R}^n \rightarrow \B{R}^m$$ to denote the
    4743$cref/AD function/glossary/AD Function/$$ corresponding to $icode f$$.
    48 For a fixed matrix $latex R \in \B{R}^{n \times q}$$ 
     44For a fixed matrix $latex R \in \B{R}^{n \times q}$$
    4945and a fixed vector $latex S \in \B{R}^{1 \times m}$$,
    50 we define 
     46we define
    5147$latex \[
    5248\begin{array}{rcl}
    53 H(x) 
     49H(x)
    5450& = & \partial_x \left[ \partial_u S * F[ x + R * u ] \right]_{u=0}
    5551\\
    5652& = & R^\R{T} * (S * F)^{(2)} ( x )
    5753\\
    58 H(x)^\R{T} 
     54H(x)^\R{T}
    5955& = & (S * F)^{(2)} ( x ) * R
    6056\end{array}
    6157\] $$
    6258Given a
    63 $cref/sparsity pattern/glossary/Sparsity Pattern/$$ 
     59$cref/sparsity pattern/glossary/Sparsity Pattern/$$
    6460for the matrix $latex R$$ and the vector $latex S$$,
    6561$code RevSparseHes$$ returns a sparsity pattern for the $latex H(x)$$.
     
    8379It specifies the number of columns in $latex R \in \B{R}^{n \times q}$$
    8480and the number of rows in $latex H(x) \in \B{R}^{q \times n}$$.
    85 It must be the same value as in the previous $cref ForSparseJac$$ call 
     81It must be the same value as in the previous $cref ForSparseJac$$ call
    8682$codei%
    8783        %f%.ForSparseJac(%q%, %r%, %r_transpose%)
     
    105101see $cref/r/ForSparseJac/r/$$.
    106102The type of the elements of
    107 $cref/VectorSet/RevSparseHes/VectorSet/$$ must be the 
     103$cref/VectorSet/RevSparseHes/VectorSet/$$ must be the
    108104same as the type of the elements of $icode r$$.
    109105
     
    119115its size is one and all the elements of $icode%s%[0]%$$
    120116are between zero and $latex m - 1$$.
    121 It specifies a 
    122 $cref/sparsity pattern/glossary/Sparsity Pattern/$$ 
     117It specifies a
     118$cref/sparsity pattern/glossary/Sparsity Pattern/$$
    123119for the vector $icode S$$.
    124120
     
    136132its size is $latex q$$ and all the set elements are between
    137133zero and $icode%n%-1%$$ inclusive.
    138 It specifies a 
    139 $cref/sparsity pattern/glossary/Sparsity Pattern/$$ 
     134It specifies a
     135$cref/sparsity pattern/glossary/Sparsity Pattern/$$
    140136for the matrix $latex H(x)$$.
    141137
     
    146142its size is $latex n$$ and all the set elements are between
    147143zero and $icode%q%-1%$$ inclusive.
    148 It specifies a 
    149 $cref/sparsity pattern/glossary/Sparsity Pattern/$$ 
     144It specifies a
     145$cref/sparsity pattern/glossary/Sparsity Pattern/$$
    150146for the matrix $latex H(x)^\R{T}$$.
    151147
     
    157153of the difference.
    158154The type of the elements of
    159 $cref/VectorSet/RevSparseHes/VectorSet/$$ must be the 
     155$cref/VectorSet/RevSparseHes/VectorSet/$$ must be the
    160156same as the type of the elements of $icode r$$.
    161157
     
    167163$latex \[
    168164S_j = \left\{ \begin{array}{ll}
    169         1  & {\rm if} \; j = k 
     165        1  & {\rm if} \; j = k
    170166        \\
    171167        0  & {\rm otherwise}
    172 \end{array} \right. 
     168\end{array} \right.
    173169\] $$
    174170In this case,
    175 the corresponding value $icode h$$ is a 
     171the corresponding value $icode h$$ is a
    176172sparsity pattern for the Hessian matrix
    177173$latex F_k^{(2)} (x) \in \B{R}^{n \times n}$$.
     
    180176$children%
    181177        example/rev_sparse_hes.cpp
     178        %example/sparsity_sub.cpp
    182179%$$
    183180The file
     
    185182contains an example and test of this operation.
    186183It returns true if it succeeds and false otherwise.
     184The file
     185$cref/sparsity_sub.cpp/sparsity_sub.cpp/RevSparseHes/$$
     186contains an example and test of using $code RevSparseHes$$
     187to compute the sparsity pattern for a subset of the Hessian.
    187188
    188189$end
     
    223224
    224225\param q
    225 is the value of \a q in the 
    226 by the previous call of the form 
     226is the value of \a q in the
     227by the previous call of the form
    227228\verbatim
    228229        f.ForSparseJac(q, r)
     
    234235for the vector \f$ S \f$,
    235236where \c m is the number of dependent variables
    236 corresponding to the operation sequence stored in \a play. 
     237corresponding to the operation sequence stored in \a play.
    237238
    238239\param h
     
    254255
    255256\param play
    256 is the recording that defines the function we are computing the sparsity 
     257is the recording that defines the function we are computing the sparsity
    257258pattern for.
    258259
    259260\param for_jac_sparsity
    260 is a vector of sets containing the 
    261 the forward Jacobian sparsity pattern corresponding to 
    262 $latex R$$ for all of the variables on the tape. 
     261is a vector of sets containing the
     262the forward Jacobian sparsity pattern corresponding to
     263$latex R$$ for all of the variables on the tape.
    263264*/
    264265
     
    299300        // Initialize as true for the dependent variables.
    300301        pod_vector<bool> RevJac;
    301         RevJac.extend(num_var); 
     302        RevJac.extend(num_var);
    302303        for(i = 0; i < num_var; i++)
    303304                RevJac[i] = false;
     
    316317                num_var,
    317318                &play,
    318                 for_jac_sparsity, 
     319                for_jac_sparsity,
    319320                RevJac.data(),
    320321                rev_hes_sparsity
     
    324325        CPPAD_ASSERT_UNKNOWN( size_t(h.size()) == n * q );
    325326        for(j = 0; j < n; j++)
    326         {       for(i = 0; i < q; i++) 
     327        {       for(i = 0; i < q; i++)
    327328                {       if( transpose )
    328329                                h[ j * q + i ] = false;
     
    378379
    379380\param q
    380 is the value of \a q in the 
    381 by the previous call of the form 
     381is the value of \a q in the
     382by the previous call of the form
    382383\verbatim
    383384        f.ForSparseJac(q, r)
     
    389390for the vector \f$ S \f$,
    390391where \c m is the number of dependent variables
    391 corresponding to the operation sequence stored in \a play. 
     392corresponding to the operation sequence stored in \a play.
    392393
    393394\param h
     
    410411
    411412\param play
    412 is the recording that defines the function we are computing the sparsity 
     413is the recording that defines the function we are computing the sparsity
    413414pattern for.
    414415
    415416\param for_jac_sparsity
    416 is a vector of sets containing the 
    417 the forward Jacobian sparsity pattern corresponding to 
    418 $latex R$$ for all of the variables on the tape. 
     417is a vector of sets containing the
     418the forward Jacobian sparsity pattern corresponding to
     419$latex R$$ for all of the variables on the tape.
    419420*/
    420421
     
    459460        // Initialize as true for the dependent variables.
    460461        pod_vector<bool> RevJac;
    461         RevJac.extend(num_var); 
     462        RevJac.extend(num_var);
    462463        for(i = 0; i < num_var; i++)
    463464                RevJac[i] = false;
     
    484485                num_var,
    485486                &play,
    486                 for_jac_sparsity, 
     487                for_jac_sparsity,
    487488                RevJac.data(),
    488489                rev_hes_sparsity
     
    541542
    542543\param q
    543 is the value of \a q in the 
    544 by the previous call of the form 
     544is the value of \a q in the
     545by the previous call of the form
    545546\verbatim
    546547        f.ForSparseJac(q, r, packed)
     
    554555for the vector \f$ S \f$,
    555556where \c m is the number of dependent variables
    556 corresponding to the operation sequence stored in \a play. 
     557corresponding to the operation sequence stored in \a play.
    557558
    558559\return
    559 If \c transpose is false (true), 
     560If \c transpose is false (true),
    560561the return vector is a sparsity pattern for \f$ H(x) \f$ (\f$ H(x)^T \f$).
    561562\f[
     
    613614void ADFun<Base>::RevSparseHesCase(
    614615        bool              set_type         ,
    615         bool              transpose        , 
    616         size_t            q                , 
     616        bool              transpose        ,
     617        size_t            q                ,
    617618        const VectorSet&  s                ,
    618619        VectorSet&        h                )
    619 {       size_t n = Domain();   
     620{       size_t n = Domain();
    620621        h.resize(q * n );
    621622
    622         CPPAD_ASSERT_KNOWN( 
     623        CPPAD_ASSERT_KNOWN(
    623624                for_jac_sparse_pack_.n_set() > 0,
    624625                "RevSparseHes: previous stored call to ForSparseJac did not "
     
    627628        CPPAD_ASSERT_UNKNOWN( for_jac_sparse_set_.n_set() == 0 );
    628629        CPPAD_ASSERT_UNKNOWN( for_jac_sparse_pack_.n_set() == num_var_tape_  );
    629        
     630
    630631        // use sparse_pack for the calculation
    631         CppAD::RevSparseHesBool( 
     632        CppAD::RevSparseHesBool(
    632633                transpose                ,
    633634                q                        ,
     
    638639                ind_taddr_               ,
    639640                play_                    ,
    640                 for_jac_sparse_pack_ 
     641                for_jac_sparse_pack_
    641642        );
    642643}
     
    649650
    650651\param set_type
    651 is a \c std::set<size_t> value. 
     652is a \c std::set<size_t> value.
    652653This argument is used to dispatch to the proper source
    653654code depending on the vlaue of \c VectorSet::value_type.
     
    669670void ADFun<Base>::RevSparseHesCase(
    670671        const std::set<size_t>&   set_type         ,
    671         bool                      transpose        , 
    672         size_t                    q                , 
     672        bool                      transpose        ,
     673        size_t                    q                ,
    673674        const VectorSet&          s                ,
    674675        VectorSet&                h                )
     
    678679        else    h.resize(q);
    679680
    680         CPPAD_ASSERT_KNOWN( 
     681        CPPAD_ASSERT_KNOWN(
    681682                for_jac_sparse_set_.n_set() > 0,
    682683                "RevSparseHes: previous stored call to ForSparseJac did not "
     
    685686        CPPAD_ASSERT_UNKNOWN( for_jac_sparse_pack_.n_set() == 0 );
    686687        CPPAD_ASSERT_UNKNOWN( for_jac_sparse_set_.n_set() == num_var_tape_  );
    687        
     688
    688689        // use sparse_pack for the calculation
    689         CppAD::RevSparseHesSet( 
     690        CppAD::RevSparseHesSet(
    690691                transpose                ,
    691692                q                        ,
     
    696697                ind_taddr_               ,
    697698                play_                    ,
    698                 for_jac_sparse_set_ 
     699                for_jac_sparse_set_
    699700        );
    700701}
  • trunk/example/CMakeLists.txt

    r3703 r3711  
    192192        sparse_jacobian.cpp
    193193        sparse_sub_hes.cpp
     194        sparsity_sub.cpp
    194195        sqrt.cpp
    195196        stack_machine.cpp
  • trunk/example/example.cpp

    r3703 r3711  
    166166extern bool sparse_jacobian(void);
    167167extern bool sparse_sub_hes(void);
     168extern bool sparsity_sub(void);
    168169extern bool Sqrt(void);
    169170extern bool StackMachine(void);
     
    328329        ok &= Run( sparse_jacobian,   "sparse_jacobian"  );
    329330        ok &= Run( sparse_sub_hes,    "sparse_sub_hes"   );
     331        ok &= Run( sparsity_sub,      "sparsity_sub"     );
    330332        ok &= Run( Sqrt,              "Sqrt"             );
    331333        ok &= Run( StackMachine,      "StackMachine"     );
  • trunk/example/makefile.am

    r3704 r3711  
    198198        sparse_jacobian.cpp \
    199199        sparse_sub_hes.cpp \
     200        sparsity_sub.cpp \
    200201        sqrt.cpp \
    201202        stack_machine.cpp \
  • trunk/example/makefile.in

    r3705 r3711  
    142142        runge45_2.cpp seq_property.cpp simple_vector.cpp sign.cpp \
    143143        sin.cpp sinh.cpp sparse_hessian.cpp sparse_jacobian.cpp \
    144         sparse_sub_hes.cpp sqrt.cpp stack_machine.cpp sub.cpp \
    145         sub_eq.cpp sub_sparse_hes.cpp tan.cpp tanh.cpp tape_index.cpp \
    146         thread_alloc.cpp unary_minus.cpp unary_plus.cpp value.cpp \
    147         var2par.cpp vec_ad.cpp vector_bool.cpp zdouble.cpp
     144        sparse_sub_hes.cpp sparsity_sub.cpp sqrt.cpp stack_machine.cpp \
     145        sub.cpp sub_eq.cpp sub_sparse_hes.cpp tan.cpp tanh.cpp \
     146        tape_index.cpp thread_alloc.cpp unary_minus.cpp unary_plus.cpp \
     147        value.cpp var2par.cpp vec_ad.cpp vector_bool.cpp zdouble.cpp
    148148@CppAD_ADOLC_TRUE@am__objects_1 = mul_level_adolc.$(OBJEXT) \
    149149@CppAD_ADOLC_TRUE@      mul_level_adolc_ode.$(OBJEXT)
     
    194194        sin.$(OBJEXT) sinh.$(OBJEXT) sparse_hessian.$(OBJEXT) \
    195195        sparse_jacobian.$(OBJEXT) sparse_sub_hes.$(OBJEXT) \
    196         sqrt.$(OBJEXT) stack_machine.$(OBJEXT) sub.$(OBJEXT) \
    197         sub_eq.$(OBJEXT) sub_sparse_hes.$(OBJEXT) tan.$(OBJEXT) \
    198         tanh.$(OBJEXT) tape_index.$(OBJEXT) thread_alloc.$(OBJEXT) \
    199         unary_minus.$(OBJEXT) unary_plus.$(OBJEXT) value.$(OBJEXT) \
    200         var2par.$(OBJEXT) vec_ad.$(OBJEXT) vector_bool.$(OBJEXT) \
    201         zdouble.$(OBJEXT)
     196        sparsity_sub.$(OBJEXT) sqrt.$(OBJEXT) stack_machine.$(OBJEXT) \
     197        sub.$(OBJEXT) sub_eq.$(OBJEXT) sub_sparse_hes.$(OBJEXT) \
     198        tan.$(OBJEXT) tanh.$(OBJEXT) tape_index.$(OBJEXT) \
     199        thread_alloc.$(OBJEXT) unary_minus.$(OBJEXT) \
     200        unary_plus.$(OBJEXT) value.$(OBJEXT) var2par.$(OBJEXT) \
     201        vec_ad.$(OBJEXT) vector_bool.$(OBJEXT) zdouble.$(OBJEXT)
    202202example_OBJECTS = $(am_example_OBJECTS)
    203203example_LDADD = $(LDADD)
     
    627627        sparse_jacobian.cpp \
    628628        sparse_sub_hes.cpp \
     629        sparsity_sub.cpp \
    629630        sqrt.cpp \
    630631        stack_machine.cpp \
     
    822823@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sparse_jacobian.Po@am__quote@
    823824@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sparse_sub_hes.Po@am__quote@
     825@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sparsity_sub.Po@am__quote@
    824826@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sqrt.Po@am__quote@
    825827@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stack_machine.Po@am__quote@
  • trunk/example/sub_sparse_hes.cpp

    r3703 r3711  
    2323
    2424$head See Also$$
    25 $cref sparse_sub_hes.cpp$$
     25$cref sparse_sub_hes.cpp$$, $cref sparsity_sub.cpp$$,
    2626
    2727$head Function$$
  • trunk/omh/example_list.omh

    r3703 r3711  
    239239$rref sparse_jacobian.cpp$$
    240240$rref sparse_sub_hes.cpp$$
     241$rref sparsity_sub.cpp$$
    241242$rref speed_example.cpp$$
    242243$rref speed_program.cpp$$
  • trunk/omh/whats_new/whats_new_15.omh

    r3709 r3711  
    6161assist you in learning about changes between various versions of CppAD.
    6262
     63$head 08-20$$
     64Added an example that computes the sparsity pattern for a subset
     65of the $cref/Jacobian/sparsity_sub.cpp/ForSparseJac/$$ and a subset
     66of the $cref/Hessian/sparsity_sub.cpp/RevSparseHes/$$.
     67
    6368$head 08-17$$
    6469$list number$$
Note: See TracChangeset for help on using the changeset viewer.