Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #ifndef SUNDANCE_CHAINRULEEVALUATOR_H
00043 #define SUNDANCE_CHAINRULEEVALUATOR_H
00044
00045 #include "SundanceDefs.hpp"
00046 #include "SundanceSubtypeEvaluator.hpp"
00047 #include "SundanceExprWithChildren.hpp"
00048 #include "SundanceChainRuleSum.hpp"
00049
00050 namespace Sundance
00051 {
00052
00053
00054
00055 class ChainRuleEvaluator : public SubtypeEvaluator<ExprWithChildren>
00056 {
00057 public:
00058
00059
00060 ChainRuleEvaluator(const ExprWithChildren* expr,
00061 const EvalContext& context);
00062
00063
00064 virtual ~ChainRuleEvaluator(){;}
00065
00066
00067 virtual void internalEval(const EvalManager& mgr,
00068 Array<double>& constantResults,
00069 Array<RCP<EvalVector> >& vectorResults) const ;
00070
00071
00072 int numChildren() const {return childEvaluators_.size();}
00073
00074
00075 int constArgDerivIndex(const MultiSet<int>& df) const ;
00076
00077
00078 int varArgDerivIndex(const MultiSet<int>& df) const ;
00079
00080
00081 TEUCHOS_TIMER(chainRuleEvalTimer, "chain rule evaluation");
00082
00083
00084
00085 const Array<Array<int> >& nComps(int N, int n) const ;
00086
00087
00088 void resetNumCalls() const ;
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113 virtual void evalArgDerivs(const EvalManager& mgr,
00114 const Array<RCP<Array<double> > >& constDerivsOfArgs,
00115 const Array<RCP<Array<RCP<EvalVector> > > >& varDerivOfArgs,
00116 Array<double>& constArgDerivs,
00117 Array<RCP<EvalVector> >& varArgDerivs) const = 0 ;
00118
00119
00120 static Set<MultiSet<MultipleDeriv> > chainRuleBins(const MultipleDeriv& d,
00121 const MultiSet<int>& q);
00122
00123 protected:
00124
00125 void init(const ExprWithChildren* expr,
00126 const EvalContext& context);
00127
00128
00129 void addConstArgDeriv(const MultiSet<int>& df, int index);
00130
00131
00132 void addVarArgDeriv(const MultiSet<int>& df, int index);
00133
00134
00135 const Evaluator* childEvaluator(int i) const {return childEvaluators_[i].get();}
00136
00137
00138 const SparsitySuperset* childSparsity(int i) const {return childSparsity_[i].get();}
00139
00140 static MultipleDeriv makeMD(const Array<Deriv>& d) ;
00141
00142
00143 double choose(int N, int n) const ;
00144
00145
00146 double fact(int n) const ;
00147
00148
00149
00150 double stirling2(int n, int k) const ;
00151
00152
00153 int derivComboMultiplicity(const MultiSet<MultipleDeriv>& b) const ;
00154
00155
00156 private:
00157
00158
00159 Array<RCP<ChainRuleSum> > expansions_;
00160
00161 Array<RCP<Evaluator> > childEvaluators_;
00162
00163 Array<RCP<SparsitySuperset> > childSparsity_;
00164
00165 Map<MultiSet<int>, int> constArgDerivMap_;
00166
00167 Map<MultiSet<int>, int> varArgDerivMap_;
00168
00169 int zerothDerivResultIndex_;
00170
00171 bool zerothDerivIsConstant_;
00172
00173 static Map<OrderedPair<int, int>, Array<Array<int> > >& compMap() ;
00174 };
00175
00176
00177 MultipleDeriv makeDeriv(const Expr& a);
00178
00179
00180 MultipleDeriv makeDeriv(const Expr& a, const Expr& b);
00181
00182
00183 MultipleDeriv makeDeriv(const Expr& a, const Expr& b, const Expr& c);
00184
00185
00186 }
00187
00188
00189 #endif