private Configuration zeroCostDynamicOracle(Instance instance, Collection<Configuration> oracles, Collection<Configuration> newOracles)
    {
        float bestScore = Float.NEGATIVE_INFINITY;
        Configuration bestScoringOracle = null;

        for (Configuration configuration : oracles)
        {
            if (!configuration.state.isTerminalState())
            {
                State currentState = configuration.state;
                Object[] features = FeatureExtractor.extractAllParseFeatures(configuration, featureLength);
                // I only assumed that we need zero cost ones
                if (instance.actionCost(Action.Shift, -1, currentState) == 0)
                {
                    Configuration newConfig = configuration.clone();
                    float score = classifier.shiftScore(features, false);
                    ArcEager.shift(newConfig.state);
                    newConfig.addAction(0);
                    newConfig.addScore(score);
                    newOracles.add(newConfig);

                    if (newConfig.getScore(true) > bestScore)
                    {
                        bestScore = newConfig.getScore(true);
                        bestScoringOracle = newConfig;
                    }
                }
                if (ArcEager.canDo(Action.RightArc, currentState))
                {
                    float[] rightArcScores = classifier.rightArcScores(features, false);
                    for (int dependency : dependencyRelations)
                    {
                        if (instance.actionCost(Action.RightArc, dependency, currentState) == 0)
                        {
                            Configuration newConfig = configuration.clone();
                            float score = rightArcScores[dependency];
                            ArcEager.rightArc(newConfig.state, dependency);
                            newConfig.addAction(3 + dependency);
                            newConfig.addScore(score);
                            newOracles.add(newConfig);

                            if (newConfig.getScore(true) > bestScore)
                            {
                                bestScore = newConfig.getScore(true);
                                bestScoringOracle = newConfig;
                            }
                        }
                    }
                }
                if (ArcEager.canDo(Action.LeftArc, currentState))
                {
                    float[] leftArcScores = classifier.leftArcScores(features, false);

                    for (int dependency : dependencyRelations)
                    {
                        if (instance.actionCost(Action.LeftArc, dependency, currentState) == 0)
                        {
                            Configuration newConfig = configuration.clone();
                            float score = leftArcScores[dependency];
                            ArcEager.leftArc(newConfig.state, dependency);
                            newConfig.addAction(3 + dependencyRelations.size() + dependency);
                            newConfig.addScore(score);
                            newOracles.add(newConfig);

                            if (newConfig.getScore(true) > bestScore)
                            {
                                bestScore = newConfig.getScore(true);
                                bestScoringOracle = newConfig;
                            }
                        }
                    }
                }
                if (instance.actionCost(Action.Reduce, -1, currentState) == 0)
                {
                    Configuration newConfig = configuration.clone();
                    float score = classifier.reduceScore(features, false);
                    ArcEager.reduce(newConfig.state);
                    newConfig.addAction(1);
                    newConfig.addScore(score);
                    newOracles.add(newConfig);

                    if (newConfig.getScore(true) > bestScore)
                    {
                        bestScore = newConfig.getScore(true);
                        bestScoringOracle = newConfig;
                    }
                }
            }
            else
            {
                newOracles.add(configuration);
            }
        }

        return bestScoringOracle;
    }
private Configuration zeroCostDynamicOracle ( Instance instance , Collection < Configuration > oracles , Collection < Configuration > newOracles ) { float bestScore = Float . NEGATIVE_INFINITY ; Configuration bestScoringOracle = null ; for ( Configuration configuration : oracles ) { if ( ! configuration . state . isTerminalState ( ) ) { State currentState = configuration . state ; Object [ ] features = FeatureExtractor . extractAllParseFeatures ( configuration , featureLength ) ; if ( instance . actionCost ( Action . Shift , - 1 , currentState ) == 0 ) { Configuration newConfig = configuration . clone ( ) ; float score = classifier . shiftScore ( features , false ) ; ArcEager . shift ( newConfig . state ) ; newConfig . addAction ( 0 ) ; newConfig . addScore ( score ) ; newOracles . add ( newConfig ) ; if ( newConfig . getScore ( true ) > bestScore ) { bestScore = newConfig . getScore ( true ) ; bestScoringOracle = newConfig ; } } if ( ArcEager . canDo ( Action . RightArc , currentState ) ) { float [ ] rightArcScores = classifier . rightArcScores ( features , false ) ; for ( int dependency : dependencyRelations ) { if ( instance . actionCost ( Action . RightArc , dependency , currentState ) == 0 ) { Configuration newConfig = configuration . clone ( ) ; float score = rightArcScores [ dependency ] ; ArcEager . rightArc ( newConfig . state , dependency ) ; newConfig . addAction ( 3 + dependency ) ; newConfig . addScore ( score ) ; newOracles . add ( newConfig ) ; if ( newConfig . getScore ( true ) > bestScore ) { bestScore = newConfig . getScore ( true ) ; bestScoringOracle = newConfig ; } } } } if ( ArcEager . canDo ( Action . LeftArc , currentState ) ) { float [ ] leftArcScores = classifier . leftArcScores ( features , false ) ; for ( int dependency : dependencyRelations ) { if ( instance . actionCost ( Action . LeftArc , dependency , currentState ) == 0 ) { Configuration newConfig = configuration . clone ( ) ; float score = leftArcScores [ dependency ] ; ArcEager . leftArc ( newConfig . state , dependency ) ; newConfig . addAction ( 3 + dependencyRelations . size ( ) + dependency ) ; newConfig . addScore ( score ) ; newOracles . add ( newConfig ) ; if ( newConfig . getScore ( true ) > bestScore ) { bestScore = newConfig . getScore ( true ) ; bestScoringOracle = newConfig ; } } } } if ( instance . actionCost ( Action . Reduce , - 1 , currentState ) == 0 ) { Configuration newConfig = configuration . clone ( ) ; float score = classifier . reduceScore ( features , false ) ; ArcEager . reduce ( newConfig . state ) ; newConfig . addAction ( 1 ) ; newConfig . addScore ( score ) ; newOracles . add ( newConfig ) ; if ( newConfig . getScore ( true ) > bestScore ) { bestScore = newConfig . getScore ( true ) ; bestScoringOracle = newConfig ; } } } else { newOracles . add ( configuration ) ; } } return bestScoringOracle ; }
获取 zero cost oracle

@param instance   训练实例
@param oracles    当前的oracle
@param newOracles 储存新oracle
@return 这些 oracles 中在模型看来分数最大的那个
@throws Exception