Class WelchDataFileAnalyzer

  • All Implemented Interfaces:
    ObservableIfc

    public class WelchDataFileAnalyzer
    extends java.lang.Object
    implements ObservableIfc
    This class knows how to process data collected by the WelchDataFileCollector class and produce "Welch Data". That is for every observation, this file will average across the replications and compute the average across the replications and compute the cumulative sum over the averages. It can make "wpdf" files which are binary DataOutputStream files holding the welch average and the cumulative average for each of the observations. wpdf = Welch Plot Data File It can make a csv file that holds the welch average and cumulative average An Observer can be attached. It will be notified when a call to get() occurs. getLastDataPoint(), getLastObservationIndex(), and getLastReplicationIndex() can be used by the observer to determine the value, observation number, and replication of the observation after notification. Unless specifically redirected, files produced by the operation of this class are stored in the same directory (getBaseDirectory()) that the wdf is stored as specified by the supplied WelchFileMetaDataBean information.
    • Field Detail

      • myBaseName

        protected java.lang.String myBaseName
      • myObsCounts

        protected final long[] myObsCounts
      • myTimePerObs

        protected final double[] myTimePerObs
      • myRepAvgs

        protected final double[] myRepAvgs
      • myTimeRepsEnd

        protected final double[] myTimeRepsEnd
      • myMinObsCount

        protected final long myMinObsCount
      • myRowData

        protected final double[] myRowData
      • myAcrossRepStat

        protected final Statistic myAcrossRepStat
      • myPathToWDF

        protected final java.nio.file.Path myPathToWDF
      • myWDFDataFile

        protected java.io.RandomAccessFile myWDFDataFile
    • Method Detail

      • makeFromJSON

        public static java.util.Optional<WelchDataFileAnalyzer> makeFromJSON​(java.nio.file.Path pathToWelchFileMetaDataBeanJson)
        Parameters:
        pathToWelchFileMetaDataBeanJson - must not be null, must be JSON, must represent WelchFileMetaDataBean
        Returns:
        an optional holding the WelchDataFileAnalyzer
      • getWelchFileMetaDataBean

        public final WelchFileMetaDataBean getWelchFileMetaDataBean()
        Returns:
        the meta data bean for the welch file
      • getBaseDirectory

        public final java.nio.file.Path getBaseDirectory()
        Returns:
        a path to the directory (folder) that holds the analysis files
      • getBaseFileName

        public final java.nio.file.Path getBaseFileName()
        Returns:
        the base name of the wdf file used in the analysis
      • getResponseName

        public final java.lang.String getResponseName()
        Returns:
        the name of the response
      • addObserver

        public final void addObserver​(ObserverIfc observer)
        Description copied from interface: ObservableIfc
        Allows the adding (attaching) of an observer to the observable
        Specified by:
        addObserver in interface ObservableIfc
        Parameters:
        observer - the observer to attach
      • deleteObserver

        public final void deleteObserver​(ObserverIfc observer)
        Description copied from interface: ObservableIfc
        Allows the deletion (removing) of an observer from the observable
        Specified by:
        deleteObserver in interface ObservableIfc
        Parameters:
        observer - the observer to delete
      • deleteObservers

        public final void deleteObservers()
        Description copied from interface: ObservableIfc
        Deletes all the observers from the observable
        Specified by:
        deleteObservers in interface ObservableIfc
      • contains

        public final boolean contains​(ObserverIfc observer)
        Description copied from interface: ObservableIfc
        Returns true if the observer is already attached
        Specified by:
        contains in interface ObservableIfc
        Parameters:
        observer - the observer to check
        Returns:
        true if attached
      • countObservers

        public final int countObservers()
        Description copied from interface: ObservableIfc
        Returns how many observers are currently observing the observable
        Specified by:
        countObservers in interface ObservableIfc
        Returns:
        number of observers
      • getLastDataPoint

        public final double getLastDataPoint()
        Returns the last data point read or Double.NaN if none read. Can be used by Observers when data is read.
        Returns:
        the last data point
      • makeWelchPlotDataFile

        public final java.io.File makeWelchPlotDataFile()
        Makes a file and writes out the welch data to the DataOutputStream. This produces a file with the "wpdf" extension. All observations are written Squelches inconvenient IOExceptions
        Returns:
        the file reference
      • makeWelchPlotDataFile

        public final java.io.File makeWelchPlotDataFile​(long numObs)
        Makes a file and writes out the welch data to the DataOutputStream. This produces a file with the "wpdf" extension. wpdf = Welch Plot Data File Squelches inconvenient IOExceptions
        Parameters:
        numObs - number of observations to write out
        Returns:
        the file reference
      • writeWelchPlotData

        public final void writeWelchPlotData​(java.io.DataOutputStream out,
                                             long numObs)
                                      throws java.io.IOException
        This produces a file with the "wpdf" extension. wpdf = Welch Plot Data File Writes out the welch plot data, xbar, cumxbar to the supplied DataOutputStream. The file is flushed and closed.
        Parameters:
        out - the stream to write to
        numObs - number of observations to write out
        Throws:
        java.io.IOException - could not write the data to the file for some reason
      • makeCSVWelchPlotDataFile

        public final java.io.File makeCSVWelchPlotDataFile()
        Makes and writes out the welch plot data. Squelches inconvenient IOExceptions The file is stored in the base directory holding the welch data files and has the name of the data with _WelchPlotData.csv appended. The header row is Avg, CumAvg
        Returns:
        the File reference
      • makeCSVWelchPlotDataFile

        public final java.io.File makeCSVWelchPlotDataFile​(long numObs)
        Makes and writes out the welch plot data. Squelches inconvenient IOExceptions The file is stored in the base directory holding the welch data files and has the name of the data with _WelchPlotData.csv appended. The header row is Avg, CumAvg
        Parameters:
        numObs - number of observations to write
        Returns:
        the File reference
      • writeCSVWelchPlotData

        public final void writeCSVWelchPlotData​(java.io.PrintWriter out)
                                         throws java.io.IOException
        Writes out all of the observations to the supplied PrintWriter This results in a comma separated value file that has x_bar and cum_x_bar where x_bar is the average across the replications The header row is Avg, CumAvg
        Parameters:
        out - the PrintWriter
        Throws:
        java.io.IOException - if problem writing
      • writeCSVWelchPlotData

        public final void writeCSVWelchPlotData​(java.io.PrintWriter out,
                                                long numObs)
                                         throws java.io.IOException
        Writes out the number of observations to the supplied PrintWriter This results in a comma separated value file that has x_bar and cum_x_bar where x_bar is the average across the replications. The file is flushed and closed. The header row is Avg, CumAvg
        Parameters:
        out - the PrintWriter
        numObs - how many to write
        Throws:
        java.io.IOException - if problem writing
      • makeCSVWelchDataFile

        public final java.io.File makeCSVWelchDataFile()
                                                throws java.io.IOException
        This results in a comma separated value file that has each row containing each observation for each replication and each replication as columns. The last two columns are avg is the average across the replications and cumAvg. The file is flushed and closed. The file is stored in the base directory holding the welch data files and has the name of the data with _WelchData.csv appended. The header row is: Rep1, Rep2, ..., RepN, Avg, CumAvg
        Throws:
        java.io.IOException - if problem writing
      • makeCSVWelchDataFile

        public final java.io.File makeCSVWelchDataFile​(long numObs)
                                                throws java.io.IOException
        This results in a comma separated value file that has each rows containing each observation for each replication and each replication as columns. The last two columns are avg is the average across the replications and cumAvg. The file is flushed and closed. The file is stored in the base directory holding the welch data files and has the name of the data with _WelchData.csv appended. The header row is: Rep1, Rep2, ..., RepN, Avg, CumAvg
        Parameters:
        numObs - how many to write
        Throws:
        java.io.IOException - if problem writing
      • writeCSVWelchData

        public final void writeCSVWelchData​(java.io.PrintWriter out)
                                     throws java.io.IOException
        Writes out the number of observations to the supplied PrintWriter. This results in a comma separated value file that has each rows containing each observation for each replication and each replication as columns. The last two columns are avg is the average across the replications and cumAvg. The file is flushed and closed. The header row is: Rep1, Rep2, ..., RepN, Avg, CumAvg
        Parameters:
        out - the PrintWriter
        Throws:
        java.io.IOException - if problem writing
      • writeCSVWelchData

        public final void writeCSVWelchData​(java.io.PrintWriter out,
                                            long numObs)
                                     throws java.io.IOException
        Writes out the number of observations to the supplied PrintWriter This results in a comma separated value file that has each rows containing each observation for each replication and each replication as columns. The last two columns are avg is the average across the replications and cumAvg. The file is flushed and closed. The header row is: Rep1, Rep2, ..., RepN, Avg, CumAvg
        Parameters:
        out - the PrintWriter
        numObs - how many to write
        Throws:
        java.io.IOException - if problem writing
      • getWelchAverages

        public final double[] getWelchAverages​(int numObs)
                                        throws java.io.IOException
        Returns an array of the Welch averages. Since the number of observations in the file may be very large, this may have memory implications.
        Parameters:
        numObs - the number of observations to get
        Returns:
        the array of data
        Throws:
        java.io.IOException - if there was a problem accessing the file
      • getWelchAveragesNE

        public final double[] getWelchAveragesNE​(int numObs)
        Returns an array of the Welch averages. Since the number of observations in the file may be very large, this may have memory implications. Squelches any IOExceptions
        Parameters:
        numObs - the number of observations to get
        Returns:
        the array of data
      • getCumulativeWelchAverages

        public final double[] getCumulativeWelchAverages​(int numObs)
        Returns an array of the cumulative Welch averages. Since the number of observations in the file may be very large, this may have memory implications. Squelches any IOExceptions
        Parameters:
        numObs - the number of observations to get
        Returns:
        the array of data
      • batchWelchAverages

        public final BatchStatistic batchWelchAverages()
                                                throws java.io.IOException
        Creates a BatchStatistic that batches the Welch averages according to the batching parameters. Uses the number of observations via getMinNumObservationsInReplications() to determine the number of batches based on MIN_BATCH_SIZE. No data is deleted.
        Returns:
        A BatchStatistic
        Throws:
        java.io.IOException - if there was a problem accessing the file
      • batchWelchAverages

        public final BatchStatistic batchWelchAverages​(int deletePt)
                                                throws java.io.IOException
        Creates a BatchStatistic that batches the Welch averages according to the batching parameters. Uses the number of observations via getMinNumObservationsInReplications() to determine the number of batches based on MIN_BATCH_SIZE.
        Parameters:
        deletePt - the number of observations to delete at beginning of series
        Returns:
        A BatchStatistic
        Throws:
        java.io.IOException - if there was a problem accessing the file
      • batchWelchAverages

        public final BatchStatistic batchWelchAverages​(int deletePt,
                                                       int minBatchSize)
                                                throws java.io.IOException
        Creates a BatchStatistic that batches the Welch averages according to the batching parameters. Uses the number of observations via getMinNumObservationsInReplications() to determine the number of batches based on the supplied batch size.
        Parameters:
        deletePt - the number of observations to delete at beginning of series
        minBatchSize - the size of the batches, must be GT 1
        Returns:
        A BatchStatistic
        Throws:
        java.io.IOException - if there was a problem accessing the file
      • batchWelchAverages

        public final BatchStatistic batchWelchAverages​(int deletePt,
                                                       int minNumBatches,
                                                       int minBatchSize)
                                                throws java.io.IOException
        Creates a BatchStatistic that batches the Welch averages according to the batching parameters. If the minNumBatches x minBatchSize = number of observations then the maxNBMultiple does not matter. Uses a batch multiple of 2.
        Parameters:
        deletePt - the number of observations to delete at beginning of series
        minNumBatches - the minimum number of batches to make
        minBatchSize - the minimum batch size
        Returns:
        a BatchStatistic
        Throws:
        java.io.IOException - if there was a problem accessing the file
      • batchWelchAverages

        public final BatchStatistic batchWelchAverages​(int deletePt,
                                                       int minNumBatches,
                                                       int minBatchSize,
                                                       int maxNBMultiple)
                                                throws java.io.IOException
        Creates a BatchStatistic that batches the Welch averages according to the batching parameters. If the minNumBatches x minBatchSize = number of observations then the maxNBMultiple does not matter.
        Parameters:
        deletePt - the number of observations to delete at beginning of series
        minNumBatches - the minimum number of batches to make
        minBatchSize - the minimum batch size
        maxNBMultiple - the batch means multiple
        Returns:
        the BatchStatistic
        Throws:
        java.io.IOException - if there was a problem accessing the file
      • getObservationCounts

        public final long[] getObservationCounts()
        The number of observations in each replication
        Returns:
        number of observations in each replication
      • getTimePerObservation

        public final double[] getTimePerObservation()
        Returns the average amount of time taken per observation in each of the replications
        Returns:
        the average amount of time taken per observation in each of the replications
      • getReplicationAverages

        public final double[] getReplicationAverages()
        Returns the average within each replication. That is, the average of the observations within each replication. zero is the first replication
        Returns:
        the average within each replication
      • getAverageTimePerObservation

        public final double getAverageTimePerObservation()
        The average time between observations in the simulation across all the replications. This can be used to determine a warmup period in terms of time.
        Returns:
        average time between observations
      • getMinNumObservationsInReplications

        public final long getMinNumObservationsInReplications()
        The number of observations across the replications
        Returns:
        number of observations across the replications
      • getAcrossReplicationAverage

        public final double getAcrossReplicationAverage​(long i)
                                                 throws java.io.IOException
        Computes and returns the across replication average for ith row of observations
        Parameters:
        i - row number
        Returns:
        the across replication average for ith row
        Throws:
        java.io.IOException - if there was trouble with the file
      • getAcrossReplicationData

        public final double[] getAcrossReplicationData​(long i,
                                                       double[] x)
                                                throws java.io.IOException
        Fills the supplied array with a row of observations across the replications
        Parameters:
        i - row number
        x - array to hold across replication observations
        Returns:
        the array of filled observations
        Throws:
        java.io.IOException - if there was trouble with the file
      • getNumberOfReplications

        public final int getNumberOfReplications()
        The number of replications
        Returns:
        The number of replications
      • get

        public final double get​(long i,
                                int j)
                         throws java.io.IOException
        Returns the ith observation in the jth replication
        Parameters:
        i - ith observation
        j - jth replication
        Returns:
        the ith observation in the jth replication
        Throws:
        java.io.IOException - if there was trouble with the file
      • get

        public final double get()
                         throws java.io.IOException
        Returns the value at the current position
        Returns:
        the value at the current position
        Throws:
        java.io.IOException - if there was trouble with the file
      • setPosition

        public final void setPosition​(long i,
                                      int j)
                               throws java.io.IOException
        Moves the file pointer to the position associated with the ith observation in the jth replication
        Parameters:
        i - ith observation
        j - jth replication
        Throws:
        java.io.IOException - if there was trouble with the file
      • getPosition

        public final long getPosition​(long i,
                                      int j)
        Gets the position in the file relative to the beginning of the file of the ith observation in the jth replication. This assumes that the data is a double 8 bytes stored in column major form
        Parameters:
        i - the index to the ith observation
        j - the index to the jth replication
        Returns:
        the position in the file relative to the beginning of the file of the ith observation in the jth replication
      • getLastObservationIndex

        public final long getLastObservationIndex()
        Returns the last observation index asked for. Can be used by observers Returns Integer.MIN_VALUE if no observations have been read
        Returns:
        the last observation index asked for.
      • getLastReplicationIndex

        public final long getLastReplicationIndex()
        Returns the last replication index asked for. Can be used by observers Returns Integer.MIN_VALUE if no observations have been read
        Returns:
        last replication index asked for
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • main

        public static void main​(java.lang.String[] args)