Class EventBasedTimestampWeightedTally
- java.lang.Object
-
- org.djutils.event.EventProducer
-
- org.djutils.stats.summarizers.event.EventBasedTimestampWeightedTally
-
- All Implemented Interfaces:
Serializable
,EventListener
,EventListenerInterface
,EventProducerInterface
,BasicTallyInterface
,TimestampTallyInterface
,WeightedTallyInterface
public class EventBasedTimestampWeightedTally extends EventProducer implements EventListenerInterface, TimestampTallyInterface
The TimestampWeightedTally class defines a time-weighted tally based on timestamped data. The difference with a normal time-weighed tally is that the weight of a value is only known at the occurrence of the next timestamp. Furthermore, a last timestamp needs to be specified to determine the weight of the last value. This EventBased version of the tally can be notified with timestamps and values using the EventListenerInterface. It also produces events when values are tallied and when the tally is initialized. Timestamps can be Number based or Calendar based.Copyright (c) 2020-2021 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See for project information https://simulation.tudelft.nl. The DSOL project is distributed under a three-clause BSD-style license, which can be found at https://simulation.tudelft.nl/dsol/3.0/license.html.
- Author:
- Alexander Verbraeck
- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class org.djutils.event.EventProducer
eventProducerImpl
-
Fields inherited from interface org.djutils.event.EventProducerInterface
FIRST_POSITION, LAST_POSITION
-
-
Constructor Summary
Constructors Constructor Description EventBasedTimestampWeightedTally(String description)
constructs a new EventBasefdTimestampWeightedTally with a description.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
endObservations(Number timestamp)
End the observations and closes the last interval of observations.void
endObservations(Calendar timestamp)
End the observations and closes the last interval of observations.protected <T extends Serializable & Comparable<T>>
voidfireEvents(T timestamp)
Method that can be overridden to fire own events or additional events when ingesting an observation.String
getDescription()
returns the description of this tally.double
getMax()
Returns the max.double
getMin()
Returns the min.long
getN()
Returns the number of observations.Serializable
getSourceId()
double
getWeightedPopulationStDev()
Retrieve the current weighted standard deviation of the observations.double
getWeightedPopulationVariance()
Retrieve the current weighted variance of the observations.double
getWeightedSampleMean()
Retrieve the current weighted sample mean of all observations since the initialization.double
getWeightedSampleStDev()
Retrieve the current weighted sample standard deviation of the observations.double
getWeightedSampleVariance()
Retrieve the current weighted sample variance of the observations.double
getWeightedSum()
Retrieve the current weighted sum of the values of the observations.double
ingest(Calendar timestamp, double value)
Process one observed value.<T extends Number & Comparable<T>>
doubleingest(T timestamp, double value)
Process one observed value.void
initialize()
initializes the Tally.boolean
isActive()
Return whether the statistic is active (accepting observations) or not.void
notify(EventInterface event)
String
toString()
-
Methods inherited from class org.djutils.event.EventProducer
addListener, addListener, addListener, addListener, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, getEventTypesWithListeners, getListenerReferences, hasListeners, numberOfListeners, removeAllListeners, removeAllListeners, removeListener
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.djutils.stats.summarizers.WeightedTallyInterface
getWeightedPopulationMean
-
-
-
-
Constructor Detail
-
EventBasedTimestampWeightedTally
public EventBasedTimestampWeightedTally(String description)
constructs a new EventBasefdTimestampWeightedTally with a description.- Parameters:
description
- String; the description of this EventBasedTimestampWeightedTally
-
-
Method Detail
-
getSourceId
public Serializable getSourceId()
- Specified by:
getSourceId
in interfaceEventProducerInterface
- Specified by:
getSourceId
in classEventProducer
-
initialize
public void initialize()
initializes the Tally. This methods sets the max, min, n, sum and variance values to their initial values.- Specified by:
initialize
in interfaceBasicTallyInterface
-
isActive
public final boolean isActive()
Return whether the statistic is active (accepting observations) or not.- Specified by:
isActive
in interfaceTimestampTallyInterface
- Returns:
- boolean; whether the statistic is active (accepting observations) or not
-
endObservations
public void endObservations(Number timestamp)
End the observations and closes the last interval of observations. After ending, no more observations will be accepted. Calling this method will create an extra observation, and corresponding events for the EventBased implementations of this interface will be called.- Specified by:
endObservations
in interfaceTimestampTallyInterface
- Parameters:
timestamp
- Number; the Number object representing the final timestamp
-
endObservations
public void endObservations(Calendar timestamp)
End the observations and closes the last interval of observations. After ending, no more observations will be accepted. Calling this method will create an extra observation, and corresponding events for the EventBased implementations of this interface will be called.- Specified by:
endObservations
in interfaceTimestampTallyInterface
- Parameters:
timestamp
- Calendar; the Calendar object representing the final timestamp
-
notify
public void notify(EventInterface event)
- Specified by:
notify
in interfaceEventListenerInterface
-
ingest
public double ingest(Calendar timestamp, double value)
Process one observed value.- Parameters:
timestamp
- Calendar; the Calendar object representing the timestampvalue
- double; the value to process- Returns:
- double; the value
-
ingest
public <T extends Number & Comparable<T>> double ingest(T timestamp, double value)
Process one observed value.- Type Parameters:
T
- a type for the timestamp that extends Number and is Comparable, e.g., a Double, a Long, or a djunits Time- Parameters:
timestamp
- T; the object representing the timestampvalue
- double; the value to process- Returns:
- double; the value
-
fireEvents
protected <T extends Serializable & Comparable<T>> void fireEvents(T timestamp)
Method that can be overridden to fire own events or additional events when ingesting an observation.- Type Parameters:
T
- a type for the timestamp that is Serializable and Comparable- Parameters:
timestamp
- T; the timestamp to use in the TimedEvents
-
getDescription
public final String getDescription()
returns the description of this tally.- Specified by:
getDescription
in interfaceBasicTallyInterface
- Returns:
- Sting description
-
getN
public final long getN()
Returns the number of observations.- Specified by:
getN
in interfaceBasicTallyInterface
- Returns:
- long n
-
getMax
public final double getMax()
Returns the max.- Specified by:
getMax
in interfaceBasicTallyInterface
- Returns:
- double
-
getMin
public final double getMin()
Returns the min.- Specified by:
getMin
in interfaceBasicTallyInterface
- Returns:
- double
-
getWeightedSampleMean
public final double getWeightedSampleMean()
Retrieve the current weighted sample mean of all observations since the initialization.- Specified by:
getWeightedSampleMean
in interfaceWeightedTallyInterface
- Returns:
- double; the current weighted sample mean
-
getWeightedSampleStDev
public final double getWeightedSampleStDev()
Retrieve the current weighted sample standard deviation of the observations.- Specified by:
getWeightedSampleStDev
in interfaceWeightedTallyInterface
- Returns:
- double; the current weighted sample standard deviation
-
getWeightedPopulationStDev
public final double getWeightedPopulationStDev()
Retrieve the current weighted standard deviation of the observations.- Specified by:
getWeightedPopulationStDev
in interfaceWeightedTallyInterface
- Returns:
- double; the current weighted standard deviation
-
getWeightedSampleVariance
public final double getWeightedSampleVariance()
Retrieve the current weighted sample variance of the observations.- Specified by:
getWeightedSampleVariance
in interfaceWeightedTallyInterface
- Returns:
- double; the current weighted sample variance of the observations
-
getWeightedPopulationVariance
public final double getWeightedPopulationVariance()
Retrieve the current weighted variance of the observations.- Specified by:
getWeightedPopulationVariance
in interfaceWeightedTallyInterface
- Returns:
- double; the current weighted variance of the observations
-
getWeightedSum
public final double getWeightedSum()
Retrieve the current weighted sum of the values of the observations.- Specified by:
getWeightedSum
in interfaceWeightedTallyInterface
- Returns:
- double; the current weighted sum of the values of the observations
-
-