Package microsim.statistics.regression
Class LinearRegression
- java.lang.Object
-
- microsim.statistics.regression.LinearRegression
-
- All Implemented Interfaces:
ILinearRegression
- Direct Known Subclasses:
LogitRegression
,ProbitRegression
public class LinearRegression extends java.lang.Object implements ILinearRegression
-
-
Constructor Summary
Constructors Constructor Description LinearRegression(MultiKeyCoefficientMap map)
Linear Regression object.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static double
computeScore(MultiKeyCoefficientMap coeffMultiMap, java.lang.Object agent)
To be used when the agent Object has member fields that correspond by name to all the regressors of the Regression's MultiKeyCoefficientMap map.static double
computeScore(MultiKeyCoefficientMap amap, java.util.Map<java.lang.String,java.lang.Double> values)
Warning - only use when LinearRegression object contains a MultiKeyCoefficientMap with only one key.static <T extends java.lang.Enum<T>>
doublecomputeScore(MultiKeyCoefficientMap coeffMultiMap, IDoubleSource iDblSrc, java.lang.Class<T> enumType)
Uses reflection to obtain information from the iDblSrc object, so it is possibly slow.static <T extends java.lang.Enum<T>>
doublecomputeScore(MultiKeyCoefficientMap coeffMultiMap, IDoubleSource iDblSrc, java.lang.Class<T> enumType, boolean singleKeyCoefficients)
Use this method when the underlying agent does not have any additional conditioning regression keys (such as the gender or civil status) to determine the appropriate regression co-efficients, i.e.static <T extends java.lang.Enum<T>,U extends java.lang.Enum<U>>
doublecomputeScore(MultiKeyCoefficientMap coeffMultiMap, IDoubleSource iDblSrc, java.lang.Class<T> enumTypeDouble, IObjectSource iObjSrc, java.lang.Class<U> enumTypeObject)
Requires the implementation of the IObjectSource to ascertain whether any additional conditioning regression keys are used (e.g.double
getScore(java.lang.Object agent)
To be used when the agent Object has member fields that correspond by name to all the regressors of the Regression's MultiKeyCoefficientMap map.double
getScore(java.util.Map<java.lang.String,java.lang.Double> values)
Warning - only use when LinearRegression object contains a MultiKeyCoefficientMap with only one key.<T extends java.lang.Enum<T>>
doublegetScore(IDoubleSource iDblSrc, java.lang.Class<T> enumType)
<T extends java.lang.Enum<T>,U extends java.lang.Enum<U>>
doublegetScore(IDoubleSource iDblSrc, java.lang.Class<T> enumTypeDouble, IObjectSource iObjSrc, java.lang.Class<U> enumTypeObject)
Requires the implementation of the IObjectSource to ascertain whether any additional conditioning regression keys are used (e.g.static double
multiplyCoeffsWithValues(java.util.Map<java.lang.String,java.lang.Double> regCoeffMap, java.util.Map<java.lang.String,java.lang.Double> valueMap)
-
-
-
Constructor Detail
-
LinearRegression
public LinearRegression(MultiKeyCoefficientMap map)
Linear Regression object.- Parameters:
map
- - needs to fulfil two criteria: 1) Map must have a key in the MultiKey that matches the name specified in the RegressionColumnNames enum called Regressor. 2) Map must have a value key that matches the name specified in the RegressionColumnNames enum called Coefficient. If loading from an .xls spreadsheet using the ExcelAssistant.loadCoefficientMap(), the Regressor column must be situated to the left of the Coefficient column.
-
-
Method Detail
-
getScore
public double getScore(java.util.Map<java.lang.String,java.lang.Double> values)
Warning - only use when LinearRegression object contains a MultiKeyCoefficientMap with only one key. This method only looks at the first key of the MultiKeyCoefficientMap field of LinearRegression, so any other keys that are used to distinguish a unique multiKey (i.e. if the first key occurs more than once) will be ignored! If the first key of the multiKey appears more than once, the method would return an incorrect value, so will throw an exception.- Specified by:
getScore
in interfaceILinearRegression
- Parameters:
values
-- Returns:
-
computeScore
public static double computeScore(MultiKeyCoefficientMap amap, java.util.Map<java.lang.String,java.lang.Double> values)
Warning - only use when LinearRegression object contains a MultiKeyCoefficientMap with only one key. This method only looks at the first key of the MultiKeyCoefficientMap field of LinearRegression, so any other keys that are used to distinguish a unique multiKey (i.e. if the first key occurs more than once) will be ignored! If the first key of the multiKey appears more than once, the method would return an incorrect value, so will throw an exception.- Parameters:
values
-- Returns:
-
getScore
public <T extends java.lang.Enum<T>> double getScore(IDoubleSource iDblSrc, java.lang.Class<T> enumType)
- Specified by:
getScore
in interfaceILinearRegression
-
computeScore
public static <T extends java.lang.Enum<T>> double computeScore(MultiKeyCoefficientMap coeffMultiMap, IDoubleSource iDblSrc, java.lang.Class<T> enumType, boolean singleKeyCoefficients)
Use this method when the underlying agent does not have any additional conditioning regression keys (such as the gender or civil status) to determine the appropriate regression co-efficients, i.e. the regression co-efficients do not depend on any properties of the underlying model. Requires that the MultiKeyCoefficientMap only has one entry in the multiKey - that of the name of the regressor variables.- Parameters:
coeffMultiMap
- is a MultiKeyCoefficientMap that has a MultiKey whose first Key is the name of the regressor variable.iDblSrc
- is an object that implements the IDoubleSource interface, and hence has a method getDoubleValue(enum), where the enum determines the appropriate double value to return. It must have some fields that match the (case sensitive) name of the keys of coeffMultiMap's MultiKeyenumType
- specifies the enum type that is used in the getDoubleValue(Enum.valueOf(enumType, String)) method of the iDblSrc object. The String is the name of the enum case, used as a switch to determine the appropriate double value to return
-
computeScore
public static <T extends java.lang.Enum<T>> double computeScore(MultiKeyCoefficientMap coeffMultiMap, IDoubleSource iDblSrc, java.lang.Class<T> enumType)
Uses reflection to obtain information from the iDblSrc object, so it is possibly slow. For time critical cases, use the other computeScore method that requires passing in an object that implements the IObjectSource interface; this has signature:- public static, U extends Enum<>> double computeScore(MultiKeyCoefficientMap coeffMultiMap, IDoubleSource iDblSrc, Class enumTypeDouble, IObjectSource iObjSrc, Class<> enumTypeObject) Requires the first column entry of the MultiKeyCoefficientMap (i.e. the first entry of coeffMultiMap's multiKey) to be the name of the regressor variables. The names of the other keys of the coeffMultiMap must match the (case sensitive) name of the corresponding fields of the iDblSrc class. - Parameters:
coeffMultiMap
- is a MultiKeyCoefficientMap that has a MultiKey whose first Key is the name of the regressor variable. The names of the other keys of the coeffMultiMap must match the (case sensitive) name of the corresponding fields of the iDblSrc class.iDblSrc
- is an object that implements the IDoubleSource interface, and hence has a method getDoubleValue(enum), where the enum determines the appropriate double value to return. It must have some fields that match the (case sensitive) name of the keys of coeffMultiMap's MultiKeyenumType
- specifies the enum type that is used in the getDoubleValue(Enum.valueOf(enumType, String)) method of the iDblSrc object. The String is the name of the enum case, used as a switch to determine the appropriate double value to return
-
getScore
public double getScore(java.lang.Object agent)
To be used when the agent Object has member fields that correspond by name to all the regressors of the Regression's MultiKeyCoefficientMap map. The agent must also have fields that specify any additional conditioning keys e.g. gender or civil status, of the regression map's MultiKeys.- Specified by:
getScore
in interfaceILinearRegression
- Parameters:
agent
- is the object whose fields must match by name, the regressors and additional conditioning keys of the Regression map's MultiKeys.
-
computeScore
public static double computeScore(MultiKeyCoefficientMap coeffMultiMap, java.lang.Object agent)
To be used when the agent Object has member fields that correspond by name to all the regressors of the Regression's MultiKeyCoefficientMap map. The agent must also have fields that specify any additional conditioning keys e.g. gender or civil status, of the regression map's MultiKeys.- Parameters:
agent
- is the object whose fields must match by name, the regressors and additional conditioning keys of the Regression map's MultiKeys.
-
multiplyCoeffsWithValues
public static double multiplyCoeffsWithValues(java.util.Map<java.lang.String,java.lang.Double> regCoeffMap, java.util.Map<java.lang.String,java.lang.Double> valueMap)
-
getScore
public <T extends java.lang.Enum<T>,U extends java.lang.Enum<U>> double getScore(IDoubleSource iDblSrc, java.lang.Class<T> enumTypeDouble, IObjectSource iObjSrc, java.lang.Class<U> enumTypeObject)
Requires the implementation of the IObjectSource to ascertain whether any additional conditioning regression keys are used (e.g. whether the underlying agent is female, married etc., where the regression co-efficients are conditioned on additional keys of gender and civil status, for example). If the underlying agent does not implement IObjectSource but does have additional conditioning regression keys, use the computeScore method (that uses reflection, so is slower) with signature:- public static> double getScore(IDoubleSource iDblSrc, Class enumType) If the underlying agent does not have additional conditioning regression keys, use the computeScore method with signature:- - Specified by:
getScore
in interfaceILinearRegression
- Parameters:
iDblSrc
- is an object that implements the IDoubleSource interface (e.g. the underlying agent whose properties are the covariates), and hence has a method getDoubleValue(enum), where the enum determines the appropriate double value to return. It must have some fields that match the (case sensitive) name of the first key entry of the coeffMultiMap's MultiKeyenumTypeDouble
- specifies the enum type that is used in the getDoubleValue(Enum.valueOf(enumType, String)) method of the iDblSrc object. The String is the name of the enum case, used as a switch to determine the appropriate double value to returniObjSrc
- is an object that implements the IObjectSource interface (e.g. the underlying agent whose properties are the covariates), and hence has a method getObjectValue(enum), where the enum determines the appropriate double value to return. It must have some fields that match the (case sensitive) name of the conditioning regression key entries of coeffMultiMap's MultiKey (not the first key entry, which is reserved for the regressor name)enumTypeObject
- specifies the enum type that is used in the getObjectValue(Enum.valueOf(enumType, String)) method of the iObjSrc object. The String is the name of the enum case, used as a switch to determine the appropriate object value to return
-
computeScore
public static <T extends java.lang.Enum<T>,U extends java.lang.Enum<U>> double computeScore(MultiKeyCoefficientMap coeffMultiMap, IDoubleSource iDblSrc, java.lang.Class<T> enumTypeDouble, IObjectSource iObjSrc, java.lang.Class<U> enumTypeObject)
Requires the implementation of the IObjectSource to ascertain whether any additional conditioning regression keys are used (e.g. whether the underlying agent is female, married etc., where the regression co-efficients are conditioned on additional keys of gender and civil status, for example). If the underlying agent does not implement IObjectSource but does have additional conditioning regression keys, use the computeScore method (that uses reflection, so is slower) with signature:- public static> double computeScore(MultiKeyCoefficientMap coeffMultiMap, IDoubleSource iDblSrc, Class enumType) If the underlying agent does not have additional conditioning regression keys, use the computeScore method with signature:- Requires the MultiKeyCoefficientMap coeffMultiMap to have a key in its multiKey that corresponds to the name of the regressor variables. The names of the other keys of the coeffMultiMap must match the (case sensitive) name of the corresponding fields of the iDblSrc class. - Parameters:
coeffMultiMap
- is a MultiKeyCoefficientMap that has a MultiKey containing the name of the regressor variable. The names of the other keys of the coeffMultiMap must match the (case sensitive) name of the corresponding fields of the iDblSrc class.iDblSrc
- is an object that implements the IDoubleSource interface (e.g. the underlying agent whose properties are the covariates), and hence has a method getDoubleValue(enum), where the enum determines the appropriate double value to return. It must have some fields that match the (case sensitive) name of the first key entry of the coeffMultiMap's MultiKeyenumTypeDouble
- specifies the enum type that is used in the getDoubleValue(Enum.valueOf(enumType, String)) method of the iDblSrc object. The String is the name of the enum case, used as a switch to determine the appropriate double value to returniObjSrc
- is an object that implements the IObjectSource interface (e.g. the underlying agent whose properties are the covariates), and hence has a method getObjectValue(enum), where the enum determines the appropriate double value to return. It must have some fields that match the (case sensitive) name of the conditioning regression key entries of coeffMultiMap's MultiKey (not the first key entry, which is reserved for the regressor name)enumTypeObject
- specifies the enum type that is used in the getObjectValue(Enum.valueOf(enumType, String)) method of the iObjSrc object. The String is the name of the enum case, used as a switch to determine the appropriate object value to return
-
-