mirror of
https://github.com/Relintai/pmlpp.git
synced 2025-05-05 18:11:35 +02:00
Added UniLinRegOld.
This commit is contained in:
parent
ee727b327d
commit
c49d089791
1
SCsub
1
SCsub
@ -56,6 +56,7 @@ sources = [
|
|||||||
"mlpp/hidden_layer/hidden_layer_old.cpp",
|
"mlpp/hidden_layer/hidden_layer_old.cpp",
|
||||||
"mlpp/mlp/mlp_old.cpp",
|
"mlpp/mlp/mlp_old.cpp",
|
||||||
"mlpp/pca/pca_old.cpp",
|
"mlpp/pca/pca_old.cpp",
|
||||||
|
"mlpp/uni_lin_reg/uni_lin_reg_old.cpp",
|
||||||
|
|
||||||
"test/mlpp_tests.cpp",
|
"test/mlpp_tests.cpp",
|
||||||
]
|
]
|
||||||
|
@ -5,8 +5,10 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#include "uni_lin_reg.h"
|
#include "uni_lin_reg.h"
|
||||||
|
|
||||||
#include "../lin_alg/lin_alg.h"
|
#include "../lin_alg/lin_alg.h"
|
||||||
#include "../stat/stat.h"
|
#include "../stat/stat.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
// General Multivariate Linear Regression Model
|
// General Multivariate Linear Regression Model
|
||||||
@ -15,7 +17,6 @@
|
|||||||
// Univariate Linear Regression Model
|
// Univariate Linear Regression Model
|
||||||
// ŷ = b0 + b1x1
|
// ŷ = b0 + b1x1
|
||||||
|
|
||||||
|
|
||||||
MLPPUniLinReg::MLPPUniLinReg(std::vector<real_t> x, std::vector<real_t> y) :
|
MLPPUniLinReg::MLPPUniLinReg(std::vector<real_t> x, std::vector<real_t> y) :
|
||||||
inputSet(x), outputSet(y) {
|
inputSet(x), outputSet(y) {
|
||||||
MLPPStat estimator;
|
MLPPStat estimator;
|
||||||
@ -31,4 +32,3 @@ std::vector<real_t> MLPPUniLinReg::modelSetTest(std::vector<real_t> x) {
|
|||||||
real_t MLPPUniLinReg::modelTest(real_t input) {
|
real_t MLPPUniLinReg::modelTest(real_t input) {
|
||||||
return b0 + b1 * input;
|
return b0 + b1 * input;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
|
||||||
class MLPPUniLinReg {
|
class MLPPUniLinReg {
|
||||||
public:
|
public:
|
||||||
MLPPUniLinReg(std::vector<real_t> x, std::vector<real_t> y);
|
MLPPUniLinReg(std::vector<real_t> x, std::vector<real_t> y);
|
||||||
@ -27,5 +26,4 @@ private:
|
|||||||
real_t b1;
|
real_t b1;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif /* UniLinReg_hpp */
|
#endif /* UniLinReg_hpp */
|
||||||
|
34
mlpp/uni_lin_reg/uni_lin_reg_old.cpp
Normal file
34
mlpp/uni_lin_reg/uni_lin_reg_old.cpp
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
//
|
||||||
|
// UniLinReg.cpp
|
||||||
|
//
|
||||||
|
// Created by Marc Melikyan on 9/29/20.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "uni_lin_reg_old.h"
|
||||||
|
|
||||||
|
#include "../lin_alg/lin_alg.h"
|
||||||
|
#include "../stat/stat.h"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
// General Multivariate Linear Regression Model
|
||||||
|
// ŷ = b0 + b1x1 + b2x2 + ... + bkxk
|
||||||
|
|
||||||
|
// Univariate Linear Regression Model
|
||||||
|
// ŷ = b0 + b1x1
|
||||||
|
|
||||||
|
MLPPUniLinRegOld::MLPPUniLinRegOld(std::vector<real_t> x, std::vector<real_t> y) :
|
||||||
|
inputSet(x), outputSet(y) {
|
||||||
|
MLPPStat estimator;
|
||||||
|
b1 = estimator.b1Estimation(inputSet, outputSet);
|
||||||
|
b0 = estimator.b0Estimation(inputSet, outputSet);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<real_t> MLPPUniLinRegOld::modelSetTest(std::vector<real_t> x) {
|
||||||
|
MLPPLinAlg alg;
|
||||||
|
return alg.scalarAdd(b0, alg.scalarMultiply(b1, x));
|
||||||
|
}
|
||||||
|
|
||||||
|
real_t MLPPUniLinRegOld::modelTest(real_t input) {
|
||||||
|
return b0 + b1 * input;
|
||||||
|
}
|
29
mlpp/uni_lin_reg/uni_lin_reg_old.h
Normal file
29
mlpp/uni_lin_reg/uni_lin_reg_old.h
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
|
||||||
|
#ifndef MLPP_UNI_LIN_REG_OLD_H
|
||||||
|
#define MLPP_UNI_LIN_REG_OLD_H
|
||||||
|
|
||||||
|
//
|
||||||
|
// UniLinReg.hpp
|
||||||
|
//
|
||||||
|
// Created by Marc Melikyan on 9/29/20.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "core/math/math_defs.h"
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
class MLPPUniLinRegOld {
|
||||||
|
public:
|
||||||
|
MLPPUniLinRegOld(std::vector<real_t> x, std::vector<real_t> y);
|
||||||
|
std::vector<real_t> modelSetTest(std::vector<real_t> x);
|
||||||
|
real_t modelTest(real_t x);
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<real_t> inputSet;
|
||||||
|
std::vector<real_t> outputSet;
|
||||||
|
|
||||||
|
real_t b0;
|
||||||
|
real_t b1;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* UniLinReg_hpp */
|
Loading…
Reference in New Issue
Block a user