2023-01-23 21:13:26 +01:00
|
|
|
//
|
|
|
|
// UniLinReg.cpp
|
|
|
|
//
|
|
|
|
// Created by Marc Melikyan on 9/29/20.
|
|
|
|
//
|
|
|
|
|
2023-01-24 18:12:23 +01:00
|
|
|
#include "uni_lin_reg.h"
|
2023-02-08 12:46:56 +01:00
|
|
|
|
2023-01-24 18:12:23 +01:00
|
|
|
#include "../lin_alg/lin_alg.h"
|
|
|
|
#include "../stat/stat.h"
|
2023-02-08 12:46:56 +01:00
|
|
|
|
2023-01-23 21:13:26 +01:00
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
// General Multivariate Linear Regression Model
|
|
|
|
// ŷ = b0 + b1x1 + b2x2 + ... + bkxk
|
|
|
|
|
|
|
|
// Univariate Linear Regression Model
|
|
|
|
// ŷ = b0 + b1x1
|
|
|
|
|
2023-01-27 13:01:16 +01:00
|
|
|
MLPPUniLinReg::MLPPUniLinReg(std::vector<real_t> x, std::vector<real_t> y) :
|
2023-01-24 19:00:54 +01:00
|
|
|
inputSet(x), outputSet(y) {
|
2023-02-08 12:46:56 +01:00
|
|
|
MLPPStat estimator;
|
2023-01-24 19:00:54 +01:00
|
|
|
b1 = estimator.b1Estimation(inputSet, outputSet);
|
|
|
|
b0 = estimator.b0Estimation(inputSet, outputSet);
|
|
|
|
}
|
2023-01-23 21:13:26 +01:00
|
|
|
|
2023-01-27 13:01:16 +01:00
|
|
|
std::vector<real_t> MLPPUniLinReg::modelSetTest(std::vector<real_t> x) {
|
2023-01-25 00:29:02 +01:00
|
|
|
MLPPLinAlg alg;
|
2023-01-24 19:00:54 +01:00
|
|
|
return alg.scalarAdd(b0, alg.scalarMultiply(b1, x));
|
|
|
|
}
|
2023-01-23 21:13:26 +01:00
|
|
|
|
2023-01-27 13:01:16 +01:00
|
|
|
real_t MLPPUniLinReg::modelTest(real_t input) {
|
2023-01-24 19:00:54 +01:00
|
|
|
return b0 + b1 * input;
|
2023-01-23 21:13:26 +01:00
|
|
|
}
|