package jhpro.tseries;

import jhplot.utils.SHisto;
import jhplot.F1D;
import jhplot.H1D;
import jhplot.P0D;
import jhplot.P1D;
import jhpro.stat.StatUtils;

/**
 * Analysis of data created using HStatData.
 * 
 * @author S.Chekanov
 * 
 */

public class HStatAnalysis {

	private HStatData hdata;

	/**
	 * Initialize analyser
	 * 
	 * @param hdata
	 */
	public HStatAnalysis(HStatData hdata) {

		this.hdata = hdata;

	}

	/**
	 * Autocorrelation. 
* It uses the function: autocorrelation[lag] = SUM(n=0,N) * (signal[n]*signal[n+lag]) with n is the input sample index, and * 0signal at different * times n are the same values of the same signal delays * by lag samples determines the magnitude of * autocorrelation[lag]. The output of an autocorrelation shows the * magnitude for different lag times. Note that the array length of the * signal vector must have a length from at least window length + window * shift (signal.length >= N+lag-max). If the length is smaller a null float * array will be given back. * * @param column * - column of the data series * @param int windowlength - the length of correlation build with the * summaration loop. Corresponds to lag-max * @reurn output. */ public P0D autoCorrelation(int column, int windowlength) { double[] s = hdata.getColumn(column); double[] d = StatUtils.autoCorrelate(s, windowlength, 0); return new P0D(hdata.getDescription(), d); } /** * Cross-correlation.
* Return a new array that is the cross-correlation of the two argument * arrays, starting and ending at user-specified lag values. The output * array will have length (endLag - startLag + 1). The first element of the * output will have the cross-correlation at a lag of startLag. The last * element of the output will have the cross-correlation at a lag of endLag. * * @param column1 * The first column of doubles. * @param column2 * The second column of doubles. * @param N * An integer indicating the number of samples to sum over. * @param startLag * An int indicating at which lag to start (may be negative). * @param endLag * An int indicating at which lag to end. * @return A new array of doubles. */ public P0D crossCorrelation(int column1, int column2, int N, int startLag, int endLag) { double[] x = hdata.getColumn(column1); double[] y = hdata.getColumn(column2); double[] d = StatUtils.crossCorrelation(x, y, N, startLag, endLag); return new P0D(hdata.getDescription(), d); } /** * Perform Gaussian filtering. * * @param column * column number * @param width * Gaussian width for filtering * @return output result. */ public P0D filterGaussian(int column, double width) { double[] x = hdata.getColumn(column); GaussianFilter g = new GaussianFilter(x, width); double y[] = g.getFilteredSpectrum(); return new P0D(hdata.getDescription(), y); } /** * Identify peaks in the time series. Given a spectrum and search * parameters, performs a digital filter peak search as specified in V. * Hnatowicz et al in Comp Phys Comm 60 (1990) 111-125. Setting the * sensitivity to a typical value of 3 gives a 3% chance for any peak found * to be false. Maximum separation in sigma between peaks to count them as * being in the same multiplet is 1.3 sigma. * * * @param column * column number * @param sensitivity * larger numbers (typical=3) require better defined peaks * @param width * typical FWHM of peaks in spectrum * @return centroinds. */ public P0D peakFinder(int column, double sensitivity, double width) { double[] x = hdata.getColumn(column); PeakFinder pp = new PeakFinder("Peaks", x, sensitivity, width); double y[] = pp.getCentroids(); return new P0D("Centroids", y); } /** * Transform a column inside the time series using an analytic function. * Original data will contain the modified column. * * @param column * column number. * @param function * functional form. * * The function may have one independent variable: x *

* Operators and functions
*
* the following operators are supported: *

    *
  • Addition: '2 + 2'
  • *
  • Subtraction: '2 - 2'
  • *
  • Multiplication: '2 * 2'
  • *
  • Division: '2 / 2'
  • *
  • Exponential: '2 ^ 2' or ** (raise to a power)
  • *
  • Unary Minus,Plus (Sign Operators): '+2 - (-2)'
  • *
  • Modulo: '2 % 2'
  • *
* the following functions are supported: *
    *
  • abs: absolute value
  • *
  • acos: arc cosine
  • *
  • asin: arc sine
  • *
  • atan: arc tangent
  • *
  • cbrt: cubic root
  • *
  • ceil: nearest upper integer
  • *
  • cos: cosine
  • *
  • cosh: hyperbolic cosine
  • *
  • exp: euler's number raised to the power (e^x)
  • *
  • floor: nearest lower integer
  • *
  • log: logarithms natural (base e)
  • *
  • sin: sine
  • *
  • sinh: hyperbolic sine
  • *
  • sqrt: square root
  • *
  • tan: tangent
  • *
  • tanh: hyperbolic tangent
  • *
*
*/ public void transformColumn(int column, String function) { F1D f = new F1D(function); double[] x = f.eval(hdata.getData().getCol(column)); for (int j = 0; j < hdata.getData().rows(); j++) { hdata.getData().setValAt(x[j], j, column); } return; } /** * Smooth a column of the original data. It is smoothed by averaging over a * moving window of a size specified by the method parameter: if the value * of the parameter is k then the width of the window is 2*k + * 1. If the window runs off the end of the P1D only those values which * intersect the histogram are taken into consideration. The smoothing may * optionally be weighted to favor the central value using a "triangular" * weighting. For example, for a value of k equal to 2 the central * bin would have weight 1/3, the adjacent bins 2/9, and the next adjacent * bins 1/9. Errors are kept the same as before. * * @param column * column to be smoothed. * * @param isWeighted * Whether values in X or Y will be weighted using a triangular * weighting scheme favoring bins near the central bin. * @param k * The smoothing parameter which must be non-negative. If zero, * the histogram object will be returned with no smoothing * applied. */ public void smoothColumn(int column, boolean isWeighted, int k) { SHisto sh = new SHisto(hdata.getData().rows(), 0, hdata.getData() .rows(), 1); double[] hh = hdata.getData().getCol(column); sh.setBins(hh); sh = sh.getSmoothed(isWeighted, k); for (int j = 0; j < hdata.getData().rows(); j++) { hdata.getData().setValAt(sh.getBinsFirstBand(j), j, column); } return; } /** * Return a histogram for column. * * @param column * a colimn index to be converted to a histogram. * @param nbins * number of bins. * @param min * min value of histogram * @param max * max value of histogram * @return return histogram */ public H1D getH1D(int column, int nbins, double min, double max) { H1D h1 = new H1D(hdata.getDescription(), nbins, min, max); double[] hh = hdata.getData().getCol(column); h1.fill(hh); return h1; } }

Ads help maintain this website.