Small fix
parent
b7f29a051a
commit
fbebd3ed69
|
|
@ -70,9 +70,7 @@ class AcceleratedPowerMethod : public PowerMethod<Operator> {
|
||||||
|
|
||||||
// initialize Ritz eigen vector and previous vector
|
// initialize Ritz eigen vector and previous vector
|
||||||
previousVector_ = update(x0, x00, beta_);
|
previousVector_ = update(x0, x00, beta_);
|
||||||
this->updateRitz(update(previousVector_, x0, beta_));
|
|
||||||
this->ritzVector_ = update(previousVector_, x0, beta_);
|
this->ritzVector_ = update(previousVector_, x0, beta_);
|
||||||
// this->updateRitz(update(previousVector_, x0, beta_));
|
|
||||||
this->perturb();
|
this->perturb();
|
||||||
|
|
||||||
// set beta
|
// set beta
|
||||||
|
|
|
||||||
|
|
@ -75,11 +75,9 @@ class PowerMethod {
|
||||||
return y;
|
return y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update the vector by dot product with A_
|
||||||
Vector update() const { return update(ritzVector_); }
|
Vector update() const { return update(ritzVector_); }
|
||||||
|
|
||||||
// Update the ritzVector_
|
|
||||||
void updateRitz(const Vector &ritz) { ritzVector_ = ritz; }
|
|
||||||
|
|
||||||
// Perturb the initial ritzvector
|
// Perturb the initial ritzvector
|
||||||
void perturb() {
|
void perturb() {
|
||||||
// generate a 0.03*||x_0||_2 as stated in David's paper
|
// generate a 0.03*||x_0||_2 as stated in David's paper
|
||||||
|
|
@ -87,10 +85,11 @@ class PowerMethod {
|
||||||
std::uniform_real_distribution<double> uniform01(0.0, 1.0);
|
std::uniform_real_distribution<double> uniform01(0.0, 1.0);
|
||||||
|
|
||||||
int n = dim_;
|
int n = dim_;
|
||||||
Vector disturb(n);
|
// Vector disturb(n);
|
||||||
for (int i = 0; i < n; ++i) {
|
// for (int i = 0; i < n; ++i) {
|
||||||
disturb(i) = uniform01(rng);
|
// disturb(i) = uniform01(rng);
|
||||||
}
|
// }
|
||||||
|
Vector disturb = Vector::Random(n);
|
||||||
disturb.normalize();
|
disturb.normalize();
|
||||||
|
|
||||||
Vector x0 = ritzVector_;
|
Vector x0 = ritzVector_;
|
||||||
|
|
|
||||||
|
|
@ -76,7 +76,10 @@ TEST(AcceleratedPowerMethod, useFactorGraph) {
|
||||||
|
|
||||||
// Get eigenvalues and eigenvectors with Eigen
|
// Get eigenvalues and eigenvectors with Eigen
|
||||||
auto L = fg.hessian();
|
auto L = fg.hessian();
|
||||||
|
cout << L.first << endl;
|
||||||
Eigen::EigenSolver<Matrix> solver(L.first);
|
Eigen::EigenSolver<Matrix> solver(L.first);
|
||||||
|
cout << solver.eigenvalues() << endl;
|
||||||
|
cout << solver.eigenvectors() << endl;
|
||||||
|
|
||||||
// Check that we get zero eigenvalue and "constant" eigenvector
|
// Check that we get zero eigenvalue and "constant" eigenvector
|
||||||
EXPECT_DOUBLES_EQUAL(0.0, solver.eigenvalues()[0].real(), 1e-9);
|
EXPECT_DOUBLES_EQUAL(0.0, solver.eigenvalues()[0].real(), 1e-9);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue