very low dimensional re-encoding of levels @author johnmount
| 27 | * |
| 28 | */ |
| 29 | public final class BTable { |
| 30 | public VariableEncodings oldAdapter; |
| 31 | public VariableEncodings newAdapter; |
| 32 | public double[] warmStart = null; |
| 33 | public Iterable<BurstMap> sample = null; |
| 34 | |
| 35 | private static final class BSampler implements SerialObserver<BurstMap> { |
| 36 | public final VariableEncodings oldAdapter; |
| 37 | public final ResevoirSampler<BurstMap> sampler; |
| 38 | |
| 39 | public BSampler(final VariableEncodings oldAdapter, final long randSeed) { |
| 40 | this.oldAdapter = oldAdapter; |
| 41 | sampler = new ResevoirSampler<BurstMap>(100000,randSeed); |
| 42 | } |
| 43 | |
| 44 | @Override |
| 45 | public void observe(final BurstMap row) { |
| 46 | final double weight = oldAdapter.weight(row); |
| 47 | if(weight>0.0) { |
| 48 | final String resStr = row.getAsString(oldAdapter.def().resultColumn); |
| 49 | final int category = oldAdapter.category(resStr); |
| 50 | if(category>=0) { |
| 51 | sampler.observe(row); |
| 52 | } |
| 53 | } |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | |
| 58 | |
| 59 | private static final class GeneralIndicator { |
| 60 | @SuppressWarnings("unused") |
| 61 | public final String var; |
| 62 | public final String name; |
| 63 | public final Map<String,Double> levelEncodings = new HashMap<String,Double>(); // indexed by levels of var |
| 64 | public final int warmStartOutcome; |
| 65 | |
| 66 | public GeneralIndicator(final String var, final String name, final int nlevels, final int warmStartOutcome) { |
| 67 | this.var = var; |
| 68 | this.name = name; |
| 69 | this.warmStartOutcome = warmStartOutcome; |
| 70 | } |
| 71 | |
| 72 | public double normSq() { |
| 73 | double nsq = 0.0; |
| 74 | for(final double v: levelEncodings.values()) { |
| 75 | nsq += v*v; |
| 76 | } |
| 77 | return nsq; |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | |
| 82 | public static ArrayList<GeneralIndicator> encode(final BStat stat, final String variable, final VariableEncodings oldAdapter, final double[] oldX) { |
| 83 | final ArrayList<GeneralIndicator> res = new ArrayList<GeneralIndicator>(); |
| 84 | final double smooth = 0.5; |
| 85 | final double sumAll = stat.sumTotal + smooth; |
| 86 | final Set<String> levels = oldAdapter.def().catLevels.get(variable).keySet(); |
nothing calls this directly
no outgoing calls
no test coverage detected