| 14 | import com.winvector.util.StatMap; |
| 15 | |
| 16 | public class PrimaVariableInfo implements Serializable { |
| 17 | private static final long serialVersionUID = 1L; |
| 18 | |
| 19 | // definitional |
| 20 | public String resultColumn; |
| 21 | public SortedSet<String> variables = new TreeSet<String>(); |
| 22 | public SortedSet<String> forcedNumeric = new TreeSet<String>(); |
| 23 | public SortedSet<String> forcedCategorical = new TreeSet<String>(); |
| 24 | // calculated |
| 25 | public CountMap<String> outcomes = new CountMap<String>(CountMap.strCmp); |
| 26 | public StatMap numericColumnSet = new StatMap(); |
| 27 | public SortedMap<String,CountMap<String>> catLevels = new TreeMap<String,CountMap<String>>(); |
| 28 | |
| 29 | protected void readyForDefTracking() { |
| 30 | outcomes = new CountMap<String>(CountMap.strCmp); |
| 31 | numericColumnSet = new StatMap(); |
| 32 | catLevels = new TreeMap<String,CountMap<String>>(); |
| 33 | for(final String nc: forcedNumeric) { |
| 34 | numericColumnSet.observe(nc,0.0,0.0); |
| 35 | } |
| 36 | for(final String key: forcedCategorical) { |
| 37 | catLevels.put(key,new CountMap<String>(CountMap.strCmp)); |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | public void readyForDefTracking(final Formula formula) { |
| 42 | resultColumn = formula.resultColumn; |
| 43 | variables = new TreeSet<String>(formula.variables); |
| 44 | forcedNumeric = new TreeSet<String>(formula.forcedNumeric); |
| 45 | forcedCategorical = new TreeSet<String>(formula.forcedCategorical); |
| 46 | readyForDefTracking(); |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * confirm row has complete set of non-empty independent variables |
| 51 | * @param row |
| 52 | * @return |
| 53 | */ |
| 54 | public boolean completeSetOfVars(final BurstMap row) { |
| 55 | for(final String key: variables) { |
| 56 | final String sValue = row.getAsString(key); |
| 57 | if((sValue==null)||(sValue.trim().length()<=0)) { |
| 58 | return false; |
| 59 | } |
| 60 | } |
| 61 | return true; |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * track: sets of levels, mean of numeric variable and distribution of outcomes |
| 66 | * @param row |
| 67 | */ |
| 68 | public void trackVariableDefsFromRow(final BurstMap row) { |
| 69 | if(!completeSetOfVars(row)) { |
| 70 | return; |
| 71 | } |
| 72 | for(final String key: variables) { |
| 73 | if(catLevels.containsKey(key)||forcedNumeric.contains(key)) { |
nothing calls this directly
no outgoing calls
no test coverage detected