def policyImprovement(self, policy):
        policyChanges = 0
        i = 0
        while i < self.representation.agg_states_num and self.hasTime():
            s = self.representation.stateID2state(i)
            if not self.domain.isTerminal(s) and len(self.domain.possibleActions(s)):
                for a in self.domain.possibleActions(s):
                    if not self.hasTime():
                        break
                    self.BellmanBackup(s, a, self.ns_samples, policy)
                if policy.pi(s, False, self.domain.possibleActions(s=s)) != self.representation.bestAction(s, False, self.domain.possibleActions(s=s)):
                    policyChanges += 1
            i += 1
        # This will cause the policy to be copied over
        policy.representation.weight_vec = self.representation.weight_vec.copy()
        performance_return, performance_steps, performance_term, performance_discounted_return = self.performanceRun(
        )
        self.logger.info(
            'PI #%d [%s]: BellmanUpdates=%d, Policy Change=%d, Return=%0.4f, Steps=%d' % (
                self.policy_improvement_iteration,
                hhmmss(
                    deltaT(
                        self.start_time)),
                self.bellmanUpdates,
                policyChanges,
                performance_return,
                performance_steps))

        # store stats
        self.result["bellman_updates"].append(self.bellmanUpdates)
        self.result["return"].append(performance_return)
        self.result["planning_time"].append(deltaT(self.start_time))
        self.result["num_features"].append(self.representation.features_num)
        self.result["steps"].append(performance_steps)
        self.result["terminated"].append(performance_term)
        self.result["discounted_return"].append(performance_discounted_return)
        self.result["policy_improvement_iteration"].append(self.policy_improvement_iteration)
        return policy, policyChanges
Given a policy improve it by taking the greedy action in each state based on the value function
dataset/ETHPy150Open rlpy/rlpy/rlpy/MDPSolvers/PolicyIteration.py/PolicyIteration.policyImprovement