Giter VIP home page Giter VIP logo

mdembedding's Introduction

Estimation of embedding parameters for multivariate data

This repository contains MATLAB code for estimating parameters for phase space reconstruction of multivariate data. The functions provided in this repository are described in the article:

Wallot & Mønster (2018) Calculation of average mutual information (AMI) and false-nearest neighbors (FNN) for the estimation of embedding parameters of multidimensional time-series in MATLAB Frontiers in Psychology, 9: 1679 DOI:10.3389/fpsyg.2018.01679

Installation

The functions in this repository can be used if you place the files containing them in a directory that is in your MATLAB Path. You can simply download mdDelay.m, autoMI.m and mdFnn.m or you can clone the whole repository to get all the files and examples:

git clone https://github.com/danm0nster/mdembedding.git mdembedding

If you want your cloned copy in a different directory you can change the last parameter to something else, e.g. mde-copy.

To embed time series data using the time-delayed embedding method two parameters are needed: the time delay and the embeddding dimension. We provide two functions to estimate these parameters: mdDelay() and mdFnn().

Example

This is a short example of how to use the functions using the well-known Lorenz attractor. The data have been pre-generated and the MATLAB code for generating the plots can be found in this repository under docs/Lorenz, and you can also view the full output of the MATLAB notebook. Here, we will just show the basic commands used to produce plots and other outputs.

We start by loading the data generated by a numerical solution to the Lorenz equations

data = load('lorenz_3d_timeseries.txt');

The data can be visualized by plotting the three variables x, y and z.

plot3(data(:,1), data(:,2), data(:,3), 'k')

Figure 1a from paper

Estimating the time delay

To estimate the proper time delay for embedding the data we use the function mdDelay.

tau = mdDelay(data, 'maxLag', 25, 'plottype', 'all');

Figure 2a from paper

This gives a value of tau that rounds to 15. A visual inspection of the plot of mutual information indicates that this is a reasonable value, since all three curves have minima close to that value. Alternatively we can get mdDelay() to plot the mean mutual information, by setting the plot type to "mean".

tau = mdDelay(data, 'maxLag', 25, 'plottype', 'mean');

Plot of mean AMI

Estimating the embedding dimension

The optimal embedding dimension is estimated using the method of false nearest neighbors (FNN), which is implemented in the function mdFnn(). We call this function with the value of tau found above rounded to nearest integer (in this case 15). The function returns a vector with the percent of FNN and another vector with the corresponding embedding dimensions.

[fnnPercent, embeddingDimension] = mdFnn(data, round(tau));

Figure 2b from paper

Since the number of false nearest neighbors drops to zero already at 2 embeddings we see that it is enough to embed the data in the three dimensions already present in the data, which is not surprising because we have sampled all the variables in the dynamical system.

Testing the functions

You can run a short test suite for the functions by typing the following command in the MATLAB command window.

runtests('tests/mdDelayTest.m')

If the test is successful you should see something like the output below.

Running mdDelayTest
No value below threshold found. Will use first local minimum instead
.No value below threshold found. Will use first local minimum instead
No value below threshold found. Will use first local minimum instead
.No value below threshold found. Will use first local minimum instead
No value below threshold found. Will use first local minimum instead
No value below threshold found. Will use first local minimum instead
No value below threshold found. Will use first local minimum instead
No value below threshold found. Will use first local minimum instead
.Teardown called. No action taken here.

Done mdDelayTest
__________


ans =

  1×3 TestResult array with properties:

    Name
    Passed
    Failed
    Incomplete
    Duration
    Details

Totals:
   3 Passed, 0 Failed, 0 Incomplete.
   0.097622 seconds testing time.

How to cite

If you find these functions useful and publish results where you have used them, please cite our paper:

Wallot & Mønster (2018) Calculation of average mutual information (AMI) and false-nearest neighbors (FNN) for the estimation of embedding parameters of multidimensional time-series in MATLAB Frontiers in Psychology, 9: 1679 DOI:10.3389/fpsyg.2018.01679

mdembedding's People

Contributors

danm0nster avatar wallot 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

mdembedding's Issues

use of undocumented inputParser.addOptional behaviour

The inputParser.addOptional method is being used for the optional arguments. addOptional is meant for positional arguments, i.e., arguments that are interpreted based on their position of the argument list. From mathworks documentation:

Arguments added to the input parser scheme with the addOptional function are positional. Therefore, add them to the input parser scheme in the same order they are passed into the function.

However, all examples show them being used as named parameters and out of order:

mdDelay(data, 'maxLag', 25, 'plottype', 'all');

I have tested it in Matlab and indeed it works. However, it is weird because not only the options are out of order (the options order is plottype, numBins, maxLag,...) but also because the option names seem to be ignored. Reading the documentation, one would expect that the above call would result in the following:

plottype = 'maxLag'
numBins = 25
maxLag = 'plottype'
criterion = 'all'

I don't understand how this is working in Matlab, but it would be clearer if addParameter was used instead:

Use addOptional to add an individual argument into the input parser scheme. If you want to parse an optional name-value pair, then use the addParameter function.

The reason to request this change is so that this code can also be used in Octave.

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.