This repository was archived by the owner on Oct 31, 2023. It is now read-only.
forked from rmcantin/bayesopt
-
Notifications
You must be signed in to change notification settings - Fork 1
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
2 changed files
with
152 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/** \file robust_filtering.hpp \brief Robust filtering for outliers */ | ||
/* | ||
------------------------------------------------------------------------- | ||
This file is part of BayesOpt, an efficient C++ library for | ||
Bayesian optimization. | ||
Copyright (C) 2011-2015 Ruben Martinez-Cantin <rmcantin@unizar.es> | ||
BayesOpt is free software: you can redistribute it and/or modify it | ||
under the terms of the GNU Affero General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
BayesOpt is distributed in the hope that it will be useful, but | ||
WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU Affero General Public License for more details. | ||
You should have received a copy of the GNU Affero General Public License | ||
along with BayesOpt. If not, see <http://www.gnu.org/licenses/>. | ||
------------------------------------------------------------------------ | ||
*/ | ||
|
||
|
||
#ifndef _ROBUST_FILTERING_HPP_ | ||
#define _ROBUST_FILTERING_HPP_ | ||
|
||
#include <boost/scoped_ptr.hpp> | ||
#include "bayesopt/parameters.hpp" | ||
#include "specialtypes.hpp" | ||
#include "dataset.hpp" | ||
#include "posteriormodel.hpp" | ||
|
||
|
||
/** | ||
* Namespace of the library interface | ||
*/ | ||
namespace bayesopt { | ||
|
||
|
||
//Forward declaration | ||
class PosteriorModel; | ||
class Dataset; | ||
|
||
/** \addtogroup BayesOpt | ||
* \brief Filtering for outliers | ||
*/ | ||
/*@{*/ | ||
|
||
class RobustFiltering | ||
{ | ||
public: | ||
/** | ||
* Constructor | ||
* @param params set of parameters (see parameters.hpp) | ||
*/ | ||
RobustFiltering(size_t dim, Parameters parameters, randEngine& eng); | ||
|
||
/** | ||
* Default destructor | ||
*/ | ||
virtual ~RobustFiltering(); | ||
|
||
const Dataset* filterPoints(); | ||
|
||
void setSamples(const matrixd &x, const vectord &y) | ||
{ | ||
mRobustModel->setSamples(x,y); | ||
}; | ||
|
||
void addSample(const vectord &x, double y) | ||
{ | ||
mRobustModel->addSample(x,y); | ||
}; | ||
|
||
private: | ||
boost::scoped_ptr<PosteriorModel> mRobustModel; | ||
boost::scoped_ptr<Dataset> mFilteredData; | ||
|
||
double up_margin, low_margin; | ||
|
||
RobustFiltering(); | ||
}; | ||
|
||
/**@}*/ | ||
|
||
|
||
|
||
} //namespace bayesopt | ||
|
||
|
||
#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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
------------------------------------------------------------------------- | ||
This file is part of BayesOpt, an efficient C++ library for | ||
Bayesian optimization. | ||
Copyright (C) 2011-2015 Ruben Martinez-Cantin <rmcantin@unizar.es> | ||
BayesOpt is free software: you can redistribute it and/or modify it | ||
under the terms of the GNU Affero General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
BayesOpt is distributed in the hope that it will be useful, but | ||
WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU Affero General Public License for more details. | ||
You should have received a copy of the GNU Affero General Public License | ||
along with BayesOpt. If not, see <http://www.gnu.org/licenses/>. | ||
------------------------------------------------------------------------ | ||
*/ | ||
|
||
#include "robust_filtering.hpp" | ||
|
||
namespace bayesopt | ||
{ | ||
RobustFiltering::RobustFiltering(size_t dim, Parameters parameters, randEngine& eng) | ||
{ | ||
Parameters par2 = parameters; | ||
up_margin = (100.0 - parameters.up_margin) / 100.0; | ||
low_margin = parameters.low_margin / 100.0; | ||
par2.surr_name = "sStudentTProcessNIG"; | ||
mRobustModel.reset(PosteriorModel::create(dim,par2,eng)); | ||
} | ||
|
||
RobustFiltering::~RobustFiltering(){} | ||
|
||
const Dataset* RobustFiltering::filterPoints() | ||
{ | ||
mFilteredData.reset(); | ||
vecOfvec XX = mRobustModel->getData()->mX; | ||
vectord YY = mRobustModel->getData()->mY; | ||
|
||
size_t n_points = mRobustModel->getData()->getNSamples(); | ||
|
||
for(size_t i = 0; i < n_points; ++i) | ||
{ | ||
ProbabilityDistribution* pd = mRobustModel->getPrediction(XX[i]); | ||
double f_up = pd->quantile(up_margin); | ||
double f_low = pd->quantile(low_margin); | ||
if ((YY[i] < f_up) && (YY[i] > f_low)) | ||
{ | ||
mFilteredData->mX.push_back(XX[i]); | ||
utils::append(mFilteredData->mY, YY[i]); | ||
} | ||
} | ||
return mFilteredData.get(); | ||
} | ||
|
||
} |