Class DefaultEvidenceReader
- java.lang.Object
-
- com.bayesserver.data.DefaultEvidenceReader
-
- All Implemented Interfaces:
EvidenceReader
,Closeable
,AutoCloseable
public final class DefaultEvidenceReader extends Object implements EvidenceReader
Provides a default implementation ofEvidenceReader
, used in Bayes Server for tasks such as parameter learning.If temporal data (e.g. time series data) is present, it must be sorted by case identifier and then time.
If non temporal data is present, it must be sorted by case identifier, if present.
-
-
Constructor Summary
Constructors Constructor Description DefaultEvidenceReader(DataReader reader, List<VariableReference> variables, ReaderOptions readerOptions)
Initializes a new instance of theDefaultEvidenceReader
class.DefaultEvidenceReader(DataReader reader, List<VariableReference> variables, ReaderOptions readerOptions, DataReader readerTemporal, List<VariableReference> variablesTemporal, TemporalReaderOptions temporalReaderOptions)
Initializes a new instance of theDefaultEvidenceReader
class, supporting both temporal and non temporal data.DefaultEvidenceReader(DataReader readerTemporal, List<VariableReference> variablesTemporal, TemporalReaderOptions temporalReaderOptions)
Initializes a new instance of theDefaultEvidenceReader
class.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Closes any resources associated with the data such as database connections, files etc...protected void
finalize()
boolean
getAutoReadTemporal()
Determines whether any temporal data is read automatically.DataProgress
getDataProgress()
Gets the instance used to report progress on the number of cases read.int
getDataProgressInterval()
Gets a value which determines how often progress events are raised.ReadInfo
getReadInfo()
Provides information about the last read of non temporal data.TemporalReadInfo
getTemporalReadInfo()
Provides information about the last read of temporal data.long
getUnweightedCaseCount()
Gets the number of cases (unweighted) read so far.double
getWeightedCaseCount()
Gets the number of cases (weighted) read so far.boolean
read(Evidence evidence, ReadOptions readOptions)
Reads the next case (record).boolean
readTemporal(Evidence evidence, ReadOptions readOptions)
Reads the next temporal record, setting evidence.void
setAutoReadTemporal(boolean value)
Determines whether any temporal data is read automatically.void
setDataProgress(DataProgress value)
Gets the instance used to report progress on the number of cases read.void
setDataProgressInterval(int value)
Sets a value which determines how often progress events are raised.
-
-
-
Constructor Detail
-
DefaultEvidenceReader
public DefaultEvidenceReader(DataReader reader, List<VariableReference> variables, ReaderOptions readerOptions)
Initializes a new instance of theDefaultEvidenceReader
class. This override is used when there is no temporal data.- Parameters:
reader
- The data reader to read non temporal data.variables
- The non temporal variables to read.readerOptions
- Options for reading non temporal data.
-
DefaultEvidenceReader
public DefaultEvidenceReader(DataReader readerTemporal, List<VariableReference> variablesTemporal, TemporalReaderOptions temporalReaderOptions)
Initializes a new instance of theDefaultEvidenceReader
class. This override is used when there is temporal data, but no non temporal data.- Parameters:
readerTemporal
- The data reader to read temporal data.variablesTemporal
- The temporal variables.temporalReaderOptions
- Options for reading temporal data.
-
DefaultEvidenceReader
public DefaultEvidenceReader(DataReader reader, List<VariableReference> variables, ReaderOptions readerOptions, DataReader readerTemporal, List<VariableReference> variablesTemporal, TemporalReaderOptions temporalReaderOptions)
Initializes a new instance of theDefaultEvidenceReader
class, supporting both temporal and non temporal data.- Parameters:
reader
- The data reader to read non temporal data.variables
- The non temporal variables.readerOptions
- Options for reading non temporal data.readerTemporal
- The data reader to read temporal data.variablesTemporal
- The temporal variables.temporalReaderOptions
- Options for reading temporal data.
-
-
Method Detail
-
finalize
protected void finalize() throws Throwable
-
getDataProgress
public DataProgress getDataProgress()
Gets the instance used to report progress on the number of cases read. Can be null.
-
setDataProgress
public void setDataProgress(DataProgress value)
Gets the instance used to report progress on the number of cases read. Can be null.
-
getDataProgressInterval
public int getDataProgressInterval()
Gets a value which determines how often progress events are raised. Progress will be raised each time this number of (unweighted) cases or temporal rows are read.
-
setDataProgressInterval
public void setDataProgressInterval(int value)
Sets a value which determines how often progress events are raised. Progress will be raised each time this number of (unweighted) cases or temporal rows are read.
-
getAutoReadTemporal
public boolean getAutoReadTemporal()
Determines whether any temporal data is read automatically.When no temporal data is present, this option has no effect.
When
true
(the default),readTemporal(com.bayesserver.inference.Evidence, com.bayesserver.data.ReadOptions)
is called automatically (in a loop), each timeread(com.bayesserver.inference.Evidence, com.bayesserver.data.ReadOptions)
is called.When
false
,readTemporal(com.bayesserver.inference.Evidence, com.bayesserver.data.ReadOptions)
must be manually called (in a loop) to read any temporal data, after each call toread(com.bayesserver.inference.Evidence, com.bayesserver.data.ReadOptions)
. This allows temporal information to be extracted viaTemporalReadInfo
, during the read process.
-
setAutoReadTemporal
public void setAutoReadTemporal(boolean value)
Determines whether any temporal data is read automatically.When no temporal data is present, this option has no effect.
When
true
(the default),readTemporal(com.bayesserver.inference.Evidence, com.bayesserver.data.ReadOptions)
is called automatically (in a loop), each timeread(com.bayesserver.inference.Evidence, com.bayesserver.data.ReadOptions)
is called.When
false
,readTemporal(com.bayesserver.inference.Evidence, com.bayesserver.data.ReadOptions)
must be manually called (in a loop) to read any temporal data, after each call toread(com.bayesserver.inference.Evidence, com.bayesserver.data.ReadOptions)
. This allows temporal information to be extracted viaTemporalReadInfo
, during the read process.
-
getReadInfo
public ReadInfo getReadInfo()
Provides information about the last read of non temporal data.
-
getTemporalReadInfo
public TemporalReadInfo getTemporalReadInfo()
Provides information about the last read of temporal data. Only valid whengetAutoReadTemporal()
isfalse
.
-
close
public void close()
Closes any resources associated with the data such as database connections, files etc...- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceEvidenceReader
-
read
public boolean read(Evidence evidence, ReadOptions readOptions)
Reads the next case (record). Read must be called to move to the first record.- Specified by:
read
in interfaceEvidenceReader
- Parameters:
evidence
- The destination evidence.readOptions
- Read options.- Returns:
true
if a case was sucessfully read,false
if no more cases (records) were present.
-
getUnweightedCaseCount
public long getUnweightedCaseCount()
Gets the number of cases (unweighted) read so far. This counter is reset to zero whencom.bayesserver.data.DefaultEvidenceReader#reset
is called.
-
getWeightedCaseCount
public double getWeightedCaseCount()
Gets the number of cases (weighted) read so far. This counter is reset to zero whencom.bayesserver.data.DefaultEvidenceReader#reset
is called.
-
readTemporal
public boolean readTemporal(Evidence evidence, ReadOptions readOptions)
Reads the next temporal record, setting evidence.This method can only be called if
getAutoReadTemporal()
isfalse
.This method must be called in order to move to the first temporal record that corresponds to the current
read(com.bayesserver.inference.Evidence, com.bayesserver.data.ReadOptions)
.Note that even if there is only temporal data,
read(com.bayesserver.inference.Evidence, com.bayesserver.data.ReadOptions)
must still be called.This method should be called repeatedly until it returns
false
, within each call toread(com.bayesserver.inference.Evidence, com.bayesserver.data.ReadOptions)
, which should also be called repeatedly.- Parameters:
evidence
- The evidence to update.readOptions
- Read options.- Returns:
true
if the read was successful,false
if there is no more temporal data for this case.- See Also:
read(com.bayesserver.inference.Evidence, com.bayesserver.data.ReadOptions)
,TemporalReadInfo
-
-