Commit 2c3b77ad authored by niklas.baumgarten's avatar niklas.baumgarten
Browse files

refactored linear_fit

parent 1f04010f
......@@ -92,12 +92,12 @@ void MultilevelMonteCarlo::estimateExponents(bool excludeBaseLevel) {
costs.push_back(log2(iter->second->avgCost));
}
vector<double> v = linear_fit(levelList, avgsY);
alpha = v.front();
v = linear_fit(levelList, varsY);
beta = v.front();
v = linear_fit(levelList, costs);
gamma = v.front();
pair<double, double> res = linear_fit(levelList, avgsY);
alpha = res.first;
res = linear_fit(levelList, varsY);
beta = res.first;
res = linear_fit(levelList, costs);
gamma = res.first;
logger->InnerMsg("alpha: " + to_string(alpha) +
" beta: " + to_string(beta) +
......
#include "Utils.h"
#include "m++.h"
#define REAL 0
#define IMAG 1
vector<double> linear_fit(vector<double> &x, vector<double> &y) {
pair<double, double> linear_fit(vector<double> &x, vector<double> &y) {
long xSize = x.size();
double xSum = 0, ySum = 0, xxSum = 0, xySum = 0, slope, intercept;
for (long i = 0; i < xSize; i++) {
......@@ -13,11 +12,12 @@ vector<double> linear_fit(vector<double> &x, vector<double> &y) {
xxSum += x[i] * x[i];
xySum += x[i] * y[i];
}
slope = (xSize * xySum - xSum * ySum) / (xSize * xxSum - xSum * xSum);
intercept = (ySum - slope * xSum) / xSize;
vector<double> res;
res.push_back(slope);
res.push_back(intercept);
slope = ((double) xSize * xySum - xSum * ySum) /
((double) xSize * xxSum - xSum * xSum);
intercept = (ySum - slope * xSum) / ((double) xSize);
pair<double, double> res;
res.first = slope;
res.second = intercept;
return res;
}
......@@ -80,11 +80,12 @@ void fft2(int N2, int N1, fftw_complex *in, fftw_complex *out) {
fftw_cleanup();
}
void fft2(const vector<vector<complex<double>>> &in, vector<vector<complex<double>>> &out) {
void fft2(const vector<vector<complex<double>>> &in,
vector<vector<complex<double>>> &out) {
int N2 = in.size();
int N1 = in[0].size();
auto in_arr = new fftw_complex[N2 * N1];
auto out_arr= new fftw_complex[N2 * N1];
auto out_arr = new fftw_complex[N2 * N1];
for (int i = 0; i < N2; i++) {
for (int j = 0; j < N1; j++) {
in_arr[i * N2 + j][REAL] = in[i][j].real();
......
#ifndef MLMC_UTILITIES_HPP
#define MLMC_UTILITIES_HPP
#include <utility>
#include <map>
#include <vector>
#include <complex>
......@@ -8,7 +9,7 @@
using namespace std;
vector<double> linear_fit(vector<double> &x, vector<double> &y);
pair<double, double> linear_fit(vector<double> &x, vector<double> &y);
vector<double> linspace(const double &start, const double &end, int num);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment