5 #ifndef BPP_PHYL_LIKELIHOOD_DATAFLOW_DATAFLOWCWISECOMPUTING_H
6 #define BPP_PHYL_LIKELIHOOD_DATAFLOW_DATAFLOWCWISECOMPUTING_H
18 #include <type_traits>
34 template<
typename Result,
typename From>
class CWiseAdd;
35 template<
typename Result,
typename From,
typename Prop>
class CWiseMean;
36 template<
typename Result,
typename From>
class CWiseSub;
37 template<
typename Result,
typename From>
class CWiseMul;
38 template<
typename Result,
typename From>
class CWiseDiv;
40 template<
typename R,
typename T0,
typename T1>
class MatrixProduct;
49 template<
typename R,
typename T0,
typename T1>
class ScalarProduct;
50 template<
typename R,
typename T0,
typename T1>
class LogSumExp;
80 checkNthDependencyIsValue<T>(
typeid (
Self), deps, 0);
81 checkNthDependencyIsValue<F>(
typeid (
Self), deps, 1);
83 return cachedAs<Value<R>>(c, std::make_shared<Self>(std::move (deps), dim));
94 using namespace numeric;
101 return dynamic_cast<const Self*
>(&other) !=
nullptr;
141 return "doubleoctagon";
151 return "Function Apply";
158 typename std::enable_if<std::is_base_of<U, MatrixLik>::value && std::is_same<F, TransitionFunction>::value,
void>::type
161 using namespace numeric;
163 const auto& x0 = accessValueConstCast<T>(*this->
dependency (0));
164 const auto& func = accessValueConstCast<F>(*this->
dependency (1));
166 for (
auto i = 0; i < x0.cols(); i++)
168 bppLik_[(size_t)i] = func(x0.col(i));
174 std::cerr <<
"=== Function Apply === " <<
this << std::endl;
175 std::cerr <<
"x0= " << x0 << std::endl;
176 std::cerr <<
"res=" << result << std::endl;
177 std::cerr <<
"=== end Function Apply === " <<
this << std::endl << std::endl;
206 template<
typename R,
typename T0,
typename T1>
class CWiseAdd<R, std::tuple<T0, T1>> :
public Value<R>
217 checkNthDependencyIsValue<T0>(
typeid (
Self), deps, 0);
218 checkNthDependencyIsValue<T1>(
typeid (
Self), deps, 1);
222 if (zeroDep0 && zeroDep1)
226 else if (zeroDep0 && !zeroDep1)
230 else if (!zeroDep0 && zeroDep1)
236 return cachedAs<Value<R>>(c, std::make_shared<Self>(std::move (deps), dim));
245 using namespace numeric;
267 return dynamic_cast<const Self*
>(&other) !=
nullptr;
276 constexpr std::size_t n = 2;
278 for (std::size_t i = 0; i < n; ++i)
280 derivedDeps[i] = this->
dependency (i)->derive (c, node);
294 typename std::enable_if<!std::is_same<U, TransitionFunction>::value,
void>::type
297 using namespace numeric;
299 const auto& x0 = accessValueConstCast<T0>(*this->
dependency (0));
300 const auto& x1 = accessValueConstCast<T1>(*this->
dependency (1));
304 std::cerr <<
"=== Add === " <<
this << std::endl;
305 std::cerr <<
"x0= " << x0 << std::endl;
306 std::cerr <<
"x1= " << x1 << std::endl;
307 std::cerr <<
"res=" << result << std::endl;
308 std::cerr <<
"=== end Add === " <<
this << std::endl << std::endl;
313 typename std::enable_if<std::is_same<U, TransitionFunction>::value,
void>::type
316 using namespace numeric;
318 const auto& x0 = accessValueConstCast<T0>(*this->
dependency (0));
319 const auto& x1 = accessValueConstCast<T1>(*this->
dependency (1));
341 template<
typename R,
typename T0,
typename T1>
class CWiseSub<R, std::tuple<T0, T1>> :
public Value<R>
352 checkNthDependencyIsValue<T0>(
typeid (
Self), deps, 0);
353 checkNthDependencyIsValue<T1>(
typeid (
Self), deps, 1);
357 if (zeroDep0 && zeroDep1)
361 else if (zeroDep0 && !zeroDep1)
365 else if (!zeroDep0 && zeroDep1)
371 return cachedAs<Value<R>>(c, std::make_shared<Self>(std::move (deps), dim));
380 using namespace numeric;
387 return dynamic_cast<const Self*
>(&other) !=
nullptr;
396 constexpr std::size_t n = 2;
398 for (std::size_t i = 0; i < n; ++i)
400 derivedDeps[i] = this->
dependency (i)->derive (c, node);
413 using namespace numeric;
415 const auto& x0 = accessValueConstCast<T0>(*this->
dependency (0));
416 const auto& x1 = accessValueConstCast<T1>(*this->
dependency (1));
419 std::cerr <<
"=== Sub === " <<
this << std::endl;
420 std::cerr <<
"x0= " << x0 << std::endl;
421 std::cerr <<
"x1= " << x1 << std::endl;
422 std::cerr <<
"result= " << result << std::endl;
423 std::cerr <<
"=== end Sub === " <<
this << std::endl << std::endl;
450 checkDependencyRangeIsValue<T>(
typeid (
Self), deps, 0, deps.size ());
456 if (deps.size () == 0)
460 else if (deps.size () == 1)
464 else if (deps.size () == 2)
470 return cachedAs<Value<R>>(c, std::make_shared<Self>(std::move (deps), dim));
479 using namespace numeric;
486 return dynamic_cast<const Self*
>(&other) !=
nullptr;
497 for (std::size_t i = 0; i < n; ++i)
499 derivedDeps[i] = this->
dependency (i)->derive (c, node);
513 typename std::enable_if<!std::is_same<U, TransitionFunction>::value,
void>::type
516 using namespace numeric;
521 result += accessValueConstCast<T>(*depNodeRef);
526 typename std::enable_if<std::is_same<U, TransitionFunction>::value,
void>::type
529 using namespace numeric;
531 std::list<const T*> lT;
534 lT.push_back(&accessValueConstCast<T>(*depNodeRef));
540 for (
const auto f:lT)
579 return cachedAs<Value<R>>(c, std::make_shared<Self>(std::move (deps), dim));
588 using namespace numeric;
595 return dynamic_cast<const Self*
>(&other) !=
nullptr;
615 template<
class U,
class V>
616 typename std::enable_if<(std::is_base_of<V, MatrixLik>::value) && (std::is_same<U, RowLik>::value || std::is_same<U, Eigen::RowVectorXd>::value),
void>::type
619 const auto& mat = accessValueConstCast<T>(*this->
dependency(0));
623 template<
class U,
class V>
624 typename std::enable_if<(std::is_base_of<V, MatrixLik>::value) && (std::is_same<U, VectorLik>::value || std::is_same<U, Eigen::VectorXd>::value),
void>::type
627 const auto& mat = accessValueConstCast<T>(*this->
dependency(0));
631 template<
class U,
class V>
632 typename std::enable_if<(std::is_base_of<V, VectorLik>::value) || (std::is_same<V, RowLik>::value || std::is_same<V, Eigen::RowVectorXd>::value),
void>::type
635 const auto& vec = accessValueConstCast<T>(*this->
dependency(0));
666 if (deps.size() % 2 == 1)
669 size_t half = deps.size () / 2;
671 checkDependencyRangeIsValue<T>(
typeid (
Self), deps, 0, half);
672 checkDependencyRangeIsValue<P>(
typeid (
Self), deps, half, deps.size());
676 for (
size_t i = 0; i < half; i++)
691 if (deps.size() == 0)
695 return cachedAs<Value<R>>(c, std::make_shared<Self>(std::move (deps), dim));
703 using namespace numeric;
725 return dynamic_cast<const Self*
>(&other) !=
nullptr;
738 for (std::size_t i = 0; i < half; ++i)
740 derivedDeps_T[i] = this->
dependency (i)->derive (c, node);
742 for (std::size_t i = half; i < n; ++i)
749 for (std::size_t i = 0; i < half; ++i)
753 for (std::size_t i = half; i < n; ++i)
755 derivedDeps_P[i] = this->
dependency (i)->derive (c, node);
771 using namespace numeric;
775 for (
size_t i = 0; i < half; i++)
794 if (deps.size () <= 1)
796 checkDependencyRangeIsValue<T>(
typeid (
Self), deps, 0, deps.size () - 1);
797 checkNthDependencyIsValue<P>(
typeid (
Self), deps, deps.size () - 1);
802 if (std::all_of (deps.begin (), deps.end () - 1, [](
const NodeRef& dep)->bool {
803 return dep->hasNumericalProperty (NumericalProperty::ConstantZero);
810 return cachedAs<Value<R>>(c, std::make_shared<Self>(std::move (deps), dim));
818 using namespace numeric;
840 return dynamic_cast<const Self*
>(&other) !=
nullptr;
851 for (std::size_t i = 0; i < n - 1; ++i)
853 derivedDeps_T[i] = this->
dependency (i)->derive (c, node);
855 derivedDeps_T[n - 1] = this->
dependency (n - 1);
859 for (std::size_t i = 0; i < n - 1; ++i)
863 derivedDeps_P[n - 1] = this->
dependency (n - 1)->derive (c, node);
876 using namespace numeric;
881 std::cerr <<
"=== CWiseMean === " <<
this << std::endl;
884 std::cerr <<
"p= " << p << std::endl;
885 std::cerr <<
"=== end CWiseMean === " <<
this << std::endl << std::endl;
889 for (Eigen::Index i = 1; i < Eigen::Index(this->
nbDependencies() - 1); i++)
911 template<
typename R,
typename T0,
typename T1>
class CWiseMul<R, std::tuple<T0, T1>> :
public Value<R>
922 checkNthDependencyIsValue<T0>(
typeid (
Self), deps, 0);
923 checkNthDependencyIsValue<T1>(
typeid (
Self), deps, 1);
925 if (std::any_of (deps.begin (), deps.end (), [](
const NodeRef& dep) ->
bool {
926 return dep->hasNumericalProperty (NumericalProperty::ConstantZero);
934 if (oneDep0 && oneDep1)
938 else if (oneDep0 && !oneDep1)
942 else if (!oneDep0 && oneDep1)
948 return cachedAs<Value<R>>(c, std::make_shared<Self>(std::move (deps), dim));
957 using namespace numeric;
979 return dynamic_cast<const Self*
>(&other) !=
nullptr;
988 constexpr std::size_t n = 2;
990 for (std::size_t i = 0; i < n; ++i)
993 ithMulDeps[i] = this->
dependency (i)->derive (c, node);
1007 template<
class U,
class V>
1008 typename std::enable_if<!std::is_same<U, TransitionFunction>::value && !std::is_same<V, TransitionFunction>::value,
void>::type
1011 using namespace numeric;
1013 const auto& x0 = accessValueConstCast<U>(*this->
dependency (0));
1014 const auto& x1 = accessValueConstCast<V>(*this->
dependency (1));
1016 std::cerr <<
"=== Mul === " <<
this << std::endl;
1017 std::cerr <<
"x0= " << x0 << std::endl;
1018 std::cerr <<
"x1= " << x1 << std::endl;
1023 std::cerr <<
"result= " << result << std::endl;
1024 std::cerr <<
"=== end Mul === " <<
this << std::endl << std::endl;
1028 template<
class U,
class V>
1029 typename std::enable_if<std::is_same<U, TransitionFunction>::value && std::is_same<V, TransitionFunction>::value,
void>::type
1032 using namespace numeric;
1034 const auto& x0 = accessValueConstCast<U>(*this->
dependency (0));
1035 const auto& x1 = accessValueConstCast<V>(*this->
dependency (1));
1040 std::cerr <<
"=== Mul Transition Function X Transition Function === " <<
this << std::endl;
1041 std::cerr <<
"=== end Mul Transition Function X Transition Function === " <<
this << std::endl << std::endl;
1045 template<
class U,
class V>
1046 typename std::enable_if<std::is_same<U, TransitionFunction>::value && !std::is_same<V, TransitionFunction>::value,
void>::type
1049 using namespace numeric;
1051 const auto& x0 = accessValueConstCast<U>(*this->
dependency (0));
1052 const auto& x1 = accessValueConstCast<V>(*this->
dependency (1));
1057 std::cerr <<
"=== Mul Transition Function X Normal === " <<
this << std::endl;
1058 std::cerr <<
"x1= " << x1 << std::endl;
1059 std::cerr <<
"=== end Mul Transition Function X Normal === " <<
this << std::endl << std::endl;
1063 template<
class U,
class V>
1064 typename std::enable_if<!std::is_same<U, TransitionFunction>::value && std::is_same<V, TransitionFunction>::value,
void>::type
1067 using namespace numeric;
1069 const auto& x0 = accessValueConstCast<U>(*this->
dependency (0));
1070 const auto& x1 = accessValueConstCast<V>(*this->
dependency (1));
1075 std::cerr <<
"=== Mul Normal X Transition Function === " <<
this << std::endl;
1076 std::cerr <<
"x0= " << x0 << std::endl;
1077 std::cerr <<
"=== end Mul Normal X Transition Function === " <<
this << std::endl << std::endl;
1103 checkDependencyRangeIsValue<T>(
typeid (
Self), deps, 0, deps.size ());
1105 if (std::any_of (deps.begin (), deps.end (), [](
const NodeRef& dep) ->
bool {
1106 return dep->hasNumericalProperty (NumericalProperty::ConstantZero);
1116 if (deps.size () == 0)
1120 else if (deps.size () == 1)
1124 else if (deps.size () == 2)
1130 return cachedAs<Value<R>>(c, std::make_shared<Self>(std::move (deps), dim));
1139 using namespace numeric;
1146 return dynamic_cast<const Self*
>(&other) !=
nullptr;
1157 for (std::size_t i = 0; i < n; ++i)
1160 ithMulDeps[i] = this->
dependency (i)->derive (c, node);
1174 using namespace numeric;
1179 cwise(result) *=
cwise (accessValueConstCast<T>(*depNodeRef));
1198 template<
typename R,
typename T0,
typename T1>
class CWiseDiv<R, std::tuple<T0, T1>> :
public Value<R>
1209 checkNthDependencyIsValue<T0>(
typeid (
Self), deps, 0);
1210 checkNthDependencyIsValue<T1>(
typeid (
Self), deps, 1);
1217 return cachedAs<Value<R>>(c, std::make_shared<Self>(std::move (deps), dim));
1225 using namespace numeric;
1247 return dynamic_cast<const Self*
>(&other) !=
nullptr;
1259 auto fp0 = this->
dependency (0)->derive (c, node);
1260 auto fp1 = this->
dependency (1)->derive (c, node);
1278 template<
class U,
class V>
1279 typename std::enable_if<!std::is_same<U, TransitionFunction>::value && !std::is_same<V, TransitionFunction>::value,
void>::type
1282 using namespace numeric;
1284 const auto& x0 = accessValueConstCast<U>(*this->
dependency (0));
1285 const auto& x1 = accessValueConstCast<V>(*this->
dependency (1));
1289 template<
class U,
class V>
1290 typename std::enable_if<std::is_same<U, TransitionFunction>::value && std::is_same<V, TransitionFunction>::value,
void>::type
1293 using namespace numeric;
1295 const auto& x0 = accessValueConstCast<U>(*this->
dependency (0));
1296 const auto& x1 = accessValueConstCast<V>(*this->
dependency (1));
1301 template<
class U,
class V>
1302 typename std::enable_if<std::is_same<U, TransitionFunction>::value && !std::is_same<V, TransitionFunction>::value,
void>::type
1305 using namespace numeric;
1307 const auto& x0 = accessValueConstCast<U>(*this->
dependency (0));
1308 const auto& x1 = accessValueConstCast<V>(*this->
dependency (1));
1313 template<
class U,
class V>
1314 typename std::enable_if<!std::is_same<U, TransitionFunction>::value && std::is_same<V, TransitionFunction>::value,
void>::type
1317 using namespace numeric;
1319 const auto& x0 = accessValueConstCast<U>(*this->
dependency (0));
1320 const auto& x1 = accessValueConstCast<V>(*this->
dependency (1));
1347 checkNthDependencyIsValue<T>(
typeid (
Self), deps, 0);
1355 return cachedAs<Value<T>>(c, std::make_shared<Self>(std::move (deps), dim));
1364 using namespace numeric;
1371 return dynamic_cast<const Self*
>(&other) !=
nullptr;
1391 using namespace numeric;
1393 const auto& x = accessValueConstCast<T>(*this->
dependency (0));
1419 checkNthDependencyIsValue<T>(
typeid (
Self), deps, 0);
1427 return cachedAs<Value<T>>(c, std::make_shared<Self>(std::move (deps), dim));
1436 using namespace numeric;
1443 return dynamic_cast<const Self*
>(&other) !=
nullptr;
1467 using namespace numeric;
1469 const auto& x = accessValueConstCast<T>(*this->
dependency (0));
1497 checkNthDependencyIsValue<T>(
typeid (
Self), deps, 0);
1505 return cachedAs<Value<T>>(c, std::make_shared<Self>(std::move (deps), dim));
1514 using namespace numeric;
1521 return dynamic_cast<const Self*
>(&other) !=
nullptr;
1544 using namespace numeric;
1546 const auto& x = accessValueConstCast<T>(*this->
dependency (0));
1574 checkNthDependencyIsValue<T>(
typeid (
Self), deps, 0);
1582 return cachedAs<Value<T>>(c, std::make_shared<Self>(std::move (deps), dim));
1591 using namespace numeric;
1598 return dynamic_cast<const Self*
>(&other) !=
nullptr;
1621 using namespace numeric;
1623 const auto& x = accessValueConstCast<T>(*this->
dependency (0));
1651 checkNthDependencyIsValue<T>(
typeid (
Self), deps, 0);
1656 using namespace numeric;
1659 else if (exponent == 1.)
1665 else if (exponent == -1.)
1675 return cachedAs<Value<T>>(c, std::make_shared<Self>(std::move (deps), exponent, factor, dim));
1684 using namespace numeric;
1692 const auto* derived =
dynamic_cast<const Self*
>(&other);
1693 return derived !=
nullptr && exponent_ == derived->
exponent_ && factor_ == derived->factor_;
1697 std::size_t seed = 0;
1723 using namespace numeric;
1725 const auto& x = accessValueConstCast<T>(*this->
dependency (0));
1726 result = factor_ *
pow (
cwise (x), exponent_);
1754 checkNthDependencyIsValue<T0>(
typeid (
Self), deps, 0);
1755 checkNthDependencyIsValue<T1>(
typeid (
Self), deps, 1);
1764 return cachedAs<Value<R>>(c, std::make_shared<Self>(std::move (deps)));
1772 using namespace numeric;
1779 return dynamic_cast<const Self*
>(&other) !=
nullptr;
1790 auto dx0_prod =
Self::create (c, {x0->derive (c, node), x1});
1791 auto dx1_prod =
Self::create (c, {x0, x1->derive (c, node)});
1805 const auto& x0 = accessValueConstCast<T0>(*this->
dependency (0));
1806 const auto& x1 = accessValueConstCast<T1>(*this->
dependency (1));
1807 auto d = x0.dot (x1);
1838 checkNthDependencyIsValue<F>(
typeid (
Self), deps, 0);
1839 if (deps.size() == 2)
1840 checkNthDependencyIsValue<Eigen::RowVectorXi>(
typeid (
Self), deps, 1);
1841 return cachedAs<Value<DataLik>>(c, std::make_shared<Self>(std::move (deps), mDim));
1845 :
Value<
DataLik>(std::move (deps)), mTargetDimension_ (mDim)
1855 using namespace numeric;
1862 return dynamic_cast<const Self*
>(&other) !=
nullptr;
1868 auto dm_dn = m->derive (c, node);
1881 return Self::create (c, std::move (deps), mTargetDimension_);
1887 template<
class G = F>
1888 typename std::enable_if<std::is_convertible<G*, Eigen::DenseBase<G>*>::value,
void>::type
1892 std::cerr <<
"=== SumOfLogarithms === " <<
this << std::endl;
1897 const auto& m = accessValueConstCast<F>(*this->
dependency (0));
1907 r.normalize_small ();
1910 result = product.
log();
1912 std::cerr <<
"product= " << product << std::endl;
1913 std::cerr <<
"result log= " << result << std::endl;
1918 const auto& p = accessValueConstCast<Eigen::RowVectorXi>(*this->
dependency (1));
1922 temp_ = m.unaryExpr ([](
double d) {
1928 for (Eigen::Index i = 0; i < Eigen::Index(p.size()); i++)
1930 temp_[i] = temp_[i].pow(p[i]);
1939 result = product.
log ();
1941 std::cerr <<
"PRODUCT= " << product << std::endl;
1942 std::cerr <<
"RESULT log= " << result << std::endl;
1946 std::cerr <<
"=== end SumOfLogarithms === " <<
this << std::endl;
1950 template<
class G = F>
1951 typename std::enable_if<std::is_convertible<G*, ExtendedFloatEigenBase<G>*>::value,
void>::type
1955 std::cerr <<
"=== SumOfLogarithms === " <<
this << std::endl;
1960 const auto& m = accessValueConstCast<F>(*this->
dependency (0));
1970 r.normalize_small ();
1975 std::cerr <<
"product= " << product <<
"* 2^" << m.size() * m.
exponent_part() << std::endl;
1976 std::cerr <<
"result log= " << result << std::endl;
1981 const auto& p = accessValueConstCast<Eigen::RowVectorXi>(*this->
dependency (1));
1985 temp_ = m.float_part().unaryExpr ([](
double d) {
1991 for (Eigen::Index i = 0; i < Eigen::Index(p.size()); i++)
1993 temp_[i] = temp_[i].pow(p[i]);
2004 std::cerr <<
"RESULT log= " << result << std::endl;
2008 std::cerr <<
"=== end SumOfLogarithms === " <<
this << std::endl;
2014 Eigen::Matrix<ExtendedFloat, 1, Eigen::Dynamic>
temp_;
2038 checkNthDependencyIsValue<T0>(
typeid (
Self), deps, 0);
2039 checkNthDependencyIsValue<T1>(
typeid (
Self), deps, 1);
2041 return cachedAs<Value<R>>(c, std::make_shared<Self>(std::move (deps), mDim));
2045 :
Value<R>(std::move (deps)), mTargetDimension_ (mDim) {}
2049 using namespace numeric;
2056 return dynamic_cast<const Self*
>(&other) !=
nullptr;
2077 return Self::create (c, std::move (deps), mTargetDimension_);
2083 using namespace numeric;
2085 const auto& v = accessValueConstCast<T0>(*this->
dependency (0));
2086 const auto& p = accessValueConstCast<T1>(*this->
dependency (1));
2088 auto M = v.maxCoeff();
2094 v2 =
exp(
cwise(v - T0::Constant(mTargetDimension_.rows, mTargetDimension_.cols, M)));
2095 auto ve = v2.dot(p);
2096 result =
log(ve) + M;
2125 checkNthDependencyIsValue<DepT0>(
typeid (
Self), deps, 0);
2126 checkNthDependencyIsValue<DepT1>(
typeid (
Self), deps, 1);
2128 if (std::any_of (deps.begin (), deps.end (), [](
const NodeRef& dep) ->
bool {
2129 return dep->hasNumericalProperty (NumericalProperty::ConstantZero);
2137 if (identityDep0 && identityDep1)
2140 using namespace numeric;
2143 else if (identityDep0 && !identityDep1)
2147 else if (!identityDep0 && identityDep1)
2153 return cachedAs<Value<R>>(c, std::make_shared<Self>(std::move (deps), dim));
2163 using namespace numeric;
2169 return "doubleoctagon";
2180 return "Matrix Product";
2186 return dynamic_cast<const Self*
>(&other) !=
nullptr;
2211 const auto& x0 = accessValueConstCast<DepT0>(*this->
dependency (0));
2212 const auto& x1 = accessValueConstCast<DepT1>(*this->
dependency (1));
2216 if ((x1.cols() + x1.rows() < 100 ) && (x0.cols() + x0.rows() < 100))
2218 std::cerr <<
"=== MatrixProd === " <<
this << std::endl;
2219 std::cerr <<
"x0= " << x0.rows() <<
" x " << x0.cols() << std::endl;
2221 std::cerr <<
"x1= " << x1.rows() <<
" x " << x1.cols() << std::endl;
2223 std::cerr <<
"result= " << result << std::endl;
2224 std::cerr <<
"=== end MatrixProd === " <<
this << std::endl << std::endl;
2255 checkNthDependencyIsValue<double>(
typeid (
Self), deps, 0);
2256 checkNthDependencyIsValue<T>(
typeid (
Self), deps, 1);
2258 auto& delta = deps[0];
2260 auto* xAsShiftDelta =
dynamic_cast<const ShiftDelta<T>*
>(x.get ());
2261 if (xAsShiftDelta !=
nullptr && xAsShiftDelta->dependency (0) == delta)
2269 return convertRef<Value<T>>(x);
2273 return cachedAs<Value<T>>(c, std::make_shared<Self>(std::move (deps), n, dim));
2282 using namespace numeric;
2290 const auto* derived =
dynamic_cast<const Self*
>(&other);
2291 return derived !=
nullptr && n_ == derived->
n_;
2295 std::size_t seed = 0;
2321 using namespace numeric;
2323 const auto& delta = accessValueConstCast<double>(*this->
dependency (0));
2324 const auto& x = accessValueConstCast<T>(*this->
dependency (1));
2325 result = n_ * delta +
cwise (x);
2362 checkNthDependencyIsValue<double>(
typeid (
Self), deps, 0);
2363 checkDependencyRangeIsValue<T>(
typeid (
Self), deps, 1, deps.size ());
2365 auto cleanAndCreateNode = [&c, &dim](
NodeRefVec&& deps2,
int n2,
2368 for (std::size_t i = 0; i < coeffs2.size ();)
2372 coeffs2.erase (coeffs2.begin () + std::ptrdiff_t (i));
2373 deps2.erase (deps2.begin () + std::ptrdiff_t (i + 1));
2381 if (coeffs2.empty ())
2387 return cachedAs<Value<T>>(
2388 c, std::make_shared<Self>(std::move (deps2), n2, std::move (coeffs2), dim));
2392 const auto& delta = deps[0];
2393 auto isSelfWithSameDelta = [&delta](
const NodeRef& dep) ->
bool {
2394 return dynamic_cast<const Self*
>(dep.get ()) !=
nullptr && dep->
dependency (0) == delta;
2396 if (!coeffs.empty () && std::all_of (deps.begin () + 1, deps.end (), isSelfWithSameDelta))
2398 const auto depN =
static_cast<const Self&
>(*deps[1]).getN ();
2399 auto useSameNasDep1 = [depN](
const NodeRef& dep) {
2400 return static_cast<const Self&
>(*dep).
getN () == depN;
2402 if (std::all_of (deps.begin () + 2, deps.end (), useSameNasDep1))
2412 std::vector<double> mergedCoeffs;
2413 for (std::size_t i = 0; i < coeffs.size (); ++i)
2415 const auto& dep =
static_cast<const Self&
>(*deps[i + 1]);
2416 const auto& depCoeffs = dep.
getCoeffs ();
2417 for (std::size_t j = 0; j < depCoeffs.size (); ++j)
2419 const auto& subDep = dep.dependency (j + 1);
2420 auto it = std::find (mergedDeps.begin () + 1, mergedDeps.end (), subDep);
2421 if (it != mergedDeps.end ())
2424 const auto subDepIndexInMerged =
2425 static_cast<std::size_t
>(std::distance (mergedDeps.begin () + 1, it));
2426 mergedCoeffs[subDepIndexInMerged] += coeffs[i] * depCoeffs[j];
2431 mergedDeps.emplace_back (subDep);
2432 mergedCoeffs.emplace_back (coeffs[i] * depCoeffs[j]);
2436 return cleanAndCreateNode (std::move (mergedDeps), n + depN, std::move (mergedCoeffs));
2440 return cleanAndCreateNode (std::move (deps), n, std::move (coeffs));
2446 assert (this->coeffs_.size () + 1 == this->nbDependencies ());
2451 std::string s =
" CombineDeltaShifted n=" +
std::to_string (n_) +
" coeffs={";
2452 if (!coeffs_.empty ())
2455 for (std::size_t i = 1; i < coeffs_.size (); ++i)
2466 using namespace numeric;
2474 const auto* derived =
dynamic_cast<const Self*
>(&other);
2475 return derived !=
nullptr && n_ == derived->
n_ && coeffs_ == derived->coeffs_;
2479 std::size_t seed = 0;
2481 for (
const auto d : coeffs_)
2504 derivedDeps[0] = delta;
2505 for (std::size_t i = 1; i < nbDeps; ++i)
2507 derivedDeps[i] = this->
dependency (i)->derive (c, node);
2517 const std::vector<double>&
getCoeffs ()
const {
return coeffs_; }
2525 typename std::enable_if<!std::is_same<U, TransitionFunction>::value,
void>::type
2528 using namespace numeric;
2530 const auto& delta = accessValueConstCast<double>(*this->
dependency (0));
2531 const double lambda =
pow (delta, -n_);
2533 for (std::size_t i = 0; i < coeffs_.size (); ++i)
2535 const auto& x = accessValueConstCast<T>(*this->
dependency (1 + i));
2536 cwise (result) += (lambda * coeffs_[i]) *
cwise (x);
2541 typename std::enable_if<std::is_same<U, TransitionFunction>::value,
void>::type
2544 using namespace numeric;
2546 const auto& delta = accessValueConstCast<double>(*this->
dependency (0));
2547 const double lambda =
pow (delta, -n_);
2549 std::vector<const T*> vT;
2552 for (
size_t i = 1; i < dep.size(); i++)
2554 vT.push_back(&accessValueConstCast<T>(*dep[i]));
2558 using namespace numeric;
2561 for (std::size_t i = 0; i < this->coeffs_.size (); ++i)
2563 cwise(r) += (lambda * this->coeffs_[i]) *
cwise((*vT[i])(x));
2723 template<
typename NodeT,
typename DepT,
typename B>
2730 if (config.
delta ==
nullptr)
2734 switch (config.
type)
2741 combineDeps[0] = config.
delta;
2742 combineDeps[1] = buildNodeWithDep (std::move (shift_m1));
2743 combineDeps[2] = buildNodeWithDep (std::move (shift_p1));
2753 combineDeps[0] = config.
delta;
2754 combineDeps[1] = buildNodeWithDep (std::move (shift_m2));
2755 combineDeps[2] = buildNodeWithDep (std::move (shift_m1));
2756 combineDeps[3] = buildNodeWithDep (std::move (shift_p1));
2757 combineDeps[4] = buildNodeWithDep (std::move (shift_p2));
2759 {1. / 12., -2. / 3., 2. / 3., -1. / 12.}, nodeDim);
2766 template<
typename NodeT,
typename B>
2773 if (config.
delta ==
nullptr)
2778 if (param ==
nullptr)
2779 throw Exception(
"generateNumericalDerivative : dependency should be ConfiguredParameter");
2781 switch (config.
type)
2788 combineDeps[0] = config.
delta;
2789 combineDeps[1] = buildNodeWithDep (std::move (shift_m1));
2790 combineDeps[2] = buildNodeWithDep (std::move (shift_p1));
2800 combineDeps[0] = config.
delta;
2801 combineDeps[1] = buildNodeWithDep (std::move (shift_m2));
2802 combineDeps[2] = buildNodeWithDep (std::move (shift_m1));
2803 combineDeps[3] = buildNodeWithDep (std::move (shift_p1));
2804 combineDeps[4] = buildNodeWithDep (std::move (shift_p2));
2806 {1. / 12., -2. / 3., 2. / 3., -1. / 12.}, nodeDim);
CWiseAdd(NodeRefVec &&deps, const Dimension< R > &dim)
static ValueRef< R > create(Context &c, NodeRefVec &&deps, const Dimension< R > &dim)
Build a new CWiseAdd node with the given output dimensions.
Dimension< R > targetDimension_
bool compareAdditionalArguments(const Node_DF &other) const final
Compare node-specific configuration to another.
std::enable_if< std::is_same< U, TransitionFunction >::value, void >::type compute()
Computation implementation.
std::string debugInfo() const override
Node debug info (default = ""): user defined detailed info for DF graph debug.
NodeRef recreate(Context &c, NodeRefVec &&deps) final
Recreate the node with different dependencies.
NodeRef derive(Context &c, const Node_DF &node) final
Returns a node computing d(this_node_expression)/d(node_expression).
void compute() override
Computation implementation.
std::enable_if<!std::is_same< U, TransitionFunction >::value, void >::type compute()
Computation implementation.
void compute() override
Computation implementation.
bool compareAdditionalArguments(const Node_DF &other) const final
Compare node-specific configuration to another.
NodeRef derive(Context &c, const Node_DF &node) final
Returns a node computing d(this_node_expression)/d(node_expression).
Dimension< R > targetDimension_
std::string shape() const override
std::string debugInfo() const override
Node debug info (default = ""): user defined detailed info for DF graph debug.
std::enable_if<!std::is_same< U, TransitionFunction >::value, void >::type compute()
Computation implementation.
std::string color() const override
std::string description() const override
Node pretty name (default = type name).
std::enable_if< std::is_same< U, TransitionFunction >::value, void >::type compute()
Computation implementation.
NodeRef recreate(Context &c, NodeRefVec &&deps) final
Recreate the node with different dependencies.
CWiseAdd(NodeRefVec &&deps, const Dimension< R > &dim)
static ValueRef< R > create(Context &c, NodeRefVec &&deps, const Dimension< R > &dim)
Build a new CWiseAdd node with the given output dimensions.
NodeRef derive(Context &c, const Node_DF &node) final
Returns a node computing d(this_node_expression)/d(node_expression).
std::enable_if<(std::is_base_of< V, VectorLik >::value)||(std::is_same< V, RowLik >::value||std::is_same< V, Eigen::RowVectorXd >::value), void >::type compute()
Computation implementation.
void compute() override
Computation implementation.
std::enable_if<(std::is_base_of< V, MatrixLik >::value) &&(std::is_same< U, VectorLik >::value||std::is_same< U, Eigen::VectorXd >::value), void >::type compute()
Computation implementation.
std::string debugInfo() const override
Node debug info (default = ""): user defined detailed info for DF graph debug.
std::enable_if<(std::is_base_of< V, MatrixLik >::value) &&(std::is_same< U, RowLik >::value||std::is_same< U, Eigen::RowVectorXd >::value), void >::type compute()
Computation implementation.
NodeRef recreate(Context &c, NodeRefVec &&deps) final
Recreate the node with different dependencies.
Dimension< R > targetDimension_
CWiseAdd(NodeRefVec &&deps, const Dimension< R > &dim)
static ValueRef< R > create(Context &c, NodeRefVec &&deps, const Dimension< R > &dim)
Build a new CWiseAdd node with the given output dimensions.
bool compareAdditionalArguments(const Node_DF &other) const final
Compare node-specific configuration to another.
static ValueRef< R > create(Context &c, NodeRefVec &&deps, const Dimension< R > &dim)
Build a new CWiseApply node.
void compute() override
Computation implementation.
bool compareAdditionalArguments(const Node_DF &other) const final
Compare node-specific configuration to another.
std::enable_if< std::is_base_of< U, MatrixLik >::value &&std::is_same< F, TransitionFunction >::value, void >::type compute()
Computation implementation.
std::string debugInfo() const override
Node debug info (default = ""): user defined detailed info for DF graph debug.
NodeRef recreate(Context &c, NodeRefVec &&deps) final
Recreate the node with different dependencies.
std::string shape() const override
std::string color() const override
CWiseApply(NodeRefVec &&deps, const Dimension< R > &dim)
Dimension< R > targetDimension_
std::vector< VectorLik > bppLik_
For computation purpose.
NodeRef derive(Context &c, const Node_DF &node) final
Returns a node computing d(this_node_expression)/d(node_expression).
std::string description() const override
Node pretty name (default = type name).
NodeRef derive(Context &c, const Node_DF &node) final
Returns a node computing d(this_node_expression)/d(node_expression).
bool compareAdditionalArguments(const Node_DF &other) const final
Compare node-specific configuration to another.
void compute() final
Computation implementation.
NodeRef recreate(Context &c, NodeRefVec &&deps) final
Recreate the node with different dependencies.
std::size_t hashAdditionalArguments() const final
Return the hash of node-specific configuration.
std::string debugInfo() const override
Node debug info (default = ""): user defined detailed info for DF graph debug.
Dimension< T > targetDimension_
static ValueRef< T > create(Context &c, NodeRefVec &&deps, double exponent, double factor, const Dimension< T > &dim)
Build a new CWiseConstantPow node with the given output dimensions and factors.
CWiseConstantPow(NodeRefVec &&deps, double exponent, double factor, const Dimension< T > &dim)
NodeRef derive(Context &c, const Node_DF &node) final
Returns a node computing d(this_node_expression)/d(node_expression).
std::enable_if< std::is_same< U, TransitionFunction >::value &&!std::is_same< V, TransitionFunction >::value, void >::type compute()
Computation implementation.
std::enable_if< std::is_same< U, TransitionFunction >::value &&std::is_same< V, TransitionFunction >::value, void >::type compute()
Computation implementation.
std::string color() const override
std::string debugInfo() const override
Node debug info (default = ""): user defined detailed info for DF graph debug.
std::enable_if<!std::is_same< U, TransitionFunction >::value &&!std::is_same< V, TransitionFunction >::value, void >::type compute()
Computation implementation.
std::string description() const override
Node pretty name (default = type name).
Dimension< R > targetDimension_
NodeRef recreate(Context &c, NodeRefVec &&deps) final
Recreate the node with different dependencies.
static ValueRef< R > create(Context &c, NodeRefVec &&deps, const Dimension< R > &dim)
Build a new CWiseDiv node with the given output dimensions.
CWiseDiv(NodeRefVec &&deps, const Dimension< R > &dim)
std::string shape() const override
void compute() override
Computation implementation.
std::enable_if<!std::is_same< U, TransitionFunction >::value &&std::is_same< V, TransitionFunction >::value, void >::type compute()
Computation implementation.
bool compareAdditionalArguments(const Node_DF &other) const final
Compare node-specific configuration to another.
Dimension< T > targetDimension_
std::string debugInfo() const override
Node debug info (default = ""): user defined detailed info for DF graph debug.
void compute() final
Computation implementation.
NodeRef derive(Context &c, const Node_DF &node) final
Returns a node computing d(this_node_expression)/d(node_expression).
static ValueRef< T > create(Context &c, NodeRefVec &&deps, const Dimension< T > &dim)
Build a new CWiseExp node with the given output dimensions.
NodeRef recreate(Context &c, NodeRefVec &&deps) final
Recreate the node with different dependencies.
bool compareAdditionalArguments(const Node_DF &other) const final
Compare node-specific configuration to another.
CWiseExp(NodeRefVec &&deps, const Dimension< T > &dim)
CWiseInverse(NodeRefVec &&deps, const Dimension< T > &dim)
NodeRef recreate(Context &c, NodeRefVec &&deps) final
Recreate the node with different dependencies.
static ValueRef< T > create(Context &c, NodeRefVec &&deps, const Dimension< T > &dim)
Build a new CWiseInverse node with the given output dimensions.
bool compareAdditionalArguments(const Node_DF &other) const final
Compare node-specific configuration to another.
NodeRef derive(Context &c, const Node_DF &node) final
Returns a node computing d(this_node_expression)/d(node_expression).
Dimension< T > targetDimension_
void compute() final
Computation implementation.
std::string debugInfo() const override
Node debug info (default = ""): user defined detailed info for DF graph debug.
NodeRef derive(Context &c, const Node_DF &node) final
Returns a node computing d(this_node_expression)/d(node_expression).
CWiseLog(NodeRefVec &&deps, const Dimension< T > &dim)
std::string debugInfo() const override
Node debug info (default = ""): user defined detailed info for DF graph debug.
static ValueRef< T > create(Context &c, NodeRefVec &&deps, const Dimension< T > &dim)
Build a new CWiseLog node with the given output dimensions.
bool compareAdditionalArguments(const Node_DF &other) const final
Compare node-specific configuration to another.
NodeRef recreate(Context &c, NodeRefVec &&deps) final
Recreate the node with different dependencies.
void compute() final
Computation implementation.
Dimension< T > targetDimension_
std::string debugInfo() const override
Node debug info (default = ""): user defined detailed info for DF graph debug.
std::string shape() const override
void compute() final
Computation implementation.
static ValueRef< R > create(Context &c, NodeRefVec &&deps, const Dimension< R > &dim)
Build a new CWiseMean node with the given output dimensions.
std::string color() const override
CWiseMean(NodeRefVec &&deps, const Dimension< R > &dim)
Dimension< R > targetDimension_
NodeRef derive(Context &c, const Node_DF &node) final
Returns a node computing d(this_node_expression)/d(node_expression).
bool compareAdditionalArguments(const Node_DF &other) const final
Compare node-specific configuration to another.
NodeRef recreate(Context &c, NodeRefVec &&deps) final
Recreate the node with different dependencies.
std::string description() const override
Node pretty name (default = type name).
bool compareAdditionalArguments(const Node_DF &other) const final
Compare node-specific configuration to another.
void compute() final
Computation implementation.
NodeRef recreate(Context &c, NodeRefVec &&deps) final
Recreate the node with different dependencies.
std::string color() const override
std::string description() const override
Node pretty name (default = type name).
CWiseMean(NodeRefVec &&deps, const Dimension< R > &dim)
std::string shape() const override
Dimension< R > targetDimension_
std::string debugInfo() const override
Node debug info (default = ""): user defined detailed info for DF graph debug.
NodeRef derive(Context &c, const Node_DF &node) final
Returns a node computing d(this_node_expression)/d(node_expression).
static ValueRef< R > create(Context &c, NodeRefVec &&deps, const Dimension< R > &dim)
Build a new CWiseMean node with the given output dimensions.
Dimension< R > targetDimension_
static ValueRef< R > create(Context &c, NodeRefVec &&deps, const Dimension< R > &dim)
Build a new CWiseMul node with the given output dimensions.
std::string debugInfo() const override
Node debug info (default = ""): user defined detailed info for DF graph debug.
bool compareAdditionalArguments(const Node_DF &other) const final
Compare node-specific configuration to another.
NodeRef derive(Context &c, const Node_DF &node) final
Returns a node computing d(this_node_expression)/d(node_expression).
CWiseMul(NodeRefVec &&deps, const Dimension< R > &dim)
NodeRef recreate(Context &c, NodeRefVec &&deps) final
Recreate the node with different dependencies.
void compute() final
Computation implementation.
std::enable_if< std::is_same< U, TransitionFunction >::value &&!std::is_same< V, TransitionFunction >::value, void >::type compute()
Computation implementation.
std::string color() const override
bool compareAdditionalArguments(const Node_DF &other) const final
Compare node-specific configuration to another.
NodeRef recreate(Context &c, NodeRefVec &&deps) final
Recreate the node with different dependencies.
Dimension< R > targetDimension_
std::enable_if< std::is_same< U, TransitionFunction >::value &&std::is_same< V, TransitionFunction >::value, void >::type compute()
Computation implementation.
CWiseMul(NodeRefVec &&deps, const Dimension< R > &dim)
std::string debugInfo() const override
Node debug info (default = ""): user defined detailed info for DF graph debug.
void compute() override
Computation implementation.
std::string description() const override
Node pretty name (default = type name).
std::string shape() const override
std::enable_if<!std::is_same< U, TransitionFunction >::value &&!std::is_same< V, TransitionFunction >::value, void >::type compute()
Computation implementation.
std::enable_if<!std::is_same< U, TransitionFunction >::value &&std::is_same< V, TransitionFunction >::value, void >::type compute()
Computation implementation.
static ValueRef< R > create(Context &c, NodeRefVec &&deps, const Dimension< R > &dim)
Build a new CWiseMul node with the given output dimensions.
NodeRef derive(Context &c, const Node_DF &node) final
Returns a node computing d(this_node_expression)/d(node_expression).
CWiseNegate(NodeRefVec &&deps, const Dimension< T > &dim)
bool compareAdditionalArguments(const Node_DF &other) const final
Compare node-specific configuration to another.
void compute() final
Computation implementation.
NodeRef derive(Context &c, const Node_DF &node) final
Returns a node computing d(this_node_expression)/d(node_expression).
static ValueRef< T > create(Context &c, NodeRefVec &&deps, const Dimension< T > &dim)
Build a new CWiseNegate node with the given output dimensions.
NodeRef recreate(Context &c, NodeRefVec &&deps) final
Recreate the node with different dependencies.
Dimension< T > targetDimension_
std::string debugInfo() const override
Node debug info (default = ""): user defined detailed info for DF graph debug.
static ValueRef< R > create(Context &c, NodeRefVec &&deps, const Dimension< R > &dim)
Build a new CWiseSub node with the given output dimensions.
std::string debugInfo() const override
Node debug info (default = ""): user defined detailed info for DF graph debug.
NodeRef derive(Context &c, const Node_DF &node) final
Returns a node computing d(this_node_expression)/d(node_expression).
void compute() final
Computation implementation.
bool compareAdditionalArguments(const Node_DF &other) const final
Compare node-specific configuration to another.
CWiseSub(NodeRefVec &&deps, const Dimension< R > &dim)
NodeRef recreate(Context &c, NodeRefVec &&deps) final
Recreate the node with different dependencies.
Dimension< R > targetDimension_
std::string debugInfo() const override
Node debug info (default = ""): user defined detailed info for DF graph debug.
static ValueRef< T > create(Context &c, NodeRefVec &&deps, int n, std::vector< double > &&coeffs, const Dimension< T > &dim)
Build a new CombineDeltaShifted node with the given output dimensions, exponent and weights.
std::size_t hashAdditionalArguments() const final
Return the hash of node-specific configuration.
const std::vector< double > & getCoeffs() const
void compute() override
Computation implementation.
std::string description() const override
Node pretty name (default = type name).
NodeRef recreate(Context &c, NodeRefVec &&deps) final
Recreate the node with different dependencies.
NodeRef derive(Context &c, const Node_DF &node) final
Returns a node computing d(this_node_expression)/d(node_expression).
std::enable_if< std::is_same< U, TransitionFunction >::value, void >::type compute()
Computation implementation.
Dimension< T > targetDimension_
CombineDeltaShifted(NodeRefVec &&deps, int n, std::vector< double > &&coeffs, const Dimension< T > &dim)
std::enable_if<!std::is_same< U, TransitionFunction >::value, void >::type compute()
Computation implementation.
bool compareAdditionalArguments(const Node_DF &other) const final
Compare node-specific configuration to another.
std::vector< double > coeffs_
static std::shared_ptr< Self > create(Context &c, const Dimension< T > &dim)
Build a new ConstantOne node of the given dimension.
static std::shared_ptr< Self > create(Context &c, const Dimension< T > &dim)
Build a new ConstantZero node of the given dimension.
Context for dataflow node construction.
static ValueRef< R > create(Context &c, NodeRefVec &&deps, const Dimension< R > &dim)
Build a new Convert node with the given output dimensions.
void normalize() noexcept
static const double ln_radix
static ExtendedFloat denorm_mul(const ExtendedFloat &lhs, const ExtendedFloat &rhs)
const FloatType & float_part() const noexcept
const ExtType & exponent_part() const noexcept
std::string debugInfo() const override
Node debug info (default = ""): user defined detailed info for DF graph debug.
NodeRef derive(Context &c, const Node_DF &node) final
Returns a node computing d(this_node_expression)/d(node_expression).
bool compareAdditionalArguments(const Node_DF &other) const final
Compare node-specific configuration to another.
LogSumExp(NodeRefVec &&deps, const Dimension< T0 > &mDim)
void compute() final
Computation implementation.
Dimension< T0 > mTargetDimension_
NodeRef recreate(Context &c, NodeRefVec &&deps) final
Recreate the node with different dependencies.
static ValueRef< R > create(Context &c, NodeRefVec &&deps, const Dimension< T0 > &mDim)
Build a new LogSumExp node with the given input matrix dimensions.
std::string description() const override
Node pretty name (default = type name).
bool compareAdditionalArguments(const Node_DF &other) const final
Compare node-specific configuration to another.
NodeRef recreate(Context &c, NodeRefVec &&deps) final
Recreate the node with different dependencies.
std::string shape() const override
static ValueRef< R > create(Context &c, NodeRefVec &&deps, const Dimension< R > &dim)
Build a new MatrixProduct node with the given output dimensions.
Dimension< R > targetDimension_
MatrixProduct(NodeRefVec &&deps, const Dimension< R > &dim)
typename NumericalDependencyTransform< T0 >::DepType DepT0
void compute() final
Computation implementation.
NodeRef derive(Context &c, const Node_DF &node) final
Returns a node computing d(this_node_expression)/d(node_expression).
typename NumericalDependencyTransform< T1 >::DepType DepT1
std::string debugInfo() const override
Node debug info (default = ""): user defined detailed info for DF graph debug.
std::string color() const override
Base dataflow Node class.
const NodeRef & dependency(std::size_t i) const noexcept
virtual bool hasNumericalProperty(NumericalProperty prop) const
Test if the node has the given numerical property.
std::size_t nbDependencies() const noexcept
Number of dependencies (ie nodes we depend on)
const NodeRefVec & dependencies() const noexcept
static std::shared_ptr< Self > create(Context &c, Args &&... args)
Build a new NumericConstant node with T(args...) value.
NodeRef derive(Context &c, const Node_DF &node) final
Returns a node computing d(this_node_expression)/d(node_expression).
void compute() final
Computation implementation.
ScalarProduct(NodeRefVec &&deps)
NodeRef recreate(Context &c, NodeRefVec &&deps) final
Recreate the node with different dependencies.
static ValueRef< R > create(Context &c, NodeRefVec &&deps)
Build a new ScalarProduct node.
bool compareAdditionalArguments(const Node_DF &other) const final
Compare node-specific configuration to another.
std::string debugInfo() const override
Node debug info (default = ""): user defined detailed info for DF graph debug.
static ValueRef< T > create(Context &c, NodeRefVec &&deps, int n, const Dimension< T > &dim)
Build a new ShiftDelta node with the given output dimensions and shift number.
Dimension< T > targetDimension_
void compute() final
Computation implementation.
NodeRef derive(Context &c, const Node_DF &node) final
Returns a node computing d(this_node_expression)/d(node_expression).
bool compareAdditionalArguments(const Node_DF &other) const final
Compare node-specific configuration to another.
std::string debugInfo() const override
Node debug info (default = ""): user defined detailed info for DF graph debug.
ShiftDelta(NodeRefVec &&deps, int n, const Dimension< T > &dim)
std::size_t hashAdditionalArguments() const final
Return the hash of node-specific configuration.
NodeRef recreate(Context &c, NodeRefVec &&deps) final
Recreate the node with different dependencies.
static std::shared_ptr< ConfiguredParameter > create(Context &c, NodeRefVec &&deps, Parameter ¶m, const int n)
Build a new ShiftDelta node with the given output dimensions and shift number.
bool compareAdditionalArguments(const Node_DF &other) const final
Compare node-specific configuration to another.
SumOfLogarithms(NodeRefVec &&deps, const Dimension< F > &mDim)
std::enable_if< std::is_convertible< G *, ExtendedFloatEigenBase< G > * >::value, void >::type compute()
Computation implementation.
NodeRef derive(Context &c, const Node_DF &node) final
Returns a node computing d(this_node_expression)/d(node_expression).
Dimension< F > mTargetDimension_
static ValueRef< DataLik > create(Context &c, NodeRefVec &&deps, const Dimension< F > &mDim)
Build a new SumOfLogarithms node with the given input matrix dimensions.
std::string debugInfo() const override
Node debug info (default = ""): user defined detailed info for DF graph debug.
std::enable_if< std::is_convertible< G *, Eigen::DenseBase< G > * >::value, void >::type compute()
Computation implementation.
void compute() override
Computation implementation.
NodeRef recreate(Context &c, NodeRefVec &&deps) final
Recreate the node with different dependencies.
Eigen::Matrix< ExtendedFloat, 1, Eigen::Dynamic > temp_
Abstract Node storing a value of type T.
const R & accessValueConst() const noexcept
Raw value access (const).
R & accessValueMutable() noexcept
T identity(const Dimension< T > &)
bool isinf(const double &d)
T one(const Dimension< T > &)
std::string debug(const T &t, typename std::enable_if< std::is_arithmetic< T >::value >::type *=0)
T zero(const Dimension< T > &)
Defines the basic types of data flow nodes.
void removeDependenciesIf(NodeRefVec &deps, Predicate p)
double log(const ExtendedFloat &ef)
ExtendedFloat exp(const ExtendedFloat &ef)
NumericConstant< char > NodeX('X')
std::shared_ptr< Value< T > > ValueRef
Shared pointer alias for Value<T>.
void checkDependenciesNotNull(const std::type_info &contextNodeType, const NodeRefVec &deps)
Checks that all dependencies are not null, throws if not.
ValueRef< NodeT > generateNumericalDerivative(Context &c, const NumericalDerivativeConfiguration &config, NodeRef dep, const Dimension< DepT > &depDim, Dimension< NodeT > &nodeDim, B buildNodeWithDep)
Helper used to generate data flow expressions computing a numerical derivative.
std::string to_string(const NoDimension &)
ExtendedFloat pow(const ExtendedFloat &ef, double exp)
void failureDeltaNotDerivable(const std::type_info &contextNodeType)
std::vector< NodeRef > NodeRefVec
Alias for a dependency vector (of NodeRef).
template void copyBppToEigen(const std::vector< ExtendedFloat > &bppVector, Eigen::RowVectorXd &eigenVector)
void checkDependencyVectorSize(const std::type_info &contextNodeType, const NodeRefVec &deps, std::size_t expectedSize)
bool isTransitivelyDependentOn(const Node_DF &searchedDependency, const Node_DF &node)
Check if searchedDependency if a transitive dependency of node.
void checkDependencyVectorMinSize(const std::type_info &contextNodeType, const NodeRefVec &deps, std::size_t expectedMinSize)
Checks the minimum size of a dependency vector, throws if mismatch.
void combineHash(std::size_t &seed, const T &t)
Combine hashable value to a hash, from Boost library.
void failureNumericalDerivationNotConfigured()
std::shared_ptr< Node_DF > NodeRef
Configuration for a numerical derivation: what delta to use, and type of derivation.
NumericalDerivativeType type