diff options
author | Jaron Kent-Dobias <jaron@kent-dobias.com> | 2021-06-11 17:25:13 +0200 |
---|---|---|
committer | Jaron Kent-Dobias <jaron@kent-dobias.com> | 2021-06-11 17:25:13 +0200 |
commit | d890337e6cb24dd003b8887ffdca140b85ffe776 (patch) | |
tree | be2bd2c2020ffaf5ac3b060d4db3f949f6651418 | |
parent | fb6b828d755dffd73b9168158b1d5c4d7d0a9923 (diff) | |
download | code-d890337e6cb24dd003b8887ffdca140b85ffe776.tar.gz code-d890337e6cb24dd003b8887ffdca140b85ffe776.tar.bz2 code-d890337e6cb24dd003b8887ffdca140b85ffe776.zip |
Implemented planting.
-rw-r--r-- | tensor.hpp | 21 |
1 files changed, 21 insertions, 0 deletions
@@ -89,6 +89,27 @@ Tensor<Scalar, p> generateCouplings(unsigned N, Distribution d, Generator& r) { return J; } +template <class Scalar, int p, class Distribution, class Generator> +Tensor<Scalar, p> plantState(const Tensor<Scalar, p>& J, const Vector<Scalar>& z, double β) { + Tensor<Scalar, p> JPlanted = J; + + std::function<void(Tensor<Scalar, p>&, std::array<unsigned, p>)> plant = + [&z, β] (Tensor<Scalar, p>& JJ, std::array<unsigned, p> ind) { + Scalar Ji = getJ<Scalar, p>(JJ, ind); + Scalar zzz = 1; + + for (unsigned i : ind) { + zzz *= z(i); + } + + setJ<Scalar, p>(JJ, ind, Ji - β * zzz / pow(zzz.size(), p)); + }; + + iterateOver<Scalar, p>(JPlanted, plant); + + return JPlanted; +} + template <class Scalar> Matrix<Scalar> contractDown(const Tensor<Scalar, 2>& J, const Vector<Scalar>& z) { return Eigen::Map<const Matrix<Scalar>>(J.data(), z.size(), z.size()); |