-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mtc: Optimal frequency regression #136
Open
maxguy2001
wants to merge
7
commits into
master
Choose a base branch
from
mtc-linear_regression
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
32b496c
Mtc: Optimal frequency regression
maxguy2001 2dea38d
Structure edit
maxguy2001 ba46bee
structure update
maxguy2001 1279797
make code less broken
maxguy2001 0649fd6
changed class setup.
maxguy2001 56f86c1
implemented linear regression class
maxguy2001 3afb106
Merge branch 'master' into mtc-linear_regression
maxguy2001 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#include "regression.hpp" | ||
|
||
namespace hyped::utils::math { | ||
|
||
Regression::Regression() | ||
{ | ||
} | ||
|
||
void Regression::CaulculateCoefficients(const std::vector<double> x_data, | ||
const std::vector<double> y_data) | ||
{ | ||
double x_sum = 0; | ||
double y_sum = 0; | ||
|
||
for (size_t i = 0; i < x_data.size(); ++i) { | ||
x_sum += x_data.at(i); | ||
y_sum += y_data.at(i); | ||
} | ||
|
||
double x_mean = static_cast<double>(x_sum / x_data.size()); | ||
double y_mean = static_cast<double>(y_sum / y_data.size()); | ||
double s_xx = 0; | ||
double s_yy = 0; | ||
double s_xy = 0; | ||
|
||
for (size_t i = 0; i < x_data.size(); ++i) { | ||
s_xx += std::pow(x_data.at(i) - x_mean, 2); | ||
s_yy += std::pow(y_data.at(i) - y_mean, 2); | ||
s_xy += (x_data.at(i) - x_mean) * (y_data.at(i) - y_mean); | ||
} | ||
// regressed function will have form y = beta1*x + beta0 | ||
double beta1 = s_xy / s_xx; | ||
double beta0 = y_mean - (beta1 - x_mean); | ||
|
||
coefficients_ = {beta1, beta0}; | ||
} | ||
} // namespace hyped::utils::math |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#pragma once | ||
#include <cmath> | ||
|
||
#include <vector> | ||
|
||
namespace hyped::utils::math { | ||
|
||
class Regression { | ||
public: | ||
Regression(); | ||
|
||
/** | ||
* @brief calculates regressed coefficients using basic x-y linear regression. | ||
* only works for straight lines! | ||
* | ||
* @param x_data vector of x-data points | ||
* @param y_data vector of y-data points | ||
*/ | ||
void CaulculateCoefficients(std::vector<double> x_data, std::vector<double> y_data); | ||
|
||
// calculated coefficients from regression function | ||
std::vector<double> coefficients_; | ||
}; | ||
} // namespace hyped::utils::math |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like this setup. I may rewrite it for times sake.