summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaron Kent-Dobias <jaron@kent-dobias.com>2021-06-11 17:25:13 +0200
committerJaron Kent-Dobias <jaron@kent-dobias.com>2021-06-11 17:25:13 +0200
commitd890337e6cb24dd003b8887ffdca140b85ffe776 (patch)
treebe2bd2c2020ffaf5ac3b060d4db3f949f6651418
parentfb6b828d755dffd73b9168158b1d5c4d7d0a9923 (diff)
downloadcode-d890337e6cb24dd003b8887ffdca140b85ffe776.tar.gz
code-d890337e6cb24dd003b8887ffdca140b85ffe776.tar.bz2
code-d890337e6cb24dd003b8887ffdca140b85ffe776.zip
Implemented planting.
-rw-r--r--tensor.hpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/tensor.hpp b/tensor.hpp
index 6a5b2c2..1d90c78 100644
--- a/tensor.hpp
+++ b/tensor.hpp
@@ -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());