3
0
mirror of https://github.com/triqs/dft_tools synced 2024-11-01 03:33:50 +01:00

API change for tail fitters

python fit_tail, replace_by_tail ==> fit_tail_depr, replace_by_tail_depr
c++ set_tail_from_fit ==> fit_tail
This commit is contained in:
Priyanka Seth 2014-10-01 10:52:32 +02:00
parent 11f17631b5
commit 71fa498833
9 changed files with 29 additions and 30 deletions

View File

@ -6,9 +6,9 @@ API
The tail of a given ``gf<imfreq>/gf<block_index, gf<imfreq>> gw`` can be fitted using the two following functions:
``void set_tail_from_fit(gf<imfreq> &gf, tail_view known_moments, int n_moments, size_t n_min, size_t n_max, bool replace_by_fit = false);``
``void fit_tail(gf<imfreq> &gf, tail_view known_moments, int n_moments, size_t n_min, size_t n_max, bool replace_by_fit = false);``
``void set_tail_from_fit(gf<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);``
``void fit_tail(gf<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);``
where
@ -33,7 +33,7 @@ where
Example
~~~~~~~~
.. triqs_example:: ./set_tail_from_fit_0.cpp
.. triqs_example:: ./fit_tail_0.cpp
Implementation
~~~~~~~~~~~~~~~

View File

@ -28,11 +28,11 @@ In TRIQS, the tail is implemented as an object ``tail``. Here is a simple exampl
Fitting the tail of a Green's function
---------------------------------------
Given an imaginary-frequency Green's function, one can compute the moments of its high-frequency tail with the function ``set_tail_from_fit``:
Given an imaginary-frequency Green's function, one can compute the moments of its high-frequency tail with the function ``fit_tail``:
.. triqs_example:: ./tail_1.cpp
The full documentation of ``set_tail_from_fit`` is :doc:`here<set_tail_from_fit>`.
The full documentation of ``fit_tail`` is :doc:`here<fit_tail>`.
API
****

View File

@ -16,8 +16,7 @@ int main() {
int order_min = 1; // means that the first moment in the final tail will be the first moment
auto known_moments = local::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, n_min, n_max,
true); // true replace the gf data in the fitting range by the tail values
fit_tail(gw, known_moments, n_moments, n_min, n_max, true); // true replace the gf data in the fitting range by the tail values
std::cout << gw.singularity() << std::endl;
}

View File

@ -16,7 +16,7 @@ int main() {
auto known_moments = local::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, n_min, n_max, true);
fit_tail(gw, known_moments, n_moments, n_min, n_max, true);
std::cout << gw.singularity() << std::endl;
}

View File

@ -41,13 +41,13 @@ def plot(self, opt_dict):
#-------------- OTHER OPERATIONS -----------------------------------------------------
def replace_by_tail(self,start) :
def replace_by_tail_depr(self,start) :
d = self.data
t = self.tail
for n, om in enumerate(self.mesh) :
if n >= start : d[n,:,:] = t(om)
def fit_tail(self, fixed_coef, order_max, fit_start, fit_stop, replace_tail = True):
def fit_tail_depr(self, fixed_coef, order_max, fit_start, fit_stop, replace_tail = True):
"""
Fit the tail of the Green's function
Input:
@ -109,4 +109,4 @@ def fit_tail(self, fixed_coef, order_max, fit_start, fit_stop, replace_tail = Tr
self.tail[len(known_coef[n1][n2])+order-1][n1,n2] = numpy.array([[ moment ]])
self.tail.mask.fill(order_max)
# Replace then end of the Green's function by the tail
if replace_tail: self.replace_by_tail(ninit);
if replace_tail: self.replace_by_tail_depr(ninit);

View File

@ -369,14 +369,14 @@ g.add_method(name = "set_from_legendre",
calling_pattern = "self_c = legendre_to_imfreq(*gl)",
doc = """Fills self with the legendre transform of gl""")
g.add_method(name = "set_tail_from_fit",
g.add_method(name = "fit_tail",
signature = "void(tail_view known_moments, int n_moments, int n_min, int n_max, bool replace_by_fit = true)",
calling_pattern = "set_tail_from_fit(self_c, known_moments, n_moments, n_min, n_max, replace_by_fit)",
calling_pattern = "fit_tail(self_c, known_moments, n_moments, n_min, n_max, replace_by_fit)",
doc = """Set the tail by fitting""")
# Pure python methods
g.add_pure_python_method("pytriqs.gf.local._gf_imfreq.replace_by_tail")
g.add_pure_python_method("pytriqs.gf.local._gf_imfreq.fit_tail")
g.add_pure_python_method("pytriqs.gf.local._gf_imfreq.replace_by_tail_depr")
g.add_pure_python_method("pytriqs.gf.local._gf_imfreq.fit_tail_depr")
# For legacy Python code : authorize g + Matrix
#g.number_protocol['add'].add_overload(calling_pattern = "+", signature = "gf<imfreq>(gf<imfreq> x,matrix<std:complex<double>> y)")

View File

@ -39,8 +39,8 @@ void test_0(){
int n_moments=3; //number of moments in the final tail (including known ones)
//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);
fit_tail(gw, known_moments, n_moments, wn_min, wn_max);
fit_tail(gw_s, known_moments, n_moments, wn_min, wn_max);
TEST(gw.singularity());
TEST(gw_s.singularity());
@ -60,7 +60,7 @@ void test_0(){
order_min=1; //means that the first moment in the final tail will be the first moment
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
fit_tail(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());
/*
@ -90,8 +90,8 @@ void test_1(){
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
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
fit_tail(gw, known_moments, n_moments, wn_min, wn_max, true);//true replace the gf data in the fitting range by the tail values
fit_tail(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());
}
@ -112,7 +112,7 @@ void test_2(){
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
fit_tail(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());
}

View File

@ -85,7 +85,7 @@ namespace triqs { namespace gfs { namespace local {
return res; // return tail
}
void set_tail_from_fit(gf_view<imfreq> gf, tail_view known_moments, int n_moments, int n_min, int n_max,
void fit_tail(gf_view<imfreq> gf, tail_view known_moments, int n_moments, int n_min, int n_max,
bool replace_by_fit ) {
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);
@ -98,15 +98,15 @@ namespace triqs { namespace gfs { namespace local {
}
}
void set_tail_from_fit(gf_view<block_index, gf<imfreq>> block_gf, tail_view known_moments, int n_moments, int n_min,
void fit_tail(gf_view<block_index, gf<imfreq>> block_gf, tail_view known_moments, int n_moments, int n_min,
int n_max, bool replace_by_fit ) {
// for(auto &gf : block_gf) set_tail_from_fit(gf, known_moments, n_moments, n_min, n_max, replace_by_fit);
// for(auto &gf : block_gf) fit_tail(gf, known_moments, n_moments, n_min, n_max, replace_by_fit);
for (int 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);
fit_tail(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, int n_min, int n_max, bool replace_by_fit ) {
set_tail_from_fit(reinterpret_scalar_valued_gf_as_matrix_valued(gf), known_moments, n_moments, n_min, n_max, replace_by_fit );
void fit_tail(gf_view<imfreq, scalar_valued> gf, tail_view known_moments, int n_moments, int n_min, int n_max, bool replace_by_fit ) {
fit_tail(reinterpret_scalar_valued_gf_as_matrix_valued(gf), known_moments, n_moments, n_min, n_max, replace_by_fit );
}
}}} // namespace

View File

@ -48,11 +48,11 @@ namespace triqs { namespace gfs { namespace local {
tail fit_tail_impl(gf_view<imfreq> gf, const tail_view known_moments, int n_moments, int n_min, int n_max) ;
void set_tail_from_fit(gf_view<imfreq> gf, tail_view known_moments, int n_moments, int n_min, int n_max,
void fit_tail(gf_view<imfreq> gf, tail_view known_moments, int n_moments, int n_min, int n_max,
bool replace_by_fit = false) ;
void set_tail_from_fit(gf_view<block_index, gf<imfreq>> block_gf, tail_view known_moments, int n_moments, int n_min,
void fit_tail(gf_view<block_index, gf<imfreq>> block_gf, tail_view known_moments, int n_moments, int n_min,
int n_max, bool replace_by_fit = false) ;
void set_tail_from_fit(gf_view<imfreq, scalar_valued> gf, tail_view known_moments, int n_moments, int n_min, int n_max, bool replace_by_fit = false) ;
void fit_tail(gf_view<imfreq, scalar_valued> gf, tail_view known_moments, int n_moments, int n_min, int n_max, bool replace_by_fit = false) ;
}}} // namespace