/usr/share/octave/packages/tisean-0.2.3/timerev.m is in octave-tisean 0.2.3-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | ## Copyright (C) 2015 Piotr Held
## Copyright (C) 2015 Juan Pablo Carbajal
##
## This file is part of Octave.
##
## Octave 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.
##
## Octave 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 Octave; see the file COPYING. If not,
## see <http://www.gnu.org/licenses/>.
## -*- texinfo -*-
## @deftypefn{Function File} {@var{output} =} timerev (@var{S})
## @deftypefnx{Function File} {@var{output} =} timerev (@var{S}, @var{delay})
##
## Calculates time reversal assymetry statistic.
##
## Accomplishes this using the following equation applied to each component
## separately:
##
## @iftex
## @tex
## $$\frac{\sum (y_n-y_{n-d})^3}{\sum (y_n-y_{n-d})^2}$$
## @end tex
## @end iftex
## @ifnottex
## @example
## 3
## sum (y - y )
## n n-d
## ------------------
## 2
## sum (y - y )
## n n-d
## @end example
## @end ifnottex
##
## @strong{Input}
##
## @table @var
## @item S
## This function always assumes that each time series is along the longer
## dimension of matrix @var{S}. It also assumes that every dimension
## (counting along the shorter dimension) of @var{S} is considered a
## component of the time series.
## @item delay
## The delay for the statistic ('d' in the equation above) [default = 1].
## @end table
##
## @strong{Output}
##
## The output is the calculated time reversal asymmetry statistic. It is calculated
## for each component separately and is alligned with the components, so if the
## input's components were columns vectors the output will be a row vector and
## vice versa.
##
## @strong{Algorithms}
##
## The algorithms for this functions have been taken from the TISEAN package.
## @end deftypefn
## Author: Piotr Held <pjheld@gmail.com>.
## This function is based on timerev of TISEAN 3.0.1
## https://github.com/heggus/Tisean"
function output = timerev (S, delay);
# Input validation
if (nargin != 1 && nargin != 2)
print_usage;
endif
if ((!ismatrix (S)) || (!isreal(S)))
error ('Octave:invalid-input-arg', "S is not a realmatrix");
endif
# If no delay was given assign 1
if (nargin == 1)
delay = 1;
endif
# Verify delay is a positive integer
isPositiveInteger = @(x) isreal(x) && isscalar (x) && (x > 0) ...
&& (x-round(x) == 0);
if (!isPositiveInteger(delay))
error ("Octave:invalid-input-arg", "delay must be a positive integer");
endif
# Verify the input series 'S' is at least as long as 'delay + 1'
if (delay >= length (S))
error ("Octave:invalid-input-arg", ["the length of the input series must ",...
"be at least as long as 'delay + 1'"]);
endif
# Correct S to always have more rows than columns
trnspsd = false;
if (rows (S) < columns (S))
S = S.';
trnspsd = true;
endif
# Calculate output
idx = delay+1:rows(S);
t2 = sum ((S(idx,:) - S(idx-delay,:)).^2);
t3 = sum ((S(idx,:) - S(idx-delay,:)).^3);
output = t3./t2;
# Transpose output if input components were row vectors and not column vectors
if (trnspsd)
output = output.';
endif
endfunction
%% Test output against TISEAN program 'timerev'
%!assert (timerev (henon (1000)(:,1),4),0.313235879,-1e-6)
%!assert (timerev (henon (1000), 4), [0.313235879, 0.312556326], -1e-6)
%!assert (timerev (henon(1000).', 4), [0.313235879; 0.312556326], -1e-6)
%% Testing input validation
%!error <positive> timerev (1, 0);
%!error <long> timerev ([1 2], 2);
%% Test if default values load properly
%!assert (timerev (henon (100)), timerev (henon (100),1))
|