Code Monkey home page Code Monkey logo

rlibeemd's Introduction

R-CMD-check codecov.io downloads cran version

Rlibeemd

An R interface for libeemd C library for ensemble empirical mode decomposition (EEMD) and its complete variant (CEEMDAN). These methods decompose possibly nonlinear and/or nonstationary time series data into a finite amount of components (called IMFs, insintric mode functions) separated by instantaneous frequencies. This decomposition provides a powerful method to look into the different processes behind a given time series, and provides a way to separate short time-scale events from a general trend.

If you use Rlibeemd/libeemd for scientific work please cite Luukko, P.J.J., Helske, J., Räsänen, E., Comput. Stat. 31, 545 (2016) (also on arXiv). This article also describes in detail what libeemd actually computes. You should definitely read it if you are unsure about what EMD, EEMD and CEEMDAN are.

OpenMP parallel computing support

Current CRAN policies do not allow the use of SHLIB_OPENMP_CFLAGS combined with linking with C++. Therefore the CRAN version does not use OpenMP at all anymore (OpenMP flags have been removed from Makevars), but the the version on GitHub version does. So if you want to use parallel version of the Rlibeemd, please install the package via

devtools::install_github("helske/Rlibeemd")

Note that this installs the package from source, so you need to have GSL installed. For Linux, use something like sudo apt-get install libgsl2 libgsl-dev, whereas in Windows you can download GSL files from here: https://www.stats.ox.ac.uk/pub/Rtools/goodies/multilib/ (file local323.zip or equivalent). You also need to add environmental variable LIB_GSL=<path/to/gsl>. For Windows, binaries are also available (see the latest release) which is probably easier option:

install.packages("https://github.com/helske/Rlibeemd/releases/download/v1.4.2/Rlibeemd_1.4.2.zip", repos = NULL)

Please file an issue if you encounter portability issues (so far none found), or if you figure out a way to enable OpenMP in CRAN version without CRAN checks complaining.

Example

Here a CEEMDAN decomposition is performed for the UK gas consumption series (length n = 108). By default, ceemdan extracts [log_2(n)] components, so here we get five IMFs and the residual.

library("Rlibeemd")
data(UKgas, package = "datasets")
imfs <- ceemdan(UKgas, ensemble_size = 1000)
plot(imfs, main = "Five IMFs and residual extracted by CEEMDAN algorithm")

imfs

The residual components shows smooth trend whereas the first IMF contains clear multiplicative trend. The remaining IMFs are bit more complex, and one could argue that they are partly seasonal, trend or just some irregularity i.e. noise.

Let us compare the decomposition with basic structural time series model fit from StructTS (for smoothing of more complex state space models, one could use KFAS)

bsm <- tsSmooth(StructTS(UKgas))
plot(bsm[, c(1, 3)], main = "Local linear trend and seasonal components by StructTS")

bsm

StructTS decomposes the data for three components, where one of the components is (possibly time varying) slope, which has no direct effect to overall signal (it is the slope of the level component).

ts.plot(cbind(UKgas, imfs[, ncol(imfs)], rowSums(imfs[, 5:6]), bsm[,"level"]), col = 1:4,
  main = "Quarterly UK gas consumption", ylab = "Million therms")
legend("topleft", c("Observations", "Residual", "Last IMF + residual", "Trend from BSM"),
  col = 1:4, lty = 1)

ceemdan_and_bsm

The IMF_5 + residual is quite close to the trend obtained by structural time series model of StructTS.

rlibeemd's People

Contributors

helske avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

rlibeemd's Issues

Rlibeemd does not install, MacOS Catalina, R 4.0.0

Here's the command and the following error messages. I know the formatting is a little goofy: R colored its responses red.

clang++ -mmacosx-version-min=10.13 -std=gnu++11 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -Wl,-rpath,/Library/Frameworks/R.framework/Resources/lib /Library/Frameworks/R.framework/Resources/lib/libc++abi.1.dylib -L/Library/Frameworks/R.framework/Resources/lib -L/usr/local/lib -o Rlibeemd.so RcppExports.o bemd.o bemdR.o ceemdan.o ceemdanR.o eemdR.o eemd_routine.o emd.o emd_num_imfsR.o error.o extrema.o extremaR.o gslErrorHandlerOff.o printError.o spline.o version.o workspace.o -L/usr/local/lib -lgsl -lgslcblas -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation

clang-7: error: no such file or directory: '/Library/Frameworks/R.framework/Resources/lib/libc++abi.1.dylib'
make: *** [Rlibeemd.so] Error 1
ERROR: compilation failed for package ‘Rlibeemd’
* removing ‘/Library/Frameworks/R.framework/Versions/4.0/Resources/library/Rlibeemd’
* restoring previous ‘/Library/Frameworks/R.framework/Versions/4.0/Resources/library/Rlibeemd’
Error: Failed to install 'Rlibeemd' from GitHub:
  (converted from warning) installation of package ‘/var/folders/j1/f2wn1_k51dl2_wgn8m0b5m_00000gn/T//Rtmplmblob/filed2d4c395e77/Rlibeemd_1.4.1.tar.gz’ had non-zero exit status

Installation error

devtools::install_github("helske/Rlibeemd")
Downloading GitHub repo helske/Rlibeemd@HEAD
checking for file ‘/tmp/RtmptW0VkH/remotes777d3cfa4949/helske-Rlibeemd-a237af ✔ checking for file ‘/tmp/RtmptW0VkH/remotes777d3cfa4949/helske-Rlibeemd-a237af 1/DESCRIPTION’
─ preparing ‘Rlibeemd’:
✔ checking DESCRIPTION meta-information ...
─ cleaning src
─ running ‘cleanup’
─ checking for LF line-endings in source and make files and shell scripts
─ checking for empty or unneeded directories
─ looking to see if a ‘data/datalist’ file should be added
─ building ‘Rlibeemd_1.4.1.tar.gz’

Installing package into ‘/home/lasorte/R_Libs’
(as ‘lib’ is unspecified)

  • installing source package ‘Rlibeemd’ ...
    ** using staged installation
    checking for gsl-config... /home/lasorte/appdir/bin/gsl-config
    configure: creating ./config.status
    config.status: creating src/Makevars
    ** libs
    g++ -m64 -std=gnu++11 -I"/usr/include/R" -DNDEBUG -I"/home/lasorte/R_Libs/Rcpp/ include" -I/usr/local/include -fopenmp -fpic -O2 -g -pipe -Wall -Wp,-D_FORTIFY_ SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecor d-gcc-switches -m64 -mtune=generic -c RcppExports.cpp -o RcppExports.o
    gcc -m64 -std=gnu99 -I"/usr/include/R" -DNDEBUG -I"/home/lasorte/R_Libs/Rcpp/in clude" -I/usr/local/include -I/home/lasorte/appdir/include -fopenmp -fpic -O2 - g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --pa ram=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -c bemd.c -o bemd.o
    g++ -m64 -std=gnu++11 -I"/usr/include/R" -DNDEBUG -I"/home/lasorte/R_Libs/Rcpp/ include" -I/usr/local/include -fopenmp -fpic -O2 -g -pipe -Wall -Wp,-D_FORTIFY_ SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecor d-gcc-switches -m64 -mtune=generic -c bemdR.cpp -o bemdR.o
    In file included from bemdR.cpp:4:
    bemd.h:23:10: fatal error: gsl/gsl_errno.h: No such file or directory
    #include <gsl/gsl_errno.h>
    ^~~~~~~~~~~~~~~~~
    compilation terminated.
    make: *** [bemdR.o] Error 1
    ERROR: compilation failed for package ‘Rlibeemd’
  • removing ‘/home/lasorte/R_Libs/Rlibeemd’
    Error: Failed to install 'Rlibeemd' from GitHub:
    (converted from warning) installation of package ‘/tmp/RtmptW0VkH/file777d2b59 7194/Rlibeemd_1.4.1.tar.gz’ had non-zero exit status

CRAN warning about combining OpenMP flags with both C and C++

From latest CRAN checks:

src/Makevars.in: SHLIB_OPENMP_CFLAGS is included in PKG_LIBS but linking is by C++
src/Makevars.in: it is not portable to include multiple SHLIB_OPENMP_*' macros in PKG_LIBS

I tried several combinations of CFLAGS and CXXFLAGS no luck. At the moment it seems that I have to disable OpenMP with CRAN version and add a startup message which points to github for parallel version...

ceemdan(): default num_imfs=0 does not necessarily result in maximum number of IMFs

I came across an issue with the ceemdan() function parameter setting num_imfs. In the documentation, the default values of num_imfs=0 is said to correspond to a

maximal number of IMFs

. However, depending on other parameter settings (e.g. noise_strength), this is not necessarily the case. A residual with two non-edge extrema, which could be further decomposed, is possible.
Then (for N>3), not num_imfs=emd_num_imfs(N) (which seems to take floor(log2(N)) as the num_imfs-value), but the smallest integer which is not less than log2(N), thus, num_imfs=ceiling(log2(N)), appears to correspond to the maximal number of IMFs (meaning the residual has maximum one non-edge extremum). Whether floor(log2(N)) or ceiling(log2(N)) corresponds to the maximal number of IMFs depends on other parameter settings such as noise_strength. Maybe the number of non-edge extrema should be checked to decide on either floor(log2(N)) or ceiling(log2(N)) for num_imfs.

Attached I provide an example. An NDVI (Normalised Difference Vegetation Index) time series of length 340 (example_NDVI.txt). It is decomposed in R using ceemdan() (ceemdan_issue.txt). When setting a noise_strength=0.3, the default setting of num_imfs=0 results in a residual with two non-edge extrema.

I hope I am not missing anything/getting wrong and this information is of help. In case it is a bug, an edit would be appreciated.

These are my sessionInfo:

R version 3.4.4 (2018-03-15)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

packageVersion("Rlibeemd")
[1] ‘1.4.0’

Best, Katharina

[macOS] configure does not define SHLIB_OPENMP_CFLAGS, so OpenMP is not used

@helske Turned out, OpenMP detection does not work, at least in 1.4.3:

This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.

It was created by Rlibeemd configure 1.4.2, which was
generated by GNU Autoconf 2.69.  Invocation command line was

  $ ./configure 

## --------- ##
## Platform. ##
## --------- ##

hostname = 10.6.shared
uname -m = x86_64
uname -r = 10.8.0
uname -s = Darwin
uname -v = Darwin Kernel Version 10.8.0: Tue Jun  7 16:32:41 PDT 2011; root:xnu-1504.15.3~1/RELEASE_X86_64

/usr/bin/uname -p = i386
/bin/uname -X     = unknown

/bin/arch              = unknown
/usr/bin/arch -k       = unknown
/usr/convex/getsysinfo = unknown
/usr/bin/hostinfo      = Mach kernel version:
	 Darwin Kernel Version 10.8.0: Tue Jun  7 16:32:41 PDT 2011; root:xnu-1504.15.3~1/RELEASE_X86_64
Kernel configured for up to 8 processors.
8 processors are physically available.
8 processors are logically available.
Processor type: i486 (Intel 80486)
Processors active: 0 1 2 3 4 5 6 7
Primary memory available: 8.00 gigabytes
Default processor set: 153 tasks, 392 threads, 8 processors
Load average: 3.40, Mach factor: 4.68
/bin/machine           = unknown
/usr/bin/oslevel       = unknown
/bin/universe          = unknown

PATH: /opt/local/bin
PATH: /opt/local/sbin
PATH: /bin
PATH: /sbin
PATH: /usr/bin
PATH: /usr/sbin


## ----------- ##
## Core tests. ##
## ----------- ##

configure:1685: checking for gsl-config
configure:1703: found /opt/local/bin/gsl-config
configure:1715: result: /opt/local/bin/gsl-config
configure:1889: creating ./config.status

## ---------------------- ##
## Running config.status. ##
## ---------------------- ##

This file was extended by Rlibeemd config.status 1.4.2, which was
generated by GNU Autoconf 2.69.  Invocation command line was

  CONFIG_FILES    = 
  CONFIG_HEADERS  = 
  CONFIG_LINKS    = 
  CONFIG_COMMANDS = 
  $ ./config.status 

on 10.6.shared

config.status:716: creating src/Makevars

## ---------------- ##
## Cache variables. ##
## ---------------- ##

ac_cv_env_build_alias_set=
ac_cv_env_build_alias_value=
ac_cv_env_host_alias_set=
ac_cv_env_host_alias_value=
ac_cv_env_target_alias_set=
ac_cv_env_target_alias_value=
ac_cv_path_GSL_CONFIG=/opt/local/bin/gsl-config

## ----------------- ##
## Output variables. ##
## ----------------- ##

DEFS='-DPACKAGE_NAME=\"Rlibeemd\" -DPACKAGE_TARNAME=\"rlibeemd\" -DPACKAGE_VERSION=\"1.4.2\" -DPACKAGE_STRING=\"Rlibeemd\ 1.4.2\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\"'
ECHO_C=''
ECHO_N='-n'
ECHO_T=''
GSL_CFLAGS='-I/opt/local/include'
GSL_CONFIG='/opt/local/bin/gsl-config'
GSL_LIBS='-L/opt/local/lib -lgsl -lgslcblas'
LIBOBJS=''
LIBS=''
LTLIBOBJS=''
PACKAGE_BUGREPORT=''
PACKAGE_NAME='Rlibeemd'
PACKAGE_STRING='Rlibeemd 1.4.2'
PACKAGE_TARNAME='rlibeemd'
PACKAGE_URL=''
PACKAGE_VERSION='1.4.2'
PATH_SEPARATOR=':'
SHELL='/bin/sh'
bindir='${exec_prefix}/bin'
build_alias=''
datadir='${datarootdir}'
datarootdir='${prefix}/share'
docdir='${datarootdir}/doc/${PACKAGE_TARNAME}'
dvidir='${docdir}'
exec_prefix='${prefix}'
host_alias=''
htmldir='${docdir}'
includedir='${prefix}/include'
infodir='${datarootdir}/info'
libdir='${exec_prefix}/lib'
libexecdir='${exec_prefix}/libexec'
localedir='${datarootdir}/locale'
localstatedir='${prefix}/var'
mandir='${datarootdir}/man'
oldincludedir='/usr/include'
pdfdir='${docdir}'
prefix='/usr/local'
program_transform_name='s,x,x,'
psdir='${docdir}'
runstatedir='${localstatedir}/run'
sbindir='${exec_prefix}/sbin'
sharedstatedir='${prefix}/com'
sysconfdir='${prefix}/etc'
target_alias=''

## ----------- ##
## confdefs.h. ##
## ----------- ##

/* confdefs.h */
#define PACKAGE_NAME "Rlibeemd"
#define PACKAGE_TARNAME "rlibeemd"
#define PACKAGE_VERSION "1.4.2"
#define PACKAGE_STRING "Rlibeemd 1.4.2"
#define PACKAGE_BUGREPORT ""
#define PACKAGE_URL ""

configure: exit 0

Build is fine, but OpenMP is not used, despite being, obviously, supported by GCC.

Makevars are written like:

GSL_CFLAGS = -I/opt/local/include
GSL_LIBS = -L/opt/local/lib -lgsl -lgslcblas
PKG_LIBS=$(GSL_LIBS) $(SHLIB_OPENMP_CFLAGS)
PKG_CFLAGS=$(GSL_CFLAGS) $(SHLIB_OPENMP_CFLAGS)

And then SHLIB_OPENMP_CFLAGS are undefined. Should be -fopenmp there instead for it to work.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.