GithubHelp home page GithubHelp logo

Comments (5)

luator avatar luator commented on May 30, 2024

Thanks a lot for tracking this down!

Regarding fix 1:
I did some quick benchmark and can confirm that np.clip is indeed much slower than calling np.minimum and np.maximum (factor 8 on my machine...), so fixing this makes a lot of sense. From a discussion on the numpy repo I learned that there is also np.core.umath.clip which has overall best performance, so I would suggest using that instead of np.minimum/maximum (it also gives more readable code).

Regarding fix 2: I'm not sure about this change, let's discuss it in the meeting tomorrow.

from causalworld.

michaelfeil avatar michaelfeil commented on May 30, 2024

Thanks for your comment! I was not aware of np.core.umath.clip. It seems like from numpy version 1.16 to 1.17 this got ~11 times slower

timeit.timeit("np.clip(a, -3, +3)",setup="import numpy as np;a=np.asarray([1,1,2,4,-5])", number=1000000)

np.core.umath.clip is not part of the public api of numpy and not available for versions before numpy 1.17. It has comparable speed to np.minimum/maximum (around 5% faster) and is more readable.

For speed across versions, I think the np.minimum/maximum might be still the way to go.

from causalworld.

luator avatar luator commented on May 30, 2024

Hm, how about something like

try:
    clip = np.core.umath.clip
except AttributeError:
    clip = np.clip

at the top of the file? For <=1.16 np.clip should still be good and for later versions there is np.core.umath.clip.

I'd really prefer to avoid minimum/maxium as I think it makes the code much less readable (and thus easier to miss mistakes).

from causalworld.

michaelfeil avatar michaelfeil commented on May 30, 2024

I think this is a good idea!
As this also happens on 3 other parts in CausalWorld (

return np.clip(observation, self._low_norm, self._high_norm)
,
return np.clip(observation, self._low_norm, self._high_norm)
and
return np.clip(action, -1.0, 1.0)
), which are called for every step()

I would add your proposal to the utils.
https://github.com/rr-learning/CausalWorld/blob/7e2958a1db3af4f801d6d6df4fd1e507304ca537/causal_world/utils/env_utils.py

from causalworld.

michaelfeil avatar michaelfeil commented on May 30, 2024

Is resolved, the logic with 2x clipping works as damping for higher velocities and #102

from causalworld.

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.