Package jsl.utilities.statistic.welch
Class WelchDataFileAnalyzer
- java.lang.Object
-
- jsl.utilities.statistic.welch.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 Summary
Fields Modifier and Type Field Description static int
MIN_BATCH_SIZE
protected Statistic
myAcrossRepStat
protected java.lang.String
myBaseName
protected long
myMinObsCount
protected ObservableComponent
myObsComponent
protected long[]
myObsCounts
protected java.nio.file.Path
myPathToWDF
protected double[]
myRepAvgs
protected double[]
myRowData
protected double[]
myTimePerObs
protected double[]
myTimeRepsEnd
protected java.io.RandomAccessFile
myWDFDataFile
protected WelchFileMetaDataBean
myWFMDBean
static int
NUMBYTES
-
Constructor Summary
Constructors Constructor Description WelchDataFileAnalyzer(WelchFileMetaDataBean bean)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addObserver(ObserverIfc observer)
Allows the adding (attaching) of an observer to the observableBatchStatistic
batchWelchAverages()
Creates a BatchStatistic that batches the Welch averages according to the batching parameters.BatchStatistic
batchWelchAverages(int deletePt)
Creates a BatchStatistic that batches the Welch averages according to the batching parameters.BatchStatistic
batchWelchAverages(int deletePt, int minBatchSize)
Creates a BatchStatistic that batches the Welch averages according to the batching parameters.BatchStatistic
batchWelchAverages(int deletePt, int minNumBatches, int minBatchSize)
Creates a BatchStatistic that batches the Welch averages according to the batching parameters.BatchStatistic
batchWelchAverages(int deletePt, int minNumBatches, int minBatchSize, int maxNBMultiple)
Creates a BatchStatistic that batches the Welch averages according to the batching parameters.boolean
contains(ObserverIfc observer)
Returns true if the observer is already attachedint
countObservers()
Returns how many observers are currently observing the observablevoid
deleteObserver(ObserverIfc observer)
Allows the deletion (removing) of an observer from the observablevoid
deleteObservers()
Deletes all the observers from the observabledouble
get()
Returns the value at the current positiondouble
get(long i, int j)
Returns the ith observation in the jth replicationdouble
getAcrossReplicationAverage(long i)
Computes and returns the across replication average for ith row of observationsdouble[]
getAcrossReplicationData(long i, double[] x)
Fills the supplied array with a row of observations across the replicationsdouble
getAverageTimePerObservation()
The average time between observations in the simulation across all the replications.java.nio.file.Path
getBaseDirectory()
java.nio.file.Path
getBaseFileName()
double[]
getCumulativeWelchAverages(int numObs)
Returns an array of the cumulative Welch averages.double
getLastDataPoint()
Returns the last data point read or Double.NaN if none read.long
getLastObservationIndex()
Returns the last observation index asked for.long
getLastReplicationIndex()
Returns the last replication index asked for.long
getMinNumObservationsInReplications()
The number of observations across the replicationsint
getNumberOfReplications()
The number of replicationslong[]
getObservationCounts()
The number of observations in each replicationlong
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.double[]
getReplicationAverages()
Returns the average within each replication.java.lang.String
getResponseName()
double[]
getTimePerObservation()
Returns the average amount of time taken per observation in each of the replicationsdouble[]
getWelchAverages(int numObs)
Returns an array of the Welch averages.double[]
getWelchAveragesNE(int numObs)
Returns an array of the Welch averages.WelchFileMetaDataBean
getWelchFileMetaDataBean()
static void
main(java.lang.String[] args)
java.io.File
makeCSVWelchDataFile()
This results in a comma separated value file that has each row containing each observation for each replication and each replication as columns.java.io.File
makeCSVWelchDataFile(long numObs)
This results in a comma separated value file that has each rows containing each observation for each replication and each replication as columns.java.io.File
makeCSVWelchPlotDataFile()
Makes and writes out the welch plot data.java.io.File
makeCSVWelchPlotDataFile(long numObs)
Makes and writes out the welch plot data.static java.util.Optional<WelchDataFileAnalyzer>
makeFromJSON(java.nio.file.Path pathToWelchFileMetaDataBeanJson)
java.io.File
makeWelchPlotDataFile()
Makes a file and writes out the welch data to the DataOutputStream.java.io.File
makeWelchPlotDataFile(long numObs)
Makes a file and writes out the welch data to the DataOutputStream.void
setPosition(long i, int j)
Moves the file pointer to the position associated with the ith observation in the jth replicationjava.lang.String
toString()
void
writeCSVWelchData(java.io.PrintWriter out)
Writes out the number of observations to the supplied PrintWriter.void
writeCSVWelchData(java.io.PrintWriter out, long numObs)
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.void
writeCSVWelchPlotData(java.io.PrintWriter out)
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, CumAvgvoid
writeCSVWelchPlotData(java.io.PrintWriter out, long numObs)
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.void
writeWelchPlotData(java.io.DataOutputStream out, long numObs)
This produces a file with the "wpdf" extension.
-
-
-
Field Detail
-
NUMBYTES
public static final int NUMBYTES
- See Also:
- Constant Field Values
-
MIN_BATCH_SIZE
public static final int MIN_BATCH_SIZE
- See Also:
- Constant Field Values
-
myWFMDBean
protected final WelchFileMetaDataBean myWFMDBean
-
myBaseName
protected java.lang.String myBaseName
-
myObsComponent
protected final ObservableComponent myObsComponent
-
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
-
-
Constructor Detail
-
WelchDataFileAnalyzer
public WelchDataFileAnalyzer(WelchFileMetaDataBean bean)
-
-
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 interfaceObservableIfc
- 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 interfaceObservableIfc
- 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 interfaceObservableIfc
-
contains
public final boolean contains(ObserverIfc observer)
Description copied from interface:ObservableIfc
Returns true if the observer is already attached- Specified by:
contains
in interfaceObservableIfc
- 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 interfaceObservableIfc
- 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 tonumObs
- 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 PrintWriternumObs
- 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 PrintWriternumObs
- 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 seriesminBatchSize
- 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 seriesminNumBatches
- the minimum number of batches to makeminBatchSize
- 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 seriesminNumBatches
- the minimum number of batches to makeminBatchSize
- the minimum batch sizemaxNBMultiple
- 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 numberx
- 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 observationj
- 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 observationj
- 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 observationj
- 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 classjava.lang.Object
-
main
public static void main(java.lang.String[] args)
-
-