1
0
mirror of https://github.com/aportelli/LatAnalyze.git synced 2025-06-14 13:57:06 +01:00

66 Commits
3.1 ... 3.3.1

Author SHA1 Message Date
8a229ec0b0 minor portability fixes 2018-04-23 11:34:36 +01:00
d5b743b985 Merge branch 'release/3.3' 2017-11-16 19:33:05 +00:00
e0e4bd327b ready for release 2017-11-16 19:12:14 +00:00
07bbdca089 latan-resample fix 2017-11-16 19:12:04 +00:00
28a036ca9c gitignore update 2017-11-16 18:13:46 +00:00
260c70cbeb More HDF5 CI fix 2017-11-16 17:04:37 +00:00
5e96db7b24 HDF5 CI fix 2017-11-16 16:53:59 +00:00
6b624186cd FFT with GSL 2017-10-10 16:56:23 +01:00
839159831f More general sample-element util 2017-10-10 16:56:13 +01:00
98cf39efda option to dump bootstrap sequence while resampling 2017-10-02 11:54:12 +01:00
3d514ef026 gitignore update 2017-07-19 19:03:41 +02:00
a498a836ce Tabulated functions: method to change interpolation type 2017-07-19 19:03:22 +02:00
6906b0c00d sample-combine fix 2017-07-09 14:31:14 +01:00
e43a7c6d0b latan-sample-combine now accepts mix of DSample & DMatSample 2017-07-09 14:15:37 +01:00
92822348f6 GSL integrator generalised to integrals with infinite bounds 2017-07-09 14:15:01 +01:00
810c860256 Infinity is now a math constant 2017-07-09 14:14:36 +01:00
5641f3b481 Sample plot utility 2017-07-09 14:14:11 +01:00
76dffb7775 Merge branch 'release/3.2.2' 2017-07-05 15:09:04 +01:00
769dfd2e05 .gitignore update 2017-01-11 11:28:20 +00:00
4576d73379 vector version of setUnidimData 2016-12-13 10:37:37 +00:00
d80b160521 Math interpreter: added infinity as a constant 2016-12-13 10:30:02 +00:00
c6bc8c9af2 XYSampleData: variance matrix compute fix 2016-12-13 10:29:37 +00:00
005ffeea5f Merge branch 'hotfix/3.2.1' into develop
# Conflicts:
#	configure.ac
2016-06-15 19:26:15 +01:00
af78c201e6 Merge branch 'hotfix/3.2.1' 2016-06-15 19:25:38 +01:00
91cdfa9f8b preparation for 3.2.1 2016-06-15 19:25:30 +01:00
582528f243 wrong argument check in latan-resample 2016-06-15 19:22:24 +01:00
ba8056d9b0 start of 3.2 unstable 2016-06-14 19:33:13 +01:00
a89ed85e43 Merge branch 'release/3.2' 2016-06-14 19:31:57 +01:00
01672cef99 Merge branch 'release/3.2' into develop 2016-06-14 19:31:57 +01:00
77a585ac4b Readme update 2016-06-14 18:55:51 +01:00
84993d85b4 Merge branch 'develop' into release/3.2 2016-06-14 18:55:25 +01:00
cbdb2fba6f Merge commit '82d020c82fb0a3ac8f1b56da8b3e00a0fff4716d' into develop
# Conflicts:
#	utils/Makefile.am
2016-06-14 18:40:03 +01:00
553181787f more Travis fix 2016-06-14 18:28:51 +01:00
761d68bc82 Travis debug 2016-06-14 18:19:41 +01:00
6a37baaf28 Travis debug 2016-06-14 18:12:32 +01:00
b6a96619d2 Travis debug 2016-06-14 18:07:08 +01:00
9631a2565f Travis fix 2016-06-14 18:03:17 +01:00
3bff42b554 Travis fix 2016-06-14 17:58:24 +01:00
3603d67d97 Travis fix 2016-06-14 17:46:04 +01:00
16ea3e753a Travis fix 2016-06-14 17:39:45 +01:00
05ac1cc3ad Travis: fix for Linux clang builds 2016-06-14 17:31:47 +01:00
2976f6f347 preparing for 3.2 2016-06-14 14:08:02 +01:00
1bede86547 systematically using LatCore argument parser for utilities 2016-06-14 14:06:59 +01:00
83afc7901b 2-pt fitter moved here from UKAnalyze 2016-06-14 12:35:17 +01:00
85d76052ce more consistent naming of utilities 2016-06-14 12:34:46 +01:00
b925a365e2 Plot: bands 2016-06-14 12:33:27 +01:00
82d020c82f Utils: Renamed sample_flatten.cpp to sample_element.cpp as suggested 2016-06-09 17:38:41 +01:00
1f3a8c27a1 Utils: Added little utility to flatten 1x1 DMatSamples 2016-06-07 18:11:01 +01:00
7e3ab34a31 Merge branch 'master' into develop 2016-06-06 18:38:41 +01:00
f3959e14cc Readme update 2016-06-06 18:37:56 +01:00
6616c5a206 Merge branch 'hotfix/3.1.2' into develop 2016-06-06 18:36:17 +01:00
558fe80bf9 Merge branch 'hotfix/3.1.2' 2016-06-06 18:36:17 +01:00
6f70c44d12 Build scripts: HDF5 link update 2016-06-06 18:22:30 +01:00
fe0f32e42c XYSampleData: more stable fit initialisation strategy 2016-05-27 13:40:57 +01:00
67c4119859 Merge branch 'hotfix/3.1.1' into develop 2016-04-19 19:26:49 -07:00
bda9135a44 Merge branch 'hotfix/3.1.1' 2016-04-19 19:25:36 -07:00
baf2b695c6 3.1.1 release 2016-04-19 19:25:11 -07:00
9edec3709b consistent boolean notation 2016-04-19 19:21:05 -07:00
60170db570 fix in fit dimension name indexing 2016-04-19 19:15:42 -07:00
1f7dba7779 Minuit precsion fix 2016-04-15 18:23:45 +01:00
0bd347d010 more robust type cast in I/O functions 2016-04-15 18:23:17 +01:00
1a6b877f4e more precise output for fit results 2016-04-15 18:21:40 +01:00
e7fd245c10 start of 3.1 unstable branch 2016-04-13 12:54:05 +01:00
fe73be2725 Merge branch 'master' into develop 2016-04-13 12:52:53 +01:00
7c12ea6e64 Merge branch 'master' into develop 2016-04-13 12:49:58 +01:00
b25cfdc308 Merge branch 'release/3.1' into develop 2016-04-13 12:47:07 +01:00
46 changed files with 1191 additions and 198 deletions

11
.gitignore vendored
View File

@ -3,7 +3,7 @@ build/*
build_debug/*
sandbox/*
# Apple stuffs
# Apple stuff
*.xcodeproj
.DS_Store
@ -30,3 +30,12 @@ lib/eigen_files.mk
# CI builds
ci-scripts/local/*
# CLion stuff
.idea/*
CMakeLists.txt
cmake-build-debug/*
# VS Code Studio stuff
.vscode
*.code-workspace

View File

@ -7,6 +7,7 @@ notifications:
cache:
directories:
- ci-scripts/local
- ci-scripts/clang
matrix:
include:
@ -44,37 +45,43 @@ matrix:
apt:
sources:
- ubuntu-toolchain-r-test
- llvm-toolchain-precise-3.6
packages:
- clang-3.6
- g++-4.8
- libgsl0-dev
- flex
- bison
env: VERSION=-3.6
env: CLANG_LINK=http://llvm.org/releases/3.6.0/clang+llvm-3.6.0-x86_64-linux-gnu-ubuntu-14.04.tar.xz
- compiler: clang
addons:
apt:
sources:
- ubuntu-toolchain-r-test
- llvm-toolchain-precise-3.7
packages:
- clang-3.7
- g++-4.8
- libgsl0-dev
- flex
- bison
env: VERSION=-3.7
env: CLANG_LINK=http://llvm.org/releases/3.7.0/clang+llvm-3.7.0-x86_64-linux-gnu-ubuntu-14.04.tar.xz
before_install:
- export LATDIR=`pwd`
- cd ci-scripts
- if [[ "$TRAVIS_OS_NAME" == "linux" ]] && [[ "$CC" == "clang" ]] && [ ! -e clang/bin ]; then wget $CLANG_LINK; tar -xf `basename $CLANG_LINK`; mkdir clang; mv clang+*/* clang/; fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]] && [[ "$CC" == "clang" ]]; then export PATH="${LATDIR}/ci-scripts/clang/bin:${PATH}"; fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]] && [[ "$CC" == "clang" ]]; then export LD_LIBRARY_PATH="${LATDIR}/ci-scripts/clang/lib:${LD_LIBRARY_PATH}"; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install gsl; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install bison flex; export PATH="/usr/local/opt/flex/bin:/usr/local/opt/bison/bin:$PATH"; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]] && [[ "$CC" == "gcc" ]]; then brew install gcc5; fi
install:
- export LATDIR=`pwd`
- export CC=$CC$VERSION
- export CXX=$CXX$VERSION
- cd ci-scripts
- echo $PATH
- which $CC
- $CC --version
- which $CXX
- $CXX --version
- ./install-deps.sh `pwd`/local
- cd ..
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then export LD_LIBRARY_PATH=${LATDIR}/ci-scripts/local/lib:$LD_LIBRARY_PATH; fi

View File

@ -1,3 +1,3 @@
SUBDIRS = lib utils examples
SUBDIRS = lib utils physics examples
ACLOCAL_AMFLAGS = -I .buildutils/m4

View File

@ -55,6 +55,51 @@ in the `ci-scripts` directory where `<prefix>` is where you want LatAnalyze (and
For a more customised installation, one first needs to generate the build system by running `./bootstrap.sh` in the root directory. Then the library can be built and installed through the usual GNU mantra `./configure <options> && make && make install`. Use `./configure --help` to obtain a list of possible options for `./configure`. Because Eigen expressions rely a lot on inlining and compiler optimisations it is strongly recommended to set the `CXXFLAGS` variable to `-O3 -march=native -mtune=native`.
## History
#### v3.3
Additions:
* Sample plot CL utility.
* Infinity as a math constant.
* Option to dump bootstrap sequence while resampling.
* FFT through the GSL.
Changes:
* GSL integrator accepts infinite bounds.
* `latan-sample-combine` accepts mixes of `DSample` and `DMatSample`.
* More general `latan-sample-element` command.
#### v3.2.2
Additions:
* The math interpreter supports `inf` for infinity.
Changes:
* Vector version of `setUnidimData`.
Fixes:
* Variance matrix computation fix.
#### v3.2.1
Fix:
* Wrong argument number check in `latan-resample`
#### v3.2 (needs LatCore 1.1)
Additions:
* 2-pt function fitter `latan-2pt-fit`
* Tool to extract one element of a matrix sample `latan-sample-element`
* Band plotting
Changes:
* Sample utilities renamed `latan-sample-*`
* Resample utility renamed `latan-resample`
#### v3.1.2
Fixes:
* HDF5 archive URL update in build scripts
#### v3.1.1 (needs LatCore 1.0)
Fixes:
* Minuit precision fixed
* Minor fit interface fixes
#### v3.1
Additions:
* Wrappers to NLopt and GSL minimisers.

View File

@ -1,6 +1,6 @@
#!/usr/bin/env bash
NAME='hdf5-1.8.16'
NAME='hdf5-1.10.1'
if (( $# != 1 )); then
echo "usage: `basename $0` <prefix> {osx|linux}" 1>&2
@ -11,7 +11,7 @@ PREFIX=$1
set -ex
INITDIR=`pwd`
cd local/build
wget http://www.hdfgroup.org/ftp/HDF5/current/src/${NAME}.tar.gz
wget https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.10/${NAME}/src/${NAME}.tar.gz
tar -xzvf ${NAME}.tar.gz
mkdir ${NAME}/build
cd ${NAME}/build

View File

@ -2,7 +2,7 @@
# Initialization
AC_PREREQ([2.63])
AC_INIT([LatAnalyze],[3.1],[antonin.portelli@me.com],[LatAnalyze])
AC_INIT([LatAnalyze],[3.3],[antonin.portelli@me.com],[LatAnalyze])
AC_CONFIG_AUX_DIR([.buildutils])
AC_CONFIG_SRCDIR([lib/Global.cpp])
AC_CONFIG_SRCDIR([utils/sample_read.cpp])
@ -131,7 +131,8 @@ AC_SUBST([LIBS])
AC_SUBST([AM_CFLAGS])
AC_SUBST([AM_LDFLAGS])
AC_CONFIG_FILES([Makefile lib/Makefile utils/Makefile examples/Makefile])
AC_CONFIG_FILES([Makefile lib/Makefile utils/Makefile physics/Makefile
examples/Makefile])
AC_OUTPUT
echo "*********************************************"

View File

@ -7,8 +7,8 @@ using namespace Latan;
int main(void)
{
constexpr double a = 1., b = 10.;
DoubleFunction f1([a](const double *x){return a*(1.-x[0]);}, 2);
DoubleFunction f2([b](const double *x){return b*(x[1]-x[0]*x[0]);}, 2);
DoubleFunction f1([](const double *x){return a*(1.-x[0]);}, 2);
DoubleFunction f2([](const double *x){return b*(x[1]-x[0]*x[0]);}, 2);
vector<DoubleFunction *> system = {&f1, &f2};
GslHybridRootFinder solve;
DVec init(2), x;

View File

@ -170,7 +170,7 @@ void AsciiFile::open(const string &name, const unsigned int mode)
std::string AsciiFile::load(const string &name)
{
if ((mode_ & Mode::read)&&(isOpen()))
if ((mode_ & Mode::read) and (isOpen()))
{
if (!isParsed_)
{

View File

@ -47,6 +47,8 @@ public:
// resampling
Sample<T> bootstrapMean(const Index nSample, const SeedType seed);
Sample<T> bootstrapMean(const Index nSample);
void dumpBootstrapSeq(std::ostream &out, const Index nSample,
const SeedType seed);
private:
// mean from pointer vector for resampling
void ptVectorMean(T &m, const std::vector<const T *> &v);
@ -114,6 +116,23 @@ Sample<T> Dataset<T>::bootstrapMean(const Index nSample)
return bootstrapMean(nSample, rd());
}
template <typename T>
void Dataset<T>::dumpBootstrapSeq(std::ostream &out, const Index nSample,
const SeedType seed)
{
std::mt19937 gen(seed);
std::uniform_int_distribution<Index> dis(0, this->size() - 1);
for (Index i = 0; i < nSample; ++i)
{
for (unsigned int j = 0; j < this->size(); ++j)
{
out << dis(gen) << " " << std::endl;
}
out << std::endl;
}
}
template <typename T>
void Dataset<T>::ptVectorMean(T &m, const std::vector<const T *> &v)
{

53
lib/FFT.hpp Normal file
View File

@ -0,0 +1,53 @@
/*
* FFT.hpp, part of LatAnalyze
*
* Copyright (C) 2013 - 2017 Antonin Portelli
*
* LatAnalyze is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LatAnalyze is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LatAnalyze. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef Latan_FFT_hpp_
#define Latan_FFT_hpp_
#include <LatAnalyze/Global.hpp>
BEGIN_LATAN_NAMESPACE
/******************************************************************************
* FFT abstract class *
******************************************************************************/
class FFT
{
public:
enum
{
Forward = 0,
Backward = 1
};
public:
// constructor
FFT(void) = default;
FFT(const Index size);
// destructor
virtual ~FFT(void) = default;
// size
virtual void resize(const Index size) = 0;
// FFT
virtual void operator()(CMat &x, const unsigned int dir = FFT::Forward) = 0;
};
END_LATAN_NAMESPACE
#endif // Latan_FFT_hpp_

View File

@ -57,7 +57,7 @@ void File::deleteData(void)
void File::checkWritability(void)
{
if (!((mode_ & Mode::write)||(mode_ & Mode::append))||!isOpen())
if (!((mode_ & Mode::write) or (mode_ & Mode::append)) or !isOpen())
{
LATAN_ERROR(Io, "file '" + name_ + "' is not writable");
}

View File

@ -110,6 +110,12 @@ const IoT& File::getData(const std::string &name) const
LATAN_ERROR(Definition, "no data with name '" + name + "' in file "
+ name_);
}
catch(std::bad_cast)
{
LATAN_ERROR(Definition, "data with name '" + name + "' in file "
+ name_ + " does not have type '" + typeid(IoT).name()
+ "'");
}
}
END_LATAN_NAMESPACE

View File

@ -58,7 +58,7 @@ void FitInterface::addXDim(const Index nData, const string name,
scheduleDataCoordInit();
if (!name.empty())
{
xName().setName(getNXDim(), name);
xName().setName(getNXDim() - 1, name);
}
}
}
@ -70,7 +70,7 @@ void FitInterface::addYDim(const string name)
scheduleLayoutInit();
if (!name.empty())
{
yName().setName(getNYDim(), name);
yName().setName(getNYDim() - 1, name);
}
}

View File

@ -183,7 +183,7 @@ DoubleFunction & DoubleFunction::operator op##=(const DoubleFunction &f)\
setFunction(res, getNArg());\
return *this;\
}\
DoubleFunction & DoubleFunction::operator op##=(const DoubleFunction &&f)\
DoubleFunction & DoubleFunction::operator op##=(const DoubleFunction and f)\
{\
*this op##= f;\
return *this;\

89
lib/GslFFT.cpp Normal file
View File

@ -0,0 +1,89 @@
/*
* GslFFT.cpp, part of LatAnalyze
*
* Copyright (C) 2013 - 2017 Antonin Portelli
*
* LatAnalyze is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LatAnalyze is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LatAnalyze. If not, see <http://www.gnu.org/licenses/>.
*/
#include <LatAnalyze/GslFFT.hpp>
#include <LatAnalyze/includes.hpp>
using namespace std;
using namespace Latan;
/******************************************************************************
* GslFFT implementation *
******************************************************************************/
// constructor /////////////////////////////////////////////////////////////////
GslFFT::GslFFT(const Index size)
{
resize(size);
}
// destructor //////////////////////////////////////////////////////////////////
GslFFT::~GslFFT(void)
{
clear();
}
// size ////////////////////////////////////////////////////////////////////////
void GslFFT::resize(const Index size)
{
if (size_ != size)
{
size_ = size;
wavetable_ = gsl_fft_complex_wavetable_alloc(size_);
workspace_ = gsl_fft_complex_workspace_alloc(size_);
}
}
// fft /////////////////////////////////////////////////////////////////////////
void GslFFT::operator()(CMat &x, const unsigned int dir)
{
if (x.size() != size_)
{
LATAN_ERROR(Size, "wrong input vector size");
}
else
{
switch (dir)
{
case FFT::Forward:
gsl_fft_complex_forward((double *)x.data(), 1, size_,
wavetable_, workspace_);
break;
case FFT::Backward:
gsl_fft_complex_backward((double *)x.data(), 1, size_,
wavetable_, workspace_);
break;
default:
LATAN_ERROR(Argument, "invalid FT direction");
break;
}
}
}
// destroy GSL objects /////////////////////////////////////////////////////////
void GslFFT::clear(void)
{
if (!wavetable_)
{
gsl_fft_complex_wavetable_free(wavetable_);
}
if (!workspace_)
{
gsl_fft_complex_workspace_free(workspace_);
}
}

57
lib/GslFFT.hpp Normal file
View File

@ -0,0 +1,57 @@
/*
* GslFFT.hpp, part of LatAnalyze
*
* Copyright (C) 2013 - 2017 Antonin Portelli
*
* LatAnalyze is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LatAnalyze is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LatAnalyze. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef Latan_GslFFT_hpp_
#define Latan_GslFFT_hpp_
#include <LatAnalyze/Global.hpp>
#include <LatAnalyze/Mat.hpp>
#include <LatAnalyze/FFT.hpp>
#include <gsl/gsl_fft_complex.h>
BEGIN_LATAN_NAMESPACE
/******************************************************************************
* GSL FFT *
******************************************************************************/
class GslFFT: public FFT
{
public:
// constructors
GslFFT(void) = default;
GslFFT(const Index size);
// destructor
virtual ~GslFFT(void);
// size
void resize(const Index size);
// fft
virtual void operator()(CMat &x, const unsigned int dir = FFT::Forward);
private:
// destroy GSL objects
void clear(void);
private:
Index size_{0};
gsl_fft_complex_wavetable *wavetable_{nullptr};
gsl_fft_complex_workspace *workspace_{nullptr};
};
END_LATAN_NAMESPACE
#endif // Latan_GslFFT_hpp_

View File

@ -122,7 +122,7 @@ GslHybridRootFinder::operator()(const vector<DoubleFunction *> &func)
break;
}
status = gsl_multiroot_test_residual(solver_->f, getPrecision());
} while ((status == GSL_CONTINUE)&&(iter < getMaxIteration()));
} while ((status == GSL_CONTINUE) and (iter < getMaxIteration()));
if (verbosity >= Verbosity::Debug)
{
cout << "--- done" << endl;

View File

@ -19,6 +19,7 @@
#include <LatAnalyze/GslQagsIntegrator.hpp>
#include <LatAnalyze/includes.hpp>
#include <LatAnalyze/Math.hpp>
using namespace std;
using namespace Latan;
@ -55,9 +56,26 @@ double GslQagsIntegrator::operator()(const DoubleFunction &f, const double xMin,
gslF.function = fWrap;
gslF.params = reinterpret_cast<void *>(&const_cast<DoubleFunction &>(f));
gsl_integration_qags(&gslF, xMin, xMax, 0.0, precision_, limit_, workspace_,
&result, &error_);
if ((xMin > -Math::inf) and (xMax < Math::inf))
{
gsl_integration_qags(&gslF, xMin, xMax, 0.0, precision_, limit_,
workspace_, &result, &error_);
}
else if (xMax < Math::inf)
{
gsl_integration_qagil(&gslF, xMax, 0.0, precision_, limit_,
workspace_, &result, &error_);
}
else if (xMin > -Math::inf)
{
gsl_integration_qagiu(&gslF, xMin, 0.0, precision_, limit_,
workspace_, &result, &error_);
}
else
{
gsl_integration_qagi(&gslF, 0.0, precision_, limit_,
workspace_, &result, &error_);
}
return result;
}

View File

@ -207,14 +207,14 @@ string Hdf5File::getFirstGroupName(void)
{
string res;
if ((mode_ & Mode::read)&&(isOpen()))
if ((mode_ & Mode::read) and (isOpen()))
{
auto firstGroupName = [](hid_t loc_id, const char *name, void *fname)
{
H5G_stat_t statbuf;
H5Gget_objinfo(loc_id, name, 0, &statbuf);
if ((statbuf.type == H5G_GROUP) && (strlen((char *)fname) == 0))
if ((statbuf.type == H5G_GROUP) and (strlen((char *)fname) == 0))
{
strncpy((char *)fname, name, maxGroupNameSize);
}
@ -268,7 +268,7 @@ void Hdf5File::load(DSample &ds, const DataSet &d)
string Hdf5File::load(const string &name)
{
if ((mode_ & Mode::read)&&(isOpen()))
if ((mode_ & Mode::read) and (isOpen()))
{
string groupName;
Group group;

View File

@ -165,7 +165,7 @@ double Histogram::operator()(const double x) const
// percentiles & confidence interval ///////////////////////////////////////////
double Histogram::percentile(const double p) const
{
if ((p < 0.0)||(p > 100.0))
if ((p < 0.0) or (p > 100.0))
{
LATAN_ERROR(Range, "percentile (" + strFrom(p) + ")"
" is outside the [0, 100] range");

View File

@ -38,7 +38,7 @@ unique_ptr<File> Io::open(const std::string &fileName, const unsigned int mode)
{
string ext = extension(fileName);
if ((ext == "dat")||(ext == "sample")||(ext == "seed"))
if ((ext == "dat") or (ext == "sample") or (ext == "seed"))
{
return unique_ptr<File>(new AsciiFile(fileName, mode));
}

View File

@ -31,6 +31,7 @@ libLatAnalyze_la_SOURCES = \
FitInterface.cpp \
Function.cpp \
Global.cpp \
GslFFT.cpp \
GslHybridRootFinder.cpp\
GslMinimizer.cpp \
GslQagsIntegrator.cpp \
@ -59,10 +60,12 @@ libLatAnalyze_la_HEADERS = \
Dataset.hpp \
Derivative.hpp \
Exceptions.hpp \
FFT.hpp \
Function.hpp \
File.hpp \
FitInterface.hpp \
Global.hpp \
GslFFT.hpp \
GslHybridRootFinder.hpp\
GslMinimizer.hpp \
GslQagsIntegrator.hpp \

View File

@ -228,7 +228,7 @@ Index MatSample<T>::BlockTemplate<S>::getNCol(void) const
// assignement operators ///////////////////////////////////////////////////////
template <typename T>
template <class S>
MatSample<T>::BlockTemplate<S> &
typename MatSample<T>::template BlockTemplate<S> &
MatSample<T>::BlockTemplate<S>::operator=(const S &sample)
{
FOR_STAT_ARRAY(sample_, s)
@ -241,7 +241,7 @@ MatSample<T>::BlockTemplate<S>::operator=(const S &sample)
template <typename T>
template <class S>
MatSample<T>::BlockTemplate<S> &
typename MatSample<T>::template BlockTemplate<S> &
MatSample<T>::BlockTemplate<S>::operator=(const S &&sample)
{
*this = sample;

View File

@ -72,8 +72,9 @@ namespace MATH_NAMESPACE
DMat varToCorr(const DMat &var);
// Constants
const double pi = 3.1415926535897932384626433832795028841970;
const double e = 2.7182818284590452353602874713526624977572;
constexpr double pi = 3.1415926535897932384626433832795028841970;
constexpr double e = 2.7182818284590452353602874713526624977572;
constexpr double inf = std::numeric_limits<double>::infinity();
}

View File

@ -478,7 +478,7 @@ void SemicolonNode::compile(Program &program, RunContext &context) const
bool isSemiColumn = isDerivedFrom<SemicolonNode>(&n[i]);
bool isKeyword = isDerivedFrom<KeywordNode>(&n[i]);
if (isAssign||isSemiColumn||isKeyword)
if (isAssign or isSemiColumn or isKeyword)
{
n[i].compile(program, context);
}
@ -513,7 +513,7 @@ void AssignNode::compile(Program &program, RunContext &context) const
}
// MathOpNode compile //////////////////////////////////////////////////////////
#define IFNODE(name, nArg) if ((n.getName() == (name))&&(n.getNArg() == nArg))
#define IFNODE(name, nArg) if ((n.getName() == (name)) and (n.getNArg() == nArg))
#define ELIFNODE(name, nArg) else IFNODE(name, nArg)
#define ELSE else
@ -689,7 +689,8 @@ void MathInterpreter::compile(RunContext &context)
{
if (root_)
{
context.addVariable("pi", Math::pi);
context.addVariable("pi", Math::pi);
context.addVariable("inf", Math::inf);
ADD_STDMATH_FUNCS(context);
root_->compile(program_, context);
for (unsigned int i = 0; i < program_.size(); ++i)
@ -703,7 +704,7 @@ void MathInterpreter::compile(RunContext &context)
}
}
}
if (!root_||!gotReturn)
if (!root_ or !gotReturn)
{
LATAN_ERROR(Syntax, "expected 'return' in program '" + codeName_
+ "'");

View File

@ -58,9 +58,10 @@ const DVec & MinuitMinimizer::operator()(const DoubleFunction &f)
using namespace ROOT;
using namespace Minuit2;
DVec &x = getState();
int printLevel = 0;
EMinimizerType minuitAlg = kCombined;
DVec &x = getState();
int printLevel = 0;
EMinimizerType minuitAlg = kCombined;
double prec = getPrecision();
// convert Latan parameters to Minuit parameters
switch (getVerbosity())
@ -75,16 +76,21 @@ const DVec & MinuitMinimizer::operator()(const DoubleFunction &f)
printLevel = 3;
break;
}
// The factor of 0.002 here is to compensate the dirty hack in Minuit
// source used to match the C++ and F77 versions
// (cf. VariableMetricBuilder.cxx)
switch (getAlgorithm())
{
case Algorithm::migrad:
minuitAlg = kMigrad;
minuitAlg = kMigrad;
prec /= 0.002;
break;
case Algorithm::simplex:
minuitAlg = kSimplex;
break;
case Algorithm::combined:
minuitAlg = kCombined;
minuitAlg = kCombined;
prec /= 0.002;
break;
}
@ -99,7 +105,7 @@ const DVec & MinuitMinimizer::operator()(const DoubleFunction &f)
min.SetStrategy(2);
min.SetMaxFunctionCalls(getMaxIteration());
min.SetTolerance(getPrecision());
min.SetTolerance(prec);
min.SetPrintLevel(printLevel);
// set function and variables
@ -146,7 +152,7 @@ const DVec & MinuitMinimizer::operator()(const DoubleFunction &f)
min.Minimize();
status = min.Status();
n++;
} while (status and (n < getMaxPass()));
} while ((status >= 2) and (n < getMaxPass()));
if (getVerbosity() >= Verbosity::Normal)
{
cout << "=================================================" << endl;
@ -154,7 +160,8 @@ const DVec & MinuitMinimizer::operator()(const DoubleFunction &f)
switch (status)
{
case 1:
LATAN_WARNING("invalid minimum: covariance matrix was made positive");
// covariance matrix was made positive, the minimum is still good
// it just means that Minuit error analysis is inaccurate
break;
case 2:
LATAN_WARNING("invalid minimum: Hesse analysis is not valid");

View File

@ -183,6 +183,20 @@ PlotHLine::PlotHLine(const double y)
setCommand(strFrom(y));
}
// PlotHBand constructor ///////////////////////////////////////////////////////
PlotBand::PlotBand(const double xMin, const double xMax, const double yMin,
const double yMax, const double opacity)
{
setCommand("'< printf \"%e %e\\n%e %e\\n%e %e\\n%e %e\\n%e %e\\n\" "
+ strFrom(xMin) + " " + strFrom(yMin) + " "
+ strFrom(xMax) + " " + strFrom(yMin) + " "
+ strFrom(xMax) + " " + strFrom(yMax) + " "
+ strFrom(xMin) + " " + strFrom(yMax) + " "
+ strFrom(xMin) + " " + strFrom(yMin)
+ "' u 1:2 w filledcurves closed fs solid " + strFrom(opacity)
+ " noborder");
}
// PlotFunction constructor ////////////////////////////////////////////////////
PlotFunction::PlotFunction(const DoubleFunction &function, const double xMin,
const double xMax, const unsigned int nPoint)
@ -458,7 +472,7 @@ void Plot::getProgramPath(void)
{
for (i=0;path[i];)
{
for (j=i;(path[j])&&(path[j]!=':');j++);
for (j=i;(path[j]) and (path[j]!=':');j++);
lg = j - i;
strncpy(buf,path + i,(size_t)(lg));
if (lg == 0)

View File

@ -106,6 +106,16 @@ public:
virtual ~PlotHLine(void) = default;
};
class PlotBand: public PlotObject
{
public:
// constructor
PlotBand(const double xMin, const double xMax, const double yMin,
const double yMax, const double opacity = 0.15);
// destructor
virtual ~PlotBand(void) = default;
};
class PlotFunction: public PlotObject
{
public:

View File

@ -262,7 +262,7 @@ namespace ReducOp
inline Mat<double> tensProd(const Mat<double> &v1,
const Mat<double> &v2)
{
if ((v1.cols() != 1)||(v2.cols() != 1))
if ((v1.cols() != 1) or (v2.cols() != 1))
{
LATAN_ERROR(Size,
"tensorial product is only valid with column vectors");

View File

@ -29,18 +29,11 @@ using namespace Latan;
// constructors ////////////////////////////////////////////////////////////////
TabFunction::TabFunction(const DVec &x, const DVec &y,
const InterpType interpType)
: interpType_(interpType)
{
setData(x, y);
setInterpolationType(interpType);
}
//TabFunction::TabFunction(const XYStatData &data, const Index i, const Index j,
// const InterpType interpType)
//: interpType_(interpType)
//{
// setData(data, i, j);
//}
// access //////////////////////////////////////////////////////////////////////
void TabFunction::setData(const DVec &x, const DVec &y)
{
@ -54,10 +47,10 @@ void TabFunction::setData(const DVec &x, const DVec &y)
}
}
//void TabFunction::setData(const XYStatData &data, const Index i, const Index j)
//{
// setData(data.x(i), data.y(j));
//}
void TabFunction::setInterpolationType(const InterpType interpType)
{
interpType_ = interpType;
}
// function call ///////////////////////////////////////////////////////////////
double TabFunction::operator()(const double *arg) const
@ -65,7 +58,7 @@ double TabFunction::operator()(const double *arg) const
double result = 0.0, x = arg[0];
if ((x < value_.begin()->first) || (x >= value_.rbegin()->first)) {
if ((x < value_.begin()->first) or (x >= value_.rbegin()->first)) {
LATAN_ERROR(Range, "tabulated function variable out of range "
"(x= " + strFrom(x) + " not in ["
+ strFrom(value_.begin()->first) + ", "
@ -154,12 +147,6 @@ DoubleFunction Latan::interpolate(const DVec &x, const DVec &y,
return TabFunction(x, y, interpType).makeFunction();
}
//DoubleFunction Latan::interpolate(const XYStatData &data, const Index i,
// const Index j, const InterpType interpType)
//{
// return TabFunction(data, i, j, interpType).makeFunction();
//}
map<double, double>::const_iterator TabFunction::nearest(const double x) const
{
map<double, double>::const_iterator ret;

View File

@ -45,13 +45,11 @@ public:
TabFunction(void) = default;
TabFunction(const DVec &x, const DVec &y,
const InterpType interpType = InterpType::LINEAR);
//TabFunction(const XYStatData &data, const Index i = 0, const Index j = 0,
// const InterpType interpType = InterpType::LINEAR);
// destructor
virtual ~TabFunction(void) = default;
// access
void setData(const DVec &x, const DVec &y);
// void setData(const XYStatData &data, const Index i = 0, const Index j = 0);
void setInterpolationType(const InterpType interpType);
// function call
double operator()(const double *arg) const;
// factory
@ -65,9 +63,6 @@ private:
DoubleFunction interpolate(const DVec &x, const DVec &y,
const InterpType interpType = InterpType::LINEAR);
//DoubleFunction interpolate(const XYStatData &data, const Index i = 0,
// const Index j = 0,
// const InterpType interpType = InterpType::LINEAR);
END_LATAN_NAMESPACE

View File

@ -98,7 +98,7 @@ void SampleFitResult::print(const bool printXsi, ostream &out) const
Index pMax = printXsi ? size() : nPar_;
DMat err = this->variance().cwiseSqrt();
sprintf(buf, "chi^2/dof= %.1f/%d= %.2f -- p-value= %.2e", getChi2(),
sprintf(buf, "chi^2/dof= %.1e/%d= %.2e -- p-value= %.2e", getChi2(),
static_cast<int>(getNDof()), getChi2PerDof(), getPValue());
out << buf << endl;
for (Index p = 0; p < pMax; ++p)
@ -171,6 +171,20 @@ const DSample & XYSampleData::y(const Index k, const Index j) const
return yData_[j].at(k);
}
void XYSampleData::setUnidimData(const DMatSample &xData,
const vector<const DMatSample *> &v)
{
FOR_STAT_ARRAY(xData, s)
FOR_VEC(xData[central], r)
{
x(r, 0)[s] = xData[s](r);
for (unsigned int j = 0; j < v.size(); ++j)
{
y(r, j)[s] = (*(v[j]))[s](r);
}
}
}
const DMat & XYSampleData::getXXVar(const Index i1, const Index i2)
{
checkXDim(i1);
@ -253,6 +267,7 @@ void XYSampleData::setDataToSample(const Index s)
const XYStatData & XYSampleData::getData(void)
{
setDataToSample(central);
computeVarMat();
return data_;
}
@ -277,12 +292,12 @@ SampleFitResult XYSampleData::fit(std::vector<Minimizer *> &minimizer,
if (s == central)
{
sampleResult = data_.fit(minimizer, initCopy, v);
initCopy = sampleResult.segment(0, initCopy.size());
}
else
{
sampleResult = data_.fit(*(minimizer.back()), initCopy, v);
}
initCopy = sampleResult.segment(0, initCopy.size());
result[s] = sampleResult;
result.chi2_[s] = sampleResult.getChi2();
for (unsigned int j = 0; j < v.size(); ++j)

View File

@ -80,6 +80,8 @@ public:
const DMatSample & x(const Index k);
DSample & y(const Index k, const Index j);
const DSample & y(const Index k, const Index j) const;
void setUnidimData(const DMatSample &xData,
const std::vector<const DMatSample *> &v);
template <typename... Ts>
void setUnidimData(const DMatSample &xData,
const Ts & ...yDatas);
@ -141,17 +143,9 @@ void XYSampleData::setUnidimData(const DMatSample &xData, const Ts & ...yDatas)
static_assert(static_or<std::is_assignable<DMatSample, Ts>::value...>::value,
"y data arguments are not compatible with DMatSample");
std::vector<const DMatSample *> yData{&yDatas...};
std::vector<const DMatSample *> v{&yDatas...};
FOR_STAT_ARRAY(xData, s)
FOR_VEC(xData[central], r)
{
x(r, 0)[s] = xData[s](r);
for (unsigned int j = 0; j < yData.size(); ++j)
{
y(r, j)[s] = (*(yData[j]))[s](r);
}
}
setUnidimData(xData, v);
}
template <typename... Ts>

View File

@ -66,7 +66,7 @@ void FitResult::print(const bool printXsi, ostream &out) const
char buf[256];
Index pMax = printXsi ? size() : nPar_;
sprintf(buf, "chi^2/dof= %.1f/%d= %.2f -- p-value= %.2e", getChi2(),
sprintf(buf, "chi^2/dof= %.1e/%d= %.2e -- p-value= %.2e", getChi2(),
static_cast<int>(getNDof()), getChi2PerDof(), getPValue());
out << buf << endl;
for (Index p = 0; p < pMax; ++p)

332
physics/2pt-fit.cpp Normal file
View File

@ -0,0 +1,332 @@
#include <LatCore/OptParser.hpp>
#include <LatAnalyze/CompiledModel.hpp>
#include <LatAnalyze/Io.hpp>
#include <LatAnalyze/MatSample.hpp>
#include <LatAnalyze/Math.hpp>
#include <LatAnalyze/MinuitMinimizer.hpp>
#include <LatAnalyze/NloptMinimizer.hpp>
#include <LatAnalyze/Plot.hpp>
#include <LatAnalyze/XYSampleData.hpp>
using namespace std;
using namespace Latan;
int main(int argc, char *argv[])
{
// parse arguments /////////////////////////////////////////////////////////
OptParser opt;
bool parsed, doPlot, doHeatmap, doCorr, fold;
string corrFileName, model, outFileName, outFmt;
Index ti, tf, shift, nPar, thinning;
double svdTol;
Minimizer::Verbosity verbosity;
opt.addOption("" , "ti" , OptParser::OptType::value , false,
"initial fit time");
opt.addOption("" , "tf" , OptParser::OptType::value , false,
"final fit time");
opt.addOption("t" , "thinning", OptParser::OptType::value , true,
"thinning of the time interval", "1");
opt.addOption("s", "shift" , OptParser::OptType::value , true,
"time variable shift", "0");
opt.addOption("m", "model" , OptParser::OptType::value , true,
"fit model (exp|exp2|exp3|cosh|cosh2|cosh3|<interpreter code>)", "cosh");
opt.addOption("" , "nPar" , OptParser::OptType::value , true,
"number of model parameters for custom models "
"(-1 if irrelevant)", "-1");
opt.addOption("" , "svd" , OptParser::OptType::value , true,
"singular value elimination threshold", "0.");
opt.addOption("v", "verbosity", OptParser::OptType::value , true,
"minimizer verbosity level (0|1|2)", "0");
opt.addOption("o", "output", OptParser::OptType::value , true,
"output file", "");
opt.addOption("" , "uncorr" , OptParser::OptType::trigger, true,
"only do the uncorrelated fit");
opt.addOption("" , "fold" , OptParser::OptType::trigger, true,
"fold the correlator");
opt.addOption("p", "plot" , OptParser::OptType::trigger, true,
"show the fit plot");
opt.addOption("h", "heatmap" , OptParser::OptType::trigger, true,
"show the fit correlation heatmap");
opt.addOption("", "help" , OptParser::OptType::trigger, true,
"show this help message and exit");
parsed = opt.parse(argc, argv);
if (!parsed or (opt.getArgs().size() != 1) or opt.gotOption("help"))
{
cerr << "usage: " << argv[0] << " <options> <correlator file>" << endl;
cerr << endl << "Possible options:" << endl << opt << endl;
return EXIT_FAILURE;
}
corrFileName = opt.getArgs().front();
ti = opt.optionValue<Index>("ti");
tf = opt.optionValue<Index>("tf");
thinning = opt.optionValue<Index>("t");
shift = opt.optionValue<Index>("s");
model = opt.optionValue("m");
nPar = opt.optionValue<Index>("nPar");
svdTol = opt.optionValue<double>("svd");
outFileName = opt.optionValue<string>("o");
doCorr = !opt.gotOption("uncorr");
fold = opt.gotOption("fold");
doPlot = opt.gotOption("p");
doHeatmap = opt.gotOption("h");
switch (opt.optionValue<unsigned int>("v"))
{
case 0:
verbosity = Minimizer::Verbosity::Silent;
break;
case 1:
verbosity = Minimizer::Verbosity::Normal;
break;
case 2:
verbosity = Minimizer::Verbosity::Debug;
break;
default:
cerr << "error: wrong verbosity level" << endl;
return EXIT_FAILURE;
}
// load correlator /////////////////////////////////////////////////////////
DMatSample tmp, corr;
Index nSample, nt;
tmp = Io::load<DMatSample>(corrFileName);
nSample = tmp.size();
nt = tmp[central].rows();
tmp = tmp.block(0, 0, nt, 1);
corr = tmp;
FOR_STAT_ARRAY(corr, s)
{
for (Index t = 0; t < nt; ++t)
{
corr[s]((t - shift + nt)%nt) = tmp[s](t);
}
}
if (fold)
{
tmp = corr;
FOR_STAT_ARRAY(corr, s)
{
for (Index t = 0; t < nt; ++t)
{
corr[s](t) = 0.5*(tmp[s](t) + tmp[s]((nt - t) % nt));
}
}
}
// make model //////////////////////////////////////////////////////////////
DoubleModel mod;
bool coshModel = false;
if ((model == "exp") or (model == "exp1"))
{
nPar = 2;
mod.setFunction([](const double *x, const double *p)
{
return p[1]*exp(-p[0]*x[0]);
}, 1, nPar);
}
else if (model == "exp2")
{
nPar = 4;
mod.setFunction([](const double *x, const double *p)
{
return p[1]*exp(-p[0]*x[0]) + p[3]*exp(-p[2]*x[0]);
}, 1, nPar);
}
else if (model == "exp3")
{
nPar = 6;
mod.setFunction([](const double *x, const double *p)
{
return p[1]*exp(-p[0]*x[0]) + p[3]*exp(-p[2]*x[0])
+ p[5]*exp(-p[4]*x[0]);
}, 1, nPar);
}
else if ((model == "cosh") or (model == "cosh1"))
{
coshModel = true;
nPar = 2;
mod.setFunction([nt](const double *x, const double *p)
{
return p[1]*(exp(-p[0]*x[0])+exp(-p[0]*(nt-x[0])));
}, 1, nPar);
}
else if (model == "cosh2")
{
coshModel = true;
nPar = 4;
mod.setFunction([nt](const double *x, const double *p)
{
return p[1]*(exp(-p[0]*x[0])+exp(-p[0]*(nt-x[0])))
+ p[3]*(exp(-p[2]*x[0])+exp(-p[2]*(nt-x[0])));
}, 1, nPar);
}
else if (model == "cosh3")
{
coshModel = true;
nPar = 6;
mod.setFunction([nt](const double *x, const double *p)
{
return p[1]*(exp(-p[0]*x[0])+exp(-p[0]*(nt-x[0])))
+ p[3]*(exp(-p[2]*x[0])+exp(-p[2]*(nt-x[0])))
+ p[5]*(exp(-p[2]*x[0])+exp(-p[4]*(nt-x[0])));
}, 1, nPar);
}
else
{
if (nPar > 0)
{
mod = compile(model, 1, nPar);
}
else
{
cerr << "error: please specify the number of model parameter"
" using the --nPar function" << endl;
return EXIT_FAILURE;
}
}
// fit /////////////////////////////////////////////////////////////////////
DMatSample tvec(nSample);
XYSampleData data(nSample);
SampleFitResult fit;
DVec init(nPar);
NloptMinimizer globMin(NloptMinimizer::Algorithm::GN_CRS2_LM);
MinuitMinimizer locMin;
vector<Minimizer *> unCorrMin{&globMin, &locMin};
FOR_STAT_ARRAY(tvec, s)
{
tvec[s] = DVec::LinSpaced(nt, 0, nt - 1);
}
data.addXDim(nt, "t/a", true);
data.addYDim("C(t)");
data.setUnidimData(tvec, corr);
for (Index p = 0; p < nPar; p += 2)
{
mod.parName().setName(p, "E_" + strFrom(p/2));
mod.parName().setName(p + 1, "Z_" + strFrom(p/2));
}
init(0) = log(data.y(nt/4, 0)[central]/data.y(nt/4 + 1, 0)[central]);
init(1) = data.y(nt/4, 0)[central]/(exp(-init(0)*nt/4));
for (Index p = 2; p < nPar; p += 2)
{
init(p) = 2*init(p - 2);
init(p + 1) = init(p - 1)/2.;
}
for (Index p = 0; p < nPar; p += 2)
{
globMin.setLowLimit(p, 0.);
globMin.setHighLimit(p, 10.*init(p));
globMin.setLowLimit(p + 1, -10.*init(p + 1));
globMin.setHighLimit(p + 1, 10.*init(p + 1));
locMin.setLowLimit(p, 0.);
}
globMin.setPrecision(0.001);
globMin.setMaxIteration(100000);
globMin.setVerbosity(verbosity);
locMin.setMaxIteration(1000000);
locMin.setVerbosity(verbosity);
for (Index t = 0; t < nt; ++t)
{
data.fitPoint((t >= ti) and (t <= tf)
and ((t - ti) % thinning == 0), t);
}
if (doCorr)
{
cout << "-- uncorrelated fit..." << endl;
}
cout << "using model '" << model << "'" << endl;
data.setSvdTolerance(svdTol);
data.assumeYYCorrelated(false, 0, 0);
fit = data.fit(unCorrMin, init, mod);
fit.print();
if (doCorr)
{
cout << "-- correlated fit..." << endl;
cout << "using model '" << model << "'" << endl;
init = fit[central];
data.assumeYYCorrelated(true, 0, 0);
fit = data.fit(locMin, init, mod);
fit.print();
}
// plots ///////////////////////////////////////////////////////////////////
if (doPlot)
{
Plot p;
DMatSample effMass(nSample);
DVec effMassT, fitErr;
Index maxT = (coshModel) ? (nt - 2) : (nt - 1);
double e0, e0Err;
p << PlotRange(Axis::x, 0, nt - 1);
p << LogScale(Axis::y);
p << Color("rgb 'blue'") << PlotPredBand(fit.getModel(_), 0, nt - 1);
p << Color("rgb 'blue'") << PlotFunction(fit.getModel(), 0, nt - 1);
p << Color("rgb 'red'") << PlotData(data.getData());
p.display();
effMass.resizeMat(maxT, 1);
effMassT.setLinSpaced(maxT, 1, maxT);
fitErr = fit.variance().cwiseSqrt();
e0 = fit[central](0);
e0Err = fitErr(0);
if (coshModel)
{
FOR_STAT_ARRAY(effMass, s)
{
for (Index t = 1; t < nt - 1; ++t)
{
effMass[s](t - 1) = acosh((corr[s](t-1) + corr[s](t+1))
/(2.*corr[s](t)));
}
}
}
else
{
FOR_STAT_ARRAY(effMass, s)
{
for (Index t = 1; t < nt; ++t)
{
effMass[s](t - 1) = log(corr[s](t-1)/corr[s](t));
}
}
}
p.reset();
p << PlotRange(Axis::x, 1, maxT);
p << PlotRange(Axis::y, e0 - 20.*e0Err, e0 + 20.*e0Err);
p << Color("rgb 'blue'") << PlotBand(0, maxT, e0 - e0Err, e0 + e0Err);
p << Color("rgb 'blue'") << PlotHLine(e0);
p << Color("rgb 'red'") << PlotData(effMassT, effMass);
p.display();
p.save("test");
}
if (doHeatmap)
{
Plot p;
Index n = data.getFitVarMat().rows();
DMat id = DMat::Identity(n, n);
p << PlotMatrix(Math::varToCorr(data.getFitVarMat()));
p << Caption("correlation matrix");
p.display();
if (svdTol > 0.)
{
p.reset();
p << PlotMatrix(id - data.getFitVarMat()*data.getFitVarMatPInv());
p << Caption("singular space projector");
p.display();
}
}
// output //////////////////////////////////////////////////////////////////
if (!outFileName.empty())
{
Io::save(fit, outFileName);
}
return EXIT_SUCCESS;
}

1
physics/LatAnalyze Symbolic link
View File

@ -0,0 +1 @@
../lib

15
physics/Makefile.am Normal file
View File

@ -0,0 +1,15 @@
if CXX_GNU
COM_CXXFLAGS = -Wall -W -pedantic -Wno-deprecated-declarations
else
if CXX_INTEL
COM_CXXFLAGS = -wd1682 -Wall
endif
endif
bin_PROGRAMS = latan-2pt-fit
latan_2pt_fit_SOURCES = 2pt-fit.cpp
latan_2pt_fit_CXXFLAGS = $(COM_CXXFLAGS)
latan_2pt_fit_LDFLAGS = -L../lib/.libs -lLatAnalyze
ACLOCAL_AMFLAGS = -I .buildutils/m4

View File

@ -7,25 +7,40 @@ endif
endif
bin_PROGRAMS = \
latan_make_fake_sample\
latan_sample_combine \
latan_sample_plot_corr\
latan_sample_read \
latan_resample
latan-sample-combine \
latan-sample-element \
latan-sample-fake \
latan-sample-ft \
latan-sample-plot \
latan-sample-plot-corr\
latan-sample-read \
latan-resample
latan_make_fake_sample_SOURCES = make_fake_sample.cpp
latan_make_fake_sample_CXXFLAGS = $(COM_CXXFLAGS)
latan_make_fake_sample_LDFLAGS = -L../lib/.libs -lLatAnalyze
latan_sample_combine_SOURCES = sample_combine.cpp
latan_sample_combine_SOURCES = sample-combine.cpp
latan_sample_combine_CXXFLAGS = $(COM_CXXFLAGS)
latan_sample_combine_LDFLAGS = -L../lib/.libs -lLatAnalyze
latan_sample_plot_corr_SOURCES = sample_plot_corr.cpp
latan_sample_element_SOURCES = sample-element.cpp
latan_sample_element_CXXFLAGS = $(COM_CXXFLAGS)
latan_sample_element_LDFLAGS = -L../lib/.libs -lLatAnalyze
latan_sample_fake_SOURCES = sample-fake.cpp
latan_sample_fake_CXXFLAGS = $(COM_CXXFLAGS)
latan_sample_fake_LDFLAGS = -L../lib/.libs -lLatAnalyze
latan_sample_ft_SOURCES = sample-ft.cpp
latan_sample_ft_CXXFLAGS = $(COM_CXXFLAGS)
latan_sample_ft_LDFLAGS = -L../lib/.libs -lLatAnalyze
latan_sample_plot_corr_SOURCES = sample-plot-corr.cpp
latan_sample_plot_corr_CXXFLAGS = $(COM_CXXFLAGS)
latan_sample_plot_corr_LDFLAGS = -L../lib/.libs -lLatAnalyze
latan_sample_read_SOURCES = sample_read.cpp
latan_sample_plot_SOURCES = sample-plot.cpp
latan_sample_plot_CXXFLAGS = $(COM_CXXFLAGS)
latan_sample_plot_LDFLAGS = -L../lib/.libs -lLatAnalyze
latan_sample_read_SOURCES = sample-read.cpp
latan_sample_read_CXXFLAGS = $(COM_CXXFLAGS)
latan_sample_read_LDFLAGS = -L../lib/.libs -lLatAnalyze

View File

@ -17,74 +17,69 @@
* along with LatAnalyze 3. If not, see <http://www.gnu.org/licenses/>.
*/
#include <LatCore/OptParser.hpp>
#include <LatAnalyze/Dataset.hpp>
#include <LatAnalyze/Io.hpp>
#include <LatAnalyze/includes.hpp>
#ifndef DEF_NSAMPLE
#define DEF_NSAMPLE 100
#define DEF_NSAMPLE "100"
#endif
#ifdef HAVE_HDF5
#define DEF_FMT "h5"
#else
#define DEF_FMT "sample"
#endif
using namespace std;
using namespace Latan;
static void usage(const string &cmdName)
{
cerr << "usage: " << cmdName;
cerr << " [-n <nsample> -b <bin size> -r <seed> -o <output dir> -f {h5|sample}]";
cerr << " <data list> <name list>";
cerr << endl;
exit(EXIT_FAILURE);
}
int main(int argc, char *argv[])
{
// argument parsing ////////////////////////////////////////////////////////
int c;
OptParser opt;
bool parsed, dumpBoot;
random_device rd;
SeedType seed = rd();
string manFileName, nameFileName, cmdName, outDirName = ".";
string ext = "h5";
Index binSize = 1, nSample = DEF_NSAMPLE;
string manFileName, nameFileName, outDirName;
string ext;
Index binSize, nSample;
opterr = 0;
cmdName = basename(argv[0]);
while ((c = getopt(argc, argv, "b:n:r:o:f:")) != -1)
opt.addOption("n", "nsample" , OptParser::OptType::value, true,
"number of samples", DEF_NSAMPLE);
opt.addOption("b", "bin" , OptParser::OptType::value, true,
"bin size", "1");
opt.addOption("r", "seed" , OptParser::OptType::value, true,
"random generator seed (default: random)");
opt.addOption("o", "output-dir", OptParser::OptType::value, true,
"output directory", ".");
opt.addOption("f", "format" , OptParser::OptType::value, true,
"output file format", DEF_FMT);
opt.addOption("d", "dump-boot" , OptParser::OptType::trigger, true,
"dump bootstrap sequence");
opt.addOption("" , "help" , OptParser::OptType::trigger, true,
"show this help message and exit");
parsed = opt.parse(argc, argv);
if (!parsed or (opt.getArgs().size() != 2) or opt.gotOption("help"))
{
switch (c)
{
case 'b':
binSize = strTo<Index>(optarg);
break;
case 'n':
nSample = strTo<Index>(optarg);
break;
case 'o':
outDirName = optarg;
break;
case 'r':
seed = strTo<SeedType>(optarg);
break;
case 'f':
ext = optarg;
break;
case '?':
cerr << "error parsing option -" << char(optopt) << endl;
usage(cmdName);
break;
default:
usage(cmdName);
break;
}
cerr << "usage: " << argv[0];
cerr << " <datafile list> <name list> <options>" << endl;
cerr << endl << "Possible options:" << endl << opt << endl;
return EXIT_FAILURE;
}
if (argc - optind == 2)
nSample = opt.optionValue<Index>("n");
binSize = opt.optionValue<Index>("b");
if (opt.gotOption("r"))
{
manFileName = argv[optind];
nameFileName = argv[optind+1];
}
else
{
usage(cmdName);
seed = opt.optionValue<SeedType>("r");
}
ext = opt.optionValue("f");
outDirName = opt.optionValue("o");
dumpBoot = opt.gotOption("d");
manFileName = opt.getArgs()[0];
nameFileName = opt.getArgs()[1];
// parameter parsing ///////////////////////////////////////////////////////
vector<string> dataFileName, name;
@ -132,6 +127,15 @@ int main(int argc, char *argv[])
cout << '\r' << ProgressBar(i + 1, name.size());
data[name[i]].bin(binSize);
if ((i == 0) and dumpBoot)
{
ofstream file(outDirName + "/" + manFileName + ".bootseq");
file << "# bootstrap sequences" << endl;
file << "# manifest file: " << manFileName << endl;
file << "# bin size: " << binSize << endl;
data[name[i]].dumpBootstrapSeq(file, nSample, seed);
}
s = data[name[i]].bootstrapMean(nSample, seed);
Io::save<DMatSample>(s, outDirName + "/" + outFileName,
File::Mode::write, outFileName);

View File

@ -17,31 +17,29 @@
* along with LatAnalyze 3. If not, see <http://www.gnu.org/licenses/>.
*/
#include <LatCore/OptParser.hpp>
#include <LatAnalyze/Io.hpp>
#include <LatAnalyze/CompiledFunction.hpp>
using namespace std;
using namespace Latan;
static void usage(const string &cmdName)
template <typename T>
static void loadAndCheck(vector<T> &sample __dumb,
const vector<string> &fileName __dumb)
{
cerr << "usage: " << cmdName;
cerr << " [-o <output sample>]";
cerr << " <n> <function> <sample 1> ... <sample n>";
cerr << endl;
exit(EXIT_FAILURE);
abort();
}
template <typename T>
static void loadAndCheck(vector<T> &sample, const vector<string> &fileName)
template <>
void loadAndCheck(vector<DSample> &sample, const vector<string> &fileName)
{
const unsigned int n = sample.size();
const unsigned int n = static_cast<unsigned int>(sample.size());
Index nSample = 0;
cout << "-- loading data..." << endl;
for (unsigned int i = 0; i < n; ++i)
{
sample[i] = Io::load<T>(fileName[i]);
sample[i] = Io::load<DSample>(fileName[i]);
if (i == 0)
{
nSample = sample[i].size();
@ -55,6 +53,62 @@ static void loadAndCheck(vector<T> &sample, const vector<string> &fileName)
}
}
template <>
void loadAndCheck(vector<DMatSample> &sample, const vector<string> &fileName)
{
const unsigned int n = static_cast<unsigned int>(sample.size());
Index nSample = 0;
set<unsigned int> failed;
bool gotSize = false;
Index nRow = 0, nCol = 0;
for (unsigned int i = 0; i < n; ++i)
{
try
{
sample[i] = Io::load<DMatSample>(fileName[i]);
if (!gotSize)
{
nSample = sample[i].size();
nRow = sample[i][central].rows();
nCol = sample[i][central].cols();
gotSize = true;
}
}
catch (Exceptions::Definition)
{
failed.insert(i);
}
}
for (unsigned int i: failed)
{
DSample buf;
buf = Io::load<DSample>(fileName[i]);
sample[i].resize(nSample);
FOR_STAT_ARRAY(sample[i], s)
{
sample[i][s] = DMat::Constant(nRow, nCol, buf[s]);
}
}
for (unsigned int i = 0; i < n; ++i)
{
if (sample[i].size() != nSample)
{
cerr << "error: number of sample mismatch (between '";
cerr << fileName[0] << "' and '" << fileName[i] << "')" << endl;
abort();
}
if ((sample[i][central].rows() != nRow) and
(sample[i][central].cols() != nCol))
{
cerr << "error: matrix size mismatch (between '";
cerr << fileName[0] << "' and '" << fileName[i] << "')" << endl;
abort();
}
}
}
template <typename T>
static void combine(const string &outFileName __dumb,
const vector<T> &sample __dumb, const string &code __dumb)
@ -66,7 +120,7 @@ template <>
void combine(const string &outFileName, const vector<DSample> &sample,
const string &code)
{
const unsigned int n = sample.size();
const unsigned int n = static_cast<unsigned int>(sample.size());
DoubleFunction f = compile(code, n);
DSample result(sample[0]);
DVec buf(n);
@ -96,7 +150,7 @@ template <>
void combine(const string &outFileName, const vector<DMatSample> &sample,
const string &code)
{
const unsigned int n = sample.size();
const unsigned int n = static_cast<unsigned int>(sample.size());
DoubleFunction f = compile(code, n);
DVec buf(n);
DMatSample result(sample[0]);
@ -137,49 +191,41 @@ void process(const string &outFileName, const vector<string> &fileName,
int main(int argc, char *argv[])
{
// argument parsing ////////////////////////////////////////////////////////
OptParser opt;
bool parsed;
string cmdName, outFileName = "", code;
vector<string> fileName;
int c;
unsigned int n = 0;
opterr = 0;
cmdName = basename(argv[0]);
while ((c = getopt(argc, argv, "o:")) != -1)
opt.addOption("o", "output", OptParser::OptType::value , true,
"output file name (default: result not saved)");
opt.addOption("" , "help" , OptParser::OptType::trigger, true,
"show this help message and exit");
parsed = opt.parse(argc, argv);
if (opt.getArgs().size() >= 1)
{
switch (c)
{
case 'o':
outFileName = optarg;
break;
case '?':
cerr << "error parsing option -" << char(optopt) << endl;
usage(cmdName);
break;
default:
usage(cmdName);
break;
}
}
if (argc - optind >= 1)
{
n = strTo<unsigned int>(argv[optind]);
if (argc - optind == static_cast<int>(n + 2))
{
fileName.resize(n);
code = argv[optind + 1];
for (unsigned int i = 0; i < n; ++i)
{
fileName[i] = argv[optind + 2 + i];
}
}
else
{
usage(cmdName);
}
n = strTo<unsigned int>(opt.getArgs()[0]);
}
else
{
usage(cmdName);
parsed = false;
}
if (!parsed or (opt.getArgs().size() != n + 2) or opt.gotOption("help"))
{
cerr << "usage: " << argv[0];
cerr << " <options> <n> <function> <sample 1> ... <sample n>" << endl;
cerr << endl << "Possible options:" << endl << opt << endl;
return EXIT_FAILURE;
}
if (opt.gotOption("o"))
{
outFileName = opt.optionValue("o");
}
code = opt.getArgs()[1];
for (unsigned int i = 0; i < n; ++i)
{
fileName.push_back(opt.getArgs()[2 + i]);
}
// process data ////////////////////////////////////////////////////////////
@ -187,7 +233,7 @@ int main(int argc, char *argv[])
{
process<DSample>(outFileName, fileName, code);
}
catch (bad_cast &e)
catch (Exceptions::Definition)
{
process<DMatSample>(outFileName, fileName, code);
}

103
utils/sample-element.cpp Normal file
View File

@ -0,0 +1,103 @@
/*
* sample-element.cpp, part of LatAnalyze 3
*
* Copyright (C) 2013 - 2016 Antonin Portelli, Matt Spraggs
*
* LatAnalyze 3 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LatAnalyze 3 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LatAnalyze 3. If not, see <http://www.gnu.org/licenses/>.
*/
#include <LatCore/OptParser.hpp>
#include <LatAnalyze/Io.hpp>
#include <LatAnalyze/MatSample.hpp>
using namespace std;
using namespace Latan;
int main(int argc, char* argv[])
{
// argument parsing ////////////////////////////////////////////////////////
OptParser opt;
bool parsed;
string inFilename, outFilename;
Index r, c, nr, nc;
opt.addOption("r", "row", OptParser::OptType::value , false,
"row");
opt.addOption("c", "col", OptParser::OptType::value , false,
"column");
opt.addOption("" , "nrow", OptParser::OptType::value , true,
"number of rows (default: 1)", "1");
opt.addOption("" , "ncol", OptParser::OptType::value , true,
"number of columns (default: 1)", "1");
opt.addOption("o", "output", OptParser::OptType::value , true,
"output file name (default: result not saved)", "");
opt.addOption("" , "help" , OptParser::OptType::trigger, true,
"show this help message and exit");
parsed = opt.parse(argc, argv);
if (!parsed or (opt.getArgs().size() != 1) or opt.gotOption("help"))
{
cerr << "usage: " << argv[0];
cerr << " <options> <input file>" << endl;
cerr << endl << "Possible options:" << endl << opt << endl;
return EXIT_FAILURE;
}
inFilename = opt.getArgs()[0];
outFilename = opt.optionValue("o");
r = opt.optionValue<Index>("r");
c = opt.optionValue<Index>("c");
nr = opt.optionValue<Index>("nrow");
nc = opt.optionValue<Index>("ncol");
// Data extraction /////////////////////////////////////////////////////////
auto inputData = Io::load<DMatSample>(inFilename);
if ((nr == 1) and (nc == 1))
{
DSample outputData(inputData.size());
FOR_STAT_ARRAY(inputData, s)
{
outputData[s] = inputData[s](r, c);
}
cout << scientific;
cout << "central value:\n" << outputData[central] << endl;
cout << "standard deviation:\n";
cout << sqrt(outputData.variance()) << endl;
if (not outFilename.empty())
{
Io::save(outputData, outFilename);
}
}
else
{
DMatSample outputData(inputData.size(), nr, nc);
FOR_STAT_ARRAY(inputData, s)
{
outputData[s] = inputData[s].block(r, c, nr, nc);
}
cout << scientific;
cout << "central value:\n" << outputData[central] << endl;
cout << "standard deviation:\n";
cout << outputData.variance().cwiseSqrt() << endl;
if (not outFilename.empty())
{
Io::save(outputData, outFilename);
}
}
return EXIT_SUCCESS;
}

94
utils/sample-ft.cpp Normal file
View File

@ -0,0 +1,94 @@
/*
* sample-ft.cpp, part of LatAnalyze 3
*
* Copyright (C) 2013 - 2016 Antonin Portelli
*
* LatAnalyze 3 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LatAnalyze 3 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LatAnalyze 3. If not, see <http://www.gnu.org/licenses/>.
*/
#include <LatCore/OptParser.hpp>
#include <LatAnalyze/GslFFT.hpp>
#include <LatAnalyze/Io.hpp>
using namespace std;
using namespace Latan;
int main(int argc, char *argv[])
{
// argument parsing ////////////////////////////////////////////////////////
OptParser opt;
bool parsed;
string inFilename, outFilename;
unsigned int dir = FFT::Forward;
opt.addOption("o", "output", OptParser::OptType::value , true,
"output file name (default: result not saved)", "");
opt.addOption("b", "backward", OptParser::OptType::trigger, true,
"backward Fourier transform (forward by default)");
opt.addOption("" , "help" , OptParser::OptType::trigger, true,
"show this help message and exit");
parsed = opt.parse(argc, argv);
if (!parsed or (opt.getArgs().size() != 1) or opt.gotOption("help"))
{
cerr << "usage: " << argv[0];
cerr << " <options> <input file>" << endl;
cerr << endl << "Possible options:" << endl << opt << endl;
return EXIT_FAILURE;
}
inFilename = opt.getArgs()[0];
outFilename = opt.optionValue("o");
if (opt.gotOption("b"))
{
dir = FFT::Backward;
}
// Fourier transform ///////////////////////////////////////////////////////
DMatSample in = Io::load<DMatSample>(inFilename);
Index nSample = in.size(), l = in[central].rows();
bool isInComplex = (in[central].cols() > 1);
CMatSample res(nSample, l, 1);
DMatSample out(nSample, l, 2);
GslFFT ft(l);
cout << "-- computing Fourier transform..." << endl;
FOR_STAT_ARRAY(in, s)
{
res[s].real() = in[s].col(0);
if (isInComplex)
{
res[s].imag() = in[s].col(1);
}
else
{
res[s].imag() = DVec::Constant(l, 0.);
}
ft(res[s], dir);
out[s].col(0) = res[s].real();
out[s].col(1) = res[s].imag();
}
// output /////////////////////////////////////////////////////////////////
cout << scientific;
cout << "central value:\n" << out[central];
cout << endl;
cout << "standard deviation:\n" << out.variance().cwiseSqrt();
cout << endl;
if (!outFilename.empty())
{
Io::save<DMatSample>(out, outFilename);
}
return EXIT_SUCCESS;
}

View File

@ -42,6 +42,7 @@ int main(int argc, char *argv[])
cout << "-- computing variance matrix from '" << fileName << "'..." << endl;
name = Io::getFirstName(fileName);
sample = Io::load<DMatSample>(fileName);
sample = sample.block(0, 0, sample[central].rows(), 1);
var = sample.varianceMatrix();
p << PlotMatrix(varToCorr(var));
p.display();

51
utils/sample-plot.cpp Normal file
View File

@ -0,0 +1,51 @@
/*
* sample-plot.cpp, part of LatAnalyze 3
*
* Copyright (C) 2013 - 2016 Antonin Portelli
*
* LatAnalyze 3 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LatAnalyze 3 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LatAnalyze 3. If not, see <http://www.gnu.org/licenses/>.
*/
#include <LatAnalyze/Io.hpp>
#include <LatAnalyze/Math.hpp>
#include <LatAnalyze/Plot.hpp>
using namespace std;
using namespace Latan;
using namespace Math;
int main(int argc, char *argv[])
{
string xFileName, yFileName;
if (argc != 3)
{
cerr << "usage: " << argv[0] << " <x sample> <y sample>" << endl;
return EXIT_FAILURE;
}
xFileName = argv[1];
yFileName = argv[2];
Plot p;
DMatSample x, y;
x = Io::load<DMatSample>(xFileName);
y = Io::load<DMatSample>(yFileName);
p << PlotData(x, y);
p.display();
return EXIT_SUCCESS;
}

View File

@ -24,7 +24,7 @@ using namespace Latan;
int main(int argc, char *argv[])
{
if ((argc < 2) || (argc > 3))
if ((argc < 2) or (argc > 3))
{
cerr << "usage: " << argv[0] << " <file> [<copy>]" << endl;
@ -46,7 +46,7 @@ int main(int argc, char *argv[])
Io::save(s, copy, File::Mode::write, name);
}
}
catch (bad_cast &e)
catch (Exceptions::Definition)
{
DSample s = Io::load<DSample>(fileName);
string name = Io::getFirstName(fileName);