/* * Class ProbabilityPlot * * USAGE: Probability Plots * * WRITTEN BY: Dr Michael Thomas Flanagan * * DATE: 29-30 September 2008, 1-5 October 2008, 13-24 October 2009, 2 November 2010, 8 December 2010 * 7 December 2011, 4 January 2012 * * DOCUMENTATION: * See Michael Thomas Flanagan's Java library on-line web page: * http://www.ee.ucl.ac.uk/~mflanaga/java/ProbabilityPlot.html * http://www.ee.ucl.ac.uk/~mflanaga/java/ * * Copyright (c) 2009 Michael Thomas Flanagan * * PERMISSION TO COPY: * * Permission to use, copy and modify this software and its documentation for NON-COMMERCIAL purposes is granted, without fee, * provided that an acknowledgement to the author, Dr Michael Thomas Flanagan at www.ee.ucl.ac.uk/~mflanaga, appears in all copies * and associated documentation or publications. * * Redistributions of the source code of this source code, or parts of the source codes, must retain the above copyright notice, this list of conditions * and the following disclaimer and requires written permission from the Michael Thomas Flanagan: * * Redistribution in binary form of all or parts of this class must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution and requires written permission from the Michael Thomas Flanagan: * * Dr Michael Thomas Flanagan makes no representations about the suitability or fitness of the software for any or for a particular purpose. * Dr Michael Thomas Flanagan shall not be liable for any damages suffered as a result of using, modifying or distributing this software * or its derivatives. * ***************************************************************************************/ package flanagan.analysis; import java.util.*; import java.math.*; import flanagan.math.*; import flanagan.plot.PlotGraph; import flanagan.interpolation.CubicSpline; import flanagan.io.PrintToScreen; public class ProbabilityPlot{ // INSTANCE VARIABLES private double[] array = null; // array of data private Stat arrayAsStat = null; // array of data as Stat private double[] sortedData = null; // data sorted into ascending order private double[] weights = null; // weights private boolean weighted = false; // = true if weighted regression to be performed private double mean = Double.NaN; // array mean private double standardDeviation = Double.NaN; // array standard deviation private double minimum = Double.NaN; // array minimum private double maximum = Double.NaN; // array maximum private double range = Double.NaN; // array range private double halfWidth = Double.NaN; // rough estimate of peak width at half peak height private double peakPoint = Double.NaN; // rough estimate of peak position private int numberOfDataPoints = 0; // number of data points private double dataOffset = 0.0; // data offset if data shifted private boolean dataShifted = false; // = true if data offset private double[] initialEstimates = null; // initial estimates used in last call to a probability plot method private int lastMethod = 0; // Last probability plot method called // 0 Gaussian // 1 Weibull (three parameter) // 2 Exponential // 3 Rayleigh // 4 Pareto // 5 Gumbel (minimum order statistic) // 6 Gumbel (maximum order statistic) // 7 Frechet // 8 Logistic // 9 Lorentzian // TO BE ADDED // 10 Log-Normal (three parameter) // TO BE ADDED // 11 Log-Normal (two parameter // TO BE ADDED // 12 Weibull (two parameter) // 13 Weibull (standard) // 14 Standard Gaussian // 15 F-distribution private boolean supressPlot = false; // set to true to supress the display of the plot private int gaussianNumberOfParameters = 2; // number of Gaussian parameters private double[] gaussianOrderMedians = null; // Gaussian order statistic medians private double[] gaussianParam = null; // Gaussian parameters obtained by the minimization procedure private double[] gaussianParamErrors = null; // estimates of the errors of the Gaussian parameters obtained by the minimization procedure private double gaussianSumOfSquares = Double.NaN; // sum of squares at Gaussian minimum private double gaussianUnweightedSumOfSquares = Double.NaN; // unweighted sum of squares at Gaussian minimum private double[] gaussianLine = null; // Gaussian probability plot gradient and intercept private double[] gaussianLineErrors = null; // estimated errors of the Gaussian probability plot gradient and intercept private double gaussianCorrCoeff = Double.NaN; // Gaussian correlation coefficient of the probability plot private boolean gaussianDone = false; // = true after Gaussian probability plot drawn private int gaussianStandardNumberOfParameters = 0; // number of Standard Gauss parameters private double[] gaussianStandardOrderMedians = null; // Standard Gauss order statistic medians private double gaussianStandardSumOfSquares = Double.NaN; // sum of squares at Standard Gauss minimum private double[] gaussianStandardLine = null; // Standard Gauss probability plot gradient and intercept private double[] gaussianStandardLineErrors = null; // estimated errors of the Standard Gauss probability plot gradient and intercept private double gaussianStandardCorrCoeff = Double.NaN; // Standard Gauss correlation coefficient of the probability plot private boolean gaussianStandardDone = false; // = true after Standard Gauss probability plot drawn private int exponentialNumberOfParameters = 2; // number of Exponential parameters private double[] exponentialOrderMedians = null; // Exponential order statistic medians private double[] exponentialParam = null; // Exponential parameters obtained by the minimization procedure private double[] exponentialParamErrors = null; // estimates of the errors of the Exponential parameters obtained by the minimization procedure private double exponentialSumOfSquares = Double.NaN; // sum of squares at Exponential minimum private double[] exponentialLine = null; // Exponential probability plot gradient and intercept private double[] exponentialLineErrors = null; // estimated errors of the Exponential probability plot gradient and intercept private double exponentialCorrCoeff = Double.NaN; // Exponential correlation coefficient of the probability plot private boolean exponentialDone = false; // = true after Exponential probability plot drawn private int fDistributionNumberOfParameters = 0; // number of F-distribution parameters private double[] fDistributionOrderMedians = null; // F-distribution order statistic medians private double fDistributionSumOfSquares = Double.NaN; // sum of squares at F-distribution minimum private double[] fDistributionLine = null; // F-distribution probability plot gradient and intercept private double[] fDistributionLineErrors = null; // estimated errors of the F-distribution probability plot gradient and intercept private double fDistributionCorrCoeff = Double.NaN; // F-distribution correlation coefficient of the probability plot private boolean fDistributionDone = false; // = true after F-distribution probability plot drawn private int frechetNumberOfParameters = 3; // number of Frechet parameters private double[] frechetOrderMedians = null; // Frechet order statistic medians private double[] frechetParam = null; // Frechet parameters obtained by the minimization procedure private double[] frechetParamErrors = null; // estimates of the errors of the Frechet parameters obtained by the minimization procedure private double frechetSumOfSquares = Double.NaN; // sum of squares at Frechet minimum private double[] frechetLine = null; // Frechet probability plot gradient and intercept private double[] frechetLineErrors = null; // estimated errors of the Frechet probability plot gradient and intercept private double frechetCorrCoeff = Double.NaN; // Frechet correlation coefficient of the probability plot private boolean frechetDone = false; // = true after Frechet probability plot drawn private int gumbelMinNumberOfParameters = 3; // number of Gumbel (minimum order statistic) parameters private double[] gumbelMinOrderMedians = null; // Gumbel (minimum order statistic) order statistic medians private double[] gumbelMinParam = null; // Gumbel (minimum order statistic) parameters obtained by the minimization procedure private double[] gumbelMinParamErrors = null; // estimates of the errors of the Gumbel (minimum order statistic) parameters obtained by the minimization procedure private double gumbelMinSumOfSquares = Double.NaN; // sum of squares at Gumbel (minimum order statistic) minimum private double[] gumbelMinLine = null; // Gumbel (minimum order statistic) probability plot gradient and intercept private double[] gumbelMinLineErrors = null; // estimated errors of the Gumbel (minimum order statistic) probability plot gradient and intercept private double gumbelMinCorrCoeff = Double.NaN; // Gumbel (minimum order statistic) correlation coefficient of the probability plot private boolean gumbelMinDone = false; // = true after Gumbel (minimum order statistic) probability plot drawn private int gumbelMaxNumberOfParameters = 3; // number of Gumbel (maximum order statistic) parameters private double[] gumbelMaxOrderMedians = null; // Gumbel (maximum order statistic) order statistic medians private double[] gumbelMaxParam = null; // Gumbel (maximum order statistic) parameters obtained by the maximization procedure private double[] gumbelMaxParamErrors = null; // estimates of the errors of the Gumbel (maximum order statistic) parameters obtained by the maximization procedure private double gumbelMaxSumOfSquares = Double.NaN; // sum of squares at Gumbel (maximum order statistic) maximum private double[] gumbelMaxLine = null; // Gumbel (maximum order statistic) probability plot gradient and intercept private double[] gumbelMaxLineErrors = null; // estimated errors of the Gumbel (maximum order statistic) probability plot gradient and intercept private double gumbelMaxCorrCoeff = Double.NaN; // Gumbel (maximum order statistic) correlation coefficient of the probability plot private boolean gumbelMaxDone = false; // = true after Gumbel (maximum order statistic) probability plot drawn private int logisticNumberOfParameters = 3; // number of Logistic parameters private double[] logisticOrderMedians = null; // Logistic order statistic medians private double[] logisticParam = null; // Logistic parameters obtained by the minimization procedure private double[] logisticParamErrors = null; // estimates of the errors of the Logistic parameters obtained by the minimization procedure private double logisticSumOfSquares = Double.NaN; // sum of squares at Logistic minimum private double[] logisticLine = null; // Logistic probability plot gradient and intercept private double[] logisticLineErrors = null; // estimated errors of the Logistic probability plot gradient and intercept private double logisticCorrCoeff = Double.NaN; // Logistic correlation coefficient of the probability plot private boolean logisticDone = false; // = true after Logistic probability plot drawn private int paretoNumberOfParameters = 2; // number of Pareto parameters private double[] paretoOrderMedians = null; // Pareto order statistic medians private double[] paretoParam = null; // Pareto parameters obtained by the minimization procedure private double[] paretoParamErrors = null; // estimates of the errors of the Pareto parameters obtained by the minimization procedure private double paretoSumOfSquares = Double.NaN; // sum of squares at Pareto minimum private double[] paretoLine = null; // Pareto probability plot gradient and intercept private double[] paretoLineErrors = null; // estimated errors of the Pareto probability plot gradient and intercept private double paretoCorrCoeff = Double.NaN; // Pareto correlation coefficient of the probability plot private boolean paretoDone = false; // = true after Pareto probability plot drawn private int rayleighNumberOfParameters = 2; // number of Rayleigh parameters private double[] rayleighOrderMedians = null; // Rayleigh order statistic medians private double[] rayleighParam = null; // Rayleigh parameters obtained by the minimization procedure private double[] rayleighParamErrors = null; // estimates of the errors of the Rayleigh parameters obtained by the minimization procedure private double rayleighSumOfSquares = Double.NaN; // sum of squares at Rayleigh minimum private double[] rayleighLine = null; // Rayleigh probability plot gradient and intercept private double[] rayleighLineErrors = null; // estimated errors of the Rayleigh probability plot gradient and intercept private double rayleighCorrCoeff = Double.NaN; // Rayleigh correlation coefficient of the probability plot private boolean rayleighDone = false; // = true after Rayleigh probability plot drawn private int weibullNumberOfParameters = 3; // number of Three Parameter Weibull parameters private double[] weibullOrderMedians = null; // Three Parameter Weibull order statistic medians private double[] weibullParam = null; // Three Parameter Weibull parameters obtained by the minimization procedure private double[] weibullParamErrors = null; // estimates of the errors of the Three Parameter Weibull parameters obtained by the minimization procedure private double weibullSumOfSquares = Double.NaN; // sum of squares at Three Parameter Weibull minimum private double[] weibullLine = null; // Three Parameter Weibull probability plot gradient and intercept private double[] weibullLineErrors = null; // estimated errors of the Three Parameter Weibull probability plot gradient and intercept private double weibullCorrCoeff = Double.NaN; // Three Parameter Weibull correlation coefficient of the probability plot private boolean weibullDone = false; // = true after Three Parameter Weibull probability plot drawn private int weibullTwoParNumberOfParameters = 2; // number of Two Parameter Weibull parameters private double[] weibullTwoParOrderMedians = null; // Two Parameter Weibull order statistic medians private double[] weibullTwoParParam = null; // Two Parameter Weibull parameters obtained by the minimization procedure private double[] weibullTwoParParamErrors = null; // estimates of the errors of the Two Parameter Weibull parameters obtained by the minimization procedure private double weibullTwoParSumOfSquares = Double.NaN; // sum of squares at Two Parameter Weibull minimum private double[] weibullTwoParLine = null; // Two Parameter Weibull probability plot gradient and intercept private double[] weibullTwoParLineErrors = null; // estimated errors of the Two Parameter Weibull probability plot gradient and intercept private double weibullTwoParCorrCoeff = Double.NaN; // Two Parameter Weibull correlation coefficient of the probability plot private boolean weibullTwoParDone = false; // = true after Two Parameter Weibull probability plot drawn private int weibullStandardNumberOfParameters = 1; // number of Standard Weibull parameters private double[] weibullStandardOrderMedians = null; // Standard Weibull order statistic medians private double[] weibullStandardParam = null; // Standard Weibull parameters obtained by the minimization procedure private double[] weibullStandardParamErrors = null; // estimates of the errors of the Standard Weibull parameters obtained by the minimization procedure private double weibullStandardSumOfSquares = Double.NaN;// sum of squares at Standard Weibull minimum private double[] weibullStandardLine = null; // Standard Weibull probability plot gradient and intercept private double[] weibullStandardLineErrors = null; // estimated errors of the Standard Weibull probability plot gradient and intercept private double weibullStandardCorrCoeff = Double.NaN; // Standard Weibull correlation coefficient of the probability plot private boolean weibullStandardDone = false; // = true after Standard Weibull probability plot drawn private boolean probPlotDone = false; // = true after any probability plot drawn private double delta = 1e-3; // step fraction in numerical differentiation private boolean nFactorOptionI = false; // = true variance, covariance and standard deviation denominator = n // = false varaiance, covariance and standard deviation denominator = n-1 private boolean nFactorReset = false; // = true when instance method resetting the denominator is called // CONSTRUCTORS public ProbabilityPlot(double[] xx){ this.arrayAsStat = new Stat(xx); this.array = this.arrayAsStat.array(); this.initialize(); } public ProbabilityPlot(Double[] xx){ this.arrayAsStat = new Stat(xx); this.array = this.arrayAsStat.array(); this.initialize(); } public ProbabilityPlot(float[] xx){ this.arrayAsStat = new Stat(xx); this.array = this.arrayAsStat.array(); this.initialize(); } public ProbabilityPlot(Float[] xx){ this.arrayAsStat = new Stat(xx); this.array = this.arrayAsStat.array(); this.initialize(); } public ProbabilityPlot(long[] xx){ this.arrayAsStat = new Stat(xx); this.array = this.arrayAsStat.array(); this.initialize(); } public ProbabilityPlot(Long[] xx){ this.arrayAsStat = new Stat(xx); this.array = this.arrayAsStat.array(); this.initialize(); } public ProbabilityPlot(int[] xx){ this.arrayAsStat = new Stat(xx); this.array = this.arrayAsStat.array(); this.initialize(); } public ProbabilityPlot(Integer[] xx){ this.arrayAsStat = new Stat(xx); this.array = this.arrayAsStat.array(); this.initialize(); } public ProbabilityPlot(short[] xx){ this.arrayAsStat = new Stat(xx); this.array = this.arrayAsStat.array(); this.initialize(); } public ProbabilityPlot(Short[] xx){ this.arrayAsStat = new Stat(xx); this.array = this.arrayAsStat.array(); this.initialize(); } public ProbabilityPlot(byte[] xx){ this.arrayAsStat = new Stat(xx); this.array = this.arrayAsStat.array(); this.initialize(); } public ProbabilityPlot(Byte[] xx){ this.arrayAsStat = new Stat(xx); this.array = this.arrayAsStat.array(); this.initialize(); } public ProbabilityPlot(BigDecimal[] xx){ this.arrayAsStat = new Stat(xx); this.initialize(); } public ProbabilityPlot(BigInteger[] xx){ this.arrayAsStat = new Stat(xx); this.array = this.arrayAsStat.array(); this.initialize(); } public ProbabilityPlot(Object[] xx){ this.arrayAsStat = new Stat(xx); this.array = this.arrayAsStat.array(); this.initialize(); } public ProbabilityPlot(Vector xx){ this.arrayAsStat = new Stat(xx); this.array = this.arrayAsStat.array(); this.initialize(); } public ProbabilityPlot(ArrayList xx){ this.arrayAsStat = new Stat(xx); this.array = this.arrayAsStat.array(); this.initialize(); } public ProbabilityPlot(ArrayMaths xx){ double[] aa = xx.array(); this.arrayAsStat = new Stat(aa); this.array = this.arrayAsStat.array(); this.initialize(); } public ProbabilityPlot(Stat xx){ this.arrayAsStat = xx; this.array = this.arrayAsStat.array(); this.initialize(); } // INITIALIZATIONS private void initialize(){ this.numberOfDataPoints = this.array.length; ArrayMaths sorted = arrayAsStat.sort(); this.sortedData = sorted.array(); this.mean = arrayAsStat.mean(); this.standardDeviation = arrayAsStat.standardDeviation(); this.minimum = arrayAsStat.minimum(); this.maximum = arrayAsStat.maximum(); this.range = this.maximum - this.minimum; this.weights = new double[this.numberOfDataPoints]; for(int i=0; i=1000){ interpData = this.sortedData; nInterp = this.numberOfDataPoints; } else{ double[] dataX = new double[this.numberOfDataPoints]; for(int i=0; i=nInterp)test = false; while(test){ if(interpData[counter]=nInterp)test = false; } binLower = binUpper; binUpper = binLower + binWidth; } if(counter=2){ double[] interpLy = new double[maxIindex+1]; double[] interpLx = new double[maxIindex+1]; for(int i=0; i<=maxIindex; i++){ interpLy[i] = binnedData[i]; interpLx[i] = bins[i]; } CubicSpline csl = new CubicSpline(interpLx, interpLy); double[] tempx = new double[100]; double[] tempy = new double[100]; double incr = (interpLx[maxIindex]-interpLx[0])/99; double intr = interpLx[0]; for(int i=0; i<99; i++){ tempx[i] = intr; tempy[i] = csl.interpolate(intr); intr += incr; } tempy[99] = interpLy[maxIindex]; tempx[99] = interpLx[maxIindex]; boolean testt = true; int ii = 0; while(testt){ if(halfHeight<=tempy[ii]){ if(ii==0){ widthLower = tempx[0]; testt = false; lowerCheck = true; }else{ if(ii==99){ widthLower = tempx[99]; testt = false; lowerCheck = true; } else{ widthLower = (tempx[ii] + tempx[ii-1])/2.0; testt = false; lowerCheck = true; } } } ii++; if(ii>=100)testt = false; } } else{ if(maxIindex==2){ if(binnedData[1]>=halfHeight){ widthLower = bins[0] + (bins[1] - bins[0])*(halfHeight - binnedData[0])/(binnedData[1] - binnedData[0]); lowerCheck = true; } else{ widthLower = bins[1] + (bins[2] - bins[1])*(halfHeight - binnedData[1])/(binnedData[2] - binnedData[1]); lowerCheck = true; } } else{ widthLower = bins[0] + (bins[1] - bins[0])*(halfHeight - binnedData[0])/(binnedData[1] - binnedData[0]); lowerCheck = true; } } } else{ if(maxIindex>2){ if((binnedData[maxIindex]-binnedData[0])>halfHeight*0.5){ widthLower = bins[0] + (bins[1] - bins[0])*(halfHeight - binnedData[0])/(binnedData[1] - binnedData[0]); lowerCheck = true; } } } } // upper limit int nTop = nBins - 1; int nDif = nBins - maxIindex; if(binnedData[nTop]==halfHeight){ widthUpper = bins[nTop]; upperCheck = true; } else{ if(binnedData[nTop]=3){ double[] interpLy = new double[nDif]; double[] interpLx = new double[nDif]; int ii = 0; for(int i=maxIindex; i=100)testt = false; } } else{ if(nDif==2){ if(binnedData[nTop-1]>=halfHeight){ widthUpper = bins[nTop-1] + (bins[nTop] - bins[nTop-1])*(halfHeight - binnedData[nTop-1])/(binnedData[nTop] - binnedData[nTop-1]); upperCheck = true; } else{ widthUpper = bins[nTop-2] + (bins[nTop-1] - bins[nTop-2])*(halfHeight - binnedData[nTop-2])/(binnedData[nTop-1] - binnedData[nTop-2]); upperCheck = true; } } else{ widthUpper = bins[nTop-1] + (bins[nTop] - bins[nTop-1])*(halfHeight - binnedData[nTop-1])/(binnedData[nTop] - binnedData[nTop-1]); upperCheck = true; } } } else{ if(nDif>2){ if((binnedData[maxIindex]-binnedData[nTop])>halfHeight*0.5){ widthUpper = bins[nTop-1] + (bins[nTop] - bins[nTop-1])*(halfHeight - binnedData[nTop-1])/(binnedData[nTop] - binnedData[nTop-1]); upperCheck = true; } } } } // combine lower and upper half widths if(lowerCheck){ if(upperCheck){ this.halfWidth = widthUpper - widthLower; } else{ this.halfWidth = (this.peakPoint - widthLower)*1.3; } } else{ if(upperCheck){ this.halfWidth = (widthUpper - this.peakPoint)*1.3; } else{ System.out.println("Half height width could not be calculated - half range returned"); this.halfWidth = this.range/2.0; } } return this.halfWidth; } // GAUSSIAN PROBABILITY PLOT public void gaussianProbabilityPlot(){ this.lastMethod = 0; // Check for suffient data points this.gaussianNumberOfParameters = 2; if(this.numberOfDataPoints<3)throw new IllegalArgumentException("There must be at least three data points - preferably considerably more"); // Create instance of Regression Regression min = new Regression(this.sortedData, this.sortedData); double meanest = this.mean; if(this.mean==0)meanest = this.standardDeviation/3.0; double[] start = {meanest, this.standardDeviation}; this.initialEstimates = start; double[] step = {0.3*meanest, 0.3*this.standardDeviation}; double tolerance = 1e-10; // Add constraint; sigma>0 min.addConstraint(1, -1, 0); // Create an instance of GaussProbPlotFunc GaussProbPlotFunc gppf = new GaussProbPlotFunc(); gppf.setDataArray(this.numberOfDataPoints); // Obtain best probability plot varying mu and sigma // by minimizing the sum of squares of the differences between the ordered data and the ordered statistic medians min.simplex(gppf, start, step, tolerance); // Get mu and sigma for best correlation coefficient this.gaussianParam = min.getBestEstimates(); // Get mu and sigma errors for best correlation coefficient this.gaussianParamErrors = min.getBestEstimatesErrors(); // Calculate Gaussian order statistic medians this.gaussianOrderMedians = Stat.gaussianOrderStatisticMedians(this.gaussianParam[0], this.gaussianParam[1], this.numberOfDataPoints); // Regression of the ordered data on the Gaussian order statistic medians Regression reg = new Regression(this.gaussianOrderMedians, this.sortedData); reg.linear(); // Intercept and gradient of best fit straight line this.gaussianLine = reg.getBestEstimates(); // Estimated erors of the intercept and gradient of best fit straight line this.gaussianLineErrors = reg.getBestEstimatesErrors(); // Correlation coefficient this.gaussianCorrCoeff = reg.getSampleR(); // Initialize data arrays for plotting double[][] data = PlotGraph.data(2,this.numberOfDataPoints); // Assign data to plotting arrays data[0] = this.gaussianOrderMedians; data[1] = this.sortedData; data[2] = this.gaussianOrderMedians; for(int i=0; i0 min.addConstraint(1, -1, 0); // Create an instance of LogisticProbPlotFunc LogisticProbPlotFunc lppf = new LogisticProbPlotFunc(); lppf.setDataArray(this.numberOfDataPoints); // Obtain best probability plot varying mu and sigma // by minimizing the sum of squares of the differences between the ordered data and the ordered statistic medians min.simplex(lppf, start, step, tolerance); // Get mu and beta for best correlation coefficient this.logisticParam = min.getBestEstimates(); // Get mu and beta errors for best correlation coefficient this.logisticParamErrors = min.getBestEstimatesErrors(); // Get sum of squares this.logisticSumOfSquares = min.getSumOfSquares(); // Calculate Logistic order statistic medians this.logisticOrderMedians = Stat.logisticOrderStatisticMedians(this.logisticParam[0], this.logisticParam[1], this.numberOfDataPoints); // Regression of the ordered data on the Logistic order statistic medians Regression reg = new Regression(this.logisticOrderMedians, this.sortedData); reg.linear(); // Intercept and gradient of best fit straight line this.logisticLine = reg.getBestEstimates(); // Estimated erors of the intercept and gradient of best fit straight line this.logisticLineErrors = reg.getBestEstimatesErrors(); // Correlation coefficient this.logisticCorrCoeff = reg.getSampleR(); // Initialize data arrays for plotting double[][] data = PlotGraph.data(2,this.numberOfDataPoints); // Assign data to plotting arrays data[0] = this.logisticOrderMedians; data[1] = this.sortedData; data[2] = logisticOrderMedians; for(int i=0; i0, gamma>0 min.addConstraint(0, +1, minimum); min.addConstraint(1, -1, 0); min.addConstraint(2, -1, 0); // Create an instance of WeibullProbPlotFunc WeibullProbPlotFunc wppf = new WeibullProbPlotFunc(); wppf.setDataArray(this.numberOfDataPoints); // Obtain best probability plot varying mu, sigma and gamma // by minimizing the sum of squares of the differences between the ordered data and the ordered statistic medians min.simplex(wppf, Conv.copy(start), step, tolerance); // Obtain best estimates or first minimisation double[] firstBests = min.getBestEstimates(); // Get mu and sigma value errors double[] firstErrors = min.getBestEstimatesErrors(); // Get sum of squares double ss = min.getSumOfSquares(); //Calculate new initial estimates double[] start2 = new double[this.weibullNumberOfParameters]; start2[0] = 2.0*firstBests[0] - start[0]; if(start2[0]>minimum)start2[0] = minimum*(1.0 - Math.abs(minimum)*0.05); step[0] = Math.abs(start2[0]*0.1); if(step[0]==0)step[0] = this.range*0.01; start2[1] = 2.0*firstBests[1] - start[1]; if(start2[1]<=0.0)start2[1] = Math.abs(2.0*firstBests[1] - 0.98*start[1]); step[1] = Math.abs(start2[1]*0.1); start2[2] = 2.0*firstBests[2] - start[2]; if(start2[1]<=0.0)start2[2] = Math.abs(2.0*firstBests[2] - 0.98*start[2]); step[2] = Math.abs(start2[2]*0.1); min.simplex(wppf, Conv.copy(start2), step, tolerance); // Get mu, sigma and gamma for best correlation coefficient this.weibullParam = min.getBestEstimates(); // Get mu and sigma value errors this.weibullParamErrors = min.getBestEstimatesErrors(); // Get sum of squares this.weibullSumOfSquares = min.getSumOfSquares(); if(ss0, gamma>0 min.addConstraint(0, -1, 0); min.addConstraint(1, -1, 0); // Create an instance of WeibullTwoParProbPlotFunc WeibullTwoParProbPlotFunc wppf = new WeibullTwoParProbPlotFunc(); wppf.setDataArray(this.numberOfDataPoints); // Obtain best probability plot varying sigma and gamma // by minimizing the sum of squares of the differences between the ordered data and the ordered statistic medians min.simplex(wppf, Conv.copy(start), step, tolerance); // Obtain best estimates or first minimisation double[] firstBests = min.getBestEstimates(); // Get mu and sigma value errors double[] firstErrors = min.getBestEstimatesErrors(); // Get sum of squares double ss = min.getSumOfSquares(); //Calculate new initial estimates double[] start2 = new double[this.weibullTwoParNumberOfParameters]; start2[0] = 2.0*firstBests[0] - start[0]; if(start2[0]>minimum)start2[0] = minimum*(1.0 - Math.abs(minimum)*0.05); step[0] = Math.abs(start2[0]*0.1); if(step[0]==0)step[0] = this.range*0.01; start2[1] = 2.0*firstBests[1] - start[1]; if(start2[1]<=0.0)start2[1] = Math.abs(2.0*firstBests[1] - 0.98*start[1]); step[1] = Math.abs(start2[1]*0.1); min.simplex(wppf, Conv.copy(start2), step, tolerance); // Get sigma and gamma for best correlation coefficient this.weibullTwoParParam = min.getBestEstimates(); // Get sigma and gamma value errors this.weibullTwoParParamErrors = min.getBestEstimatesErrors(); // Get sum of squares this.weibullTwoParSumOfSquares = min.getSumOfSquares(); if(ss0 min.addConstraint(0, -1, 0); // Create an instance of WeibullStandardProbPlotFunc WeibullStandardProbPlotFunc wppf = new WeibullStandardProbPlotFunc(); wppf.setDataArray(this.numberOfDataPoints); // Obtain best probability plot varying gamma // by minimizing the sum of squares of the differences between the ordered data and the ordered statistic medians min.simplex(wppf, Conv.copy(start), step, tolerance); // Obtain best estimates or first minimisation double[] firstBests = min.getBestEstimates(); // Get mu and sigma value errors double[] firstErrors = min.getBestEstimatesErrors(); // Get sum of squares double ss = min.getSumOfSquares(); //Calculate new initial estimates double[] start2 = new double[this.weibullStandardNumberOfParameters]; start2[0] = 2.0*firstBests[0] - start[0]; if(start2[0]>minimum)start2[0] = minimum*(1.0 - Math.abs(minimum)*0.05); step[0] = Math.abs(start2[0]*0.1); if(step[0]==0)step[0] = this.range*0.01; min.simplex(wppf, Conv.copy(start2), step, tolerance); // Get gamma for best correlation coefficient this.weibullStandardParam = min.getBestEstimates(); // Get gamma value errors this.weibullStandardParamErrors = min.getBestEstimatesErrors(); // Get sum of squares this.weibullStandardSumOfSquares = min.getSumOfSquares(); // Calculate Weibull Standard order statistic medians this.weibullStandardOrderMedians = Stat.weibullOrderStatisticMedians(this.weibullStandardParam[0], this.numberOfDataPoints); // Regression of the ordered data on the Weibull order statistic medians Regression reg = new Regression(this.weibullStandardOrderMedians, this.sortedData); reg.linear(); // Intercept and gradient of best fit straight line this.weibullStandardLine = reg.getBestEstimates(); // Estimated erors of the intercept and gradient of best fit straight line this.weibullStandardLineErrors = reg.getBestEstimatesErrors(); // Correlation coefficient this.weibullStandardCorrCoeff = reg.getSampleR(); // Initialize data arrays for plotting double[][] data = PlotGraph.data(2,this.numberOfDataPoints); // Assign data to plotting arrays data[0] = this.weibullStandardOrderMedians; data[1] = this.sortedData; data[2] = weibullStandardOrderMedians; for(int i=0; i0 min.addConstraint(1, -1, 0); // Create an instance of ExponentialProbPlotFunc ExponentialProbPlotFunc eppf = new ExponentialProbPlotFunc(); eppf.setDataArray(this.numberOfDataPoints); // Obtain best probability plot varying mu and sigma // by minimizing the sum of squares of the differences between the ordered data and the ordered statistic medians min.simplex(eppf, start, step, tolerance); // Get mu and sigma values this.exponentialParam = min.getBestEstimates(); // Get mu and sigma value errors this.exponentialParamErrors = min.getBestEstimatesErrors(); // Get sum of squares this.exponentialSumOfSquares = min.getSumOfSquares(); // Calculate Exponential order statistic medians (Weibull with gamma = 1) this.exponentialOrderMedians = Stat.weibullOrderStatisticMedians(this.exponentialParam[0], this.exponentialParam[1], 1.0, this.numberOfDataPoints); // Regression of the ordered data on the Exponential order statistic medians Regression reg = new Regression(this.exponentialOrderMedians, this.sortedData); reg.linear(); // Intercept and gradient of best fit straight line this.exponentialLine = reg.getBestEstimates(); // Estimated erors of the intercept and gradient of best fit straight line this.exponentialLineErrors = reg.getBestEstimatesErrors(); // Correlation coefficient this.exponentialCorrCoeff = reg.getSampleR(); // Initialize data arrays for plotting double[][] data = PlotGraph.data(2,this.numberOfDataPoints); // Assign data to plotting arrays data[0] = this.exponentialOrderMedians; data[1] = this.sortedData; data[2] = exponentialOrderMedians; for(int i=0; i0, gamma>0 min.addConstraint(0, +1, minimum); min.addConstraint(1, -1, 0); min.addConstraint(2, -1, 0); // Create an instance of FrechetProbPlotFunc FrechetProbPlotFunc fppf = new FrechetProbPlotFunc(); fppf.setDataArray(this.numberOfDataPoints); // Obtain best probability plot varying mu, sigma and gamma // by minimizing the sum of squares of the differences between the ordered data and the ordered statistic medians min.simplex(fppf, Conv.copy(start), step, tolerance); // Obtain best estimates or first minimisation double[] firstBests = min.getBestEstimates(); double ss = min.getSumOfSquares(); //Calculate new initial estimates double[] start2 = new double[this.frechetNumberOfParameters]; start2[0] = 2.0*firstBests[0] - start[0]; if(start2[0]>minimum)start2[0] = minimum*(1.0 - Math.abs(minimum)*0.05); step[0] = Math.abs(start2[0]*0.1); if(step[0]==0)step[0] = this.range*0.01; start2[1] = 2.0*firstBests[1] - start[1]; if(start2[1]<=0.0)start2[1] = Math.abs(2.0*firstBests[1] - 0.98*start[1]); step[1] = Math.abs(start2[1]*0.1); start2[2] = 2.0*firstBests[2] - start[2]; if(start2[1]<=0.0)start2[2] = Math.abs(2.0*firstBests[2] - 0.98*start[2]); step[2] = Math.abs(start2[2]*0.1); min.simplex(fppf, Conv.copy(start2), step, tolerance); // Get mu, sigma and gamma for best correlation coefficient this.frechetParam = min.getBestEstimates(); double ss2 = min.getSumOfSquares(); if(ss0 min.addConstraint(1, -1, 0); // Create an instance of Gumbel (minimum order statistic)ProbPlotFunc GumbelMinProbPlotFunc gmippf = new GumbelMinProbPlotFunc(); gmippf.setDataArray(this.numberOfDataPoints); // Obtain best probability plot varying mu and sigma // by minimizing the sum of squares of the differences between the ordered data and the ordered statistic medians min.simplex(gmippf, start, step, tolerance); // Get mu and sigma values this.gumbelMinParam = min.getBestEstimates(); // Get mu and sigma value errors this.gumbelMinParamErrors = min.getBestEstimatesErrors(); // Get sum of squares this.gumbelMinSumOfSquares = min.getSumOfSquares(); // Calculate Gumbel (minimum order statistic) order statistic medians this.gumbelMinOrderMedians = Stat.gumbelMinOrderStatisticMedians(this.gumbelMinParam[0], this.gumbelMinParam[1], this.numberOfDataPoints); // Regression of the ordered data on the Gumbel (minimum order statistic) order statistic medians Regression reg = new Regression(this.gumbelMinOrderMedians, this.sortedData); reg.linear(); // Intercept and gradient of best fit straight line this.gumbelMinLine = reg.getBestEstimates(); // Estimated erors of the intercept and gradient of best fit straight line this.gumbelMinLineErrors = reg.getBestEstimatesErrors(); // Correlation coefficient this.gumbelMinCorrCoeff = reg.getSampleR(); // Initialize data arrays for plotting double[][] data = PlotGraph.data(2,this.numberOfDataPoints); // Assign data to plotting arrays data[0] = this.gumbelMinOrderMedians; data[1] = this.sortedData; data[2] = gumbelMinOrderMedians; for(int i=0; i0 min.addConstraint(1, -1, 0); // Create an instance of Gumbel (maximum order statistic)ProbPlotFunc GumbelMaxProbPlotFunc gmappf = new GumbelMaxProbPlotFunc(); gmappf.setDataArray(this.numberOfDataPoints); // Obtain best probability plot varying mu and sigma // by minimizing the sum of squares of the differences between the ordered data and the ordered statistic medians min.simplex(gmappf, start, step, tolerance); // Get mu and sigma values this.gumbelMaxParam = min.getBestEstimates(); // Get mu and sigma value errors this.gumbelMaxParamErrors = min.getBestEstimatesErrors(); // Get sum of squares this.gumbelMaxSumOfSquares = min.getSumOfSquares(); // Calculate Gumbel (maximum order statistic) order statistic medians this.gumbelMaxOrderMedians = Stat.gumbelMaxOrderStatisticMedians(this.gumbelMaxParam[0], this.gumbelMaxParam[1], this.numberOfDataPoints); // Regression of the ordered data on the Gumbel (maximum order statistic) order statistic medians Regression reg = new Regression(this.gumbelMaxOrderMedians, this.sortedData); reg.linear(); // Intercept and gradient of best fit straight line this.gumbelMaxLine = reg.getBestEstimates(); // Correlation coefficient this.gumbelMaxCorrCoeff = reg.getSampleR(); // Initialize data arrays for plotting double[][] data = PlotGraph.data(2,this.numberOfDataPoints); // Assign data to plotting arrays data[0] = this.gumbelMaxOrderMedians; data[1] = this.sortedData; data[2] = gumbelMaxOrderMedians; for(int i=0; i0 min.addConstraint(0, -1, 0); // Create an instance of RayleighProbPlotFunc RayleighProbPlotFunc rppf = new RayleighProbPlotFunc(); rppf.setDataArray(this.numberOfDataPoints); // Obtain best probability plot varying beta // by minimizing the sum of squares of the differences between the ordered data and the ordered statistic medians min.simplex(rppf, start, step, tolerance); // Get mu and sigma values this.rayleighParam = min.getBestEstimates(); // Get mu and sigma value errors this.rayleighParamErrors = min.getBestEstimatesErrors(); // Get sum of squares this.rayleighSumOfSquares = min.getSumOfSquares(); // Calculate Rayleigh order statistic medians (Weibull with mu = 0, sigma = sqrt(2).beta, gamma = 2) this.rayleighOrderMedians = Stat.weibullOrderStatisticMedians(0.0, this.rayleighParam[0]*Math.sqrt(2.0), 2.0, this.numberOfDataPoints); // Regression of the ordered data on the Rayleigh order statistic medians Regression reg = new Regression(this.rayleighOrderMedians, this.sortedData); reg.linear(); // Intercept and gradient of best fit straight line this.rayleighLine = reg.getBestEstimates(); // Estimated erors of the intercept and gradient of best fit straight line this.rayleighLineErrors = reg.getBestEstimatesErrors(); // Correlation coefficient this.rayleighCorrCoeff = reg.getSampleR(); // Initialize data arrays for plotting double[][] data = PlotGraph.data(2,this.numberOfDataPoints); // Assign data to plotting arrays data[0] = this.rayleighOrderMedians; data[1] = this.sortedData; data[2] = rayleighOrderMedians; for(int i=0; i