src/main/java/Alergia.java
private void normalize(List<FptaNode> red) {
        int index = 0;
        for(FptaNode r : red){
            r.stateId = "q" + index;
            index += 1;
            r.childrenProbability = new HashMap<>();

            if(modelType == ModelType.MC){
                int totalOutput = r.inputFrequency.values().stream().mapToInt(Integer::intValue).sum();
                for (String io : r.inputFrequency.keySet())
                    r.childrenProbability.put(io, r.inputFrequency.get(io).doubleValue() / totalOutput);
            }else{
                HashMap<String, Double> outputsPerInput = new HashMap<>();
                for (String io : r.inputFrequency.keySet()) {
                    List<String> inputAndOutput = Arrays.asList(io.split("/"));
                    outputsPerInput.put(inputAndOutput.get(0), r.inputFrequency.get(io) +
                            outputsPerInput.getOrDefault(inputAndOutput.get(0), 0.));
                }
                for (String io : r.inputFrequency.keySet()) {
                    List<String> inputAndOutput = Arrays.asList(io.split("/"));
                    r.childrenProbability.put(io, r.inputFrequency.get(io) / outputsPerInput.get(inputAndOutput.get(0)));
                }
            }
        }
    }
/**
     * Normalizes probabilities of final states, that it assigns probabilities to transitions for each state.
     * @param red list of states of learned automaton
     */
Normalizes probabilities of final states, that it assigns probabilities to transitions for each state.
@param red list of states of learned automaton
Normalizes probabilities of final states that it assigns probabilities to transitions for each state . @param red list of states of learned automaton
private void normalize(List<FptaNode> red) {
        int index = 0;
        for(FptaNode r : red){
            r.stateId = "q" + index;
            index += 1;
            r.childrenProbability = new HashMap<>();
            if(modelType == ModelType.MC){
                int totalOutput = r.inputFrequency.values().stream().mapToInt(Integer::intValue).sum();
                for (String io : r.inputFrequency.keySet())
                    r.childrenProbability.put(io, r.inputFrequency.get(io).doubleValue() / totalOutput);
            }else{
                HashMap<String, Double> outputsPerInput = new HashMap<>();
                for (String io : r.inputFrequency.keySet()) {
                    List<String> inputAndOutput = Arrays.asList(io.split("/"));
                    outputsPerInput.put(inputAndOutput.get(0), r.inputFrequency.get(io) +
                            outputsPerInput.getOrDefault(inputAndOutput.get(0), 0.));
                }
                for (String io : r.inputFrequency.keySet()) {
                    List<String> inputAndOutput = Arrays.asList(io.split("/"));
                    r.childrenProbability.put(io, r.inputFrequency.get(io) / outputsPerInput.get(inputAndOutput.get(0)));
                }
            }
        }
    }
private void normalize ( List < FptaNode > red ) { int index = 0 ; for ( FptaNode r : red ) { r . stateId = "q" + index ; index += 1 ; r . childrenProbability = new HashMap < > ( ) ; if ( modelType == ModelType . MC ) { int totalOutput = r . inputFrequency . values ( ) . stream ( ) . mapToInt ( Integer :: intValue ) . sum ( ) ; for ( String io : r . inputFrequency . keySet ( ) ) r . childrenProbability . put ( io , r . inputFrequency . get ( io ) . doubleValue ( ) / totalOutput ) ; } else { HashMap < String , Double > outputsPerInput = new HashMap < > ( ) ; for ( String io : r . inputFrequency . keySet ( ) ) { List < String > inputAndOutput = Arrays . asList ( io . split ( "/" ) ) ; outputsPerInput . put ( inputAndOutput . get ( 0 ) , r . inputFrequency . get ( io ) + outputsPerInput . getOrDefault ( inputAndOutput . get ( 0 ) , 0. ) ) ; } for ( String io : r . inputFrequency . keySet ( ) ) { List < String > inputAndOutput = Arrays . asList ( io . split ( "/" ) ) ; r . childrenProbability . put ( io , r . inputFrequency . get ( io ) / outputsPerInput . get ( inputAndOutput . get ( 0 ) ) ) ; } } } }
Normalizes probabilities of final states, that it assigns probabilities to transitions for each state.
Normalizes probabilities of final states that it assigns probabilities to transitions for each state .