-
Notifications
You must be signed in to change notification settings - Fork 201
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- tidy up unit tests - add makefile - removed message on wrong gradient (instead return false/true) - add short intro in README.md
- Loading branch information
Patrick Wieschollek
committed
Dec 4, 2014
1 parent
233ad61
commit 7ad417c
Showing
15 changed files
with
433 additions
and
353 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,56 @@ | ||
CXX=g++ | ||
CXXFLAGS := -Wall -Wextra -pedantic-errors -std=c++11 -fopenmp -Ieigen | ||
CXXFLAGSTEST := -Wall -Wextra -pedantic-errors -std=c++11 -fopenmp -Ieigen -Igtest/include | ||
|
||
|
||
main: src/main.cpp | ||
$(CXX) $(CXXFLAGS) -o main src/Meta.cpp src/ISolver.cpp src/GradientDescentSolver.cpp src/ConjugateGradientSolver.cpp src/NewtonDescentSolver.cpp src/BfgsSolver.cpp src/LbfgsSolver.cpp src/LbfgsbSolver.cpp src/main.cpp | ||
|
||
test: src/unittests.cpp | ||
$(CXX) $(CXXFLAGSTEST) -o test src/Meta.cpp src/ISolver.cpp src/GradientDescentSolver.cpp src/ConjugateGradientSolver.cpp src/NewtonDescentSolver.cpp src/BfgsSolver.cpp src/LbfgsSolver.cpp src/LbfgsbSolver.cpp src/unittests.cpp libgtest.a | ||
|
||
|
||
install: | ||
# google-testing-framework | ||
rm -f gtest-1.7.0.zip | ||
rm -fR gtest-1.7.0 | ||
wget -O gtest-1.7.0.zip https://googletest.googlecode.com/files/gtest-1.7.0.zip | ||
unzip gtest-1.7.0.zip | ||
g++ -Igtest-1.7.0/include -Igtest-1.7.0 -c "gtest-1.7.0/src/gtest-all.cc" | ||
ar -rv libgtest.a gtest-all.o | ||
rm -f gtest-1.7.0.zip | ||
mv gtest-1.7.0 gtest | ||
# eigen library | ||
wget -c http://bitbucket.org/eigen/eigen/get/3.2.2.tar.bz2 -O eigen-3.2.2.tar.bz2 | ||
bunzip2 eigen-3.2.2.tar.bz2 | ||
tar xvf eigen-3.2.2.tar | ||
mv eigen-eigen-* eigen | ||
rm -Rf eigen-3.2.2.tar | ||
rm -Rf eigen-3.2.2.tar.bz2 | ||
|
||
|
||
|
||
# test: unittests.cpp | ||
# $(CXX) $(CXXFLAGSTEST) -o test Neighborhood.hpp Neighborhood.cpp Vector.hpp Vector.cpp ProQuantization.hpp ProQuantization.cpp ProTree.hpp ProTree.cpp unittests.cpp libgtest.a -lglog | ||
# GLOG_logtostderr=1 ./test | ||
|
||
# gtest: | ||
# rm -f gtest-1.7.0.zip | ||
# rm -fR gtest-1.7.0 | ||
# wget -O gtest-1.7.0.zip https://googletest.googlecode.com/files/gtest-1.7.0.zip | ||
# unzip gtest-1.7.0.zip | ||
# g++ -Igtest-1.7.0/include -Igtest-1.7.0 -c "gtest-1.7.0/src/gtest-all.cc" | ||
# ar -rv libgtest.a gtest-all.o | ||
# rm -f gtest-1.7.0.zip | ||
# mv gtest-1.7.0 gtest | ||
|
||
|
||
# cleanall: | ||
# rm -f test | ||
# rm -f main | ||
|
||
# cleanmain: | ||
# rm -f main | ||
|
||
# cleantest: | ||
# rm -f test |
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,73 @@ | ||
/** | ||
* Copyright (c) 2014 Patrick Wieschollek | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
#include "ConjugateGradientSolver.h" | ||
#include <iostream> | ||
namespace pwie | ||
{ | ||
|
||
ConjugateGradientSolver::ConjugateGradientSolver() : ISolver() | ||
{ | ||
|
||
|
||
} | ||
|
||
|
||
void ConjugateGradientSolver::internalSolve(Vector & x, | ||
const FunctionOracleType & FunctionValue, | ||
const GradientOracleType & FunctionGradient, | ||
const HessianOracleType & FunctionHessian) | ||
{ | ||
UNUSED(FunctionHessian); | ||
size_t iter = 0; | ||
|
||
Vector grad(x.rows()); | ||
Vector grad_old(x.rows()); | ||
Vector Si(x.rows()); | ||
Vector Si_old(x.rows()); | ||
do | ||
{ | ||
FunctionGradient(x, grad); | ||
|
||
if(iter==0){ | ||
Si = -grad; | ||
}else{ | ||
const double beta = grad.dot(grad)/(grad_old.dot(grad_old)); | ||
Si = -grad + beta*Si_old; | ||
} | ||
|
||
const double rate = linesearch(x, Si, FunctionValue, FunctionGradient) ; | ||
|
||
x = x + rate * Si; | ||
|
||
iter++; | ||
grad_old = grad; | ||
Si_old = Si; | ||
|
||
} | ||
while((grad.lpNorm<Eigen::Infinity>() > settings.gradTol) && (iter < settings.maxIter)); | ||
|
||
|
||
} | ||
} | ||
|
||
/* namespace pwie */ |
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,42 @@ | ||
/** | ||
* Copyright (c) 2014 Patrick Wieschollek | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
#ifndef CONJUGATEGRADIENTSOLVER_H_ | ||
#define CONJUGATEGRADIENTSOLVER_H_ | ||
#include "ISolver.h" | ||
namespace pwie | ||
{ | ||
|
||
class ConjugateGradientSolver : public ISolver | ||
{ | ||
public: | ||
ConjugateGradientSolver(); | ||
void internalSolve(Vector & x0, | ||
const FunctionOracleType & FunctionValue, | ||
const GradientOracleType & FunctionGradient, | ||
const HessianOracleType & FunctionHessian = std::function<void(const Eigen::VectorXd & x, Eigen::MatrixXd & hessian)>()); | ||
|
||
}; | ||
|
||
} /* namespace pwie */ | ||
|
||
#endif /* CONJUGATEGRADIENTSOLVER_H_ */ |
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
Oops, something went wrong.