net.sourceforge.openforecast
Class Observation

java.lang.Object
  extended by net.sourceforge.openforecast.Observation
All Implemented Interfaces:
DataPoint

public class Observation
extends Object
implements DataPoint

Represents a single observation or data point, consisting of one value of a dependent variable, and one or more values of independent variables. Note that an Observation can refer to a previously observed data value, or a future forecast value (an expected Observation).

Since:
0.3
Author:
Steven R. Gould

Constructor Summary
Observation(DataPoint dataPoint)
          Like a copy constructor, but constructs a new Observation object by making a copy of the values from the given data point.
Observation(double dependentValue)
          Initializes the current Observation with the given value of the dependent variable.
 
Method Summary
 boolean equals(DataPoint dp)
          Compares the given DataPoint to the current DataPoint/Observation, and returns true if, and only if, the two data points represent the same data point.
 double getDependentValue()
          Returns the current value assigned to the dependent variable.
 double getIndependentValue(String name)
          Returns the current value assigned to the named independent variable.
 String[] getIndependentVariableNames()
          Returns an array of all independent variable names.
 void setDependentValue(double value)
          Sets the dependent variables' value to the given value.
 void setIndependentValue(String name, double value)
          Sets the named independent variables' value to the given value.
 String toString()
          Overrides the default toString method to provide a more meaningful output of an Observation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Observation

public Observation(double dependentValue)
Initializes the current Observation with the given value of the dependent variable. Note that this is provided as somewhat of a convenience - it will be necessary to call setIndependentValue for each independent variable name and value associated with this data point

Parameters:
dependentValue - the initial value of the dependent variable.

Observation

public Observation(DataPoint dataPoint)
Like a copy constructor, but constructs a new Observation object by making a copy of the values from the given data point.

Parameters:
dataPoint - the data point that is to be copied.
Method Detail

setDependentValue

public void setDependentValue(double value)
Sets the dependent variables' value to the given value.

Specified by:
setDependentValue in interface DataPoint
Parameters:
value - the new value for the dependent variable.

getDependentValue

public double getDependentValue()
Returns the current value assigned to the dependent variable. This value can be changed by calling setDependentValue.

Specified by:
getDependentValue in interface DataPoint
Returns:
the current value of the dependent variable.

setIndependentValue

public void setIndependentValue(String name,
                                double value)
Sets the named independent variables' value to the given value. Each Observation can have one or more name-value pairs that represent the independent variables and their associated values.

Specified by:
setIndependentValue in interface DataPoint
Parameters:
value - the new value for the dependent variable.

getIndependentValue

public double getIndependentValue(String name)
Returns the current value assigned to the named independent variable. This value can be changed by calling setIndependentValue.

Specified by:
getIndependentValue in interface DataPoint
Parameters:
name - the name of the independent variable required.
Returns:
the current value of the named independent variable.

getIndependentVariableNames

public String[] getIndependentVariableNames()
Returns an array of all independent variable names. No checks are made to ensure that the names are unique. Rather, the names are extracted directly from the names used in defining and initializing the Observation.

Specified by:
getIndependentVariableNames in interface DataPoint
Returns:
an array of independent variable names for this Observation.

equals

public boolean equals(DataPoint dp)
Compares the given DataPoint to the current DataPoint/Observation, and returns true if, and only if, the two data points represent the same data point. That is, the dependent value matches and all the independent values match.

Specified by:
equals in interface DataPoint
Parameters:
dp - the DataPoint to compare this DataPoint/Observation object to.
Returns:
true if the given DataPoint represents the same data point as this DataPoint/Observation object.

toString

public String toString()
Overrides the default toString method to provide a more meaningful output of an Observation. Each independent variable is listed with its value, then the dependent variable and its value are listed.

Overrides:
toString in class Object
Returns:
a string representation of this Observation.


OpenForecast, Copyright (c) Steven Gould, 2002-2011