summaryrefslogtreecommitdiffstats
path: root/Master/Modellbildung_und_Simulation/Aufgabenblatt2/Aufgabe2und3/src/CholeskyDecomposition.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Master/Modellbildung_und_Simulation/Aufgabenblatt2/Aufgabe2und3/src/CholeskyDecomposition.cpp')
-rw-r--r--Master/Modellbildung_und_Simulation/Aufgabenblatt2/Aufgabe2und3/src/CholeskyDecomposition.cpp100
1 files changed, 100 insertions, 0 deletions
diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt2/Aufgabe2und3/src/CholeskyDecomposition.cpp b/Master/Modellbildung_und_Simulation/Aufgabenblatt2/Aufgabe2und3/src/CholeskyDecomposition.cpp
new file mode 100644
index 0000000..f74c99c
--- /dev/null
+++ b/Master/Modellbildung_und_Simulation/Aufgabenblatt2/Aufgabe2und3/src/CholeskyDecomposition.cpp
@@ -0,0 +1,100 @@
+/*
+ * CholeskyDecomposition.cpp
+ *
+ * Created on: 20.05.2011
+ * Author: sven
+ */
+#ifndef PARAMETRISATION_H_
+ #include "Parametrisation.h"
+#endif
+
+#include <iostream>
+#include <iomanip>
+#include <cmath>
+
+#include "CholeskyDecomposition.h"
+
+CholeskyDecomposition::CholeskyDecomposition()
+{
+ for (UInt32 c = nenDaimler; c < nenEndOfCompanies ; c++)
+ {
+ mCholeskyMatrixOneDay.push_back(std::vector<double>(nenEndOfCompanies));
+ mCholeskyMatrixTenDays.push_back(std::vector<double>(nenEndOfCompanies));
+ }
+}
+
+CholeskyDecomposition::~CholeskyDecomposition() {
+}
+
+void CholeskyDecomposition::dumpCholeskyMatrices()
+{
+ std::cout << "Cholesky Matrix for one day" << std::endl;
+ int width = 12;
+ int prec = 6;
+ for(UInt32 i = 0; i < nenEndOfCompanies ; i++)
+ {
+ for (UInt32 j = 0; j < nenEndOfCompanies ; j++)
+ {
+ std::cout << std::setw(width) << std::setprecision(prec) << std::fixed << mCholeskyMatrixOneDay.at(i).at(j);
+ }
+ std::cout << std::endl;
+ }
+ std::cout << "Cholesky Matrix for ten days" << std::endl;
+ for(UInt32 i = 0; i < nenEndOfCompanies ; i++)
+ {
+ for (UInt32 j = 0; j < nenEndOfCompanies ; j++)
+ {
+ std::cout << std::setw(width) << std::setprecision(prec) << std::fixed << mCholeskyMatrixTenDays.at(i).at(j);
+ }
+ std::cout << std::endl;
+ }
+}
+
+void CholeskyDecomposition::calcCholeskyMatrix(CholeskyMatrix& d, const CovarianceMatrix& b)
+{
+ double sum,dp,diff;
+ for(int i = 0; i < nenEndOfCompanies ; i++)
+ {
+ for (int j = 0; j < nenEndOfCompanies ; j++)
+ {
+ if ( i < j)
+ {
+ d.at(i).at(j) = 0.0;
+ }
+ else if (i == j)
+ {
+ sum = 0.0;
+ int k=0;
+ while ( k < (i-1) )
+ {
+ dp = d.at(i).at(k);
+ sum += dp*dp;
+ k++;
+ }
+ diff = b.at(i).at(i) - sum;
+ d.at(i).at(j) = std::sqrt(diff);
+ }
+ else if (i > j)
+ {
+ sum = 0.0;
+ int k=0;
+ while (k < (i-1) )
+ {
+ sum += d.at(i).at(k) * d.at(j).at(k);
+ k++;
+ }
+ diff = b.at(i).at(j) - sum;
+ d.at(i).at(j) = (1.0 / d.at(j).at(j) ) * diff;
+ }
+ }
+ }
+}
+
+void CholeskyDecomposition::calcCholeskyDecompostions(const Parametrisation& params)
+{
+ calcCholeskyMatrix(mCholeskyMatrixOneDay,params.getCovarianceMatrix(nenOneDay));
+ calcCholeskyMatrix(mCholeskyMatrixTenDays,params.getCovarianceMatrix(nenTenDays));
+ dumpCholeskyMatrices();
+}
+
+