Monday, November 13, 2017

Update to RL Code

changed the method to get the value -
 1) state string splitter should be ':'
 2) substates are averaged by the probablity of being in this state.
 3) the final value is averaged with the substate value.

    static double getTransitionChangeValue(String state, int i) {
        /* THIS METHOD IS RECURSIVE */
        if (stateTableCnt.get(state) == null | stateTablePriceChangeTotal.get(state) == null)
            // let calling method know that this state has not been recorded
            return Double.MAX_VALUE;

        double got;
        // start with what this state is worth
        got = (stateTablePriceChangeTotal.get(state) / stateTableCnt.get(state));

        if (i > 0) {
            double sum = 0;
            int cnt = 0;
            for (String key : stateTableTransition.keySet()) {
                // now get average of what all of the subsequent states.
                String split[] = key.split(":");
                if (split[0].compareTo(state) == 0) {
                    sum += getTransitionChangeValue(split[1], i - 1)
                            * (stateTableTransition.get(key)/stateTableCnt.get(state));
                    cnt++;
                }
            }
            if (cnt > 0) {
                got += sum;
                got /= 2;
            }
        }
        return got;

    }


No comments: