net.simplace.sim.transformers.LinearRegressionTransformer
Calculates linear Regression (slope and intercept) from two double arrays
The transformer takes the field/column names from a resource that
act as x and y values.
It outputs
- the keys of the original resource in same order and same datatypes
- the slope m (DOUBLE)
- intercept b (DOUBLE)
- the mean of x values (DOUBLE)
- the mean of y values (DOUBLE)
- r square (DOUBLE)
\[
\begin{eqnarray}
\bar{x} &=& \frac{1}{n}\sum_{i=1}^n x_i \\
\bar{y} &=& \frac{1}{n}\sum_{i=1}^n y_i \\
u &=& \frac{1}{n}\sum_{i=1}^n x_i y_i - \bar{x} \bar{y} \\
v &=& \frac{1}{n}\sum_{i=1}^n x_i x_i - \bar{x} \bar{x} \\
m &=& \frac{u}{v} \\
b &=& \bar{y} -m \bar{x}
\end{eqnarray}
\]
public class LinearRegressionTransformer extends
net.simplace.sim.io.resources.FWSimResourceTransformer {
// Public Constructors
public LinearRegressionTransformer(FWSimSession aSession, Element
aResourceElement, Integer aOrderNumber);
public LinearRegressionTransformer(FWSimSession aSession, Integer
aOrderNumber);
// Public Instance Methods public HashMap createVariables(); // Defines
net.simplace.sim.io.FWSimIOAdapter
public FWSimResourceCache getData(FWSimVarMap aVarMap)
throws MissingSimResourceException; // Defines
net.simplace.sim.io.resources.FWSimInputAdapter
standard method from outside
public FWSimResourceCache
getData(FWSimVarMap aVarMap, FWSimResourceCache
aResourceCache) throws MissingSimResourceException;
used by test cases
- aVarMap
variable map
- aResourceCache
Cached resources (soil data)
returns delivered new data from transformer
public FWSimResourceCache
calculateLinearRegression(FWSimVariable aXName,
FWSimVariable aYName, String aProjectID, FWSimResourceCache aCache)
throws MissingSimResourceException;
Calculates the linear regression from two vectors X and Y by the least square approach.
- aXName
- aYName
- aProjectID id of the project
- aCache original data
returns the new created {@link FWSimResourceCache}
public void updateFields(FWObservable aObservable);
// Defines net.simplace.sim.io.resources.FWSimResourceTransformer
// Protected Instance Methods protected Object[] MergeKeysAndValues(int aKeyFieldCount, Object aKeys,
HashMap aValues);
}
Hierarchy: java.lang.Object - net.simplace.sim.io.FWSimIOAdapter (net.simplace.sim.util.FWSimFieldContainer) - net.simplace.sim.io.resources.FWSimInputAdapter - net.simplace.sim.io.resources.FWSimResourceTransformer - LinearRegressionTransformer