Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
ee0e1d7
print samples to be fitted
LupoA Jul 6, 2023
3634477
fit class
LupoA Jul 6, 2023
72b861b
Test for gaussian fitting of spectrum
nickforce989 Jul 17, 2023
9b7bf4a
Updating fits
nickforce989 Jul 24, 2023
405d871
Package first commit
nickforce98 Feb 8, 2024
b355bf0
Correcting README
nickforce98 Feb 8, 2024
db14c8b
Minor changes
nickforce98 Feb 8, 2024
2924528
Minor changes
nickforce98 Feb 8, 2024
23e90f3
Minor correction
nickforce98 Feb 8, 2024
da34ea9
Systematics evaluation
nickforce98 Feb 8, 2024
f938177
Adding Cauchy Kernel and rho fits
nickforce98 Feb 9, 2024
bc58d65
Removed unnecessry pycache
nickforce98 Feb 9, 2024
5a55143
Solving issue #30, renaming exec in examples
nickforce98 Feb 9, 2024
b4be62c
Restructuring a bit
nickforce98 Feb 9, 2024
1953c14
Solving PR review
nickforce98 Feb 11, 2024
df2fc57
Correct README
nickforce98 Feb 11, 2024
23affa8
Change package name
nickforce98 Feb 11, 2024
31595ca
Adding HalfNorm Gauss
nickforce98 Feb 11, 2024
6a2afa8
Fix small error
nickforce98 Feb 11, 2024
6d16327
Fix small error
nickforce98 Feb 11, 2024
432ae24
Examples and documents out of src and other minor
nickforce98 Feb 12, 2024
07910ce
Package named lsdensities
nickforce98 Feb 12, 2024
fab82b3
Updated README
nickforce98 Feb 12, 2024
c1f2b32
Updated README
nickforce98 Feb 12, 2024
e711a9d
Fix runExact
nickforce98 Feb 13, 2024
d62b82e
print fitting details in a file
nickforce98 Feb 14, 2024
dd046f3
pip will install dependencies
LupoA Feb 15, 2024
386f89d
default kernel was not allowed. Raise error if kernel is not supported
LupoA Feb 15, 2024
67acf54
resolve conflicts
LupoA Feb 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
675 changes: 675 additions & 0 deletions LICENSE.txt

Large diffs are not rendered by default.

36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# lsdensities: Spectral densities from two-point correlation functions

lsdensities is a Python library for operating spectral density reconstruction and
related studies, by using the HLT (Hansen-Lupo-Tantalo) method or Gaussian processes.

## Authors

Niccolò Forzano, Alessandro Lupo.

## Installation

One can download, build and install the package

```bash
pip install https://github.com/LupoA/rhos
```

## Usage

```python
import lsdensities

# e.g. compute the S matrix
lsdensities.core.Smatrix_mp(t_max, alpha)
```

## Contributing

Pull requests are welcome. For major changes, please open an issue first
to discuss what you would like to change.

Please make sure to update tests as appropriate.

## License

[GPL](https://choosealicense.com/licenses/gpl-3.0/)
36 changes: 31 additions & 5 deletions exec/test_GPerrorHLT.py → examples/GPerrorHLT.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,29 @@
import sys

sys.path.append("..")
from importall import *

import rhoUtils as u
from .rhoUtils import init_precision
from .rhoUtils import LogMessage
from .rhoUtils import end
from .rhoUtils import Obs
from .rhoUtils import adjust_precision
from .rhoUtils import Inputs
from .rhoUtils import *
from .rhoStat import *
from .rhoMath import *
from .core import *
from .rhoParser import *
from .transform import *
from .abw import *
from .rhoParallelUtils import *
from .HLT_class import *
from .GPHLT_class import *
from .GP_class import *
from .correlatorUtils import foldPeriodicCorrelator
from .correlatorUtils import symmetrisePeriodicCorrelator
from .mpmath import mp, mpf
from .InverseProblemWrapper import *
from .plotutils import *


def init_variables(args_):
Expand Down Expand Up @@ -79,6 +101,11 @@ def main():
corr.evaluate_covmatrix(plot=False)
corr.corrmat_from_covmat(plot=False)

with open(os.path.join(par.outdir,'corrmatrix.txt'), "w") as output:
for i in range(par.time_extent):
for j in range(par.time_extent):
print(i, j, corr.corrmat[i,j], file=output)

# Make it into a mp sample
print(LogMessage(), "Converting correlator into mpmath type")
# mpcorr_sample = mp.matrix(par.num_boot, tmax)
Expand All @@ -88,11 +115,10 @@ def main():
cNorm = mpf(str(corr.central[1] ** 2))

lambdaMax = 1e+4

# Prepare
hltParams = AlgorithmParameters(
alphaA=0,
alphaB=-1.99,
alphaB=1/2,
alphaC=+1.99,
lambdaMax=lambdaMax,
lambdaStep=lambdaMax/2,
Expand All @@ -104,7 +130,7 @@ def main():
matrix_bundle = MatrixBundle(Bmatrix=corr.mpcov, bnorm=cNorm)

# Wrapper for the Inverse Problem
HLTGP = HLTWGPrapper(
HLTGP = HLTGPWrapper(
par=par, algorithmPar=hltParams, matrix_bundle=matrix_bundle, correlator=corr
)
HLTGP.prepareHLT()
Expand Down
Empty file added examples/__init__.py
Empty file.
36 changes: 30 additions & 6 deletions exec/testGP.py → examples/onlyGP.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,30 @@
import sys

sys.path.append("..")
from importall import *

import lsdensities.utils.rhoUtils as u
from lsdensities.utils.rhoUtils import init_precision
from lsdensities.utils.rhoUtils import LogMessage
from lsdensities.utils.rhoUtils import end
from lsdensities.utils.rhoUtils import Obs
from lsdensities.utils.rhoUtils import adjust_precision
from lsdensities.utils.rhoUtils import Inputs
from lsdensities.utils.rhoUtils import *
from lsdensities.utils.rhoStat import *
from lsdensities.utils.rhoMath import *
from lsdensities.core import *
from lsdensities.utils.rhoParser import *
from lsdensities.transform import *
from lsdensities.abw import *
from lsdensities.utils.rhoParallelUtils import *
from lsdensities.HLT_class import *
from lsdensities.GPHLT_class import *
from lsdensities.GP_class import *
from lsdensities.correlator.correlatorUtils import foldPeriodicCorrelator
from lsdensities.correlator.correlatorUtils import symmetrisePeriodicCorrelator
from mpmath import mp, mpf
from lsdensities.InverseProblemWrapper import *
from lsdensities.plotutils import *
import lsdensities

read_SIGMA_ = True

Expand All @@ -11,6 +34,7 @@ def init_variables(args_):
in_.periodicity = args_.periodicity
in_.prec = args_.prec
in_.datapath = args_.datapath
in_.kerneltype = args_.kerneltype
in_.outdir = args_.outdir
in_.massNorm = args_.mpi
in_.num_boot = args_.nboot
Expand Down Expand Up @@ -90,7 +114,7 @@ def main():
lambdaMax = 1e+6

# Prepare
hltParams = AlgorithmParameters(
hltParams = lsdensities.GP_class.AlgorithmParameters(
alphaA=0,
alphaB=1/2,
alphaC=1.99,
Expand All @@ -101,18 +125,18 @@ def main():
kfactor=0.1,
lambdaMin=1e-4
)
matrix_bundle = MatrixBundle(Bmatrix=corr.mpcov, bnorm=cNorm)
matrix_bundle = lsdensities.GP_class.MatrixBundle(Bmatrix=corr.mpcov, bnorm=cNorm)

# Wrapper for the Inverse Problem
GP = GaussianProcessWrapper(
GP = lsdensities.GP_class.GaussianProcessWrapper(
par=par, algorithmPar=hltParams, matrix_bundle=matrix_bundle, correlator=corr, read_SIGMA=read_SIGMA_
)
GP.prepareGP()

# Run
GP.run(how_many_alphas=par.Na)
GP.plotParameterScan(how_many_alphas=par.Na, save_plots=True, plot_live=True)
GP.plotRhos(savePlot=True)
GP.plothltrho(savePlot=True)

end()

Expand Down
36 changes: 30 additions & 6 deletions exec/testHLT.py → examples/onlyHLT.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,30 @@
import sys

sys.path.append("..")
from importall import *

import lsdensities.utils.rhoUtils as u
from lsdensities.utils.rhoUtils import init_precision
from lsdensities.utils.rhoUtils import LogMessage
from lsdensities.utils.rhoUtils import end
from lsdensities.utils.rhoUtils import Obs
from lsdensities.utils.rhoUtils import adjust_precision
from lsdensities.utils.rhoUtils import Inputs
from lsdensities.utils.rhoUtils import *
from lsdensities.utils.rhoStat import *
from lsdensities.utils.rhoMath import *
from lsdensities.core import *
from lsdensities.utils.rhoParser import *
from lsdensities.transform import *
from lsdensities.abw import *
from lsdensities.utils.rhoParallelUtils import *
from lsdensities.HLT_class import *
from lsdensities.GPHLT_class import *
from lsdensities.GP_class import *
from lsdensities.correlator.correlatorUtils import foldPeriodicCorrelator
from lsdensities.correlator.correlatorUtils import symmetrisePeriodicCorrelator
from mpmath import mp, mpf
from lsdensities.InverseProblemWrapper import *
from lsdensities.plotutils import *
import lsdensities


def init_variables(args_):
Expand All @@ -10,6 +33,7 @@ def init_variables(args_):
in_.periodicity = args_.periodicity
in_.prec = args_.prec
in_.datapath = args_.datapath
in_.kerneltype = args_.kerneltype
in_.outdir = args_.outdir
in_.massNorm = args_.mpi
in_.num_boot = args_.nboot
Expand Down Expand Up @@ -95,7 +119,7 @@ def main():
lambdaMax = 1e+8

# Prepare
hltParams = AlgorithmParameters(
hltParams = lsdensities.HLT_class.AlgorithmParameters(
alphaA=0,
alphaB=1/2,
alphaC=+1.99,
Expand All @@ -106,18 +130,18 @@ def main():
kfactor=0.1,
lambdaMin=1e-6
)
matrix_bundle = MatrixBundle(Bmatrix=corr.mpcov, bnorm=cNorm)
matrix_bundle = lsdensities.HLT_class.MatrixBundle(Bmatrix=corr.mpcov, bnorm=cNorm)

# Wrapper for the Inverse Problem
HLT = HLTWrapper(
HLT = lsdensities.HLT_class.HLTWrapper(
par=par, algorithmPar=hltParams, matrix_bundle=matrix_bundle, correlator=corr
)
HLT.prepareHLT()

# Run
HLT.run(how_many_alphas=par.Na)
HLT.plotParameterScan(how_many_alphas=par.Na, save_plots=True, plot_live=True)
HLT.plotRhos(savePlot=True)
HLT.plothltrho(savePlot=True)

end()

Expand Down
26 changes: 24 additions & 2 deletions exec/testHLT_singleAlpha.py → examples/onlyHLT_singleAlpha.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,29 @@
import sys

sys.path.append("..")
from importall import *

import rhoUtils as u
from .rhoUtils import init_precision
from .rhoUtils import LogMessage
from .rhoUtils import end
from .rhoUtils import Obs
from .rhoUtils import adjust_precision
from .rhoUtils import Inputs
from .rhoUtils import *
from .rhoStat import *
from .rhoMath import *
from .core import *
from .rhoParser import *
from .transform import *
from .abw import *
from .rhoParallelUtils import *
from .HLT_class import *
from .GPHLT_class import *
from .GP_class import *
from .correlatorUtils import foldPeriodicCorrelator
from .correlatorUtils import symmetrisePeriodicCorrelator
from .mpmath import mp, mpf
from .InverseProblemWrapper import *
from .plotutils import *

eNorm = False

Expand Down
44 changes: 41 additions & 3 deletions exec/runExact.py → examples/runExact.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,39 @@
import matplotlib.pyplot as plt
import os
import sys
sys.path.append("..")
from importall import *

from mpmath import mpf


import numpy as np
import os
import matplotlib.pyplot as plt

import lsdensities.utils.rhoUtils as u
from lsdensities.utils.rhoUtils import init_precision
from lsdensities.utils.rhoUtils import LogMessage
from lsdensities.utils.rhoUtils import end
from lsdensities.utils.rhoUtils import Obs
from lsdensities.utils.rhoUtils import adjust_precision
from lsdensities.utils.rhoUtils import Inputs
from lsdensities.utils.rhoUtils import *
from lsdensities.utils.rhoStat import *
from lsdensities.utils.rhoMath import *
from lsdensities.core import *
from lsdensities.utils.rhoParser import *
from lsdensities.transform import *
from lsdensities.abw import *
from lsdensities.utils.rhoParallelUtils import *
from lsdensities.HLT_class import *
from lsdensities.GPHLT_class import *
from lsdensities.GP_class import *
from lsdensities.correlator.correlatorUtils import foldPeriodicCorrelator
from lsdensities.correlator.correlatorUtils import symmetrisePeriodicCorrelator
from mpmath import mp, mpf
from lsdensities.InverseProblemWrapper import *
from lsdensities.plotutils import *
import lsdensities

pion_mass = 0.140 # in Gev
a = 0.4 # in Gev ^-1 ( 1 fm = 5.068 GeV^-1 )
a_fm = a / 5.068 # lattice spacing in fm
Expand All @@ -26,6 +55,7 @@ def init_variables(args_):
in_.periodicity = args_.periodicity
in_.prec = args_.prec
in_.outdir = args_.outdir
in_.kerneltype = args_.kerneltype
in_.massNorm = args_.mpi
in_.num_boot = args_.nboot
in_.sigma = args_.sigma
Expand Down Expand Up @@ -70,7 +100,12 @@ def generate(par, seed, espace):

for e_i in range(par.Ne):
for _n in range(STATES):
rhoStrue[e_i] += gauss_fp(peaks_location[_n], espace[e_i], par.sigma, norm="full") * weights[_n]
if par.kerneltype == 'FULLNORMGAUSS':
rhoStrue[e_i] += gauss_fp(peaks_location[_n], espace[e_i], par.sigma, norm="full") * weights[_n]
elif par.kerneltype == 'HALFNORMGAUSS':
rhoStrue[e_i] += gauss_fp(peaks_location[_n], espace[e_i], par.sigma, norm="half") * weights[_n]
elif par.kerneltype == 'CAUCHY':
rhoStrue[e_i] += cauchy(peaks_location[_n], par.sigma, espace[e_i]) * weights[_n]

if par.periodicity == "EXP":
return exact_correlator, espace, rhoStrue
Expand Down Expand Up @@ -119,6 +154,9 @@ def main():
print(LogMessage(), "Energy [a^-1]", espace[e_i])
_g_t_estar = h_Et_mp_Eslice(Sinv, par, espace[e_i], alpha_=0)
rhos[e_i] = y_combine_central_Eslice_mp(_g_t_estar, exact_correlator, par)
print('Exact Rho: ', rhoStrue[e_i])
print('Reconstructed Rho: ', rhos[e_i])


plt.plot(
espace/a,
Expand Down
Loading