Package net.simplace.sim.transformers
Class LinearRegressionTransformer
java.lang.Object
net.simplace.sim.io.FWSimIOAdapter
net.simplace.sim.io.resources.FWSimInputAdapter
net.simplace.sim.io.resources.FWSimResourceTransformer
net.simplace.sim.transformers.LinearRegressionTransformer
- All Implemented Interfaces:
net.simplace.sim.util.FWSimFieldContainer
public class LinearRegressionTransformer
extends net.simplace.sim.io.resources.FWSimResourceTransformer
Calculates linear Regression (slope and intercept) from two double arrays
WIKI_START
== Inputs and outputs ==
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)
WIKI_END
\[
\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}
\]
WIKI_START
WIKI_END
- Author:
- Andreas Enders
-
Nested Class Summary
Nested classes/interfaces inherited from class net.simplace.sim.io.FWSimIOAdapter
net.simplace.sim.io.FWSimIOAdapter.FREQUENCE
-
Field Summary
Fields inherited from class net.simplace.sim.io.resources.FWSimResourceTransformer
iFieldMap, iIntColumnMap, iLastInputValuesMap, iLastProjectID, iLastUniqueID, iPoolName, iSourceName
Fields inherited from class net.simplace.sim.io.resources.FWSimInputAdapter
iJexlScript, iShouldCacheToDB
Fields inherited from class net.simplace.sim.io.FWSimIOAdapter
iArrayMode, iFieldcount, iFrequence, iHeaderVariables, iInterface, iJexlRule, iKeyMap, iName, iOrderNumber, iProcessTime, iResourceElement, iSession, iSourceKey
-
Constructor Summary
ConstructorDescriptionLinearRegressionTransformer
(net.simplace.sim.FWSimSession aSession, Integer aOrderNumber) LinearRegressionTransformer
(net.simplace.sim.FWSimSession aSession, org.jdom2.Element aResourceElement, Integer aOrderNumber) -
Method Summary
Modifier and TypeMethodDescriptionnet.simplace.sim.io.resources.FWSimResourceCache
calculateLinearRegression
(net.simplace.sim.util.FWSimVariable<String> aXName, net.simplace.sim.util.FWSimVariable<String> aYName, String aProjectID, net.simplace.sim.io.resources.FWSimResourceCache aCache) Calculates the linear regression from two vectors X and Y by the least square approach.net.simplace.sim.io.resources.FWSimResourceCache
getData
(net.simplace.sim.util.FWSimVarMap aVarMap) standard method from outsidenet.simplace.sim.io.resources.FWSimResourceCache
getData
(net.simplace.sim.util.FWSimVarMap aVarMap, net.simplace.sim.io.resources.FWSimResourceCache aResourceCache) used by test casesprotected Object[]
MergeKeysAndValues
(int aKeyFieldCount, Object aKeys, DataTransformHelper.RegressionValues aValues) void
updateFields
(net.simplace.core.FWObservable aObservable) Methods inherited from class net.simplace.sim.io.resources.FWSimResourceTransformer
addVariable, createFormFields, createResourceTransformer, createResourceTransformer, createResourceTransformer, fillVarMap, getCreateFormXML, getEditFormXML, getSourceResourceCache, getVariable, isUpdated, toXML
Methods inherited from class net.simplace.sim.io.resources.FWSimInputAdapter
getContentType, getInputVariables, getJexlScript, getOutputVariables, getVarMap, isTransformer, shouldCacheToDB, toHTMLTablestring
Methods inherited from class net.simplace.sim.io.FWSimIOAdapter
addProcessTime, checkCondition, createFormFields, finalize, getFieldMap, getFrequence, getHeaderVariables, getHeaderXML, getInterface, getJexlRule, getKeyMap, getName, getOrderNumber, isArrayMode, isConditionCheck, removeVariable, setInterface, setOrderNumber, toString, writeHeaderList
-
Constructor Details
-
LinearRegressionTransformer
public LinearRegressionTransformer(net.simplace.sim.FWSimSession aSession, org.jdom2.Element aResourceElement, Integer aOrderNumber) - Parameters:
aSession
-aResourceElement
-aOrderNumber
-
-
LinearRegressionTransformer
- Parameters:
aSession
-aOrderNumber
-
-
-
Method Details
-
createVariables
- Specified by:
createVariables
in interfacenet.simplace.sim.util.FWSimFieldContainer
- Overrides:
createVariables
in classnet.simplace.sim.io.FWSimIOAdapter
-
getData
public net.simplace.sim.io.resources.FWSimResourceCache getData(net.simplace.sim.util.FWSimVarMap aVarMap) throws net.simplace.sim.exceptions.MissingSimResourceException standard method from outside- Specified by:
getData
in classnet.simplace.sim.io.resources.FWSimInputAdapter
- Throws:
net.simplace.sim.exceptions.MissingSimResourceException
- See Also:
-
FWSimInputAdapter.getData(net.simplace.sim.util.FWSimVarMap)
-
getData
public net.simplace.sim.io.resources.FWSimResourceCache getData(net.simplace.sim.util.FWSimVarMap aVarMap, net.simplace.sim.io.resources.FWSimResourceCache aResourceCache) throws net.simplace.sim.exceptions.MissingSimResourceException used by test cases- Parameters:
aVarMap
- variable mapaResourceCache
- Cached resources (soil data)- Returns:
- delivered new data from transformer
- Throws:
net.simplace.sim.exceptions.MissingSimResourceException
-
MergeKeysAndValues
protected Object[] MergeKeysAndValues(int aKeyFieldCount, Object aKeys, DataTransformHelper.RegressionValues aValues) -
calculateLinearRegression
public net.simplace.sim.io.resources.FWSimResourceCache calculateLinearRegression(net.simplace.sim.util.FWSimVariable<String> aXName, net.simplace.sim.util.FWSimVariable<String> aYName, String aProjectID, net.simplace.sim.io.resources.FWSimResourceCache aCache) throws net.simplace.sim.exceptions.MissingSimResourceException Calculates the linear regression from two vectors X and Y by the least square approach.- Parameters:
aXName
-aYName
-aProjectID
- id of the projectaCache
- original data- Returns:
- the new created
FWSimResourceCache
- Throws:
net.simplace.sim.exceptions.MissingSimResourceException
-
updateFields
public void updateFields(net.simplace.core.FWObservable aObservable) - Specified by:
updateFields
in classnet.simplace.sim.io.resources.FWSimResourceTransformer
- See Also:
-
FWSimResourceTransformer.updateFields(net.simplace.core.FWObservable)
-