├── .gitignore ├── .travis.yml ├── .zenodo.json ├── ACKNOWLEDGE.TXT ├── CMakeLists.txt ├── HEADER.TXT ├── LICENSE.TXT ├── README.md ├── cmake ├── EnableGtests.cmake ├── FindEigen3.cmake ├── FindGSL.cmake └── maxent_config.hpp.in ├── doxygen └── Doxyfile ├── examples ├── Advanced_Features.pdf ├── Bosonic │ ├── Bosonic_example.pdf │ ├── G_im │ ├── G_re │ ├── bosonic.param │ ├── bosonic_ph.param │ └── dat_in ├── Input_and_output_format.pdf ├── Legendre │ ├── Gl.dat │ ├── Legendre_example.pdf │ ├── Spect_in │ └── in.param ├── Self Energy │ ├── U1 │ │ ├── G_im │ │ ├── G_re │ │ ├── Selfenergy │ │ ├── Selfenergy_U1_example.pdf │ │ ├── Selfin │ │ └── in.param │ └── U10 │ │ ├── G_im │ │ ├── G_re │ │ ├── Selfenergy │ │ ├── Selfenergy_U10_example.pdf │ │ ├── Selfin │ │ ├── green.param │ │ └── in.param ├── U0 │ ├── G_im │ ├── G_re │ ├── Gtau │ ├── U0_example.pdf │ ├── in.param │ └── in_tau.param ├── U2 │ ├── G_im │ ├── G_re │ ├── G_tau │ ├── Gomegain │ ├── README.md │ ├── Selfenergy │ ├── frequency.param │ ├── self.param │ └── time.param ├── conventions_and_kernels.pdf ├── default_models.pdf └── grids.pdf ├── kk ├── CMakeLists.txt ├── README.md └── kk.cpp ├── legendre_convert ├── CMakeLists.txt ├── README.md └── legendre_convert.cpp ├── pade └── pade_arbitrary_degree │ ├── CMakeLists.txt │ ├── lu.cpp │ ├── main.cpp │ ├── main_bary.cpp │ ├── main_gmp.cpp │ ├── pade.cpp │ ├── pade.hpp │ ├── pade_grid.cpp │ ├── pade_imag.cpp │ ├── pade_interpolator.cpp │ ├── pade_interpolator_old.cpp │ ├── pade_real.cpp │ └── pade_solver.cpp ├── scripts ├── check-module-copyright-notice.py ├── fix-module-copyright-notice.py └── notice.py ├── src ├── default_model.cpp ├── default_model.hpp ├── eigen_hdf5.hpp ├── eigen_lapack.hpp ├── maxent.cpp ├── maxent.hpp ├── maxent_backcont.cpp ├── maxent_backcont.hpp ├── maxent_grid.cpp ├── maxent_grid.hpp ├── maxent_helper.cpp ├── maxent_kernel.cpp ├── maxent_kernel.hpp ├── maxent_matrix_def.hpp ├── maxent_params.cpp ├── maxent_params.hpp └── maxent_simulation.cpp └── test ├── CMakeLists.txt ├── backcontTest.cpp ├── default_modelTest.cpp ├── gridTest.cpp ├── gtest-all.cc ├── gtest.h ├── gtest_main.cc ├── paramFailureTest.cpp ├── paramsTest.cpp ├── simulationTest.cpp └── write_test_files.hpp /.gitignore: -------------------------------------------------------------------------------- 1 | #everything in folder ignored 2 | 3 | * 4 | !.gitignore 5 | !src/maxent_helper.cpp 6 | !src/maxent_parms.cpp 7 | !test/parmsTest.cpp 8 | !test/paramFailureTest.cpp 9 | !src/maxent_grid.cpp 10 | !src/maxent_kernel.cpp 11 | !src/maxent_grid.hpp 12 | !test/gridTest.cpp 13 | !src/maxent_kernel.hpp 14 | !src/maxent_parms.h 15 | !src/maxent_simulation.cpp 16 | !test/simulationTest.cpp 17 | !src/maxent_backcont.cpp 18 | !src/maxent_backcont.hpp 19 | !test/backcontTest.cpp 20 | !src/maxent_matrix_def.hpp 21 | !src/maxent.cpp 22 | !src/maxent.h 23 | !src/default_model.hpp 24 | !src/default_model.cpp 25 | !test/default_modelTest.cpp 26 | !test/write_test_files.hpp 27 | !src/maxent_legendre_util.cpp 28 | !src/maxent_legendre_util.hpp 29 | !CMakeLists.txt 30 | !cmake/ 31 | !cmake/EnableGtests.cmake 32 | !doxygen/Doxyfile 33 | !legendre_convert/legendre_convert.cpp 34 | !legendre_convert/CMakeLists.txt 35 | !src/eigen_hdf5.hpp 36 | !src/eigen_lapack.hpp 37 | !examples/ 38 | !LICENSE.TXT 39 | !ACKNOWLEDGE.TXT 40 | !COPYRIGHT.TXT 41 | !HEADER.TXT 42 | !.travis.yml 43 | !scripts/ 44 | !test/gtest* 45 | 46 | .DS_Store 47 | *.pyc 48 | *.swp 49 | 50 | #C++ Files 51 | # Compiled Object files 52 | *.slo 53 | *.lo 54 | *.o 55 | *.obj 56 | 57 | # Precompiled Headers 58 | *.gch 59 | *.pch 60 | 61 | # Compiled Dynamic libraries 62 | *.so 63 | *.dylib 64 | *.dll 65 | 66 | # Fortran module files 67 | *.mod 68 | 69 | # Compiled Static libraries 70 | *.lai 71 | *.la 72 | *.a 73 | *.lib 74 | 75 | # Executables 76 | *.exe 77 | *.out 78 | *.app 79 | /Debug/ 80 | /Debug/ 81 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | #based on ALPSCore/CT-HYB .travis.yml 2 | language: cpp 3 | sudo: required 4 | dist: trusty 5 | 6 | compiler: 7 | - gcc 8 | - clang 9 | 10 | branches: 11 | only: 12 | - master 13 | - GPLv3 14 | #- travis # To debug .travis.yml 15 | 16 | addons: 17 | apt: 18 | sources: 19 | # Boost 1.58 20 | - sourceline: ppa:kzemek/boost 21 | packages: 22 | - libboost1.58-dev 23 | - libboost-program-options1.58-dev 24 | - libboost-program-options1.58.0 25 | - openmpi-bin 26 | - openmpi-common 27 | - openmpi-doc 28 | - libopenmpi-dev 29 | - libhdf5-serial-dev 30 | - gsl-bin 31 | - libgsl0-dev 32 | 33 | install: true 34 | 35 | before_script: 36 | - export OMPI_CC=${CC} 37 | - export OMPI_CXX=${CXX} 38 | - export LD_LIBRARY_PATH=/usr/local/lib/:${LD_LIBRARY_PATH} 39 | 40 | script: 41 | # Stop on first error 42 | - set -e 43 | 44 | # Create directory for installed prerequisites 45 | - export PREREQS_DIR=$(readlink -f $TRAVIS_BUILD_DIR/../installed) 46 | - mkdir $PREREQS_DIR 47 | 48 | # Install ALPSCore wo tests 49 | - cd $TRAVIS_BUILD_DIR/.. 50 | - git clone https://github.com/ALPSCore/ALPSCore.git ALPSCore.git 51 | - mkdir ALPSCore.build && pushd ALPSCore.build 52 | - | 53 | cmake ../ALPSCore.git \ 54 | -DCMAKE_C_COMPILER=mpicc \ 55 | -DCMAKE_CXX_COMPILER=mpic++ \ 56 | -DCMAKE_INSTALL_PREFIX=$PREREQS_DIR/ALPSCore \ 57 | -DALPS_INSTALL_EIGEN=true \ 58 | -DTesting=false \ 59 | -DENABLE_MPI=ON 60 | - make -j3 61 | - make install 62 | - export ALPSCore_DIR=$PREREQS_DIR/ALPSCore 63 | 64 | # Build and test Maxent 65 | - cd $TRAVIS_BUILD_DIR/.. 66 | - mkdir build 67 | - cd build 68 | - | 69 | cmake ../Maxent \ 70 | -DCMAKE_BUILD_TYPE=Debug \ 71 | -DCMAKE_C_COMPILER=mpicc \ 72 | -DCMAKE_CXX_COMPILER=mpic++ \ 73 | -DCMAKE_INSTALL_PREFIX=$TRAVIS_BUILD_DIR/installed \ 74 | - make -j3 75 | - make test 76 | -------------------------------------------------------------------------------- /.zenodo.json: -------------------------------------------------------------------------------- 1 | { 2 | "license": "other-open", 3 | "creators": [ 4 | { 5 | "name": "Ryan Levy", 6 | "affiliation": "University of Illinois, Urbana-Champaign" 7 | }, 8 | { 9 | "name": "James P.F. LeBlanc", 10 | "affiliation": "Memorial University of Newfoundland, Canada" 11 | }, 12 | { 13 | "affiliation": "University of Michigan", 14 | "name": "Emanuel Gull" 15 | } 16 | ], 17 | "access_right": "open", 18 | "related_identifiers": [ 19 | { 20 | "identifier": "arXiv:1606.00368", 21 | "relation": "isSupplementTo" 22 | } 23 | ] 24 | } 25 | -------------------------------------------------------------------------------- /ACKNOWLEDGE.TXT: -------------------------------------------------------------------------------- 1 | Whenever scientific publications result from a program based on ALPS or Maxent we kindly ask for an acknowledgment of ALPS in the acknowledgment section of the paper, for a citation to the ALPS Maxent paper, and for a citation to the most current ALPS paper: 2 | 3 | 1) The most current Maxent Paper: 4 | 5 | R. Levy, J.P.F. LeBlanc, E. Gull, Comput. Phys. Commun. 215 (2017). 6 | http://www.sciencedirect.com/science/article/pii/S0010465517300309 7 | http://dx.doi.org/10.1016/j.cpc.2017.01.018 8 | 9 | 2) The most current ALPS Core Libraries paper: 10 | 11 | A. Gaenko et al., Comp. Phys. Comm. (2017) v.213, p.235-251 12 | http://www.sciencedirect.com/science/article/pii/S0010465516303885 13 | http://dx.doi.org/10.1016/j.cpc.2016.12.009 14 | 15 | 3) The most current ALPS paper: 16 | 17 | B. Bauer et al., J. Stat. Mech. (2011) P05001. 18 | http://iopscience.iop.org/1742-5468/2011/05/P05001/ 19 | http://dx.doi.org/10.1088/1742-5468/2011/05/P05001 20 | 21 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.1) 2 | project (MAXENT) 3 | 4 | SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) 5 | find_package(ALPSCore 2.0 REQUIRED) 6 | 7 | list(APPEND LINK_ALL ${ALPSCore_LIBRARIES}) 8 | #note: LAPACK also finds BLAS 9 | find_package(LAPACK) 10 | if(LAPACK_FOUND AND USE_LAPACK) 11 | set(HAVE_BLAS 1) 12 | set(HAVE_LAPACK 1) 13 | message(STATUS "Using LAPACK and BLAS routines for SVD") 14 | list(APPEND LINK_ALL ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES}) 15 | else() 16 | set(HAVE_BLAS 0) 17 | set(HAVE_LAPACK 0) 18 | endif() 19 | configure_file( 20 | "${PROJECT_SOURCE_DIR}/cmake/maxent_config.hpp.in" 21 | "${PROJECT_BINARY_DIR}/config/maxent_config.hpp" 22 | ) 23 | 24 | include_directories("${PROJECT_BINARY_DIR}/config") 25 | list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake) 26 | message(STATUS "Finding packages, please stand by...") 27 | find_package(GSL REQUIRED) 28 | list(APPEND LINK_ALL ${GSL_LIBRARIES}) 29 | 30 | # new ALPSCore provides Eigen 31 | if (NOT ALPSCore_HAS_EIGEN_VERSION) 32 | find_package (Eigen3 3.1 REQUIRED) 33 | endif() 34 | 35 | include(CheckCXXCompilerFlag) 36 | CHECK_CXX_COMPILER_FLAG(-Wno-return-type-c-linkage SUPPORTS_FLAG) 37 | if(SUPPORTS_FLAG) 38 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-return-type-c-linkage") 39 | endif() 40 | 41 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -DNDEBUG") 42 | 43 | #let gcc take advantage of Eigen3 vectorization 44 | if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") 45 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse2") 46 | endif() 47 | 48 | include_directories(${GSL_INCLUDE_DIR}) 49 | include_directories(${EIGEN3_INCLUDE_DIR}) 50 | 51 | set(LIB_FILES 52 | ./src/maxent_helper.cpp 53 | ./src/maxent_params.cpp 54 | ./src/maxent_grid.cpp 55 | ./src/maxent_kernel.cpp 56 | ./src/maxent_simulation.cpp 57 | ./src/maxent_backcont.cpp 58 | ./src/default_model.cpp 59 | ) 60 | 61 | ADD_LIBRARY(libmaxent ${LIB_FILES}) 62 | target_link_libraries(libmaxent ${LINK_ALL}) 63 | #remove default "lib" prefix 64 | set_target_properties(libmaxent PROPERTIES PREFIX "") 65 | #executable 66 | add_executable(maxent 67 | ./src/maxent.cpp 68 | ) 69 | target_link_libraries(maxent libmaxent ${LINK_ALL}) 70 | 71 | #testing setup 72 | option(Testing "Enable testing" ON) 73 | 74 | if (Testing) 75 | add_library(gtest ./test/gtest-all.cc ./test/gtest_main.cc) 76 | list(APPEND LINK_ALL libmaxent) 77 | enable_testing(test) 78 | add_subdirectory(test) 79 | endif (Testing) 80 | 81 | 82 | #add companion utilities 83 | add_subdirectory(legendre_convert) 84 | add_subdirectory(kk) 85 | if(PADE) 86 | add_subdirectory(pade/pade_arbitrary_degree) 87 | endif(PADE) 88 | 89 | #install 90 | install(TARGETS maxent DESTINATION bin) 91 | -------------------------------------------------------------------------------- /HEADER.TXT: -------------------------------------------------------------------------------- 1 | Copyright (C) 1998-2018 ALPS Collaboration. 2 | All rights reserved. Use is subject to license terms. See LICENSE.TXT 3 | For use in publications, see ACKNOWLEDGE.TXT 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Maxent 2 | ====== 3 | [![Build Status](https://travis-ci.org/CQMP/Maxent.svg?branch=master)](https://travis-ci.org/CQMP/Maxent) 4 | 5 | The Maxent Project: A utility for performing analytic continuation using the method of Maximum Entropy. 6 | 7 | Many-body Green's functions calculated on the imaginary axis can be related to a real spectral function, but is an ill-posed problem. One algorithm to solve for the spectral function is the maximum entropy method. This code is an implementation of maximum entropy method as well as useful utilities for dealing with Green's functions and analytic continuation. 8 | 9 | Table of Contents 10 | ================= 11 | * [Maxent](#maxent) 12 | * [Table of Contents](#table-of-contents) 13 | * [Requirements](#requirements) 14 | * [Libraries](#libraries) 15 | * [Boost](#boost) 16 | * [ALPSCore](#alpscore) 17 | * [Eigen3](#eigen3) 18 | * [GSL](#gsl) 19 | * [LAPACK (Optional)](#lapack-optional) 20 | * [Installation](#installation) 21 | * [Tests](#tests) 22 | * [Convention](#convention) 23 | * [Usage](#usage) 24 | * [Input](#input) 25 | * [Particle Hole Symmetric Data](#particle-hole-symmetric-data) 26 | * [Non-Particle Hole Symmetric Data](#non-particle-hole-symmetric-data) 27 | * [Time Data](#time-data) 28 | * [Kernels](#kernels) 29 | * [Default Models](#default-models) 30 | * [Grids](#grids) 31 | * [Utilities](#utilities) 32 | * [Pade](#pade) 33 | * [Kramers-Kronig](#kramers-kronig) 34 | * [Legendre Convert](#legendre-convert) 35 | 36 | ## Requirements 37 | 38 | ### Libraries 39 | 40 | #### Boost 41 | When compiling both ALPSCore and Maxent, be careful to ensure boost was compiled with the same library and stdlib as ALPSCore and Maxent. 42 | 43 | #### ALPSCore 44 | ALPSCore needs to be properly installed, see [ALPSCore library](https://github.com/ALPSCore/ALPSCore). ALPSCore provides the location of the Boost libraries. 45 | 46 | #### Eigen3 47 | For our linear algebra routines we use Eigen3 version >=3.1. If not in your path use `-DEIGEN3_INCLUDE_DIR=/path/to/eigen3/include`, where `/path/to/eigen3/include` is the directory containing `Eigen` subdirectory with Eigen3 header files. 48 | 49 | #### GSL 50 | Maxent requires the GNU Scientific Library (GSL), which can be found [here](https://www.gnu.org/software/gsl/). The choice of BLAS library (the included CBLAS or an external ATLAS/BLAS/etc) does not matter here as the only the integration library is used. If not in your path use `-GSL_ROOT_DIR=` to the path that has `bin/gsl-config`. 51 | 52 | #### LAPACK (Optional) 53 | Eigen3 has a good SVD routine, but can be very slow for a large kernel. 54 | Some systems, like OS X or those with Intel MKL, have precompiled BLAS/LAPACK routines that can be faster and as accurate as Eigen3. 55 | To turn on LAPACK support for the SVD, please use the flag `-DUSE_LAPACK=1`. 56 | 57 | 58 | ## Installation 59 | To install provide something like: 60 | ``` 61 | $ git clone https://github.com/CQMP/Maxent 62 | $ mkdir build 63 | $ cd build 64 | $ cmake ../ -DCMAKE_INSTALL_PREFIX=/path/to/here/Maxent/build -DALPSCore_DIR=/path/to/alpscore/build/share/ALPSCore 65 | $ make -j 8 66 | ``` 67 | Sometimes it is more convenient to have `CC=gcc CXX=g++` (or clang, etc) before the cmake command. 68 | 69 | ### Tests 70 | Once compiled please run `make test` 71 | to ensure everything works. 72 | 73 | ## Convention 74 | The Maxent project uses the following conventions: 75 | 76 | ![convention](https://cloud.githubusercontent.com/assets/7354063/10086355/ef8c8362-62db-11e5-938a-1c24139c72df.png) 77 | 78 | ![convention_gtau](https://cloud.githubusercontent.com/assets/7354063/10086425/570a68ce-62dc-11e5-8cd3-1e871f89c695.png) 79 | 80 | ![convention_A_omega](https://cloud.githubusercontent.com/assets/7354063/10056184/0ce6afd4-6208-11e5-9bdd-556ae958857c.png) 81 | 82 | To see more, see [this pdf](examples/conventions_and_kernels.pdf). 83 | 84 | ## Usage 85 | Upon installation there will be a binary `maxent`. It uses [ALPSCore parameters](https://github.com/ALPSCore/ALPSCore/wiki/Tutorial%3A-parameters), which can take a param file as input (see [examples](./examples)), or command line arguments of the form `--PARAMETER=value`. 86 | The three required parameters are `BETA` (inverse temperature), `NDAT` (the number of input data points), and either the location of the input data `DATA` or input through the param file using `X_i` (see below). 87 | 88 | See `./maxent --help` for a list of required and availble parameters. 89 | 90 | #### Input 91 | ##### Particle Hole Symmetric Data 92 | The Green's function for PH symmetric data is 0, therefore we only require the imaginary part. 93 | Input file: 94 | ``` 95 | omega_n imag sigma 96 | //example: 97 | omega_0 imag0 sigma0 98 | omega_1 imag1 sigma1 99 | ... 100 | ``` 101 | Data can also be stored in the parameter file using: 102 | ``` 103 | X_0= xxxx 104 | SIGMA_0=xxx 105 | X_1=xxxx 106 | SIGMA_1=xxx 107 | ... 108 | X_ndat-1=xxxx 109 | SIGMA_ndat-1=xxx 110 | ``` 111 | ##### Non-Particle Hole Symmetric Data 112 | This assumes a non-zero real part of the Green's function. Input data should be: 113 | ``` 114 | n real sigma_real 115 | n+1 imag sigma_imag 116 | //example: 117 | omega_0 real0 sigma_real0 imag0 sigma_imag0 118 | omega_1 real1 sigma_real1 imag1 sigma_imag1 119 | ``` 120 | **_NOTE:_** NDAT=#of points*2 when there is not Particle Hole Symmetric data 121 | 122 | Data can also be stored in the parameter file using: 123 | ``` 124 | X_0= xxxx 125 | SIGMA_0=xxx 126 | X_1=xxxx 127 | SIGMA_1=xxx 128 | ... 129 | ``` 130 | where `X_0` is the real part and `X_1` is the imaginary part, etc. 131 | ##### Time Data 132 | For either symmetric or non-symmetric data, G(tau) is simply input as: 133 | ``` 134 | tau_n Gtau_n sigma_n 135 | tau_n+1 Gtau_n+1 sigma_n+1 136 | ``` 137 | You can also include tau points in the parameter file, defined like: 138 | ``` 139 | TAU_0=xxx... 140 | TAU_1=xxx 141 | ... 142 | TAU_NDAT-1=xxx 143 | ``` 144 | #### Kernels 145 | ![Fermionic Kernels](https://cloud.githubusercontent.com/assets/7354063/10101709/42e4cae2-6368-11e5-999b-0483d4f4358f.png) 146 | ![Time Kernels](https://cloud.githubusercontent.com/assets/7354063/15372450/754a55fa-1d0e-11e6-8483-e2c827591946.png) 147 | 148 | For the `TZero` kernel, supply any `BETA` value. 149 | 150 | #### Default Models 151 | [View Examples Here](examples/default_models.pdf) 152 | * Flat 153 | * Gaussian 154 | * Shifted Gaussian 155 | * Double Gaussian 156 | * Two Gaussians 157 | * Double General Gaussian 158 | * Lorentzian 159 | * See Gaussian 160 | * Linear Rise Exponential Decay 161 | * Quadratic Rise Exponential Decay 162 | * Tabulated Default model = "Filename" 163 | 164 | #### Grids 165 | Maxent creats a default model on a grid between [0,1] 166 | 167 | ![grids](https://cloud.githubusercontent.com/assets/7354063/14571315/8ac93a8e-0316-11e6-8255-b9756a2710e8.png) 168 | 169 | 170 | # Utilities 171 | ## Kramers-Kronig 172 | Requires: [GSL](http://www.gnu.org/software/gsl/), Boost 173 | ## Legendre Convert 174 | Requires: Boost 175 | ## Optional 176 | ### Pade 177 | Requires: [GMP](https://gmplib.org/),[Eigen3.1](http://eigen.tuxfamily.org/index.php?title=Main_Page) 178 | Because Pade requires GMP, it does not build automatically. To include it in your build, either run `cmake` from the pade folder, or in your `maxent` build folder add `-DPADE=1` to the`cmake` command 179 | -------------------------------------------------------------------------------- /cmake/EnableGtests.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # enables testing with google test 3 | # provides add_gtest(test) and add_gtest_release(test) commands 4 | # 5 | 6 | # check xml output 7 | option(TestXMLOutput "Output tests to xml" OFF) 8 | 9 | # custom function to add gtest with xml output 10 | # arg0 - test (assume the source is ${test}.cpp 11 | function(add_gtest test) 12 | if (TestXMLOutput) 13 | set (test_xml_output --gtest_output=xml:${test}.xml) 14 | endif(TestXMLOutput) 15 | 16 | if(${ARGC} EQUAL 2) 17 | set(source "${ARGV1}/${test}") 18 | #set(gtest_src "${ARGV1}/gtest_main.cc;${ARGV1}/gtest-all.cc") 19 | else(${ARGC} EQUAL 2) 20 | set(source "${test}") 21 | #set(gtest_src "gtest_main.cc;gtest-all.cc") 22 | endif(${ARGC} EQUAL 2) 23 | 24 | add_executable(${test} ${source}) 25 | target_link_libraries(${test} ${LINK_ALL} gtest) 26 | add_test(NAME ${test} COMMAND ${test} ${test_xml_output}) 27 | endfunction(add_gtest) 28 | 29 | -------------------------------------------------------------------------------- /cmake/FindEigen3.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find Eigen3 lib 2 | # 3 | # This module supports requiring a minimum version, e.g. you can do 4 | # find_package(Eigen3 3.1.2) 5 | # to require version 3.1.2 or newer of Eigen3. 6 | # 7 | # Once done this will define 8 | # 9 | # EIGEN3_FOUND - system has eigen lib with correct version 10 | # EIGEN3_INCLUDE_DIR - the eigen include directory 11 | # EIGEN3_VERSION - eigen version 12 | # 13 | # This module reads hints about search locations from 14 | # the following enviroment variables: 15 | # 16 | # EIGEN3_ROOT 17 | # EIGEN3_ROOT_DIR 18 | 19 | # Copyright (c) 2006, 2007 Montel Laurent, 20 | # Copyright (c) 2008, 2009 Gael Guennebaud, 21 | # Copyright (c) 2009 Benoit Jacob 22 | # Redistribution and use is allowed according to the terms of the 2-clause BSD license. 23 | 24 | if(NOT Eigen3_FIND_VERSION) 25 | if(NOT Eigen3_FIND_VERSION_MAJOR) 26 | set(Eigen3_FIND_VERSION_MAJOR 2) 27 | endif(NOT Eigen3_FIND_VERSION_MAJOR) 28 | if(NOT Eigen3_FIND_VERSION_MINOR) 29 | set(Eigen3_FIND_VERSION_MINOR 91) 30 | endif(NOT Eigen3_FIND_VERSION_MINOR) 31 | if(NOT Eigen3_FIND_VERSION_PATCH) 32 | set(Eigen3_FIND_VERSION_PATCH 0) 33 | endif(NOT Eigen3_FIND_VERSION_PATCH) 34 | 35 | set(Eigen3_FIND_VERSION "${Eigen3_FIND_VERSION_MAJOR}.${Eigen3_FIND_VERSION_MINOR}.${Eigen3_FIND_VERSION_PATCH}") 36 | endif(NOT Eigen3_FIND_VERSION) 37 | 38 | macro(_eigen3_check_version) 39 | file(READ "${EIGEN3_INCLUDE_DIR}/Eigen/src/Core/util/Macros.h" _eigen3_version_header) 40 | 41 | string(REGEX MATCH "define[ \t]+EIGEN_WORLD_VERSION[ \t]+([0-9]+)" _eigen3_world_version_match "${_eigen3_version_header}") 42 | set(EIGEN3_WORLD_VERSION "${CMAKE_MATCH_1}") 43 | string(REGEX MATCH "define[ \t]+EIGEN_MAJOR_VERSION[ \t]+([0-9]+)" _eigen3_major_version_match "${_eigen3_version_header}") 44 | set(EIGEN3_MAJOR_VERSION "${CMAKE_MATCH_1}") 45 | string(REGEX MATCH "define[ \t]+EIGEN_MINOR_VERSION[ \t]+([0-9]+)" _eigen3_minor_version_match "${_eigen3_version_header}") 46 | set(EIGEN3_MINOR_VERSION "${CMAKE_MATCH_1}") 47 | 48 | set(EIGEN3_VERSION ${EIGEN3_WORLD_VERSION}.${EIGEN3_MAJOR_VERSION}.${EIGEN3_MINOR_VERSION}) 49 | if(${EIGEN3_VERSION} VERSION_LESS ${Eigen3_FIND_VERSION}) 50 | set(EIGEN3_VERSION_OK FALSE) 51 | else(${EIGEN3_VERSION} VERSION_LESS ${Eigen3_FIND_VERSION}) 52 | set(EIGEN3_VERSION_OK TRUE) 53 | endif(${EIGEN3_VERSION} VERSION_LESS ${Eigen3_FIND_VERSION}) 54 | 55 | if(NOT EIGEN3_VERSION_OK) 56 | 57 | message(STATUS "Eigen3 version ${EIGEN3_VERSION} found in ${EIGEN3_INCLUDE_DIR}, " 58 | "but at least version ${Eigen3_FIND_VERSION} is required") 59 | endif(NOT EIGEN3_VERSION_OK) 60 | endmacro(_eigen3_check_version) 61 | 62 | if (EIGEN3_INCLUDE_DIR) 63 | 64 | # in cache already 65 | _eigen3_check_version() 66 | set(EIGEN3_FOUND ${EIGEN3_VERSION_OK}) 67 | 68 | else (EIGEN3_INCLUDE_DIR) 69 | 70 | # search first if an Eigen3Config.cmake is available in the system, 71 | # if successful this would set EIGEN3_INCLUDE_DIR and the rest of 72 | # the script will work as usual 73 | find_package(Eigen3 ${Eigen3_FIND_VERSION} NO_MODULE QUIET) 74 | 75 | if(NOT EIGEN3_INCLUDE_DIR) 76 | find_path(EIGEN3_INCLUDE_DIR NAMES signature_of_eigen3_matrix_library 77 | HINTS 78 | ENV EIGEN3_ROOT 79 | ENV EIGEN3_ROOT_DIR 80 | PATHS 81 | ${CMAKE_INSTALL_PREFIX}/include 82 | ${KDE4_INCLUDE_DIR} 83 | PATH_SUFFIXES eigen3 eigen 84 | ) 85 | endif(NOT EIGEN3_INCLUDE_DIR) 86 | 87 | if(EIGEN3_INCLUDE_DIR) 88 | _eigen3_check_version() 89 | endif(EIGEN3_INCLUDE_DIR) 90 | 91 | include(FindPackageHandleStandardArgs) 92 | find_package_handle_standard_args(Eigen3 DEFAULT_MSG EIGEN3_INCLUDE_DIR EIGEN3_VERSION_OK) 93 | 94 | mark_as_advanced(EIGEN3_INCLUDE_DIR) 95 | 96 | endif(EIGEN3_INCLUDE_DIR) 97 | 98 | -------------------------------------------------------------------------------- /cmake/FindGSL.cmake: -------------------------------------------------------------------------------- 1 | # Try to find gnu scientific library GSL 2 | # See 3 | # http://www.gnu.org/software/gsl/ and 4 | # http://gnuwin32.sourceforge.net/packages/gsl.htm 5 | # 6 | # Once run this will define: 7 | # 8 | # GSL_FOUND = system has GSL lib 9 | # 10 | # GSL_LIBRARIES = full path to the libraries 11 | # on Unix/Linux with additional linker flags from "gsl-config --libs" 12 | # 13 | # CMAKE_GSL_CXX_FLAGS = Unix compiler flags for GSL, essentially "`gsl-config --cxxflags`" 14 | # 15 | # GSL_INCLUDE_DIR = where to find headers 16 | # 17 | # GSL_LINK_DIRECTORIES = link directories, useful for rpath on Unix 18 | # GSL_EXE_LINKER_FLAGS = rpath on Unix 19 | # 20 | # Felix Woelk 07/2004 21 | # Jan Woetzel 22 | # 23 | # www.mip.informatik.uni-kiel.de 24 | # Additions by Ryan Levy (github.com/ryanlevy) 25 | # -------------------------------- 26 | 27 | IF(WIN32) 28 | # JW tested with gsl-1.8, Windows XP, MSVS 7.1 29 | SET(GSL_POSSIBLE_ROOT_DIRS 30 | ${GSL_ROOT_DIR} 31 | $ENV{GSL_ROOT_DIR} 32 | ${GSL_DIR} 33 | ${GSL_HOME} 34 | $ENV{GSL_DIR} 35 | $ENV{GSL_HOME} 36 | $ENV{EXTRA} 37 | "C:/Program Files/GnuWin32" 38 | ) 39 | FIND_PATH(GSL_INCLUDE_DIR 40 | NAMES gsl/gsl_cdf.h gsl/gsl_randist.h 41 | PATHS ${GSL_POSSIBLE_ROOT_DIRS} 42 | PATH_SUFFIXES include 43 | DOC "GSL header include dir" 44 | ) 45 | 46 | FIND_LIBRARY(GSL_GSL_LIBRARY 47 | NAMES libgsl.dll.a gsl libgsl 48 | PATHS ${GSL_POSSIBLE_ROOT_DIRS} 49 | PATH_SUFFIXES lib 50 | DOC "GSL library" ) 51 | 52 | if(NOT GSL_GSL_LIBRARY) 53 | FIND_FILE(GSL_GSL_LIBRARY 54 | NAMES libgsl.dll.a 55 | PATHS ${GSL_POSSIBLE_ROOT_DIRS} 56 | PATH_SUFFIXES lib 57 | DOC "GSL library") 58 | endif(NOT GSL_GSL_LIBRARY) 59 | 60 | FIND_LIBRARY(GSL_GSLCBLAS_LIBRARY 61 | NAMES libgslcblas.dll.a gslcblas libgslcblas 62 | PATHS ${GSL_POSSIBLE_ROOT_DIRS} 63 | PATH_SUFFIXES lib 64 | DOC "GSL cblas library dir" ) 65 | 66 | if(NOT GSL_GSLCBLAS_LIBRARY) 67 | FIND_FILE(GSL_GSLCBLAS_LIBRARY 68 | NAMES libgslcblas.dll.a 69 | PATHS ${GSL_POSSIBLE_ROOT_DIRS} 70 | PATH_SUFFIXES lib 71 | DOC "GSL library") 72 | endif(NOT GSL_GSLCBLAS_LIBRARY) 73 | 74 | SET(GSL_LIBRARIES ${GSL_GSL_LIBRARY}) 75 | 76 | #MESSAGE("DBG\n" 77 | # "GSL_GSL_LIBRARY=${GSL_GSL_LIBRARY}\n" 78 | # "GSL_GSLCBLAS_LIBRARY=${GSL_GSLCBLAS_LIBRARY}\n" 79 | # "GSL_LIBRARIES=${GSL_LIBRARIES}") 80 | 81 | 82 | ELSE(WIN32) 83 | 84 | IF(UNIX) 85 | SET(GSL_CONFIG_PREFER_PATH 86 | "$ENV{GSL_DIR}/bin" 87 | "$ENV{GSL_DIR}" 88 | "$ENV{GSL_HOME}/bin" 89 | "$ENV{GSL_HOME}" 90 | "${GSL_ROOT_DIR}" 91 | "${GSL_ROOT_DIR}/bin" 92 | CACHE STRING "preferred path to GSL (gsl-config)") 93 | FIND_PROGRAM(GSL_CONFIG gsl-config 94 | ${GSL_CONFIG_PREFER_PATH} 95 | /usr/bin/ 96 | ) 97 | # MESSAGE("DBG GSL_CONFIG ${GSL_CONFIG}") 98 | 99 | IF (GSL_CONFIG) 100 | # set CXXFLAGS to be fed into CXX_FLAGS by the user: 101 | SET(GSL_CXX_FLAGS "`${GSL_CONFIG} --cflags`") 102 | 103 | # set INCLUDE_DIRS to prefix+include 104 | EXEC_PROGRAM(${GSL_CONFIG} 105 | ARGS --prefix 106 | OUTPUT_VARIABLE GSL_PREFIX) 107 | SET(GSL_INCLUDE_DIR ${GSL_PREFIX}/include CACHE STRING INTERNAL) 108 | 109 | # set link libraries and link flags 110 | #SET(GSL_LIBRARIES "`${GSL_CONFIG} --libs`") 111 | EXEC_PROGRAM(${GSL_CONFIG} 112 | ARGS --libs 113 | OUTPUT_VARIABLE GSL_LIBRARIES ) 114 | 115 | # extract link dirs for rpath 116 | EXEC_PROGRAM(${GSL_CONFIG} 117 | ARGS --libs 118 | OUTPUT_VARIABLE GSL_CONFIG_LIBS ) 119 | 120 | # extract version 121 | EXEC_PROGRAM(${GSL_CONFIG} 122 | ARGS --version 123 | OUTPUT_VARIABLE GSL_FULL_VERSION ) 124 | 125 | # split version as major/minor 126 | STRING(REGEX MATCH "(.)\\..*" GSL_VERSION_MAJOR_ "${GSL_FULL_VERSION}") 127 | SET(GSL_VERSION_MAJOR ${CMAKE_MATCH_1}) 128 | STRING(REGEX MATCH ".\\.(.*)" GSL_VERSION_MINOR_ "${GSL_FULL_VERSION}") 129 | SET(GSL_VERSION_MINOR ${CMAKE_MATCH_1}) 130 | 131 | # split off the link dirs (for rpath) 132 | # use regular expression to match wildcard equivalent "-L*" 133 | # with is a space or a semicolon 134 | STRING(REGEX MATCHALL "[-][L]([^ ;])+" 135 | GSL_LINK_DIRECTORIES_WITH_PREFIX 136 | "${GSL_CONFIG_LIBS}" ) 137 | # MESSAGE("DBG GSL_LINK_DIRECTORIES_WITH_PREFIX=${GSL_LINK_DIRECTORIES_WITH_PREFIX}") 138 | 139 | # remove prefix -L because we need the pure directory for LINK_DIRECTORIES 140 | 141 | IF (GSL_LINK_DIRECTORIES_WITH_PREFIX) 142 | STRING(REGEX REPLACE "[-][L]" "" GSL_LINK_DIRECTORIES ${GSL_LINK_DIRECTORIES_WITH_PREFIX} ) 143 | ENDIF (GSL_LINK_DIRECTORIES_WITH_PREFIX) 144 | SET(GSL_EXE_LINKER_FLAGS "-Wl,-rpath,${GSL_LINK_DIRECTORIES}" CACHE STRING INTERNAL) 145 | # MESSAGE("DBG GSL_LINK_DIRECTORIES=${GSL_LINK_DIRECTORIES}") 146 | # MESSAGE("DBG GSL_EXE_LINKER_FLAGS=${GSL_EXE_LINKER_FLAGS}") 147 | 148 | # ADD_DEFINITIONS("-DHAVE_GSL") 149 | # SET(GSL_DEFINITIONS "-DHAVE_GSL") 150 | MARK_AS_ADVANCED( 151 | GSL_CXX_FLAGS 152 | GSL_INCLUDE_DIR 153 | GSL_LIBRARIES 154 | GSL_LINK_DIRECTORIES 155 | GSL_DEFINITIONS 156 | ) 157 | MESSAGE(STATUS "Using GSL from ${GSL_PREFIX}") 158 | 159 | ELSE(GSL_CONFIG) 160 | MESSAGE("FindGSL.cmake: gsl-config not found. Please set GSL_ROOT_DIR as root or gsl-config directory") 161 | ENDIF(GSL_CONFIG) 162 | 163 | ENDIF(UNIX) 164 | ENDIF(WIN32) 165 | 166 | 167 | IF(GSL_LIBRARIES) 168 | IF(GSL_INCLUDE_DIR OR GSL_CXX_FLAGS) 169 | 170 | SET(GSL_FOUND 1) 171 | 172 | ENDIF(GSL_INCLUDE_DIR OR GSL_CXX_FLAGS) 173 | ENDIF(GSL_LIBRARIES) 174 | IF(NOT GSL_FOUND) 175 | include(FindPackageHandleStandardArgs) 176 | find_package_handle_standard_args(GSL DEFAULT_MSG GSL_ROOT_DIR) 177 | ENDIF(NOT GSL_FOUND) 178 | -------------------------------------------------------------------------------- /cmake/maxent_config.hpp.in: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // Define if you have BLAS library 4 | #cmakedefine HAVE_BLAS 5 | // 6 | // // Define if you have LAPACK library 7 | #cmakedefine HAVE_LAPACK 8 | -------------------------------------------------------------------------------- /examples/Advanced_Features.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CQMP/Maxent/a3992534228b0de732e033ae23154969724814be/examples/Advanced_Features.pdf -------------------------------------------------------------------------------- /examples/Bosonic/Bosonic_example.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CQMP/Maxent/a3992534228b0de732e033ae23154969724814be/examples/Bosonic/Bosonic_example.pdf -------------------------------------------------------------------------------- /examples/Bosonic/G_im: -------------------------------------------------------------------------------- 1 | 0 -1.27890161453e-15 1.27890161453e-16 2 | 3.14159265359 4.895943813e-06 4.895943813e-07 3 | 6.28318530718 7.44279002171e-06 7.44279002171e-07 4 | 9.42477796077 9.10677686772e-06 9.10677686772e-07 5 | 12.56637061436 1.139294386e-05 1.139294386e-06 6 | 15.70796326795 1.36423004018e-05 1.36423004018e-06 7 | 18.84955592154 1.61398883312e-05 1.61398883312e-06 8 | 21.99114857513 1.91793240789e-05 1.91793240789e-06 9 | 25.13274122872 2.21211369532e-05 2.21211369532e-06 10 | 28.27433388231 2.57167144709e-05 2.57167144709e-06 11 | 31.4159265359 2.93938132989e-05 2.93938132989e-06 12 | -------------------------------------------------------------------------------- /examples/Bosonic/G_re: -------------------------------------------------------------------------------- 1 | 0 1.20109669923 0.0001 2 | 3.14159265359 0.0894052697042 0.0001 3 | 6.28318530718 0.0342718849381 0.0001 4 | 9.42477796077 0.0180359804312 0.0001 5 | 12.56637061436 0.0110486842828 0.0001 6 | 15.70796326795 0.00743216921754 0.0001 7 | 18.84955592154 0.00535342835487 0.0001 8 | 21.99114857513 0.00406444901529 0.0001 9 | 25.13274122872 0.00322184873303 0.0001 10 | 28.27433388231 0.00265216383742 0.0001 11 | 31.4159265359 0.00226398836462 0.0001 12 | -------------------------------------------------------------------------------- /examples/Bosonic/bosonic.param: -------------------------------------------------------------------------------- 1 | NORM = 1.20109669923 #the particular normalization for this data 2 | OMEGA_MAX = 40 #Spectral function is larger than default bounds 3 | KERNEL = bosonic #Using bosonic data 4 | BETA = 2.0 #inverse temperature 5 | NFREQ = 1000 #number of output frequencies 6 | NDAT = 22 #number of input data points*2 due to non-PH symmetry 7 | MAX_IT = 4000 #increase maximum iterations for convergence 8 | DATASPACE = frequency #frequency data 9 | PARTICLE_HOLE_SYMMETRY = false #use both real and imag part of input 10 | DATA=dat_in #name of data file 11 | -------------------------------------------------------------------------------- /examples/Bosonic/bosonic_ph.param: -------------------------------------------------------------------------------- 1 | #this param file shows how the same data can be input with PH symmetry 2 | 3 | NORM = 1.20109669923 #the particular normalization for this data 4 | OMEGA_MAX = 40 #Spectral function is larger than default bounds 5 | KERNEL = bosonic #Using bosonic data 6 | BETA = 2.0 #inverse temperature 7 | NFREQ = 1000 #number of output frequencies 8 | NDAT = 11 #!\color{red}actual number of input data points! 9 | MAX_IT = 4000 #increase maximum iterations for convergence 10 | DATASPACE = frequency #frequency data 11 | PARTICLE_HOLE_SYMMETRY = true #!\color{red}PH symmetric data; only real part! 12 | DATA=G_re #name of data file 13 | -------------------------------------------------------------------------------- /examples/Bosonic/dat_in: -------------------------------------------------------------------------------- 1 | 0 1.20109669923 0.0001 -1.27890161453e-15 1.27890161453e-16 2 | 3.14159265359 0.0894052697042 0.0001 4.895943813e-06 4.895943813e-07 3 | 6.28318530718 0.0342718849381 0.0001 7.44279002171e-06 7.44279002171e-07 4 | 9.42477796077 0.0180359804312 0.0001 9.10677686772e-06 9.10677686772e-07 5 | 12.56637061436 0.0110486842828 0.0001 1.139294386e-05 1.139294386e-06 6 | 15.70796326795 0.00743216921754 0.0001 1.36423004018e-05 1.36423004018e-06 7 | 18.84955592154 0.00535342835487 0.0001 1.61398883312e-05 1.61398883312e-06 8 | 21.99114857513 0.00406444901529 0.0001 1.91793240789e-05 1.91793240789e-06 9 | 25.13274122872 0.00322184873303 0.0001 2.21211369532e-05 2.21211369532e-06 10 | 28.27433388231 0.00265216383742 0.0001 2.57167144709e-05 2.57167144709e-06 11 | 31.4159265359 0.00226398836462 0.0001 2.93938132989e-05 2.93938132989e-06 12 | -------------------------------------------------------------------------------- /examples/Input_and_output_format.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CQMP/Maxent/a3992534228b0de732e033ae23154969724814be/examples/Input_and_output_format.pdf -------------------------------------------------------------------------------- /examples/Legendre/Gl.dat: -------------------------------------------------------------------------------- 1 | 0 -0.43821467393467 2.0578273007296e-08 2 | 1 0.012631583637553 2.0389308663417e-08 3 | 2 -0.15880101626593 2.1475723695007e-08 4 | 3 -0.0021898199779289 2.144595608911e-08 5 | 4 -0.053937442255107 2.1023432483349e-08 6 | 5 -0.0034884464591916 2.0669963490111e-08 7 | 6 -0.010667914754631 2.0638330764054e-08 8 | 7 -0.0010144035966938 2.1715632156662e-08 9 | 8 -0.0013816991553527 2.0449776284774e-08 10 | 9 -0.00015788270263516 2.0497439174515e-08 11 | 10 -0.00012295380377475 2.0216610317862e-08 12 | 11 -1.5802339133869e-05 2.0651408026399e-08 13 | 12 -1.1830524273181e-06 2.0895282431275e-08 14 | 13 -3.7670651627124e-07 2.0179725392242e-08 15 | 14 8.2576357612269e-06 2.023807628189e-08 16 | 15 1.1681515124736e-06 2.0075436896289e-08 17 | 16 9.2338152156296e-06 2.1337244313937e-08 18 | 17 1.6660098957297e-06 2.0455323762428e-08 19 | 18 9.571096733186e-06 2.0525643006275e-08 20 | 19 2.1751274445699e-06 1.9971122120451e-08 21 | 20 9.6823009062916e-06 2.0934655315278e-08 22 | 21 2.774966612958e-06 1.9721376852688e-08 23 | 22 9.4829971763366e-06 2.051605027674e-08 24 | 23 3.4392985216378e-06 2.0496158815295e-08 25 | 24 8.7975326011509e-06 2.0915580290457e-08 26 | 25 4.2421276719669e-06 2.0552196057802e-08 27 | 26 7.4223151117582e-06 1.9588775007015e-08 28 | 27 5.1136853713155e-06 2.0938101637207e-08 29 | 28 5.197143682236e-06 1.9205455712255e-08 30 | 29 6.0866451591805e-06 2.0863032752443e-08 31 | 30 1.7643486351135e-06 2.0406745298558e-08 32 | 31 7.1936316056012e-06 2.0626569626578e-08 33 | 32 -3.4525125728594e-06 2.013362969374e-08 34 | 33 8.3956900968729e-06 2.078999995846e-08 35 | 34 -1.081706831946e-05 2.0631065805269e-08 36 | 35 9.709638862432e-06 2.0701050079065e-08 37 | 36 -2.1026397772912e-05 2.0556620802327e-08 38 | 37 1.1009130080412e-05 2.0345587580604e-08 39 | 38 -3.4849774503029e-05 2.0920868900366e-08 40 | 39 1.2556775659249e-05 2.0604397392123e-08 41 | -------------------------------------------------------------------------------- /examples/Legendre/Legendre_example.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CQMP/Maxent/a3992534228b0de732e033ae23154969724814be/examples/Legendre/Legendre_example.pdf -------------------------------------------------------------------------------- /examples/Legendre/in.param: -------------------------------------------------------------------------------- 1 | BETA = 2 #inverse temperature 2 | NDAT = 10 #num of data points 3 | DATASPACE=Legendre #!$G(\ell)$! 4 | KERNEL=fermionic #!\underline{fermionic}! values 5 | DATA=gl.dat #location of data file 6 | PARTICLE_HOLE_SYMMETRY=true #This example has PH symmetry 7 | NFREQ=5000 #increase omega grid for better 8 | #integration and convergence 9 | FREQUENCY_GRID=quadratic #use more points away from origin 10 | N_ALPHA=15 #reduce number alpha search space 11 | -------------------------------------------------------------------------------- /examples/Self Energy/U1/Selfenergy_U1_example.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CQMP/Maxent/a3992534228b0de732e033ae23154969724814be/examples/Self Energy/U1/Selfenergy_U1_example.pdf -------------------------------------------------------------------------------- /examples/Self Energy/U1/in.param: -------------------------------------------------------------------------------- 1 | BETA=2 #inverse temperature 2 | OMEGA_MAX=25 #the spectral function is wider than omega=10 3 | NDAT=1024 #num of data points 4 | NFREQ=1000 #num of output frequencies 5 | DATASPACE=frequency #!$G(i\omega)$! 6 | KERNEL=fermionic #fermionic|bosonic values 7 | FREQUENCY_GRID=Quadratic #this grid is better for features away from 0 8 | PARTICLE_HOLE_SYMMETRY=true #generated at half-filling 9 | DATA="Selfin" #location of data file 10 | SELF=true #this will output !$\Sigma(\omega)$! rather than !$A(\omega)$! 11 | NORM=0.25 #self energy norm = !$U^2\cdot n(1-n)$! 12 | -------------------------------------------------------------------------------- /examples/Self Energy/U10/Selfenergy_U10_example.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CQMP/Maxent/a3992534228b0de732e033ae23154969724814be/examples/Self Energy/U10/Selfenergy_U10_example.pdf -------------------------------------------------------------------------------- /examples/Self Energy/U10/green.param: -------------------------------------------------------------------------------- 1 | BETA=2 #inverse temperature 2 | NDAT=1024 #num of data points 3 | NFREQ=500 #num of output frequencies 4 | DATASPACE=frequency #!$G(i\omega)$! 5 | KERNEL=fermionic #fermionic|bosonic values 6 | FREQUENCY_GRID=Quadratic #this grid is better for features away from the origin 7 | PARTICLE_HOLE_SYMMETRY=true #false|true 8 | DATA="G_im" #location of data file 9 | OMEGA_MAX=20 #bigger !$\omega$! space needed 10 | DEFAULT_MODEL="double Gaussian" #best guess of underlying data structure 11 | SIGMA=0.5 #width of Gaussian 12 | SHIFT=5.5 #shift of Gaussian 13 | -------------------------------------------------------------------------------- /examples/Self Energy/U10/in.param: -------------------------------------------------------------------------------- 1 | BETA=2 #inverse temperature 2 | NDAT=1024 #num of data points 3 | NFREQ=500 #num of output frequencies 4 | DATASPACE=frequency #!$G(i\omega)$! 5 | KERNEL=fermionic #fermionic|bosonic values 6 | FREQUENCY_GRID=Quadratic #this grid is better for features away from 0 7 | PARTICLE_HOLE_SYMMETRY=true #generated at half-filling 8 | DATA="Selfin" #location of data file 9 | SELF=true #this will output an additional !$\Sigma(\omega)$! 10 | NORM=25 #self energy norm = !$U^2\cdot n(1-n)$! 11 | -------------------------------------------------------------------------------- /examples/U0/U0_example.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CQMP/Maxent/a3992534228b0de732e033ae23154969724814be/examples/U0/U0_example.pdf -------------------------------------------------------------------------------- /examples/U0/in.param: -------------------------------------------------------------------------------- 1 | BETA=8 #inverse temperature 2 | NDAT=1024 #num of data points 3 | NFREQ=500 #num of output frequencies 4 | DATASPACE=frequency #!$G(i\omega)$! 5 | KERNEL=fermionic #!\underline{fermionic}!|bosonic values 6 | PARTICLE_HOLE_SYMMETRY=true #generated at half-filling; only use imag part 7 | DATA="G_im" #location of data file 8 | -------------------------------------------------------------------------------- /examples/U2/README.md: -------------------------------------------------------------------------------- 1 | U=2 Example - Non-PH symmetric 2 | ============================== 3 | This is an example that is not Particle-Hole symmetric. These files illustrate the subtle input differences between the other examples and non-symmetric cases. For full details about the output of `Maxent`, please see the other PDFs in the example folder. 4 | 5 | ### Files 6 | **_G_im_** = Im[G] 7 | - Column Format: `iw_n Im[G]_n error_n ` 8 | 9 | **_G_re_** = Re[G] 10 | - Column Format: `iw_n Re[G]_n error_n` 11 | 12 | **_Gomegain_** = Input format of G for `Maxent` 13 | - Column Format: `iwn_n Re[G]_n error_re_n Im[G]_n error_im_n` 14 | 15 | **_G_tau_** = G(tau) 16 | - Column Format `tau_n G(tau)_n error_n` 17 | 18 | **_Selfenergy_** = Sigma, also input format for `Maxent` 19 | - Column Format `iwn_n Re[Sigma] error_r_n Im[Sigma] error_i_n` 20 | 21 | **_frequency.param_** = parameter file for Matsubara frequency data 22 | **_time.param_** = parameter file for time data 23 | **_self.param_** = parameter file for self-energy data 24 | -------------------------------------------------------------------------------- /examples/U2/frequency.param: -------------------------------------------------------------------------------- 1 | BETA=2 #inverse temperature 2 | NDAT=2048 #number of input data points*2 due to non-PH symmetry 3 | NFREQ=500 #num of output frequencies 4 | DATASPACE=frequency #!$G(i\omega)$! 5 | KERNEL=fermionic #fermionic values 6 | PARTICLE_HOLE_SYMMETRY=false #generated away from half-filling 7 | DATA="Gomegain" #location of data file 8 | NORM=.75643 #density is != 1 9 | -------------------------------------------------------------------------------- /examples/U2/self.param: -------------------------------------------------------------------------------- 1 | BETA=2 #inverse temperature 2 | NDAT=2048 #number of input data points*2 due to non-PH symmetry 3 | NFREQ=500 #num of output frequencies 4 | DATASPACE=frequency #!$\Sigma(i\omega)$! 5 | KERNEL=fermionic #fermionic values 6 | PARTICLE_HOLE_SYMMETRY=false #generated away from half-filling 7 | DATA="Selfenergy" #location of data file 8 | SELF=1 #output self-energy file 9 | NORM=.736975 10 | -------------------------------------------------------------------------------- /examples/U2/time.param: -------------------------------------------------------------------------------- 1 | BETA=2 #inverse temperature 2 | NDAT=1024 #num of imag data points 3 | NFREQ=500 #num of output frequencies 4 | DATASPACE=time #!$G(i\tau)$! 5 | KERNEL=fermionic #fermionic values 6 | PARTICLE_HOLE_SYMMETRY=false #generated away from half-filling 7 | DATA="G_tau" #location of data file 8 | -------------------------------------------------------------------------------- /examples/conventions_and_kernels.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CQMP/Maxent/a3992534228b0de732e033ae23154969724814be/examples/conventions_and_kernels.pdf -------------------------------------------------------------------------------- /examples/default_models.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CQMP/Maxent/a3992534228b0de732e033ae23154969724814be/examples/default_models.pdf -------------------------------------------------------------------------------- /examples/grids.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CQMP/Maxent/a3992534228b0de732e033ae23154969724814be/examples/grids.pdf -------------------------------------------------------------------------------- /kk/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8) 2 | 3 | project (kk) 4 | find_package(OpenMP) 5 | if (OPENMP_FOUND) 6 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") 7 | endif() 8 | 9 | # find_package(ALPSCore REQUIRED) # does it use ALPSCore? 10 | set(boost_req program_options) 11 | find_package (Boost 1.54.0 COMPONENTS ${boost_req} REQUIRED) 12 | message(STATUS "Found Boost includes: ${Boost_INCLUDE_DIRS}" ) 13 | message(STATUS "Found Boost libs: ${Boost_LIBRARIES}" ) 14 | 15 | 16 | SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -O3 -DNDEBUG") 17 | 18 | 19 | add_executable(kk kk.cpp ) 20 | target_include_directories(kk PUBLIC ${Boost_INCLUDE_DIRS} ${GSL_INCLUDE_DIRS}) 21 | # target_link_libraries(kk ${ALPSCore_LIBRARIES} ${GSL_LIBRARIES} ${Boost_LIBRARIES}) 22 | target_link_libraries(kk ${GSL_LIBRARIES} ${Boost_LIBRARIES}) 23 | install(TARGETS kk DESTINATION bin) 24 | -------------------------------------------------------------------------------- /kk/README.md: -------------------------------------------------------------------------------- 1 | KramersKronig 2 | ============= 3 | 4 | Kramers Kronig transform code: takes a file (usually from maxent or pade) and evaluates the Kramers Kronig transform. See `kk --help` for more options. 5 | 6 | Format input data as 7 | ```` 8 | x1 y1 9 | x2 y2 10 | ... 11 | ```` 12 | -------------------------------------------------------------------------------- /kk/kk.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 1998-2016 ALPS Collaboration 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License as published by the Free 6 | * Software Foundation; either version 2 of the License, or (at your option) 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but WITHOUT 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12 | * more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 59 16 | * Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | * For use in publications, see ACKNOWLEDGE.TXT 18 | */ 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | //#include 27 | #include 28 | #include 29 | #include 30 | 31 | inline double fun(double omegaprime, double xmin_data, double xmax_data, const gsl_spline *input_spline, gsl_interp_accel *acc){ 32 | if(omegaprime <= xmin_data || omegaprime >= xmax_data) return 0.; 33 | return -1./M_PI*gsl_spline_eval (input_spline, omegaprime, acc); 34 | } 35 | double fun2(double omegaprime, const gsl_spline *input_spline, gsl_interp_accel *acc){ 36 | return gsl_spline_eval (input_spline, omegaprime, acc); 37 | } 38 | inline double fun3(double omegaprime, double omega, double chi2_omega, double xmin_data, double xmax_data, const gsl_spline *input_spline, gsl_interp_accel *acc){ 39 | if(omegaprime==omega) return 0.; 40 | return (fun(omegaprime, xmin_data, xmax_data, input_spline, acc)-chi2_omega)/(omegaprime-omega); 41 | } 42 | 43 | 44 | double integrate(double lower_limit, double upper_limit, double pole_location, double xmin_data, double xmax_data,const gsl_spline *input_spline, gsl_interp_accel *acc){ 45 | //set the global vars 46 | double omega=pole_location; 47 | //chi2_omega = -1./M_PI*Sigma_2(omega) 48 | double chi2_omega=fun(omega, xmin_data, xmax_data, input_spline, acc); 49 | 50 | //compute the offset 51 | double offset=(pole_location<=xmin_data || pole_location >= xmax_data)?0.:chi2_omega*(-log(std::abs((upper_limit-pole_location)/(-pole_location+lower_limit)))); 52 | 53 | 54 | //return values 55 | double result; 56 | int N=100000; 57 | double dx=(upper_limit-lower_limit)/(double)N; 58 | 59 | double I=0.; 60 | int i; 61 | { 62 | I=0.; 63 | omega=pole_location; 64 | for(i=1;i(&input_file_name), "Input file, e.g. Im(Sigma) selfenergy file out of continuation") 120 | ("output_file", po::value(&output_file_name), "Output file, e.g. Re(Sigma) and Im(Sigma)") 121 | ("imag_to_real", "input is imaginary part, produce real part") 122 | ("real_to_imag", "input is real part, produce imaginary part") 123 | ; 124 | po::variables_map vm; 125 | po::store(po::parse_command_line(argc, argv, desc), vm); 126 | po::notify(vm); 127 | 128 | if (vm.count("help")) { 129 | std::cout< xgrid; 152 | std::vector input_data; 153 | std::vector output_xgrid; 154 | std::vector > output_data; 155 | do{ 156 | double x,y; 157 | std::string line; 158 | getline(input_file, line); 159 | if(line.length()!=0){ 160 | std::stringstream sstream(line); 161 | sstream>>x>>y>>std::ws; 162 | xgrid.push_back(x); 163 | input_data.push_back(y); 164 | } 165 | }while(!input_file.eof()); 166 | int N=input_data.size(); 167 | double xmin_data=xgrid[0]; 168 | double xmax_data=xgrid.back(); 169 | 170 | 171 | //interpolate the self energy 172 | gsl_spline *input_spline= gsl_spline_alloc (gsl_interp_cspline, N); 173 | gsl_interp_accel *acc= gsl_interp_accel_alloc (); 174 | gsl_spline_init (input_spline, &(xgrid[0]), &(input_data[0]), N); 175 | 176 | //compute the self energy normalization 177 | double norm=1.; 178 | if(direction_sign==1.){ 179 | norm=integrate_norm(xgrid[0]+1.e-12, xgrid.back()-1.e-12, input_spline, acc); 180 | std::cout<<"integrated norm is: "<1.999999 ?1.e-1:1.e-2)){ 187 | //for(double x=xmin;x1.999999 ?1.e-2:1.e-4)){ 188 | output_xgrid.push_back(x); 189 | } 190 | output_data.resize(output_xgrid.size()); 191 | #pragma omp parallel default(none) firstprivate(output_xgrid, xmin_data, xmax_data, input_spline, xgrid, direction_sign) shared(output_data) 192 | { 193 | gsl_interp_accel *acc= gsl_interp_accel_alloc (); 194 | #pragma omp for 195 | for(std::size_t i=0;i=xgrid.back()?0.:gsl_spline_eval (input_spline, omega, acc); 199 | output_data[i]=std::make_pair(kk_integral, kk_sourceval); 200 | } 201 | } 202 | for(std::size_t i=0;i 90% of the points should be within errorbars, otherwise decrease/increase lmax until a maximum is found 53 | 54 | ## Integration Trouble 55 | One major source of error is the integration of the conversion G(tau)->G(l). To confirm that your data is behaving properly, 56 | the convergence of the tail and low frequency points should be well behaved with and without the tail fix. 57 | Example: 58 | ``` 59 | $ ./legendre_convert --beta 2 --plot_convergence 100 60 | // generate plot 61 | $ ./legendre_convert --beta 2 --plot_convergence 100 --notail 62 | // generate plot 63 | ``` 64 | ![converg_w_tail](https://cloud.githubusercontent.com/assets/7354063/8853103/22c00bbe-3127-11e5-87c7-3a7674cfa3e9.png) 65 | ![converg_wo_tail](https://cloud.githubusercontent.com/assets/7354063/8853105/287b10da-3127-11e5-9d32-f65dbfa6040a.png) 66 | 67 | The high frequency points very quickly gain large errors relying on integration alone. On closer inspection: 68 | 69 | 70 | ![converg_wo_tail2](https://cloud.githubusercontent.com/assets/7354063/8853802/9377a8c8-312a-11e5-8f24-b0efd6f5040b.png) 71 | 72 | 73 | 74 | For lmax between 10 and 20 the conversion procedure seems well behaved. 75 | -------------------------------------------------------------------------------- /pade/pade_arbitrary_degree/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8) 2 | project (pade) 3 | 4 | list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake) 5 | 6 | find_package(ALPSCore REQUIRED COMPONENTS hdf5 accumulators mc params) 7 | find_package (Eigen3 3.1 REQUIRED) 8 | set(boost_req program_options) 9 | find_package (Boost 1.54.0 COMPONENTS ${boost_req} REQUIRED) 10 | message(STATUS "Found Boost includes: ${Boost_INCLUDE_DIRS}" ) 11 | message(STATUS "Found Boost libs: ${Boost_LIBRARIES}" ) 12 | 13 | include_directories(${EIGEN3_INCLUDE_DIR}) 14 | link_directories("/opt/local/lib") 15 | 16 | add_executable(pade pade.cpp pade_grid.cpp pade_real.cpp pade_imag.cpp pade_interpolator.cpp pade_solver.cpp) 17 | target_link_libraries(pade ${ALPSCore_LIBRARIES} gmpxx gmp ${Boost_LIBRARIES}) 18 | install(TARGETS pade DESTINATION bin) 19 | -------------------------------------------------------------------------------- /pade/pade_arbitrary_degree/lu.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 1998-2016 ALPS Collaboration 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License as published by the Free 6 | * Software Foundation; either version 2 of the License, or (at your option) 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but WITHOUT 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12 | * more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 59 16 | * Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | * For use in publications, see ACKNOWLEDGE.TXT 18 | */ 19 | #include 20 | #include 21 | #include 22 | 23 | typedef mpf_class real_t; 24 | typedef alps::numeric::matrix matrix_t; 25 | typedef std::vector vector_t; 26 | 27 | -------------------------------------------------------------------------------- /pade/pade_arbitrary_degree/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 1998-2016 ALPS Collaboration 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License as published by the Free 6 | * Software Foundation; either version 2 of the License, or (at your option) 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but WITHOUT 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12 | * more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 59 16 | * Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | * For use in publications, see ACKNOWLEDGE.TXT 18 | */ 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | void init(std::vector &s, std::vector &f, const int &N){ 25 | s.resize(N); 26 | f.resize(N); 27 | for(int i=0;i &alpha_sx, const std::vector &s, const std::vector &fs, const double &x){ 35 | for(int i=0;i &phi_mu, const std::vector &phi_mu_minus_one, const std::vector &alpha_sx, int mu){ 46 | int N=phi_mu.size(); 47 | //std::cout<<"running : "< &phi_nu, const std::vector &phi_nu_minus_one, const std::vector &alpha_sx, int nu){ 55 | int N=phi_nu.size(); 56 | //std::cout<<"running "< &phi_mu, const std::vector &s, const std::vector &fs, const std::vector &alpha_sx, const double &x, const int &mumax){ 65 | phi_mu=fs; 66 | std::vector phi_mu_minus_one(phi_mu); 67 | for(int mu=1;mu<=mumax;++mu){ 68 | phi_mu.swap(phi_mu_minus_one); 69 | neville_step(phi_mu, phi_mu_minus_one, alpha_sx, mu); 70 | } 71 | std::cout< &phi_nu, const std::vector &s, const std::vector &fs, const std::vector &alpha_sx, const double &x, const int &numax){ 75 | phi_nu=fs; 76 | std::vector phi_nu_minus_one(phi_nu); 77 | for(int nu=1;nu<=numax;++nu){ 78 | phi_nu.swap(phi_nu_minus_one); 79 | inverse_neville_step(phi_nu, phi_nu_minus_one, alpha_sx, nu); 80 | } 81 | std::cout< &phi_mu_nu, const std::vector &s, const std::vector &fs, const std::vector &alpha_sx, const double &x, const int &mumax, const int &numax){ 85 | phi_mu_nu=fs; 86 | std::vector phi_mu_nu_minus_one(phi_mu_nu); 87 | int nu=0; 88 | int mu=0; 89 | 90 | if(numax+mumax+1 != phi_mu_nu.size()) throw std::runtime_error("problem in interpolation: degree of numerator and denominator+1 has to match degree of data."); 91 | 92 | //start by doing a nu-mu inverse neville steps, until 93 | for(int interp_step=1;interp_step<=numax+mumax;++interp_step){ 94 | phi_mu_nu.swap(phi_mu_nu_minus_one); 95 | if(interp_step < numax-mumax+1){ 96 | inverse_neville_step(phi_mu_nu, phi_mu_nu_minus_one, alpha_sx, interp_step); 97 | //std::cout<<"# running inverse step (beginning)"< fs, s; 123 | //initialize function f 124 | init(s,fs, N); 125 | 126 | for(int i=0;i alpha_sx(N); 137 | if(init_alpha(N, alpha_sx, s, fs, x)) continue; 138 | 139 | std::vector phi_mu(N); 140 | pade_scheme(phi_mu, s, fs, alpha_sx, x, 30,31); 141 | } 142 | std::cout< 20 | #include 21 | #include 22 | #include 23 | 24 | #include 25 | #include 26 | typedef mpf_class real_t; 27 | typedef alps::numeric::matrix matrix_t; 28 | typedef std::vector vector_t; 29 | extern "C" void dgesv_(const int *N, const int *NRHS, double *A, const int *LDA, int *IPIV, double *B, const int *LDB, int *INFO); 30 | //void solve(const matrix_t &A, const vector_t &rhs, vector_t &res); 31 | template void solve(const alps::numeric::matrix &A, const std::vector &rhs, std::vector &res); 32 | void init_example1(std::vector &s, std::vector &f, const int &N){ 33 | if(N!=5) throw std::logic_error("this is done for the example in the paper which has N=5"); 34 | s.resize(N); 35 | f.resize(N); 36 | 37 | s[0]=-2; 38 | s[1]=-1; 39 | s[2]= 0; 40 | s[3]= 1; 41 | s[4]= 2; 42 | 43 | f[0]=-2; 44 | f[1]=-1; 45 | f[2]=-1; 46 | f[3]= 0; 47 | f[4]= 1; 48 | } 49 | void init_sin(std::vector &s, std::vector &f, const int &N){ 50 | s.resize(N); 51 | f.resize(N); 52 | 53 | for(int i=0;i &s, const real_t &x0){ 60 | if(j==0) return 1; 61 | real_t omega=1; 62 | for(int i=0;i &s){ 69 | real_t omega=1; 70 | for(int i=0;i<=k;++i){ 71 | if(i==j) continue; 72 | omega*=(s[j]-s[i]); 73 | } 74 | std::cout<<"returning omegaprime k+1 for k: "< &s, int m, int n){ 78 | for(int k=0;k<=m+n;++k){ 79 | for(int j=0;j &rhs, const matrix_t &Vinv, const std::vector &f, int m, int n){ 88 | matrix_t M(n+m,n+m+1, 0.); 89 | //assemble upper half 90 | //std::cout<<"assembling upper half"< &q, const std::vector &f, const std::vector &x, const matrix_t &Vinv, int m, int n, const real_t &x0){ 120 | //evaluate numerator 121 | real_t numerator=f[0]*q[0]; 122 | for(int k=1;k<=m;++k){ 123 | real_t dfq=0.; 124 | for(int i=0;i<=k;++i){ 125 | dfq+=Vinv(k, i)*q[i]*f[i]; 126 | } 127 | numerator+=dfq*compute_omega_j(k, x, x0); 128 | } 129 | 130 | //evaluate denominator 131 | real_t denominator=q[0]; 132 | for(int k=1;k<=n;++k){ 133 | real_t dq=0.; 134 | for(int i=0;i<=k;++i){ 135 | dq+=Vinv(k, i)*q[i]; 136 | } 137 | denominator+=dq*compute_omega_j(k, x, x0); 138 | } 139 | //std::cout<<"numerator: "< void solve(const alps::numeric::matrix &Lambda, const std::vector &rhs, std::vector &res){ 143 | std::cout<<"double precision solver. "< ipiv(size); 148 | alps::numeric::matrix Lambda2(Lambda); 149 | res=rhs; 150 | dgesv_(&size, &one, &(Lambda2(0,0)), &size, &(ipiv[0]), &(res[0]), &size, &info); 151 | } 152 | int main(){ 153 | 154 | //N points on which function is known 155 | int N=512; 156 | int n=255; //degree of denominator 157 | int m=256; //degree of numerator 158 | mpf_set_default_prec(2048); 159 | //function values are f, points of support are x 160 | std::vector s, f; 161 | //initialize function f 162 | //init_example1(s,f, N); 163 | init_sin(s,f, N); 164 | 165 | //compute Vinv: 166 | matrix_t Vinv(m+n+1,m+n+1); 167 | std::cout<<"filling"< rhs(m+n); 172 | std::vector q(m+n+1); 173 | std::cout<<"assembling"< res(rhs.size(), 0.); 177 | 178 | std::cout<<"right hand side: "< 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | typedef mpf_class real_t; 26 | 27 | void init(std::vector &s, std::vector &f, const int &N){ 28 | s.resize(N); 29 | f.resize(N); 30 | for(int i=0;i &alpha_sx, const std::vector &s, const std::vector &fs, const real_t &x){ 38 | for(int i=0;i &phi_mu, const std::vector &phi_mu_minus_one, const std::vector &alpha_sx, int mu){ 49 | int N=phi_mu.size(); 50 | //std::cout<<"running : "< &phi_nu, const std::vector &phi_nu_minus_one, const std::vector &alpha_sx, int nu){ 58 | int N=phi_nu.size(); 59 | //std::cout<<"running "< &phi_mu, const std::vector &s, const std::vector &fs, const std::vector &alpha_sx, const real_t &x, const int &mumax){ 68 | phi_mu=fs; 69 | std::vector phi_mu_minus_one(phi_mu); 70 | for(int mu=1;mu<=mumax;++mu){ 71 | phi_mu.swap(phi_mu_minus_one); 72 | neville_step(phi_mu, phi_mu_minus_one, alpha_sx, mu); 73 | } 74 | std::cout< &phi_nu, const std::vector &s, const std::vector &fs, const std::vector &alpha_sx, const real_t &x, const int &numax){ 78 | phi_nu=fs; 79 | std::vector phi_nu_minus_one(phi_nu); 80 | for(int nu=1;nu<=numax;++nu){ 81 | phi_nu.swap(phi_nu_minus_one); 82 | inverse_neville_step(phi_nu, phi_nu_minus_one, alpha_sx, nu); 83 | } 84 | std::cout< &phi_mu_nu, const std::vector &s, const std::vector &fs, const std::vector &alpha_sx, const real_t &x, const int &mumax, const int &numax){ 88 | phi_mu_nu=fs; 89 | std::vector phi_mu_nu_minus_one(phi_mu_nu); 90 | int nu=0; 91 | int mu=0; 92 | 93 | if(numax+mumax+1 != phi_mu_nu.size()) throw std::runtime_error("problem in interpolation: degree of numerator and denominator+1 has to match degree of data."); 94 | 95 | //start by doing a nu-mu inverse neville steps, until 96 | for(int interp_step=1;interp_step<=numax+mumax;++interp_step){ 97 | phi_mu_nu.swap(phi_mu_nu_minus_one); 98 | if(interp_step < numax-mumax+1){ 99 | inverse_neville_step(phi_mu_nu, phi_mu_nu_minus_one, alpha_sx, interp_step); 100 | //std::cout<<"# running inverse step (beginning)"< fs, s; 127 | //initialize function f 128 | init(s,fs, N); 129 | 130 | for(int i=0;i alpha_sx(N); 141 | if(init_alpha(N, alpha_sx, s, fs, x)) continue; 142 | 143 | std::vector phi_mu(N); 144 | pade_scheme(phi_mu, s, fs, alpha_sx, x, 30,31); 145 | } 146 | std::cout< 22 | #include 23 | #include 24 | #include 25 | #include "alps/params.hpp" 26 | //#include 27 | 28 | typedef std::vector vector_type; 29 | typedef std::vector > complex_vector_type; 30 | 31 | //typedefs: 32 | typedef mpf_class pade_real_type; 33 | typedef std::complex pade_complex_type; 34 | typedef std::vector pade_vector_type; 35 | typedef std::vector pade_complex_vector_type; 36 | 37 | //missing arithmetics 38 | inline bool isnan(pade_complex_type x){ return false;} 39 | inline bool isinf(pade_complex_type x){ return false;} 40 | #ifdef copysign 41 | #undef copysign 42 | #endif 43 | inline pade_real_type copysign(const pade_real_type &a, const pade_real_type &b){ 44 | return sgn(a)==sgn(b)?a:-1*a; 45 | } 46 | inline pade_complex_type operator/(const pade_complex_type &p, const pade_complex_type &q){ 47 | pade_real_type a=p.real(), b=p.imag(), c=q.real(), d=q.imag(); 48 | return std::complex((a*c+b*d)/(c*c+d*d), (b*c-a*d)/(c*c+d*d)); 49 | } 50 | namespace Eigen { 51 | template<> struct NumTraits 52 | : NumTraits // permits to get the epsilon, dummy_precision, lowest, highest functions 53 | { 54 | typedef pade_real_type Real; 55 | typedef pade_complex_type NonInteger; 56 | typedef pade_complex_type Nested; 57 | enum { 58 | IsComplex = 1, 59 | IsInteger = 0, 60 | IsSigned = 1, 61 | RequireInitialization = 1, 62 | ReadCost = 1, 63 | AddCost = 3, 64 | MulCost = 3 65 | }; 66 | }; 67 | } 68 | 69 | typedef Eigen::Matrix pade_complex_matrix_type; 70 | 71 | enum frequency_grid_type{ 72 | lorentzian_grid, 73 | half_lorentzian_grid, 74 | quadratic_grid, 75 | log_grid, 76 | linear_grid 77 | }; 78 | enum imaginary_domain{ 79 | tau, 80 | omegan 81 | }; 82 | 83 | class PadeParams:public alps::params { 84 | public: 85 | PadeParams(){ 86 | define_parameters(); 87 | } 88 | PadeParams(int argc, const char* argv[]):alps::params(argc, argv){ 89 | define_parameters(); 90 | } 91 | 92 | private: 93 | void define_parameters(){ 94 | define("real.NFREQ", "Number of real frequency points"); 95 | define("real.FREQUENCY_GRID", "Type of real frequency grid: Lorentzian, half Lorentzian, quadratic, log, or linear"); 96 | define("real.CUT", 0.01, "Lorentzian cutoff parameter"); 97 | define("real.SPREAD", 4, "Quadratic grid spread parameter"); 98 | define("real.LOG_MIN", 1.0e-4, "Log grid minimum point parameter"); 99 | define("real.OMEGA_MIN", -25, "lowest frequency point"); 100 | define("real.OMEGA_MAX", 25, "highest frequency point"); 101 | define("real.OUTPUT", "output file format"); 102 | 103 | define("imag.NDAT", "number of input frequency points"); 104 | define("imag.BETA", "inverse temperature"); 105 | define("imag.STATISTICS", "Fermi or Bose statistics"); 106 | define("imag.DATA", "text input data file in the format \"freq real imag\""); 107 | define("imag.NEGATIVE_DATA", false, "set to true if data for both pos and neg frequencies"); 108 | 109 | define("pade.PADE_NUMERATOR_DEGREE", "Degree of pade numerator"); 110 | define("pade.PADE_DENOMINATOR_DEGREE", "Degree of pade numerator"); 111 | define("pade.FLOAT_PRECISION", 256, "Precision of floating point arithmetics"); 112 | 113 | if (help_requested(std::cout)) { 114 | exit(0); 115 | } 116 | } 117 | }; 118 | 119 | //this class contains the real frequency discretization. A typical case is a logarithmic grid with many points near zero and few at high frequencies 120 | class grid{ 121 | public: 122 | //constructor 123 | grid(const PadeParams &p); 124 | //grid frequency points 125 | const vector_type &freq() const{ return freq_; } 126 | //delta_freq contains the half the distance between points i-1 and i+1 127 | const vector_type &delta_freq() const{ return delta_freq_; } 128 | //mapping from [0,1] to [omega_min, omega_max] 129 | double omega_of_t(const double t) const { return omega_min_ + (omega_max_-omega_min_)*t; } 130 | //mapping from [omega_min, omega_max] to [0,1] 131 | double t_of_omega(const double omega) const { return (omega-omega_min_)/(omega_max_-omega_min_); } 132 | private: 133 | //construct a grid 134 | void setup_grid(const PadeParams &p); 135 | //number of frequencies 136 | int N_freq_; 137 | //type of the grid 138 | frequency_grid_type grid_type_; 139 | //the integrated relative weight 140 | vector_type t_array_; 141 | //the actual frequency grid 142 | vector_type freq_; 143 | //delta_freq contains the half the distance between points i-1 and i+1 144 | vector_type delta_freq_; 145 | 146 | //the minimum and maximum value of the grid domain 147 | double omega_min_; 148 | double omega_max_; 149 | }; 150 | 151 | class imag_domain_grid{ 152 | public: 153 | imag_domain_grid(const PadeParams &p); 154 | const double &freq(int i) const{return freq_[i];} 155 | const vector_type &freq() const{return freq_;} 156 | private: 157 | //number of frequencies 158 | int N_freq_; 159 | //values of frequencies 160 | vector_type freq_; 161 | //inverse temperature 162 | double T_; 163 | }; 164 | 165 | //this class contains the input raw data which is stored in Matsubara frequency or imaginary time space 166 | class imaginary_domain_data{ 167 | public: 168 | //constructor 169 | imaginary_domain_data(const PadeParams &p); 170 | //get the data of frequency/time i 171 | const std::complex &operator()(int i) const{ return val_[i];} 172 | //number of data points 173 | int N_imag() const{return N_imag_;} 174 | //return normalization of data 175 | double norm() const{return norm_;} 176 | //vector of data values, mutable access 177 | complex_vector_type &val(){return val_;} 178 | //vector of data values, immutable access 179 | const complex_vector_type &val() const {return val_;} 180 | //vector of data x points, immutable access 181 | const vector_type &freq() const {return G_.freq();} 182 | //text i/o function for the input data 183 | void write(const std::string &filename) const; 184 | private: 185 | //Matsubara grid 186 | imag_domain_grid G_; 187 | //Matsubara data 188 | complex_vector_type val_; 189 | //normalization of the spectral function: (target) integral over the real axis of the continued function. 190 | double norm_; 191 | //number of input Matsubara data points. 192 | int N_imag_; 193 | }; 194 | 195 | class real_domain_data{ 196 | public: 197 | //constructor 198 | real_domain_data(const PadeParams &p); 199 | //number of real frequencies 200 | int N_real() const{return N_real_;} 201 | //function values of the continued function, immutable access 202 | const complex_vector_type &val() const{return val_;} 203 | //function values of the continued function, mutable access 204 | complex_vector_type &val() {return val_;} 205 | //evaluation point of the continued function, immutable access 206 | const vector_type &freq() const {return G_.freq();} 207 | 208 | void write(const std::string &filename) const; 209 | private: 210 | const class grid G_; 211 | complex_vector_type val_; //spectral function 212 | //number of real frequency discretization points. 213 | int N_real_; 214 | }; 215 | 216 | class pade_interpolator{ 217 | public: 218 | //constructor 219 | pade_interpolator(const PadeParams &p); 220 | //interpolation routine 221 | void pade_interpolate(const imaginary_domain_data &data, real_domain_data &real) const; 222 | 223 | private: 224 | 225 | //private functions 226 | void find_epsilon(); 227 | //evaluate a rational function in its barycentric form 228 | pade_complex_type evaluate_bary_poly(const pade_complex_vector_type &q, const pade_complex_vector_type &f, const pade_complex_vector_type &x, const pade_complex_matrix_type &Vinv, int m, int n, const pade_complex_type &x0)const; 229 | //see Eq. 3 for omega_j 230 | pade_complex_type compute_omega_j(int j, const pade_complex_vector_type &s, const pade_complex_type &x0)const; 231 | pade_complex_type compute_omegaprime_kp1_of_xj(int k, int j, const pade_complex_vector_type &s) const; 232 | //see Eq. 5 for the inverse of V 233 | void fill_Vinv_matrix(pade_complex_matrix_type &Vinv, const pade_complex_vector_type &s, int m, int n)const; 234 | //see Eq. 9, use q0=1, and build a matrix system 235 | void assemble_matrix_system(pade_complex_matrix_type &Lambda, pade_complex_vector_type &rhs, const pade_complex_matrix_type &Vinv, const pade_complex_vector_type &f, int m, int n)const; 236 | 237 | std::complex to_simple_precision(const std::complex &x) const{ return std::complex(x.real().get_d(),x.imag().get_d()); } 238 | std::complex to_simple_precision(const std::complex &x) const{ return x; } 239 | //private variables: 240 | //polynomial degree (numerator) 241 | int pade_mu_; 242 | //polynomial degree (denominator) 243 | int pade_nu_; 244 | //floating point epsilon 245 | pade_real_type epsilon_; 246 | }; 247 | 248 | class pade_solver{ 249 | public: 250 | pade_solver(){} 251 | void backsub_lower(const pade_complex_matrix_type &Linv, const pade_complex_vector_type &rhs, pade_complex_vector_type &res); 252 | void backsub_upper(const pade_complex_matrix_type &Linv, const pade_complex_vector_type &rhs, pade_complex_vector_type &res); 253 | void solve(const pade_complex_matrix_type &A, const pade_complex_vector_type &rhs, pade_complex_vector_type &res); 254 | }; 255 | -------------------------------------------------------------------------------- /pade/pade_arbitrary_degree/pade_grid.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 1998-2016 ALPS Collaboration 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License as published by the Free 6 | * Software Foundation; either version 2 of the License, or (at your option) 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but WITHOUT 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12 | * more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 59 16 | * Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | * For use in publications, see ACKNOWLEDGE.TXT 18 | */ 19 | 20 | #include "pade.hpp" 21 | #include 22 | 23 | grid::grid(const PadeParams &p){ 24 | N_freq_=p["real.NFREQ"]; 25 | std::cout<<"using a grid size of : "< temp_(N_freq_+1); 42 | if(grid_type_==lorentzian_grid){ 43 | double cut = p["real.CUT"]; 44 | std::cout<<"using Lorentzian grid with CUT parameter: "<(); 111 | std::cout<<"statistics is: "< 22 | 23 | 24 | imaginary_domain_data::imaginary_domain_data(const PadeParams &p):G_(p){ 25 | //if(!p.defined("NORM")){ throw std::runtime_error("normalization parameter NORM missing!"); } 26 | norm_=1.;//p["NORM"]; PADE DOES NOT KNOW HOW TO DEAL WITH NORM! 27 | N_imag_=p["imag.NDAT"]; 28 | val_.resize(N_imag_); 29 | 30 | //our data is defined in a data file. 31 | std::string fname = p["imag.DATA"]; 32 | std::ifstream datstream(fname.c_str()); 33 | if (!datstream) 34 | boost::throw_exception(std::invalid_argument("could not open data file: "+fname)); 35 | std::cout<<"reading column text data as #freq real imag"<> index >> X_i_real >> X_i_imag >> std::ws; 39 | std::cout<<" read: "<(X_i_real, X_i_imag)/norm_; 41 | if(std::abs(G_.freq(i)-index)>1.e-5) throw std::invalid_argument("Grid mismatch. make sure the first entry contains the grid points!!"); 42 | } 43 | } 44 | 45 | void imaginary_domain_data::write(const std::string &s) const{ 46 | std::ofstream file(s.c_str()); 47 | for(int i=0;i 22 | 23 | 24 | pade_interpolator::pade_interpolator(const PadeParams &p){ 25 | pade_mu_=p["pade.PADE_NUMERATOR_DEGREE"]; 26 | pade_nu_=p["pade.PADE_DENOMINATOR_DEGREE"]; 27 | if(pade_mu_+pade_nu_ +1 != p["imag.NDAT"].as()) throw std::runtime_error("Ill defined interpolation: please make sure that numerator degree + denominator degree + 1 = # of data points"); 28 | mpf_set_default_prec(p["pade.FLOAT_PRECISION"]); 29 | find_epsilon(); 30 | } 31 | 32 | 33 | //An implementation of the pade interpolation according to X. Zhu and G. Zhu, J. Comp. and Appl. Math 148, 341 (2002) 34 | void pade_interpolator::pade_interpolate(const imaginary_domain_data &data, real_domain_data &real)const{ 35 | 36 | int N_real=real.N_real(); 37 | int N_imag=data.N_imag(); 38 | 39 | //extract Matsubara frequencies, Matsubara data, and real frequencies 40 | pade_complex_vector_type real_frequencies(N_real); 41 | //pade_complex_vector_type imag_frequencies(N_real); 42 | pade_complex_vector_type matsubara_frequencies(N_imag); 43 | pade_complex_vector_type matsubara_values(N_imag); 44 | for(int i=0;i 22 | 23 | 24 | pade_interpolator::pade_interpolator(const alps::params &p){ 25 | pade_mu_=p["PADE_NUMERATOR_DEGREE"]; 26 | pade_nu_=p["PADE_DENOMINATOR_DEGREE"]; 27 | if(pade_mu_+pade_nu_ +1 != p["NDAT"]) throw std::runtime_error("Ill defined interpolation: please make sure that numerator degree + denominator degree + 1 = # of data points"); 28 | mpf_set_default_prec(p["FLOAT_PRECISION"]|256); 29 | find_epsilon(); 30 | } 31 | 32 | //compute 'alpha' = x - xs (distance of interpolation to grid point). If we find an interpolation point identical to the grid point, there is no need to interpolate and we return true. 33 | std::pair pade_interpolator::init_alpha(int N, pade_complex_vector_type &alpha_sx, const pade_complex_vector_type &s, const pade_complex_type &x)const{ 34 | for(int i=0;i v=init_alpha(N_imag, alpha_sx,matsubara_frequencies, x); 145 | if(v.first){ //tried to evaluate on a point where we know the function 146 | real.val()[i]=to_simple_precision(matsubara_values[v.second]); 147 | continue; 148 | } 149 | 150 | //run neville scheme 151 | #pragma omp critical 152 | std::cerr<<"computing pade for i: "< 22 | 23 | 24 | real_domain_data::real_domain_data(const PadeParams &p):G_(p){ 25 | N_real_=p["real.NFREQ"]; 26 | val_.resize(N_real_); 27 | } 28 | void real_domain_data::write(const std::string &s) const{ 29 | std::ofstream file(s.c_str()); 30 | for(int i=0;i 22 | 23 | 24 | void pade_solver::backsub_lower(const pade_complex_matrix_type &Linv, const pade_complex_vector_type &rhs, pade_complex_vector_type &res){ 25 | int N=Linv.rows(); 26 | for(int i=0;i=0;--i){ 37 | pade_complex_type tmp(0.,0.); 38 | for(int j=i+1;j pivot(N); for(int i=0;ip){ 60 | p=abs(U(i,k)); 61 | kprime=i; 62 | } 63 | } 64 | if(p==0.) throw std::runtime_error("encountered singular matrix!"); 65 | if(k != kprime){ 66 | 67 | std::swap(pivot[k],pivot[kprime]); 68 | for(int i=k;i") 31 | exit(1) 32 | 33 | # Check we have one argument 34 | if len(sys.argv) != 2: 35 | printUsage() 36 | module = sys.argv[1] 37 | 38 | # Make sure we are at the top of the repository 39 | location = os.path.dirname(os.path.realpath(sys.argv[0])) 40 | os.chdir(location) 41 | os.chdir("..") 42 | 43 | # Read header 44 | headerFile = "HEADER.TXT" 45 | cFileHeader = notice.readHeader(headerFile) 46 | 47 | # Crawl all cpp, hpp and h files 48 | # Be careful to avoid the optimization of logical expressions 49 | matches = crawlDirectory(module, "*.cpp", cFileHeader) 50 | matches = crawlDirectory(module, "*.hpp", cFileHeader) and matches 51 | matches = crawlDirectory(module, "*.h", cFileHeader) and matches 52 | matches = crawlDirectory(module, "*.h.in", cFileHeader) and matches 53 | 54 | if (not matches): 55 | exit(1) 56 | -------------------------------------------------------------------------------- /scripts/fix-module-copyright-notice.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | import os 4 | import sys 5 | import fnmatch 6 | import notice 7 | 8 | def writeHeader(f, header): 9 | for line in header: 10 | f.write(line) 11 | 12 | def fixFile(filename, header): 13 | with open(filename, "r") as f: 14 | input = f.readlines() 15 | with open(filename, "w") as f: 16 | noticeDone = False 17 | blockNotice = False 18 | lineNotice = False 19 | writeHeader(f, header) 20 | for line in input: 21 | if (not noticeDone): 22 | if (blockNotice): 23 | if "*/" in line: 24 | noticeDone = True 25 | elif (lineNotice): 26 | if not line.startswith("//"): 27 | noticeDone = True 28 | f.write(line) 29 | else: 30 | if (line.startswith("//")): 31 | lineNotice = True 32 | elif (line.startswith("/*")): 33 | blockNotice = True 34 | else: 35 | noticeDone = True 36 | f.write(line) 37 | else: 38 | f.write(line) 39 | 40 | def crawlDirectory(root, filter, header): 41 | for dirpath, dirnames, filenames in os.walk(root): 42 | for filename in fnmatch.filter(filenames, filter): 43 | absFilename = os.path.join(dirpath, filename) 44 | fixFile(absFilename, header) 45 | 46 | def printUsage(): 47 | print("fix-module-copyright-notice.py ") 48 | exit(1) 49 | 50 | # Check we have one argument 51 | if len(sys.argv) != 2: 52 | printUsage() 53 | module = sys.argv[1] 54 | 55 | # Make sure we are at the top of the repository 56 | location = os.path.dirname(os.path.realpath(sys.argv[0])) 57 | os.chdir(location) 58 | os.chdir("..") 59 | 60 | # Read header 61 | headerFile = "HEADER.TXT" 62 | cFileHeader = notice.readHeader(headerFile) 63 | 64 | crawlDirectory(module, "*.cpp", cFileHeader) 65 | crawlDirectory(module, "*.hpp", cFileHeader) 66 | crawlDirectory(module, "*.h", cFileHeader) 67 | crawlDirectory(module, "*.h.in", cFileHeader) 68 | 69 | 70 | -------------------------------------------------------------------------------- /scripts/notice.py: -------------------------------------------------------------------------------- 1 | # Reades the header from the header file 2 | def readHeader(headerFile): 3 | cFileHeader = ["/*\n"] 4 | with open(headerFile) as f: 5 | for line in f: 6 | cFileHeader.append(" * " + line) 7 | cFileHeader.append(" */\n") 8 | return cFileHeader 9 | -------------------------------------------------------------------------------- /src/default_model.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 1998-2018 ALPS Collaboration. 3 | * All rights reserved. Use is subject to license terms. See LICENSE.TXT 4 | * For use in publications, see ACKNOWLEDGE.TXT 5 | */ 6 | 7 | #include "default_model.hpp" 8 | #include 9 | #include 10 | 11 | 12 | 13 | ///This class deals with tabulated model functions 14 | TabFunction::TabFunction(const alps::params& p, std::string const& name){ 15 | std::string p_name = p[name].as(); 16 | std::ifstream defstream(p_name.c_str()); 17 | if (!defstream) 18 | boost::throw_exception(std::invalid_argument("could not open default model file: "+p[name].as())); 19 | double om, D; 20 | std::string line; 21 | while (getline(defstream, line)) { 22 | if(line.size()>0 && line[0]=='#') continue; 23 | std::stringstream linestream(line); 24 | linestream>>om>>D; 25 | Omega_.push_back(om); 26 | Def_.push_back(D); 27 | } 28 | double omega_max = p["OMEGA_MAX"]; 29 | double omega_min = p.exists("OMEGA_MIN") ? p["OMEGA_MIN"] : -omega_max; //we had a 0 here in the bosonic case. That's not a good idea if you're continuing symmetric functions like chi(omega)/omega. Change omega_min to zero manually if you need it. 30 | if(Omega_[0]>omega_min || Omega_.back() Omega_.back()) 43 | return 0.; 44 | //if we happen to exactly hit the first or last point 45 | if(omega == Omega_[0]) 46 | return Def_[0]; 47 | if(omega == Omega_.back()) 48 | return Def_.back(); 49 | 50 | //otherwise linear interpolation 51 | std::vector::const_iterator ub = std::upper_bound(Omega_.begin(), Omega_.end(), omega); 52 | int index = ub - Omega_.begin(); 53 | 54 | double om1 = Omega_[index-1]; 55 | double om2 = Omega_[index]; 56 | double D1 = Def_[index-1]; 57 | double D2 = Def_[index]; 58 | return -(D2-D1)/(om2-om1)*(om2-omega)+D2; 59 | } 60 | 61 | 62 | GeneralDefaultModel::GeneralDefaultModel(const alps::params& p, boost::shared_ptr mod) 63 | : DefaultModel(p) 64 | , Mod(mod) 65 | , ntab(5001) 66 | , xtab(ntab) { 67 | double sum = norm(); 68 | for (int o=0; o1. || x<0.) 77 | throw std::logic_error("parameter x is out of bounds!"); 78 | std::vector::const_iterator ub = std::upper_bound(xtab.begin(), xtab.end(), x); 79 | int omega_index = ub - xtab.begin(); 80 | if (ub==xtab.end()) 81 | omega_index = xtab.end() - xtab.begin() - 1; 82 | double om1 = omega_min + (omega_index-1)*(omega_max-omega_min)/(ntab-1); 83 | double om2 = omega_min + omega_index*(omega_max-omega_min)/(ntab-1); 84 | double x1 = xtab[omega_index-1]; 85 | double x2 = xtab[omega_index]; 86 | return -(om2-om1)/(x2-x1)*(x2-x)+om2; 87 | } 88 | 89 | /// returns the value of the model function at frequency omega 90 | double GeneralDefaultModel::D(const double omega) const { 91 | return (*Mod)(omega); 92 | } 93 | 94 | //I have no idea what this does. 95 | double GeneralDefaultModel::x(const double t) const { 96 | if(t>1. || t<0.) throw std::logic_error("parameter t is out of bounds!"); 97 | int od = (int)(t*(ntab-1)); 98 | if (od==(ntab-1)) 99 | return 1.; 100 | double x1 = xtab[od]; 101 | double x2 = xtab[od+1]; 102 | return -(x2-x1)*(od+1-t*ntab)+x2; 103 | } 104 | 105 | double GeneralDefaultModel::norm() { 106 | double sum = 0; 107 | xtab[0] = 0.; 108 | //this is an evaluation on an equidistant grid; sum integrated by trapezoidal rule 109 | double delta_omega = (omega_max - omega_min) / (ntab - 1); 110 | for (int o = 1; o < ntab; ++o) { 111 | double omega1 = omega_min + (o - 1) * delta_omega; 112 | double omega2 = omega_min + o * delta_omega; 113 | sum += ((*Mod)(omega1) + (*Mod)(omega2)) / 2. * delta_omega; 114 | xtab[o] = sum; 115 | } 116 | return sum; 117 | } 118 | 119 | boost::shared_ptr make_default_model(const alps::params& parms, std::string const& name){ 120 | std::string p_name = parms[name].as(); 121 | boost::to_lower(p_name); 122 | if (p_name == "flat") { 123 | std::cout << "Using flat default model" << std::endl; 124 | return boost::shared_ptr(new FlatDefaultModel(parms)); 125 | } 126 | else if (p_name == "gaussian") { 127 | std::cout << "Using Gaussian default model" << std::endl; 128 | boost::shared_ptr Mod(new Gaussian(parms)); 129 | return boost::shared_ptr(new GeneralDefaultModel(parms, Mod)); 130 | } 131 | else if (p_name == "twogaussians" || p_name == "two gaussians") { 132 | std::cout << "Using sum of two Gaussians default model" << std::endl; 133 | boost::shared_ptr Mod(new TwoGaussians(parms)); 134 | return boost::shared_ptr(new GeneralDefaultModel(parms, Mod)); 135 | } 136 | else if (p_name == "shifted gaussian" || p_name == "shiftedgaussian") { 137 | std::cout << "Using shifted Gaussian default model" << std::endl; 138 | boost::shared_ptr Mod(new ShiftedGaussian(parms)); 139 | return boost::shared_ptr(new GeneralDefaultModel(parms, Mod)); 140 | } 141 | else if (p_name == "double gaussian" || p_name == "doublegaussian") { 142 | std::cout << "Using double Gaussian default model" << std::endl; 143 | boost::shared_ptr Mod(new DoubleGaussian(parms)); 144 | return boost::shared_ptr(new GeneralDefaultModel(parms, Mod)); 145 | } 146 | else if (p_name == "general double gaussian" || p_name == "generaldoublegaussian") { 147 | std::cout << "Using general double Gaussian default model" << std::endl; 148 | boost::shared_ptr Mod(new GeneralDoubleGaussian(parms)); 149 | return boost::shared_ptr(new GeneralDefaultModel(parms, Mod)); 150 | } 151 | else if (p_name == "linear rise exp decay" || p_name == "linearriseexpdecay") { 152 | std::cout << "Using linear rise exponential decay default model" << std::endl; 153 | boost::shared_ptr Mod(new LinearRiseExpDecay(parms)); 154 | return boost::shared_ptr(new GeneralDefaultModel(parms, Mod)); 155 | } 156 | else if (p_name == "quadratic rise exp decay" || p_name == "quadraticriseexpdecay") { 157 | std::cout << "Using quadratic rise exponential decay default model" << std::endl; 158 | boost::shared_ptr Mod(new QuadraticRiseExpDecay(parms)); 159 | return boost::shared_ptr(new GeneralDefaultModel(parms, Mod)); 160 | } 161 | else if (p_name == "lorentzian") { 162 | std::cout << "Using Lorentzian default model" << std::endl; 163 | boost::shared_ptr Mod(new Lorentzian(parms)); 164 | return boost::shared_ptr(new GeneralDefaultModel(parms, Mod)); 165 | } 166 | else if (p_name == "twolorentzians" || p_name == "two lorentzians") { 167 | std::cout << "Using sum of two Lorentzians default model" << std::endl; 168 | boost::shared_ptr Mod(new TwoLorentzians(parms)); 169 | return boost::shared_ptr(new GeneralDefaultModel(parms, Mod)); 170 | } 171 | else if (p_name == "shifted lorentzian" || p_name == "shiftedlorentzian") { 172 | std::cout << "Using shifted Lorentzian default model" << std::endl; 173 | boost::shared_ptr Mod(new ShiftedLorentzian(parms)); 174 | return boost::shared_ptr(new GeneralDefaultModel(parms, Mod)); 175 | } 176 | else if (p_name == "double lorentzian" || p_name == "doublelorentzian") { 177 | std::cout << "Using double Lorentzian default model" << std::endl; 178 | boost::shared_ptr Mod(new DoubleLorentzian(parms)); 179 | return boost::shared_ptr(new GeneralDefaultModel(parms, Mod)); 180 | } 181 | else { 182 | std::cout << "Using tabulated default model" << std::endl; 183 | boost::shared_ptr Mod(new TabFunction(parms, name)); 184 | return boost::shared_ptr(new GeneralDefaultModel(parms, Mod)); 185 | } 186 | } 187 | 188 | 189 | 190 | -------------------------------------------------------------------------------- /src/default_model.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 1998-2018 ALPS Collaboration. 3 | * All rights reserved. Use is subject to license terms. See LICENSE.TXT 4 | * For use in publications, see ACKNOWLEDGE.TXT 5 | */ 6 | 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | 16 | //Note the slightly crooked structure here: 17 | 18 | //class DefaultModel 19 | // -> FlatDefaultModel : public DefaultModel 20 | // -> GeneralDefaultModel : public DefaultModel 21 | // and GeneralDefaultModel contains a 'Model' object. 22 | 23 | //class Model 24 | // -> Gaussian : public Model 25 | // -> ShiftedGaussian : public Gaussian 26 | // -> DoubleGaussian : public ShiftedGaussian 27 | // -> GeneralDoubleGaussian : public ShiftedGaussian 28 | // -> TabFunction : public Model 29 | // -> LinearRiseExpDecay : public Model 30 | // -> QuadraticRiseExpDecay : public Model 31 | 32 | class DefaultModel 33 | { 34 | public: 35 | DefaultModel(const alps::params& p) : 36 | omega_max(p["OMEGA_MAX"]), 37 | omega_min( p.exists("OMEGA_MIN") ? p["OMEGA_MIN"] : -omega_max){ //we had a 0 here in the bosonic case. That's not a good idea if you're continuing symmetric functions like chi(omega)/omega. Change omega_min to zero manually if you need it. 38 | } 39 | 40 | virtual ~DefaultModel(){} 41 | 42 | ///omega returns a frequency point, given x between 0 and 1. 43 | virtual double omega(const double x) const = 0; 44 | 45 | ///D returns the derivative of the integrated default model 46 | virtual double D(const double omega) const = 0; 47 | 48 | ///returns the integrated default model 49 | virtual double x(const double t=0) const = 0; 50 | 51 | ///equidistant mapping from [0,1] to [omega_min, omega_max] 52 | double omega_of_t(const double t) const { return omega_min + (omega_max-omega_min)*t; } 53 | 54 | ///equidistant mapping from [omega_min, omega_max] to [0,1] 55 | double t_of_omega(const double omega) const { return (omega-omega_min)/(omega_max-omega_min); } 56 | 57 | protected: 58 | ///highest frequency of grid 59 | const double omega_max; 60 | ///lowest frequency of grid 61 | const double omega_min; 62 | }; 63 | 64 | 65 | 66 | class FlatDefaultModel : public DefaultModel 67 | { 68 | public: 69 | 70 | ///construct a default model that is constant (value 1/(omega_max-omega_min) ) everywhere 71 | FlatDefaultModel(const alps::params& p) : DefaultModel(p) {} 72 | 73 | double omega(const double x) const { 74 | return x*(omega_max-omega_min) + omega_min; 75 | } 76 | 77 | double D(const double) const { 78 | return 1./(omega_max-omega_min); 79 | } 80 | 81 | double x(const double t) const { 82 | return t; 83 | } 84 | 85 | }; 86 | 87 | 88 | ///general class for a model function. Implements operator() which, given a frequency omega, will give back the value of the default model at that frequency. 89 | class Model 90 | { 91 | public: 92 | virtual double operator()(const double omega)=0; 93 | virtual ~Model(){} 94 | }; 95 | 96 | 97 | ///a model function that implements a Gaussian, i.e. 98 | /// \f$D(\omega)= \frac{1}{\sqrt{2\pi}\sigma}e^{-\frac{\omega^2}{2\sigma^2}} \f$. 99 | /// 100 | /// \f$\sigma\f$ has to be specified as a parameter SIGMA. 101 | /// This is one of the standard model functions you should always try. 102 | class Gaussian : public Model 103 | { 104 | public: 105 | Gaussian(const alps::params& p) : sigma_(static_cast(p["SIGMA"])) {} 106 | 107 | virtual double operator()(const double omega) { 108 | return std::exp(-omega*omega/2./sigma_/sigma_)/sqrt(2*M_PI)/sigma_; 109 | } 110 | 111 | private: 112 | const double sigma_; 113 | }; 114 | 115 | ///a model function that implements two Gaussians with arbitrary relative norms and arbitrary points around which they are centered. 116 | /// 117 | /// \f$\sigma\f$ has to be specified as a parameter SIGMA1 and SIGMA2 for the two gaussians. 118 | /// shift has to be defined as SHIFT1 and SHIFT2 for each Gaussian. 119 | /// NORM1 has to be defined to specify the relative weight of the two spectral functions. 120 | /// 121 | /// \f$D(\omega)=\frac{norm1}{\sqrt{2\pi}\sigma1}e^{-\frac{(\omega-shift1)^2}{2\sigma1^2}}+ \frac{(1-norm1)}{\sqrt{2\pi}\sigma2}e^{-\frac{(\omega-shift2)^2}{2\sigma2^2}}\f$ 122 | 123 | class TwoGaussians : public Model 124 | { 125 | public: 126 | TwoGaussians(const alps::params& p) : sigma1(static_cast(p["SIGMA1"])), 127 | sigma2(p["SIGMA2"].as()), 128 | shift1(p["SHIFT1"].as()), //0.0 129 | shift2(p["SHIFT2"].as()), 130 | norm1(p["NORM1"].as()) {} //0.5 131 | 132 | virtual double operator()(const double omega) { 133 | return norm1*std::exp(-(omega-shift1)*(omega-shift1)/2./sigma1/sigma1)/sqrt(2*M_PI)/sigma1+(1.0-norm1)*std::exp(-(omega-shift2)*(omega-shift2)/2./sigma2/sigma2)/sqrt(2*M_PI)/sigma2; 134 | } 135 | 136 | private: 137 | const double sigma1,sigma2,shift1,shift2,norm1; 138 | }; 139 | 140 | 141 | ///a model function that implements a Gaussian that is not centered at zero but at some other frequency, i.e. 142 | /// \f$D(\omega)= \frac{1}{\sqrt{2\pi}\sigma}e^{-\frac{(\omega-shift)^2}{2\sigma^2}} \f$. 143 | /// 144 | /// \f$\sigma\f$ has to be specified as a parameter SIGMA, and shift has to be specified as parameter SHIFT. 145 | class ShiftedGaussian : public Gaussian 146 | { 147 | public: 148 | ShiftedGaussian(const alps::params& p) : 149 | Gaussian(p), shift_(static_cast(p["SHIFT"])){} 150 | 151 | double operator()(const double omega) { 152 | return Gaussian::operator()(omega-shift_); 153 | } 154 | 155 | protected: 156 | const double shift_; 157 | }; 158 | 159 | 160 | ///a model function that implements a sum of two Gaussians, each of them shifted by +/- shift. 161 | /// \f$D(\omega)=\frac{1}{2} \left( \frac{1}{\sqrt{2\pi}\sigma}e^{-\frac{(\omega-shift)^2}{2\sigma^2}}+ \frac{1}{\sqrt{2\pi}\sigma}e^{-\frac{(\omega+shift)^2}{2\sigma^2}}\right)\f$ 162 | /// \f$\sigma\f$ has to be specified as a parameter SIGMA, and \f$shift\f$ has to be specified as parameter SHIFT. 163 | /// Try this to try to model a system with 'side peaks'. 164 | class DoubleGaussian : public ShiftedGaussian 165 | { 166 | public: 167 | DoubleGaussian(const alps::params& p) : 168 | ShiftedGaussian(p){} 169 | 170 | double operator()(const double omega) { 171 | return 0.5*(Gaussian::operator()(omega-shift_) + Gaussian::operator()(omega+shift_)); 172 | } 173 | }; 174 | ///a model function that implements a Lorentzian, i.e. 175 | /// \f$D(\omega)=\dfrac{1}{\pi\gamma\left[1+\left(\frac{\omega}{\gamma}\right)^{2}\right]}\f$ 176 | /// 177 | /// \f$\gamma\f$ is specified as a parameter GAMMA 178 | /// This is another helpful function to try if the Gaussian decays too quickly 179 | class Lorentzian : public Model 180 | { 181 | public: 182 | Lorentzian(const alps::params& p): gamma_(static_cast(p["GAMMA"])) {} 183 | 184 | virtual double operator()(const double omega){ 185 | return 1/(M_PI*gamma_) * 1.0/(1+(omega/gamma_)*(omega/gamma_)); 186 | } 187 | private: 188 | const double gamma_; 189 | }; 190 | 191 | ///a model function that implements a Lorentzian centered at some SHIFT, i.e. 192 | /// \f$D(\omega)=\dfrac{1}{\pi\gamma\left[1+\left(\frac{\omega-shift}{\gamma}\right)^{2}\right]}\f$ 193 | /// 194 | /// \f$\gamma\f$ is specified as a parameter GAMMA, and shift has to be specified as parameter SHIFT 195 | class ShiftedLorentzian : public Lorentzian 196 | { 197 | public: 198 | ShiftedLorentzian(const alps::params& p): 199 | Lorentzian(p), shift_(static_cast(p["SHIFT"])) {} 200 | 201 | double operator()(const double omega){ 202 | return Lorentzian::operator()(omega-shift_); 203 | } 204 | protected: 205 | const double shift_; 206 | }; 207 | 208 | ///a model function that implements two Lorentzians with arbitrary relative norms and arbitrary points around which they are centered. 209 | /// 210 | /// \f$\gamma\f$ has to be specified as a parameter GAMMA1 and GAMMA2 for the two Lorentzians. 211 | /// shift has to be defined as SHIFT1 and SHIFT2 for each Lorentzian. 212 | /// 213 | /// \f$2D(\omega)=\dfrac{1}{\pi\gamma_{1}\left[1+\left(\frac{\omega-shift1}{\gamma_{1}}\right)^{2}\right]}+\dfrac{1}{\pi\gamma_{2}\left[1+\left(\frac{\omega-shift2}{\gamma_{2}}\right)^{2}\right]}\f$ 214 | 215 | class TwoLorentzians : public Model 216 | { 217 | public: 218 | TwoLorentzians(const alps::params& p) : gamma1_(static_cast(p["GAMMA1"])), 219 | gamma2_(static_cast(p["GAMMA2"])), 220 | shift1(static_cast(p["SHIFT1"])), //0.0 221 | shift2(static_cast(p["SHIFT2"])) {} 222 | 223 | virtual double operator()(const double omega) { 224 | return 1.0/(2*M_PI*gamma1_) * 1.0/(1+((omega-shift1)*(omega-shift1)/gamma1_/gamma1_))+1.0/(2*M_PI*gamma2_) * 1.0/(1+((omega-shift2)*(omega-shift2)/gamma2_/gamma2_)); 225 | } 226 | 227 | private: 228 | const double gamma1_,gamma2_,shift1,shift2; 229 | }; 230 | 231 | 232 | ///a model function that implements a sum of two Lorentzians, each of them shifted by +/- shift. 233 | /// \f$2D(\omega)=\dfrac{1}{\pi\gamma\left[1+\left(\frac{\omega-shift}{\gamma}\right)^{2}\right]}+\dfrac{1}{\pi\gamma\left[1+\left(\frac{\omega+shift}{\gamma}\right)^{2}\right]}\f$ 234 | /// \f$\gamma\f$ has to be specified as a parameter GAMMA, and \f$shift\f$ has to be specified as parameter SHIFT. 235 | /// Try this to try to model a system with 'side peaks', along with DoubleGaussian 236 | class DoubleLorentzian : public ShiftedLorentzian 237 | { 238 | public: 239 | DoubleLorentzian(const alps::params& p) : 240 | ShiftedLorentzian(p){} 241 | 242 | double operator()(const double omega) { 243 | return 0.5*(Lorentzian::operator()(omega-shift_) + Lorentzian::operator()(omega+shift_)); 244 | } 245 | }; 246 | 247 | class LinearRiseExpDecay : public Model{ 248 | public: 249 | LinearRiseExpDecay(const alps::params &p): lambda_(p["LAMBDA"]){} 250 | double operator()(const double omega) { 251 | return lambda_*lambda_*omega*std::exp(-lambda_*omega); 252 | } 253 | 254 | private: 255 | const double lambda_; 256 | }; 257 | 258 | class QuadraticRiseExpDecay : public Model{ 259 | public: 260 | QuadraticRiseExpDecay(const alps::params &p): lambda_(p["LAMBDA"]){} 261 | double operator()(const double omega) { 262 | return (lambda_*lambda_*lambda_)/2.*(omega*omega)*std::exp(-lambda_*omega); 263 | } 264 | 265 | private: 266 | const double lambda_; 267 | }; 268 | 269 | class GeneralDoubleGaussian : public ShiftedGaussian 270 | { 271 | public: 272 | GeneralDoubleGaussian(const alps::params& p) : 273 | ShiftedGaussian(p), bnorm_(static_cast(p["BOSE_NORM"])) {} 274 | 275 | double operator()(const double omega) { 276 | if (omega > 0) 277 | return Gaussian::operator()(omega); 278 | else 279 | return bnorm_*Gaussian::operator()(omega+shift_); 280 | } 281 | 282 | private: 283 | const double bnorm_; 284 | }; 285 | 286 | ///This class deals with tabulated model functions 287 | class TabFunction : public Model 288 | { 289 | public: 290 | ///constructor will read in a default model from a file. File format is: 291 | /// First column: frequency 292 | /// Second column: value of default model 293 | /// anything after that: ignored. 294 | TabFunction(const alps::params& p, std::string const& name); 295 | 296 | ///return value of default model. If INSIDE interval we have data in: return linearly interpolated data. Otherwise: return zero. 297 | double operator()(const double omega); 298 | 299 | private: 300 | ///private variable to store the frequency grid 301 | std::vector Omega_; 302 | ///private variable to store the tabulated value of the default model at a frequency belonging to Omega_ 303 | std::vector Def_; 304 | }; 305 | 306 | 307 | 308 | class GeneralDefaultModel : public DefaultModel 309 | { 310 | public: 311 | 312 | GeneralDefaultModel(const alps::params& p, boost::shared_ptr mod); 313 | 314 | ///given a number x between 0 and 1, find the frequency omega belonging to x. 315 | double omega(const double x) const; 316 | 317 | ///D returns the derivative of the integrated default model 318 | ///i.e. just the value of the model function at frequency omega 319 | double D(const double omega) const; 320 | 321 | ///returns the integrated default model 322 | double x(const double t) const; 323 | 324 | private: 325 | boost::shared_ptr Mod; 326 | const int ntab; 327 | std::vector xtab; //xtab has an equidistantly tabulated discretized model function 328 | 329 | double norm(); 330 | }; 331 | 332 | 333 | 334 | boost::shared_ptr make_default_model(const alps::params& parms, std::string const& name); 335 | -------------------------------------------------------------------------------- /src/eigen_hdf5.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 1998-2018 ALPS Collaboration. 3 | * All rights reserved. Use is subject to license terms. See LICENSE.TXT 4 | * For use in publications, see ACKNOWLEDGE.TXT 5 | */ 6 | 7 | #pragma once 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | //TODO: make a complete implementation of Eigen::vector and Eigen::Matrix 14 | namespace alps { 15 | namespace hdf5 { 16 | template<> struct is_continuous 17 | : public is_continuous 18 | {}; 19 | template<> struct is_continuous 20 | : public is_continuous 21 | {}; 22 | namespace detail { 23 | template<> struct get_extent { 24 | static std::vector apply(Eigen::VectorXd const & value) { 25 | using alps::hdf5::get_extent; 26 | std::vector result(1, value.size()); 27 | if (value.size()) { 28 | std::vector first(get_extent(value[0])); 29 | if (true) 30 | for(std::size_t i=1;i size(get_extent(value[i])); 32 | if ( 33 | first.size() != size.size() 34 | || !std::equal(first.begin(), first.end(), size.begin()) 35 | ) 36 | throw archive_error("no rectangular matrix" + ALPS_STACKTRACE); 37 | } 38 | std::copy(first.begin(), first.end(), std::back_inserter(result)); 39 | } 40 | return result; 41 | } 42 | }; 43 | } 44 | void save( 45 | archive &ar 46 | , std::string const & path 47 | , Eigen::VectorXd &value 48 | , std::vector size = std::vector() 49 | , std::vector chunk =std::vector() 50 | , std::vector offset = std::vector() 51 | ) { 52 | using alps::cast; 53 | if (ar.is_group(path)) 54 | ar.delete_group(path); 55 | if (is_continuous::value && value.size() == 0) 56 | ar.write(path, static_cast(NULL), std::vector()); 57 | else if (is_continuous::value) { 58 | std::vector extent(get_extent(value)); 59 | std::copy(extent.begin(), extent.end(), std::back_inserter(size)); 60 | std::copy(extent.begin(), extent.end(), std::back_inserter(chunk)); 61 | std::fill_n(std::back_inserter(offset), extent.size(), 0); 62 | ar.write(path, value.data(), size, chunk, offset); 63 | 64 | } else if (value.size() == 0) 65 | ar.write(path, static_cast(NULL), std::vector()); 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/eigen_lapack.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 1998-2018 ALPS Collaboration. 3 | * All rights reserved. Use is subject to license terms. See LICENSE.TXT 4 | * For use in publications, see ACKNOWLEDGE.TXT 5 | */ 6 | #pragma once 7 | 8 | #ifdef HAVE_LAPACK 9 | extern "C" void dgesvd_( const char* jobu, const char* jobvt, 10 | const int* m, const int* n, double* a, const int* lda, 11 | double* s, double* u, const int* ldu, 12 | double* vt, const int* ldvt, 13 | double* work, const int* lwork, int* info); 14 | 15 | ///performs a SVD on input matrix K 16 | /// returns K = U (S) V^T where S is a vector of the diagonal values of 17 | /// matrix Sigma 18 | void lapack_svd(matrix_type &K, vector_type &S, matrix_type &Vt, matrix_type &U){ 19 | 20 | /*boost::numeric::bindings::lapack::gesvd('S', 'S', Kt, S, U_, Vt_);*/ 21 | //use 'S' for thin U,Vt matrices 22 | char jobu = 'S'; 23 | char jobvt = 'S'; 24 | int m = K.rows(); 25 | int n = K.cols(); 26 | double *a = K.data(); 27 | int lda = K.outerStride(); 28 | int ldu = U.outerStride(); 29 | int ldvt = Vt.outerStride(); 30 | 31 | double *vt = Vt.data(); 32 | double *u = U.data(); 33 | double *s =S.data(); 34 | 35 | double dummywork; 36 | int LWORK=-1; 37 | int INFO=0; 38 | //get best workspace 39 | dgesvd_(&jobu,&jobvt,&m,&n,a,&lda,s,u,&ldu,vt,&ldvt,&dummywork,&LWORK,&INFO); 40 | 41 | LWORK=int(dummywork)+32; 42 | vector_type WORK(LWORK); 43 | 44 | dgesvd_(&jobu,&jobvt,&m,&n,a,&lda,s,u,&ldu,vt,&ldvt,WORK.data(),&LWORK,&INFO); 45 | if(INFO!=0) 46 | std::cerr<<"Warning, danger! SVD failed to converge" < 9 | #include 10 | #include 11 | 12 | 13 | int main(int argc,const char** argv) 14 | { 15 | alps::params parms(argc,argv); 16 | MaxEntSimulation::define_parameters(parms); 17 | //other help messages 18 | parms.define("help.models","show help for default model"); 19 | parms.define("help.grids","show help for grids"); 20 | 21 | if (parms.help_requested(std::cout)) { 22 | return 0; 23 | } 24 | //currently ALPSCore doesn't have a good way 25 | //to show multilple error messages 26 | //This is a temp hack, so we can have 27 | //inline grid and default model 28 | //descriptions 29 | 30 | bool exitEarly = false; 31 | 32 | if(parms["help.models"]){ 33 | std::cout << "Default model help - choices for generated default models"<< std::endl; 34 | std::cout << "For more information see examples/default_models.pdf\n" << std::endl; 35 | std::cout << std::left << std::setw(23)<< "Model Name" <<'\t' << "option=default" << std::endl; 36 | std::cout << std::left << std::setw(23)<< "==========" <<'\t' << "==============" << std::endl; 37 | std::cout << std::left << std::setw(23)<< "flat" <<'\t' << "---" << "\n" 38 | << "------------------" << "\n" 39 | << std::left << std::setw(23)<< "gaussian" <<'\t' << "SIGMA" << "\n" 40 | << std::left << std::setw(23)<< "double gaussian" <<'\t' << "SIGMA;SHIFT=0" << "\n" 41 | << std::left << std::setw(23)<< "two gaussians" <<'\t' << "SIGMA1;SIGMA2;SHIFT2;NORM1=0.5;SHIFT1=0" << "\n" 42 | << std::left << std::setw(23)<< "shifted gaussians" <<'\t' << "SIGMA;SHIFT=0" << "\n" 43 | << "------------------" << "\n" 44 | << std::left << std::setw(23)<< "lorentzian" <<'\t' << "GAMMA" << "\n" 45 | << std::left << std::setw(23)<< "double lorentzian" <<'\t' << "GAMMA;SHIFT=0" << "\n" 46 | << std::left << std::setw(23)<< "two lorentzians" <<'\t' << "GAMMA1;GAMMA2;SHIFT2;SHIFT1=0" << "\n" 47 | << std::left << std::setw(23)<< "shifted lorentzian" <<'\t' << "GAMMA;SHIFT=0" << "\n" 48 | << "------------------" << "\n" 49 | << std::left << std::setw(23)<< "LinearRiseExpDecay" <<'\t' << "LAMBDA" << "\n" 50 | << std::left << std::setw(23)<< "QuadraticRiseExpDecay"<<'\t' << "LAMBDA" << std::endl; 51 | exitEarly = true; 52 | } 53 | if(parms["help.grids"]){ 54 | if(exitEarly) //display both messages 55 | std::cout << std::endl; 56 | 57 | std::cout << "Grid help - real frequency omega grid choices for A(omega)" << std::endl; 58 | std::cout << "For more information see examples/grids.pdf\n" << std::endl; 59 | std::cout <().empty() && !parms.exists("X_0") 81 | && parms["DATA_IN_HDF5"]!=true){ 82 | std::cout<<"Please supply input data"<(); 93 | 94 | try{ 95 | if(exitEarly){ 96 | throw std::runtime_error("Critical parameters not defined"); 97 | } 98 | 99 | //allow for multiple default model runs 100 | //set MODEL_RUNS = #runs 101 | //then place: 102 | //RUN_0 = "Model1" 103 | //RUN_1 = "Model2" 104 | //..etc 105 | if(parms.exists("MODEL_RUNS")){ 106 | int nruns=parms["MODEL_RUNS"]; 107 | std::cout<<"Performing " << nruns <<" runs" <("RUN_" + boost::lexical_cast(i),"Run"); 111 | //vectors to hold spectra 112 | std::vector max_spectra(nruns); 113 | std::vector av_spectra(nruns); 114 | 115 | vector_type omega_grid; 116 | for(int i=0;i(i)]; 118 | parms["DEFAULT_MODEL"]= currModel; 119 | 120 | //run a simulation with the new default model. 121 | //Change the basename to match 122 | parms["BASENAME"] = basename+'.'+currModel; 123 | MaxEntSimulation my_sim(parms); 124 | my_sim.run(); 125 | my_sim.evaluate(); 126 | 127 | //save spectra for later 128 | max_spectra[i] = my_sim.getMaxspec(); 129 | av_spectra[i] = my_sim.getAvspec(); 130 | if(i==0){ 131 | omega_grid = my_sim.getOmegaGrid(); 132 | } 133 | } 134 | 135 | //calculate variance 136 | const int nfreq = max_spectra[0].size(); 137 | vector_type mean_max = vector_type::Zero(nfreq); 138 | vector_type stdev_max(nfreq); 139 | vector_type mean_av = vector_type::Zero(nfreq); 140 | vector_type stdev_av(nfreq); 141 | 142 | determineVariance(max_spectra,mean_max,stdev_max); 143 | determineVariance(av_spectra,mean_av,stdev_av); 144 | 145 | //save to file 146 | if(parms["TEXT_OUTPUT"]){ 147 | ofstream_ spec_file; 148 | spec_file.open((basename+".varspec.dat").c_str()); 149 | spec_file << "#omega mean_maxspec stdev_maxspec mean_avspec stdev_avspec" < 10 | #include "maxent_matrix_def.hpp" 11 | #include "maxent_params.hpp" 12 | #include 13 | 14 | struct ofstream_ : std::ofstream{ 15 | explicit ofstream_(std::streamsize precision=10){ 16 | this->precision(precision); 17 | } 18 | }; 19 | 20 | class MaxEntHelper : private MaxEntParameters 21 | { 22 | public : 23 | 24 | MaxEntHelper(alps::params& p); 25 | 26 | double omega_coord(const int i) const { return MaxEntParameters::omega_coord(i); } 27 | 28 | ///getter function for the discretized default model 29 | double Default(const int i) const { return def_[i]; } 30 | ///getter function for the discretized default model 31 | const vector_type& Default() const { return def_; } 32 | 33 | //compute the 'free energy' Q (eq. 6.8 in Sebastian's thesis) according to equation D.8 in Sebastian's thesis 34 | double Q(const vector_type& u, const double alpha) const { 35 | vector_type A=transform_into_real_space(u); 36 | return 0.5*chi2(A)-alpha*entropy(A); 37 | } 38 | 39 | ///number of points for the Matsubara data 40 | int ndat() const { return MaxEntParameters::ndat(); } 41 | 42 | ///A->u 43 | vector_type transform_into_singular_space(vector_type A) const; 44 | ///u-A 45 | vector_type transform_into_real_space(vector_type u) const; 46 | ///A=A_i/\sigma_i; this removes \sigma_i 47 | vector_type get_spectrum(const vector_type& u) const; 48 | vector_type PrincipalValue(const vector_type &w,const vector_type &a) const; 49 | /// \Sigma*(V^T*RealSpace(u)*V)*\Sigma 50 | matrix_type left_side(const vector_type& u) const; 51 | /// \Sigma*U^T*(K*RealSpace(u)-y) 52 | vector_type right_side(const vector_type& u) const; 53 | /// \delta \dot (V^T*RealSpace(u)*V) 54 | double step_length(const vector_type& delta, const vector_type& u) const; 55 | double convergence(const vector_type& u, const double alpha) const; 56 | double log_prob(const vector_type& u, const double alpha) const; 57 | double chi_scale_factor(vector_type A, const double chi_sq, const double alpha) const; 58 | double chi2(const vector_type& u) const; 59 | void print_chi2(const vector_type& u, std::ostream &os) const; 60 | /// compute S=\int d\omega(A(\omega)-D(\omega)-A(\omega)\ln[A(\omega)/D(\omega)) 61 | double entropy(const vector_type& u) const; 62 | /// (back)continue A(\omega) to the imaginary axis; also writes to file 63 | void backcontinue(ofstream_ &os, const vector_type &A, const double norm, const std::string name,vector_type &ext_back); 64 | matrix_type constructGamma(const vector_type& A, const double alpha); 65 | void generateCovariantErr(const vector_type& A_in, const double alpha, ofstream_ &os); 66 | 67 | private: 68 | ///discretized and normalized version of the default model. 69 | vector_type def_; 70 | ///check that the default model is non-zero 71 | void checkDefaultModel(const vector_type &D) const; 72 | vector_type generateGaussNoise(vector_type data, vector_type err,boost::mt19937 &rng); 73 | protected: 74 | bool text_output; 75 | }; 76 | 77 | 78 | 79 | 80 | class MaxEntSimulation : private MaxEntHelper 81 | { 82 | 83 | public: 84 | 85 | ///setup of parameters 86 | MaxEntSimulation(alps::params& parms); 87 | ///the maxent calculation 88 | void run(); 89 | ///the evaluation and writing of files 90 | void evaluate(); 91 | vector_type levenberg_marquardt(vector_type u, const double alpha) const; 92 | vector_type iteration(vector_type u, const double alpha, const double mu) const; 93 | ///define parameter defaults 94 | static void define_parameters(alps::params &p); 95 | 96 | private: 97 | 98 | ///grid of alpha values 99 | vector_type alpha; 100 | const double norm; 101 | const int max_it; 102 | std::string name,Kernel_type; 103 | bool verbose,self,make_back,gen_err; 104 | const int nfreq; 105 | 106 | vector_type lprob; 107 | vector_type chi_sq; 108 | std::vector spectra; 109 | vector_type u; 110 | ///averaged spectrum 111 | vector_type avspec; 112 | ///classic MaxEnt 113 | vector_type maxspec; 114 | ///historic MaxEnt 115 | vector_type chispec; 116 | ///grid of Omega points 117 | vector_type omegaGrid; 118 | ///averaged spectrum back-continued 119 | vector_type avspec_back; 120 | ///classic MaxEnt back-continued 121 | vector_type maxspec_back; 122 | ///historic MaxEnt back-continued 123 | vector_type chispec_back; 124 | ///grid of Omega points 125 | //posterior probability of the default model 126 | double postprobdef; 127 | ///vector of calculated Q values for each alpha iteration 128 | //this is one method of checking if a minimum was found 129 | vector_type qvec; 130 | 131 | public: 132 | ///getter for avspec, the averaged spectrum 133 | const vector_type getAvspec() const{return avspec;} 134 | ///getter for chispec, the spectrum with the best chi^2 135 | const vector_type getChispec() const{return chispec;} 136 | ///getter for maxspec, the most probable spectrum 137 | const vector_type getMaxspec() const{return maxspec;} 138 | ///getter for avspec_back, the averaged spectrum back-continued 139 | const vector_type getAvspecBack() const{return avspec_back;} 140 | ///getter for maxspec_back, the back-continued maxspec 141 | const vector_type getMaxspecBack() const{return maxspec_back;} 142 | ///getter for chispec_back, the spectrum chispec back-contonued 143 | const vector_type getChispecBack() const{return chispec_back;} 144 | ///getter for the grid of omega points used in determining 145 | ///the spectral function A(omega) 146 | const vector_type getOmegaGrid() const{return omegaGrid;} 147 | ///getter for the posterior probability of the default model 148 | double getPostProb() const{return postprobdef;} 149 | ///getter for alpha values 150 | const vector_type getAlphaGrid() const{return alpha;} 151 | ///getter for vector of Q value per alpha iteration 152 | const vector_type getQvec() const{return qvec;} 153 | }; 154 | 155 | ///calculates the varience of a std::vector of eigen3 vectors 156 | //note: mean,std_dev must be initialized to Zeros(nfreq()) 157 | //located in maxent_helper.cpp 158 | void determineVariance(std::vector &in,vector_type &mean, vector_type &std_dev); 159 | -------------------------------------------------------------------------------- /src/maxent_backcont.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 1998-2018 ALPS Collaboration. 3 | * All rights reserved. Use is subject to license terms. See LICENSE.TXT 4 | * For use in publications, see ACKNOWLEDGE.TXT 5 | */ 6 | #include "maxent_backcont.hpp" 7 | 8 | Backcont::Backcont(const MaxEntParameters *param_in) : 9 | param(param_in),k_type(param->getKernelType()){ 10 | } 11 | 12 | vector_type Backcont::backcontinue(const vector_type &A){ 13 | const int ndat = param->ndat(); 14 | const int nfreq = param->nfreq(); 15 | 16 | G = vector_type(ndat); 17 | // G(X) =\int K(X,\omega)A(\omega)d\omega 18 | for(int n=0;nsigma(n); 21 | G(n)=0; 22 | for(int i=1;iK(n,i))*A(i)*(param->delta_omega(i)); 24 | double delta = (param->omega_coord(i+1)) - (param->omega_coord(i-1)); 25 | G(n) += err*(param->K(n,i))*A(i)*delta/2; 26 | } 27 | 28 | G(n) += err*(param->K(n,0))*A(0)*(param->omega_coord(1)-param->omega_coord(0))/2; 29 | G(n) += err*(param->K(n,nfreq-1))*A(nfreq-1)*(param->omega_coord(nfreq-1)-param->omega_coord(nfreq-2))/2; 30 | } 31 | 32 | return G; 33 | } 34 | double Backcont::max_error(const vector_type &y1, const vector_type &y2){ 35 | double max_err = 0.0; 36 | #ifdef NDEBUG 37 | if(y1.size() != y2.size()){ 38 | throw std::runtime_error("backcont vector size mismatch!"); 39 | } 40 | #endif 41 | for(int i=0;imax_err){ 44 | max_err = delta; 45 | } 46 | } 47 | return max_err; 48 | } 49 | -------------------------------------------------------------------------------- /src/maxent_backcont.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 1998-2018 ALPS Collaboration. 3 | * All rights reserved. Use is subject to license terms. See LICENSE.TXT 4 | * For use in publications, see ACKNOWLEDGE.TXT 5 | */ 6 | #pragma once 7 | #include "maxent.hpp" 8 | #include // needed to set up correct bindings 9 | 10 | ///This class contains necessities to analytically continue a 11 | //real function to the imaginary axis 12 | class Backcont{ 13 | public: 14 | Backcont(const MaxEntParameters *param_in); 15 | ///Backcontinue a given function A 16 | vector_type backcontinue(const vector_type &A); 17 | ///determine the maximum difference between the two functions 18 | double max_error(const vector_type &y1, const vector_type &y2); 19 | private: 20 | //pointer to Parameters, set up through MaxEntSimulation->MaxEntHelper 21 | const MaxEntParameters *param; 22 | ///holds backcontinued Green's function 23 | vector_type G; 24 | kernel_type k_type; 25 | }; 26 | -------------------------------------------------------------------------------- /src/maxent_grid.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 1998-2018 ALPS Collaboration. 3 | * All rights reserved. Use is subject to license terms. See LICENSE.TXT 4 | * For use in publications, see ACKNOWLEDGE.TXT 5 | */ 6 | #include "maxent_grid.hpp" 7 | #include 8 | #include 9 | 10 | grid::grid(const alps::params &p): 11 | nfreq_(p["NFREQ"]), 12 | t_array_(nfreq_+1){ 13 | std::string p_f_grid = p["FREQUENCY_GRID"]; 14 | boost::to_lower(p_f_grid); 15 | double cut = p["CUT"]; 16 | if (p_f_grid =="lorentzian") { 17 | initialize_lorentzian_grid(cut); 18 | } 19 | else if (p_f_grid=="half lorentzian") { 20 | initialize_half_lorentzian_grid(cut); 21 | } 22 | else if (p_f_grid=="quadratic") { 23 | double s = p["SPREAD"]; 24 | initialize_quadratic_grid(s); 25 | } 26 | else if (p_f_grid=="log") { 27 | double t_min = p["LOG_MIN"]; 28 | initialize_logarithmic_grid(t_min); 29 | } 30 | else if (p_f_grid=="linear") { 31 | initialize_linear_grid(); 32 | } 33 | else 34 | boost::throw_exception(std::invalid_argument("No valid frequency grid specified")); 35 | } 36 | void grid::initialize_linear_grid() { 37 | for (int i = 0; i < nfreq_+1; ++i) 38 | t_array_[i] = double(i) / (nfreq_); 39 | } 40 | 41 | void grid::initialize_logarithmic_grid(double t_min) { 42 | double t_max = 0.5; 43 | double scale = std::log(t_max / t_min) / ((float) ((nfreq_ / 2 - 1))); 44 | t_array_[nfreq_ / 2] = 0.5; 45 | for (int i = 0; i < nfreq_ / 2; ++i) { 46 | t_array_[nfreq_ / 2 + i + 1] = 0.5 47 | + t_min * std::exp(((float) (i)) * scale); 48 | t_array_[nfreq_ / 2 - i - 1] = 0.5 49 | - t_min * std::exp(((float) (i)) * scale); 50 | } 51 | //if we have an odd # of frequencies, this catches the last element 52 | if (nfreq_ % 2 != 0) 53 | t_array_[nfreq_ / 2 + nfreq_ / 2 + 1] = 0.5 54 | + t_min * std::exp(((float) (nfreq_) / 2) * scale); 55 | } 56 | 57 | void grid::initialize_quadratic_grid(double spread) { 58 | if (spread < 1) 59 | boost::throw_exception( 60 | std::invalid_argument("the parameter SPREAD must be greater than 1")); 61 | 62 | std::vector temp(nfreq_); 63 | double t = 0; 64 | for (int i = 0; i < nfreq_; ++i) { 65 | double a = double(i) / (nfreq_ - 1); 66 | double factor = 4 * (spread - 1) * (a * a - a) + spread; 67 | factor /= double(nfreq_ - 1) / (3. * (nfreq_ - 2)) 68 | * ((nfreq_ - 1) * (2 + spread) - 4 + spread); 69 | double delta_t = factor; 70 | t += delta_t; 71 | temp[i] = t; 72 | } 73 | t_array_[0] = 0.; 74 | for (int i = 1; i < nfreq_+1; ++i) 75 | t_array_[i] = temp[i - 1] / temp[temp.size() - 1]; 76 | } 77 | 78 | void grid::initialize_half_lorentzian_grid(double cut) { 79 | std::vector temp(nfreq_ + 1); 80 | for (int i = 0; i < nfreq_ + 1; ++i) 81 | temp[i] = tan( 82 | M_PI 83 | * (double(i + nfreq_) / (2 * nfreq_ - 1) * (1. - 2 * cut) + cut 84 | - 0.5)); 85 | for (int i = 0; i < nfreq_ + 1; ++i) 86 | t_array_[i] = (temp[i] - temp[0]) / (temp[temp.size() - 1] - temp[0]); 87 | } 88 | 89 | void grid::initialize_lorentzian_grid(double cut) { 90 | std::vector temp(nfreq_ + 1); 91 | for (int i = 0; i < nfreq_ + 1; ++i) 92 | temp[i] = tan(M_PI * (double(i) / (nfreq_) * (1. - 2 * cut) + cut - 0.5)); 93 | for (int i = 0; i < nfreq_ + 1; ++i) 94 | t_array_[i] = (temp[i] - temp[0]) / (temp[temp.size() - 1] - temp[0]); 95 | } 96 | 97 | 98 | 99 | 100 | -------------------------------------------------------------------------------- /src/maxent_grid.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 1998-2018 ALPS Collaboration. 3 | * All rights reserved. Use is subject to license terms. See LICENSE.TXT 4 | * For use in publications, see ACKNOWLEDGE.TXT 5 | */ 6 | #pragma once 7 | #include 8 | #include 9 | #include "maxent_matrix_def.hpp" 10 | 11 | class grid{ 12 | public: 13 | grid(const alps::params &p); 14 | const std::vector &t_array() const{return t_array_;} 15 | double operator()(int i)const{return t_array_[i];} 16 | private: 17 | ///the number of (real) frequency point for this grid. 18 | int nfreq_; 19 | std::vector t_array_; 20 | 21 | void initialize_linear_grid(); 22 | void initialize_logarithmic_grid(double t_min); 23 | void initialize_quadratic_grid(double spread); 24 | void initialize_half_lorentzian_grid(double cut); 25 | void initialize_lorentzian_grid(double cut); 26 | }; 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /src/maxent_kernel.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 1998-2018 ALPS Collaboration. 3 | * All rights reserved. Use is subject to license terms. See LICENSE.TXT 4 | * For use in publications, see ACKNOWLEDGE.TXT 5 | */ 6 | #include "maxent_kernel.hpp" 7 | #include 8 | #include 9 | #include 10 | #include //for Legendre kernel 11 | #include //for Legendre kernel 12 | #include //for Legendre Kernel 13 | 14 | namespace bmth = boost::math; 15 | 16 | kernel::kernel(alps::params &p, const vector_type& freq, vector_type &inputGrid): 17 | ndat_(p["NDAT"]), 18 | nfreq_(p["NFREQ"]), 19 | T_(1./static_cast(p["BETA"])), 20 | K_(ndat_,nfreq_) 21 | { 22 | using namespace boost::numeric; 23 | //K_.clear(); 24 | K_=matrix_type::Zero(ndat_,nfreq_); 25 | std::string dataspace_name = p["DATASPACE"]; 26 | std::string kernel_name = p["KERNEL"]; 27 | boost::to_lower(dataspace_name); 28 | boost::to_lower(kernel_name); 29 | bool ph_symmetry=p["PARTICLE_HOLE_SYMMETRY"]; 30 | std::cout<<"using kernel "<(i)]; 44 | } 45 | } 46 | //legacy tau points in param file 47 | else if(p.exists("TAU_0")){ 48 | std::cout<<"Using param input tau points"<("TAU_"+boost::lexical_cast(i),""); 52 | for(int i=1;i(i)]; 54 | } 55 | } 56 | else{ 57 | if(p.exists("X_2")){ 58 | //using data file entry so there is no input grid 59 | throw std::runtime_error("Missing input tau points! Define them with TAU_0=...."); 60 | } 61 | std::cout<<"Using data file tau points"< iomegan(0, (2*i+1)*M_PI*T_); 147 | inputGrid(i) = iomegan.imag(); 148 | for (int j=0; j iomegan(0, 2*i*M_PI*T_); 157 | inputGrid(i) = iomegan.imag(); 158 | inputGrid(i+1) = iomegan.imag(); 159 | for (int j=0; j iomegan(0, (2*i+1)*M_PI*T_); 168 | inputGrid(i) = iomegan.imag(); 169 | for (int j=0; jl; 251 | double omega = p->omega; 252 | double T_ = p->T_; 253 | //std::cout<< l<< std::endl; 254 | return bmth::legendre_p(l, 2*tau*T_-1)*std::exp(-tau*omega)/(1+std::exp(-omega/T_)); 255 | } 256 | void kernel::setup_legendre_kernel(const alps::params &p, const vector_type& freq,const int lmax){ 257 | if(lmax>boost::math::max_factorial::value) 258 | throw std::runtime_error("lmax is greater than boost factorial precision"); 259 | 260 | const double PI = std::acos(-1); 261 | const std::complex CONE(0,1); 262 | //recall that ndat()=lmax 263 | 264 | int N = 20000/2; 265 | gsl_integration_workspace *w = gsl_integration_workspace_alloc (1000); 266 | 267 | for(int l=0;l 8 | #include 9 | #include 10 | #include"maxent_matrix_def.hpp" 11 | ///enum that enumerates if we're in time or in frequency 12 | enum dataspace_type{ 13 | time_dataspace, 14 | frequency_dataspace, 15 | legendre_dataspace 16 | }; 17 | ///we have a range of different kernels that all need different input parameters. This enum enumerates them. 18 | enum kernel_type{ 19 | time_fermionic_kernel, 20 | time_bosonic_kernel, 21 | time_boris_kernel, 22 | time_fermionic_legendre_kernel, 23 | time_bosonic_legendre_kernel, //TODO determine boris->legendre 24 | legendre_fermionic_kernel, 25 | legendre_bosonic_kernel, 26 | frequency_fermionic_ph_kernel, 27 | frequency_bosonic_ph_kernel, 28 | frequency_anomalous_ph_kernel, 29 | frequency_fermionic_kernel, 30 | frequency_bosonic_kernel, 31 | frequency_anomalous_kernel 32 | }; 33 | class kernel{ 34 | public: 35 | kernel(alps::params &p, const vector_type& freq, vector_type &inputGrid); 36 | 37 | ///getter function for the kernel matrix 38 | const matrix_type &operator()()const{return K_;} 39 | ///getter function for kernel type 40 | kernel_type getKernelType() const{return ktype_;} 41 | ///getter function for dataspace type 42 | dataspace_type getDataspaceType() const{return dtype_;} 43 | ///getter function for tau_points 44 | const vector_type getTauPoints() const{return tau_points_;} 45 | 46 | private: 47 | ///figure out which kernel is to be used 48 | void set_kernel_type(const std::string &dataspace_name, const std::string &kernel_name, 49 | bool ph_symmetry); 50 | ///set up kernel with the legendre transform 51 | void setup_legendre_kernel(const alps::params &p, const vector_type& freq, const int lmax); 52 | ///number; of Matsubara points 53 | int ndat_; 54 | ///number of real frequency points 55 | int nfreq_; 56 | ///temperature 57 | double T_; 58 | ///type of the kernel (see enums above) 59 | kernel_type ktype_; 60 | ///type of the dataspace 61 | dataspace_type dtype_; 62 | ///kernel matrix 63 | matrix_type K_; 64 | ///array of tau points 65 | vector_type tau_points_; 66 | }; 67 | 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /src/maxent_matrix_def.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 1998-2018 ALPS Collaboration. 3 | * All rights reserved. Use is subject to license terms. See LICENSE.TXT 4 | * For use in publications, see ACKNOWLEDGE.TXT 5 | */ 6 | 7 | #pragma once 8 | 9 | #include // needed to set up correct bindings 10 | #include "maxent_config.hpp" 11 | #include 12 | 13 | typedef Eigen::MatrixXd matrix_type; 14 | typedef Eigen::MatrixXcd complex_matrix_type; 15 | typedef Eigen::VectorXd vector_type; 16 | typedef Eigen::MatrixXcd complex_vector_type; 17 | typedef std::pair omega_complex_type; 18 | 19 | ///matrix-vector multiplication. 20 | inline vector_type maxent_prec_prod(const matrix_type &p, const vector_type &q) { 21 | return p*q; 22 | } 23 | ///matrix-vector multiplication of transpose of matrix. 24 | inline vector_type maxent_prec_prod_trans(const matrix_type &p, const vector_type &q) { 25 | return p.transpose()*q; 26 | } 27 | ///matrix-matrix multiplication. 28 | inline matrix_type maxent_prec_prod(const matrix_type &p, const matrix_type &q) { 29 | return p*q; 30 | } 31 | ///matrix-matrix multiplication of transpose(p) with q. 32 | inline matrix_type maxent_prec_prod_trans(const matrix_type &p, const matrix_type &q) { 33 | return p.transpose()*q; 34 | } 35 | -------------------------------------------------------------------------------- /src/maxent_params.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 1998-2018 ALPS Collaboration. 3 | * All rights reserved. Use is subject to license terms. See LICENSE.TXT 4 | * For use in publications, see ACKNOWLEDGE.TXT 5 | */ 6 | 7 | #pragma once 8 | 9 | #include "default_model.hpp" 10 | #include "maxent_grid.hpp" 11 | #include "maxent_kernel.hpp" 12 | #include "maxent_matrix_def.hpp" 13 | 14 | ///This class has all the information about general analytic continuation things. It does not know about specifics of maxent. 15 | class ContiParameters { 16 | 17 | public: 18 | 19 | ///constructs the kernel and grid from the parameters p. Also reads in the data. 20 | ContiParameters(alps::params& p); 21 | 22 | ///value of the Matsubara data at index i 23 | double y(const int i) const { return y_[i]; } 24 | ///value of the Matsubara data 25 | const vector_type& y() const { return y_; } 26 | ///value of the covariance matrix 27 | double cov(const int i,const int j) const { return cov_(i,j); } 28 | ///value of the error (if covariance not given) 29 | double sigma(const int i) const { return sigma_[i]; } 30 | ///value of the inverse temperature 31 | double T() const { return T_; } 32 | ///number of data points 33 | int ndat() const { return ndat_; } 34 | ///number of frequency points on the real axis 35 | int nfreq() const { return nfreq_; } 36 | ///value of the Kernel matrix K(i,j). 37 | double K(const int i, const int j) const {return K_(i,j);} 38 | ///returns the entire kernel matrix 39 | const matrix_type& K() const { return K_; } 40 | ///returns kernel type of K 41 | kernel_type getKernelType() const {return k_type; } 42 | 43 | private: 44 | ///temperature 45 | const double T_; 46 | 47 | void read_data_from_text_file(const alps::params& p); 48 | void read_data_from_hdf5_file(const alps::params& p); 49 | void read_data_from_param_file(const alps::params& p); 50 | void read_covariance_matrix_from_text_file(const std::string& fname); 51 | 52 | protected: 53 | 54 | void decompose_covariance_matrix(const alps::params& p); 55 | ///This function scales both the y (data) and the kernel with the errors 56 | void scale_data_with_error(const int ntab); 57 | 58 | ///number of fitting data points / size of y 59 | int ndat_; //TODO: find a better way of changing this. If we use Gl, we change the size of y 60 | ///number of real frequencies 61 | const int nfreq_; 62 | ///vector of Matsubara data 63 | vector_type y_; 64 | ///vector of errors on y 65 | vector_type sigma_; 66 | ///Kernel matrix 67 | matrix_type K_; 68 | ///covariance matrix 69 | matrix_type cov_; 70 | ///real frequency grid 71 | grid grid_; 72 | ///vector containing input matsubara or tau data 73 | vector_type inputGrid_; 74 | ///type of kernel used 75 | kernel_type k_type; 76 | }; 77 | 78 | 79 | 80 | ///This class contains all of the maxent specific parameters, along with the singular value decomposed kernel. 81 | class MaxEntParameters : public ContiParameters 82 | { 83 | public: 84 | ///constructs the maxent specific parameters out of parameters p 85 | MaxEntParameters(alps::params& p); 86 | 87 | const matrix_type& U() const { return U_; } 88 | const matrix_type& Vt() const { return Vt_; } 89 | const matrix_type& Sigma() const { return Sigma_; } 90 | double omega_coord(const int i) const { return omega_coord_[i]; } 91 | const vector_type& omega_coord() const { return omega_coord_; } 92 | double delta_omega(const int i) const { return delta_omega_[i]; } 93 | ///getter function for the number of singular values 94 | int ns() const { return ns_; } 95 | ///getter function for the default model 96 | const DefaultModel& Default() const { return *Default_; } 97 | ///getter function for input data grid 98 | const vector_type& inputGrid() const { return inputGrid_; } 99 | ///getter function for input data grid values 100 | double inputGrid(const int i) const { return inputGrid_(i); } 101 | 102 | private: 103 | ///The default model 104 | boost::shared_ptr Default_; 105 | matrix_type U_; 106 | matrix_type Vt_; 107 | matrix_type Sigma_; 108 | vector_type omega_coord_; 109 | vector_type delta_omega_; 110 | ///the number of singular values 111 | int ns_; 112 | ///compute the minimal chi2 that is possible given the SVD of the kernel 113 | void compute_minimal_chi2() const; 114 | ///reduce the matrices to the number of non-zero singular values 115 | void truncate_to_singular_space(const vector_type& S); 116 | ///take the kernel and compute its singular value decomposition 117 | void singular_value_decompose_kernel(bool verbose, vector_type& S); 118 | ///check G~-1/iw_{n} and default model back continues same limit 119 | void check_high_frequency_limit(const vector_type& y, const kernel_type kt); 120 | }; 121 | -------------------------------------------------------------------------------- /test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8.12) 2 | include(EnableGtests) #defined in ./cmake 3 | set(test_src 4 | default_modelTest 5 | backcontTest 6 | gridTest 7 | paramsTest 8 | simulationTest 9 | paramFailureTest 10 | ) 11 | foreach(test ${test_src}) 12 | add_gtest(${test}) 13 | endforeach(test) 14 | 15 | -------------------------------------------------------------------------------- /test/default_modelTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 1998-2018 ALPS Collaboration. 3 | * All rights reserved. Use is subject to license terms. See LICENSE.TXT 4 | * For use in publications, see ACKNOWLEDGE.TXT 5 | */ 6 | 7 | 8 | #include "../src/default_model.hpp" 9 | #include 10 | #include"gtest.h" 11 | #include 12 | #include "write_test_files.hpp" 13 | 14 | 15 | ///create a tabulated default model 16 | TEST(TabFunction, TabFunctionConstruction){ 17 | alps::params p; p["OMEGA_MAX"]=20; p["OMEGA_MIN"]=-20; 18 | std::string tabparamname="TABFILE"; 19 | std::string tf=alps::temporary_filename("tab_file.dat"); 20 | p[tabparamname]=tf; 21 | write_minimal_tab_file(tf); 22 | TabFunction T(p, tabparamname); 23 | std::remove(tf.c_str()); 24 | EXPECT_EQ(T(-20.),1./40); 25 | EXPECT_EQ(T(20.),1./40); 26 | EXPECT_EQ(T(0.),1./40); 27 | } 28 | TEST(TabFunction, TabFunctionConstructionWithMoreLines){ 29 | alps::params p; p["OMEGA_MAX"]=20; p["OMEGA_MIN"]=-20; 30 | std::string tabparamname="TABFILE"; 31 | std::string tf=alps::temporary_filename("tab_file.dat"); 32 | p[tabparamname]=tf; 33 | write_minimal_tab_file(tf); 34 | TabFunction T(p, tabparamname); 35 | std::remove(tf.c_str()); 36 | EXPECT_NEAR(T(-20.),1./40, 1.e-12); 37 | EXPECT_NEAR(T(20.),1./40, 1.e-12); 38 | EXPECT_NEAR(T(0.),1./40, 1.e-12); 39 | } 40 | TEST(TabFunction, OutsideMinMaxIsZero){ 41 | alps::params p; p["OMEGA_MAX"]=20; p["OMEGA_MIN"]=-20; 42 | std::string tabparamname="TABFILE"; 43 | std::string tf=alps::temporary_filename("tab_file.dat"); 44 | p[tabparamname]=tf; 45 | write_minimal_tab_file(tf); 46 | TabFunction T(p, tabparamname); 47 | std::remove(tf.c_str()); 48 | 49 | EXPECT_EQ(T(-21.),0.); 50 | EXPECT_EQ(T(21.),0.); 51 | 52 | } 53 | TEST(TabFunction, FailOutsideRange){ 54 | //tab file is [-20,20] 55 | //ask for range [-20,25] so it will fail 56 | alps::params p; p["OMEGA_MAX"]=25; p["OMEGA_MIN"]=-20; 57 | std::string tabparamname="TABFILE"; 58 | std::string tf=alps::temporary_filename("tab_file.dat"); 59 | p[tabparamname]=tf; 60 | write_minimal_tab_file(tf); 61 | try{ 62 | TabFunction T(p, tabparamname); 63 | FAIL() << "Expected to fail parameters out of range"; 64 | } 65 | catch(std::logic_error const & err){ 66 | std::remove(tf.c_str()); 67 | EXPECT_EQ(err.what(),std::string("Input range outside of default model")); 68 | } 69 | catch(...){ 70 | std::remove(tf.c_str()); 71 | FAIL() << "expected parameters out of range error"; 72 | } 73 | } 74 | TEST(Gaussian, TwoGaussiansIsGaussian){ 75 | alps::params p; 76 | p["SIGMA1"]=1; 77 | p["SIGMA2"]=1; 78 | p["SHIFT1"]=0; 79 | p["SHIFT2"]=-1; 80 | p["NORM1"]=1; 81 | 82 | TwoGaussians TG(p); 83 | alps::params q; 84 | q["SIGMA"]=1; 85 | 86 | Gaussian G(q); 87 | 88 | for(int i=-5;i<5;++i){ 89 | EXPECT_NEAR(TG(i),G(i),1.e-10); 90 | } 91 | } 92 | TEST(Gaussian, TwoGaussiansIsDoubleGaussian){ 93 | alps::params p; 94 | p["SIGMA1"]=1; 95 | p["SIGMA2"]=1; 96 | p["SHIFT1"]=1; 97 | p["SHIFT2"]=-1; 98 | p["NORM1"]=0.5; 99 | 100 | TwoGaussians TG(p); 101 | alps::params q; 102 | q["SIGMA"]=1; 103 | q["SHIFT"]=1; 104 | 105 | DoubleGaussian D(q); 106 | for(int i=-5;i<5;++i){ 107 | EXPECT_NEAR(TG(i),D(i),1.e-10); 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /test/gridTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 1998-2018 ALPS Collaboration. 3 | * All rights reserved. Use is subject to license terms. See LICENSE.TXT 4 | * For use in publications, see ACKNOWLEDGE.TXT 5 | */ 6 | 7 | #include "../src/maxent.hpp" 8 | #include "../src/maxent_grid.hpp" 9 | #include "gtest.h" 10 | #include 11 | 12 | //these tests only make sure the grids are initiallized 13 | //to the regions of [0,1] within the NFREQ+1 size array 14 | 15 | TEST(Grid,LorentzianOdd){ 16 | alps::params p; 17 | MaxEntSimulation::define_parameters(p); 18 | const int NFREQ=2001; 19 | p["FREQUENCY_GRID"] = "Lorentzian"; 20 | p["NFREQ"] = NFREQ; 21 | 22 | grid g(p); 23 | EXPECT_EQ(g(0),0); 24 | EXPECT_EQ(g(NFREQ),1); 25 | } 26 | TEST(Grid,HalfLorentzianOdd){ 27 | alps::params p; 28 | MaxEntSimulation::define_parameters(p); 29 | 30 | const int NFREQ=2001; 31 | p["FREQUENCY_GRID"] = "half lorentzian"; 32 | p["NFREQ"] = NFREQ; 33 | 34 | grid g(p); 35 | EXPECT_EQ(g(0),0); 36 | EXPECT_EQ(g(NFREQ),1); 37 | } 38 | TEST(Grid,QuadraticOdd){ 39 | alps::params p; 40 | MaxEntSimulation::define_parameters(p); 41 | 42 | const int NFREQ=2001; 43 | p["FREQUENCY_GRID"] = "Quadratic"; 44 | p["NFREQ"] = NFREQ; 45 | 46 | grid g(p); 47 | EXPECT_EQ(g(0),0); 48 | EXPECT_EQ(g(NFREQ),1); 49 | } 50 | TEST(Grid,LogOdd){ 51 | alps::params p; 52 | MaxEntSimulation::define_parameters(p); 53 | 54 | const int NFREQ=2001; 55 | p["FREQUENCY_GRID"] = "log"; 56 | p["NFREQ"] = NFREQ; 57 | 58 | grid g(p); 59 | EXPECT_NEAR(g(0),0,1e-10); 60 | //log overshoots the default value by ~0.001 61 | EXPECT_NEAR(g(NFREQ),1,0.01); 62 | } 63 | TEST(Grid,LinearOdd){ 64 | alps::params p; 65 | MaxEntSimulation::define_parameters(p); 66 | 67 | const int NFREQ=2001; 68 | p["FREQUENCY_GRID"] = "linear"; 69 | p["NFREQ"] = NFREQ; 70 | 71 | grid g(p); 72 | EXPECT_EQ(g(0),0); 73 | EXPECT_EQ(g(NFREQ),1); 74 | } 75 | //the following tests have an even amount of points 76 | //so we test the same endpoints (which shouldn't change) 77 | //as well as the middle of symmetric grids 78 | TEST(Grid,LorentzianEven){ 79 | alps::params p; 80 | MaxEntSimulation::define_parameters(p); 81 | 82 | const int NFREQ=2000; 83 | p["FREQUENCY_GRID"] = "Lorentzian"; 84 | p["NFREQ"] = NFREQ; 85 | 86 | grid g(p); 87 | EXPECT_EQ(g(0),0); 88 | EXPECT_EQ(g(NFREQ/2), 0.5); 89 | EXPECT_EQ(g(NFREQ),1); 90 | } 91 | TEST(Grid,HalfLorentzianEven){ 92 | //this is not symmetric so there is no new test 93 | alps::params p; 94 | MaxEntSimulation::define_parameters(p); 95 | 96 | const int NFREQ=2000; 97 | p["FREQUENCY_GRID"] = "half lorentzian"; 98 | p["NFREQ"] = NFREQ; 99 | 100 | grid g(p); 101 | EXPECT_EQ(g(0),0); 102 | EXPECT_EQ(g(NFREQ),1); 103 | } 104 | TEST(Grid,QuadraticEven){ 105 | alps::params p; 106 | MaxEntSimulation::define_parameters(p); 107 | 108 | const int NFREQ=2000; 109 | p["FREQUENCY_GRID"] = "Quadratic"; 110 | p["NFREQ"] = NFREQ; 111 | 112 | grid g(p); 113 | EXPECT_EQ(g(0),0); 114 | EXPECT_NEAR(g(NFREQ/2), 0.5,1e-10); 115 | EXPECT_EQ(g(NFREQ),1); 116 | } 117 | TEST(Grid,LogEven){ 118 | alps::params p; 119 | MaxEntSimulation::define_parameters(p); 120 | 121 | const int NFREQ=2000; 122 | p["FREQUENCY_GRID"] = "log"; 123 | p["NFREQ"] = NFREQ; 124 | 125 | grid g(p); 126 | EXPECT_NEAR(g(0),0,1e-10); 127 | EXPECT_EQ(g(NFREQ/2), 0.5); 128 | //log overshoots the default value by ~0.001 129 | EXPECT_NEAR(g(NFREQ),1,0.01); 130 | } 131 | TEST(Grid,LinearEven){ 132 | alps::params p; 133 | MaxEntSimulation::define_parameters(p); 134 | const int NFREQ=2000; 135 | p["FREQUENCY_GRID"] = "linear"; 136 | p["NFREQ"] = NFREQ; 137 | 138 | grid g(p); 139 | EXPECT_EQ(g(0),0); 140 | EXPECT_EQ(g(NFREQ/2), 0.5); 141 | EXPECT_EQ(g(NFREQ),1); 142 | } 143 | 144 | 145 | 146 | -------------------------------------------------------------------------------- /test/gtest_main.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2006, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | #include 31 | 32 | #include "gtest.h" 33 | 34 | GTEST_API_ int main(int argc, char **argv) { 35 | printf("Running main() from gtest_main.cc\n"); 36 | testing::InitGoogleTest(&argc, argv); 37 | return RUN_ALL_TESTS(); 38 | } 39 | -------------------------------------------------------------------------------- /test/paramFailureTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 1998-2018 ALPS Collaboration. 3 | * All rights reserved. Use is subject to license terms. See LICENSE.TXT 4 | * For use in publications, see ACKNOWLEDGE.TXT 5 | */ 6 | 7 | #include "../src/maxent.hpp" 8 | #include "gtest.h" 9 | #include 10 | #include 11 | #include "write_test_files.hpp" 12 | 13 | TEST(Parameters,CatchMissingDataInParamFile){ 14 | std::string pf=alps::temporary_filename("param_file.dat"); 15 | write_minimal_param_file(pf); 16 | 17 | //fake input 18 | alps::params p(pf); 19 | MaxEntSimulation::define_parameters(p); 20 | p["NDAT"] = 5; 21 | 22 | try{ 23 | ContiParameters c(p); 24 | std::remove(pf.c_str()); 25 | FAIL() << "expected error on missing X_4 datapoint"; 26 | 27 | } 28 | catch(...){ 29 | //woo 30 | SUCCEED(); 31 | } 32 | 33 | p["X_4"]=0.5; 34 | 35 | try{ 36 | ContiParameters c2(p); 37 | std::remove(pf.c_str()); 38 | FAIL() << "expected error on missing SIGMA_4"; 39 | } 40 | catch(...){ 41 | SUCCEED(); 42 | std::remove(pf.c_str()); 43 | } 44 | } 45 | 46 | TEST(Parameters,CatchMissingDataInDataFile){ 47 | std::string pf=alps::temporary_filename("in_file.dat"); 48 | write_minimal_input_file(pf); 49 | 50 | //fake input 51 | alps::params p; 52 | MaxEntSimulation::define_parameters(p); 53 | p["BETA"]=3; 54 | p["DATA"]=pf; 55 | //test for off by 1 error on data input 56 | p["NDAT"] = 6; 57 | 58 | try{ 59 | ContiParameters c(p); 60 | std::remove(pf.c_str()); 61 | FAIL() << "expected error on missing 4th datapoint"; 62 | 63 | } 64 | catch(...){ 65 | //error caught, user warned 66 | SUCCEED(); 67 | std::remove(pf.c_str()); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /test/paramsTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 1998-2018 ALPS Collaboration. 3 | * All rights reserved. Use is subject to license terms. See LICENSE.TXT 4 | * For use in publications, see ACKNOWLEDGE.TXT 5 | */ 6 | 7 | #include "../src/maxent.hpp" 8 | #include "gtest.h" 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include "write_test_files.hpp" 14 | 15 | TEST(Parameters,ContiParams){ 16 | //set up parameters 17 | alps::params p; 18 | MaxEntSimulation::define_parameters(p); 19 | p["N_ALPHA"] = 60; 20 | p["ALPHA_MIN"] = .01; 21 | p["ALPHA_MAX"] = 20.0; 22 | p["NORM"] = 1.0; 23 | p["OMEGA_MAX"] = 6.0; 24 | p["KERNEL"] = "fermionic"; 25 | p["BETA"] = 2.0; 26 | p["NFREQ"] = 2001; 27 | p["NDAT"] = 5; 28 | p["FREQUENCY_GRID"] = "Lorentzian"; 29 | p["DATASPACE"] = "frequency"; 30 | p["MAX_IT"] = 200; 31 | p["DEFAULT_MODEL"] = "flat"; 32 | p["PARTICLE_HOLE_SYMMETRY"] = true; 33 | p["TEXT_OUTPUT"] = false; 34 | p["X_0"]=.1; 35 | p["X_1"]=.2; 36 | p["X_2"]=.3; 37 | p["X_3"]=.4; 38 | p["X_4"]=.5; 39 | p["SIGMA_0"]=0.5; 40 | p["SIGMA_1"]=0.5; 41 | p["SIGMA_2"]=0.5; 42 | p["SIGMA_3"]=0.5; 43 | p["SIGMA_4"]=0.5; 44 | ContiParameters c(p); 45 | 46 | EXPECT_EQ(c.ndat(),5); 47 | EXPECT_EQ(c.T(),0.5); 48 | 49 | //check input values 50 | for(int i=0;i G; 179 | for(int i=0;i iwn(0,(2*2024+1)*M_PI*c.T()); 186 | for(int j=0;j x,sigma; 223 | for(int i=1;i<6;i++){ 224 | x.push_back(i/10.0); 225 | sigma.push_back(0.5); 226 | } 227 | oar["/Data"] << x; 228 | oar["/Error"] << sigma; 229 | oar.close(); 230 | //now read in same file 231 | alps::hdf5::archive iar(tf, "r"); 232 | alps::params p; 233 | iar["/parameters"] >> p; 234 | iar.close(); 235 | 236 | ContiParameters c(p); 237 | 238 | EXPECT_EQ(c.ndat(),5); 239 | EXPECT_EQ(c.T(),0.5); 240 | 241 | //check input values 242 | for(int i=0;i x,sigma; 367 | for(int i=1;i<6;i++){ 368 | x.push_back(i/10.0); 369 | sigma.push_back(0.5); 370 | } 371 | Eigen::MatrixXd cov = Eigen::MatrixXd::Identity(5,5); 372 | cov *= 0.3; //change error from sigma 373 | std::vector cov_vec; 374 | for(int i=0;i<5;i++){ 375 | for(int j=0;j<5;j++) 376 | cov_vec.push_back(cov(i,j)); 377 | } 378 | oar["/Data"] << x; 379 | oar["/Error"] << sigma; 380 | oar["/Covariance"] << cov_vec; 381 | oar.close(); 382 | //now read in same file 383 | alps::hdf5::archive iar(tf, "r"); 384 | alps::params p; 385 | iar["/parameters"] >> p; 386 | iar.close(); 387 | 388 | MaxEntParameters c(p); 389 | 390 | EXPECT_EQ(c.ndat(),5); 391 | EXPECT_EQ(c.T(),0.5); 392 | 393 | //check input values 394 | for(int i=0;i 7 | #pragma once 8 | 9 | void write_minimal_param_file(const std::string &str){ 10 | std::ofstream tmpfile(str.c_str()); 11 | tmpfile<<"BETA=2" <