forked from mblum/libgp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
84 additions
and
2 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// libgp - Gaussian process library for Machine Learning | ||
// Copyright (c) 2013, Manuel Blum <[email protected]> | ||
// All rights reserved. | ||
|
||
#ifndef __COV_PERIODIC_H__ | ||
#define __COV_PERIODIC_H__ | ||
|
||
#include "cov.h" | ||
|
||
namespace libgp | ||
{ | ||
class CovPeriodic : public CovarianceFunction | ||
{ | ||
public: | ||
CovPeriodic (); | ||
virtual ~CovPeriodic (); | ||
bool init(int n); | ||
double get(const Eigen::VectorXd &x1, const Eigen::VectorXd &x2); | ||
void grad(const Eigen::VectorXd &x1, const Eigen::VectorXd &x2, Eigen::VectorXd &grad); | ||
void set_loghyper(const Eigen::VectorXd &p); | ||
virtual std::string to_string(); | ||
private: | ||
double ell; | ||
double sf2; | ||
double T; | ||
}; | ||
|
||
} | ||
|
||
#endif |
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,50 @@ | ||
// libgp - Gaussian process library for Machine Learning | ||
// Copyright (c) 2013, Manuel Blum <[email protected]> | ||
// All rights reserved. | ||
|
||
#include "cov_periodic.h" | ||
#include <cmath> | ||
|
||
namespace libgp | ||
{ | ||
|
||
CovPeriodic::CovPeriodic() {} | ||
|
||
CovPeriodic::~CovPeriodic() {} | ||
|
||
bool CovPeriodic::init(int n) | ||
{ | ||
input_dim = n; | ||
param_dim = 3; | ||
loghyper.resize(param_dim); | ||
loghyper.setZero(); | ||
return true; | ||
} | ||
|
||
double CovPeriodic::get(const Eigen::VectorXd &x1, const Eigen::VectorXd &x2) | ||
{ | ||
double s = sin(M_PI * (x1-x2).norm() / T) / ell; | ||
return sf2*exp(-2*s*s); | ||
} | ||
|
||
void CovPeriodic::grad(const Eigen::VectorXd &x1, const Eigen::VectorXd &x2, Eigen::VectorXd &grad) | ||
{ | ||
double k = M_PI * (x1-x2).norm() / T; | ||
double s = sin(k) / ell; | ||
grad << 4*sf2*exp(-2*s*s)*s*s, 2*sf2*exp(-2*s*s), 0;// 4*sf2/ell*exp(-2*s*s)*s*cos(k)*k; | ||
} | ||
|
||
void CovPeriodic::set_loghyper(const Eigen::VectorXd &p) | ||
{ | ||
CovarianceFunction::set_loghyper(p); | ||
ell = exp(loghyper(0)); | ||
sf2 = exp(2*loghyper(1)); | ||
T = fabs(loghyper(2)); | ||
} | ||
|
||
std::string CovPeriodic::to_string() | ||
{ | ||
return "CovPeriodic"; | ||
} | ||
|
||
} |