Giter Site home page Giter Site logo

Comments (2)

duburcqa avatar duburcqa commented on August 19, 2024

After thinking twice, I think it makes more sense provide a QuantityManager. This quantity manager can then be forwarded to independent reward components satisfying some callable protocole (which means it would be a lambda, a function or a class defining __class__ aka functor). It would more modular and easier to extend this way. To be computationally efficient, this quantity manager should heavily rely on caching. This cache must be clear manually before computing any reward component, then quantities would be computed only the first time it is requested, or never if not used. Here is a snipped:

class QuantityManager:
    def __init__(self, robot: BaseJiminyRobot, quantities: Dict[str, Callable[[], Any]]) -> None:
        self.robot = env.robot
        self.quantities = quantities
        self._cache : Dict[str, Any]

    def __getattr__(self, name: str) -> Any:
        return self.__cache.setdefault(name, self.quantities.get(name))

    def __item__(self, name:str) -> Any:
        return getattr(self, name)

    def reset() -> None:
        self.__cache.clear()

class RelativePose:
    def __init__(self, robot: BaseJiminyRobot, first_name: str, second_name: str) -> None:
        first_index = robot.pinocchio_model.getFrameId(first_name)
        second_index = robot.pinocchio_model.getFrameId(second_name)
        self.first_pose = self.robot.oMf[first_index]
        self.second_pose = self.robot.oMf[second_index]

    def __call__(self) -> pin.SE3:
        return self.first_pose.actInv(self.second_pose)

def foot_placement_reward(quantities: QuantityManager) -> float:
    return np.linalg.norm(quantities.foot_pose_rel.translation)

[...]

foot_pose_rel_qty = RelativePose(env.robot, "LeftSole", "RightSole")
quantities = QuantityManager(env.robot, {"foot_pose_rel": foot_pose_rel_qty}))

There would be a reward manager, taking a quantity manager and a set of reward components as input. It would expose a single compute_reward method, that would first call reset on the quantity manager, and then all reward components individually. Eventually, it would also feature a reset method that would call the reset method of each reward components if any. It may be beneficial to keep termination conditions and reward evaluation together, to avoid computing quantities twice. If so, then it would be more tricky to determine when to reset cached quantities automatically.

from jiminy.

duburcqa avatar duburcqa commented on August 19, 2024

This issue has been addressed. Closing. #784 #786 #787 #792

from jiminy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.