mirror of
https://github.com/triqs/dft_tools
synced 2025-01-12 22:18:23 +01:00
Extending fit_tail for scalar_valued (+ test)
-> extension by using reinterpret_scalar_valued_as_matrix_valued
This commit is contained in:
parent
da7e7ec971
commit
708c47305c
@ -16,6 +16,7 @@ void test_0(){
|
||||
int N=100;
|
||||
|
||||
auto gw = gf<imfreq>{{beta, Fermion, N},{1,1}};
|
||||
auto gw_s = gf<imfreq, scalar_valued>{{beta, Fermion, N}};
|
||||
|
||||
triqs::arrays::array<double,1> c(3);
|
||||
triqs::clef::placeholder<1> i_;
|
||||
@ -27,11 +28,13 @@ void test_0(){
|
||||
auto known_moments = tail(make_shape(1,1), size, order_min); //length is 0, first moment to fit is order_min
|
||||
|
||||
gw(iom_) << c(0)/iom_ + c(1)/iom_/iom_ + c(2)/iom_/iom_/iom_;
|
||||
gw_s(iom_) << c(0)/iom_ + c(1)/iom_/iom_ + c(2)/iom_/iom_/iom_;
|
||||
|
||||
TEST(gw.singularity());
|
||||
|
||||
//erase tail
|
||||
for(auto &i : gw.singularity().data()) i = 0.0;
|
||||
for(auto &i : gw_s.singularity().data()) i = 0.0;
|
||||
|
||||
size_t wn_min=50; //frequency to start the fit
|
||||
size_t wn_max=90; //final fitting frequency (included)
|
||||
@ -39,16 +42,17 @@ void test_0(){
|
||||
|
||||
//restore tail
|
||||
set_tail_from_fit(gw, known_moments, n_moments, wn_min, wn_max);
|
||||
set_tail_from_fit(gw_s, known_moments, n_moments, wn_min, wn_max);
|
||||
|
||||
TEST(gw.singularity());
|
||||
|
||||
TEST(gw_s.singularity());
|
||||
/*
|
||||
for(size_t i=0; i<first_dim(c); i++){
|
||||
double diff = std::abs( c(i) - gw.singularity().data()(i,0,0) );
|
||||
//std::cout<< "diff: " << diff <<std::endl;
|
||||
if (diff > precision) TRIQS_RUNTIME_ERROR<<" fit_tail error : diff="<<diff<<"\n";
|
||||
}
|
||||
|
||||
|
||||
*/
|
||||
|
||||
//erase tail
|
||||
for(auto &i : gw.singularity().data()) i = 0.0;
|
||||
@ -61,13 +65,15 @@ void test_0(){
|
||||
set_tail_from_fit(gw, known_moments, n_moments, wn_min, wn_max, true);//true replace the gf data in the fitting range by the tail values
|
||||
|
||||
TEST(gw.singularity());
|
||||
|
||||
/*
|
||||
for(size_t i=0; i<first_dim(c); i++){
|
||||
double diff = std::abs( c(i) - gw.singularity().data()(i,0,0) );
|
||||
//std::cout<< "diff: " << diff <<std::endl;
|
||||
if (diff > precision) TRIQS_RUNTIME_ERROR<<" fit_tail error : diff="<<diff<<"\n";
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
void test_1(){
|
||||
//real life test: find tails of 1/(iom -1)
|
||||
triqs::clef::placeholder<0> iom_;
|
||||
@ -75,7 +81,9 @@ void test_1(){
|
||||
int N=100;
|
||||
|
||||
auto gw = gf<imfreq>{{beta, Fermion, N}, {1, 1}};
|
||||
auto gw_b = gf<imfreq>{{beta, Boson, N}, {1, 1}};
|
||||
gw(iom_) << 1/(iom_-1);
|
||||
gw_b(iom_) << 1/(iom_-1);
|
||||
|
||||
size_t wn_min=50; //frequency to start the fit
|
||||
size_t wn_max=90; //final fitting frequency (included)
|
||||
@ -85,8 +93,11 @@ void test_1(){
|
||||
auto known_moments = tail(make_shape(1,1), size, order_min); //length is 0, first moment to fit is order_min
|
||||
known_moments(1)=1.;//set the first moment
|
||||
set_tail_from_fit(gw, known_moments, n_moments, wn_min, wn_max, true);//true replace the gf data in the fitting range by the tail values
|
||||
set_tail_from_fit(gw_b, known_moments, n_moments, wn_min, wn_max, true);//true replace the gf data in the fitting range by the tail values
|
||||
TEST(gw.singularity());
|
||||
TEST(gw_b.singularity());
|
||||
}
|
||||
|
||||
void test_2(){
|
||||
//real life test: find tails of 1/(iom -1) -- with positive and negative matsubara
|
||||
triqs::clef::placeholder<0> iom_;
|
||||
@ -106,31 +117,12 @@ void test_2(){
|
||||
set_tail_from_fit(gw, known_moments, n_moments, wn_min, wn_max, true);//true replace the gf data in the fitting range by the tail values
|
||||
TEST(gw.singularity());
|
||||
}
|
||||
void test_3(){
|
||||
//real life test: find tails of 1/(iom -1) --> bosonic case
|
||||
triqs::clef::placeholder<0> iom_;
|
||||
double beta =10;
|
||||
int N=100;
|
||||
|
||||
auto gw = gf<imfreq>{{beta, Boson, N}, {1, 1}};
|
||||
gw(iom_) << 1/(iom_-1);
|
||||
|
||||
size_t wn_min=50; //frequency to start the fit
|
||||
size_t wn_max=90; //final fitting frequency (included)
|
||||
int n_moments=4; //number of moments in the final tail (including known ones)
|
||||
int size=1; //means that we know one moment
|
||||
int order_min=1; //means that the first moment in the final tail will be the first moment
|
||||
auto known_moments = tail(make_shape(1,1), size, order_min); //length is 0, first moment to fit is order_min
|
||||
known_moments(1)=1.;//set the first moment
|
||||
set_tail_from_fit(gw, known_moments, n_moments, wn_min, wn_max, true);//true replace the gf data in the fitting range by the tail values
|
||||
TEST(gw.singularity());
|
||||
}
|
||||
|
||||
int main() {
|
||||
test_0();
|
||||
test_1();
|
||||
test_2();
|
||||
test_3();
|
||||
}
|
||||
|
||||
|
||||
|
@ -20,7 +20,11 @@
|
||||
... Order 8 =
|
||||
[[(0,0)]]
|
||||
|
||||
(gw.singularity()) ---> tail/tail_view: min/smallest/max = 1 1 3
|
||||
(gw.singularity()) ---> tail/tail_view: min/smallest/max = -1 1 3
|
||||
... Order -1 =
|
||||
[[(0,0)]]
|
||||
... Order 0 =
|
||||
[[(0,0)]]
|
||||
... Order 1 =
|
||||
[[(1,0)]]
|
||||
... Order 2 =
|
||||
@ -28,7 +32,11 @@
|
||||
... Order 3 =
|
||||
[[(5,0)]]
|
||||
|
||||
(gw.singularity()) ---> tail/tail_view: min/smallest/max = 1 1 3
|
||||
(gw_s.singularity()) ---> tail/tail_view: min/smallest/max = -1 1 3
|
||||
... Order -1 =
|
||||
[[(0,0)]]
|
||||
... Order 0 =
|
||||
[[(0,0)]]
|
||||
... Order 1 =
|
||||
[[(1,0)]]
|
||||
... Order 2 =
|
||||
@ -36,7 +44,23 @@
|
||||
... Order 3 =
|
||||
[[(5,0)]]
|
||||
|
||||
(gw.singularity()) ---> tail/tail_view: min/smallest/max = 1 1 4
|
||||
(gw.singularity()) ---> tail/tail_view: min/smallest/max = -1 1 3
|
||||
... Order -1 =
|
||||
[[(0,0)]]
|
||||
... Order 0 =
|
||||
[[(0,0)]]
|
||||
... Order 1 =
|
||||
[[(1,0)]]
|
||||
... Order 2 =
|
||||
[[(3,0)]]
|
||||
... Order 3 =
|
||||
[[(5,0)]]
|
||||
|
||||
(gw.singularity()) ---> tail/tail_view: min/smallest/max = -1 1 4
|
||||
... Order -1 =
|
||||
[[(0,0)]]
|
||||
... Order 0 =
|
||||
[[(0,0)]]
|
||||
... Order 1 =
|
||||
[[(1,0)]]
|
||||
... Order 2 =
|
||||
@ -46,23 +70,31 @@
|
||||
... Order 4 =
|
||||
[[(0.998655,0)]]
|
||||
|
||||
(gw.singularity()) ---> tail/tail_view: min/smallest/max = 1 1 4
|
||||
(gw_b.singularity()) ---> tail/tail_view: min/smallest/max = -1 1 4
|
||||
... Order -1 =
|
||||
[[(0,0)]]
|
||||
... Order 0 =
|
||||
[[(0,0)]]
|
||||
... Order 1 =
|
||||
[[(1,0)]]
|
||||
... Order 2 =
|
||||
[[(1,0)]]
|
||||
... Order 3 =
|
||||
[[(0.999251,0)]]
|
||||
... Order 4 =
|
||||
[[(0.998655,0)]]
|
||||
|
||||
(gw.singularity()) ---> tail/tail_view: min/smallest/max = 1 1 4
|
||||
... Order 1 =
|
||||
[[(1,0)]]
|
||||
... Order 2 =
|
||||
[[(1,0)]]
|
||||
... Order 3 =
|
||||
[[(0.999236,0)]]
|
||||
[[(0.999209,0)]]
|
||||
... Order 4 =
|
||||
[[(0.998631,0)]]
|
||||
|
||||
(gw.singularity()) ---> tail/tail_view: min/smallest/max = -1 1 4
|
||||
... Order -1 =
|
||||
[[(0,0)]]
|
||||
... Order 0 =
|
||||
[[(0,0)]]
|
||||
... Order 1 =
|
||||
[[(1,0)]]
|
||||
... Order 2 =
|
||||
[[(1,0)]]
|
||||
... Order 3 =
|
||||
[[(0.999251,0)]]
|
||||
... Order 4 =
|
||||
[[(0.998655,0)]]
|
||||
|
||||
|
@ -26,9 +26,7 @@
|
||||
#include <triqs/arrays/blas_lapack/gelss.hpp>
|
||||
#include <triqs/python_tools/cython_proxy.hpp>
|
||||
|
||||
namespace triqs {
|
||||
namespace gfs {
|
||||
namespace local {
|
||||
namespace triqs { namespace gfs { namespace local {
|
||||
|
||||
using triqs::gfs::imfreq;
|
||||
using triqs::gfs::block_index;
|
||||
@ -50,9 +48,9 @@ namespace gfs {
|
||||
|
||||
// output: returns the tail obtained by fitting
|
||||
|
||||
tail fit_tail_impl(gf<imfreq> &gf, const tail_view known_moments, int n_moments, int n_min, int n_max) {
|
||||
tail fit_tail_impl(gf_view<imfreq> gf, const tail_view known_moments, int n_moments, int n_min, int n_max) {
|
||||
|
||||
tail res(get_target_shape(gf), n_moments, known_moments.order_min());
|
||||
tail res(get_target_shape(gf));
|
||||
if (known_moments.size())
|
||||
for (int i = known_moments.order_min(); i <= known_moments.order_max(); i++) res(i) = known_moments(i);
|
||||
|
||||
@ -132,16 +130,14 @@ namespace gfs {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
res.mask_view()=n_moments;
|
||||
return res; // return tail
|
||||
}
|
||||
|
||||
|
||||
void set_tail_from_fit(gf<imfreq> &gf, tail_view known_moments, int n_moments, size_t n_min, size_t n_max,
|
||||
void set_tail_from_fit(gf_view<imfreq> gf, tail_view known_moments, int n_moments, size_t n_min, size_t n_max,
|
||||
bool replace_by_fit = false) {
|
||||
if (get_target_shape(gf) != known_moments.shape()) TRIQS_RUNTIME_ERROR << "shape of tail does not match shape of gf";
|
||||
gf.singularity() = fit_tail_impl(gf, known_moments, n_moments, n_min, n_max);
|
||||
|
||||
if (replace_by_fit) { // replace data in the fitting range by the values from the fitted tail
|
||||
size_t i = 0;
|
||||
for (auto iw : gf.mesh()) { // (arrays::range(n_min,n_max+1)) {
|
||||
@ -151,14 +147,15 @@ namespace gfs {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void set_tail_from_fit(gf<block_index, gf<imfreq>> &block_gf, tail_view known_moments, int n_moments, size_t n_min,
|
||||
void set_tail_from_fit(gf_view<block_index, gf<imfreq>> block_gf, tail_view known_moments, int n_moments, size_t n_min,
|
||||
size_t n_max, bool replace_by_fit = false) {
|
||||
// for(auto &gf : block_gf) set_tail_from_fit(gf, known_moments, n_moments, n_min, n_max, replace_by_fit);
|
||||
for (size_t i = 0; i < block_gf.mesh().size(); i++)
|
||||
set_tail_from_fit(block_gf[i], known_moments, n_moments, n_min, n_max, replace_by_fit);
|
||||
}
|
||||
void set_tail_from_fit(gf_view<imfreq, scalar_valued> gf, tail_view known_moments, int n_moments, size_t n_min, size_t n_max, bool replace_by_fit = false) {
|
||||
set_tail_from_fit(reinterpret_scalar_valued_gf_as_matrix_valued(gf), known_moments, n_moments, n_min, n_max, replace_by_fit );
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
}}} // namespace
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user