Giter VIP home page Giter VIP logo

Comments (4)

nickbianco avatar nickbianco commented on June 2, 2024

Hi @mrrezaie, the docs say:

Uses getRowIndexAfterTime to locate first row and getNearestRowIndexForTime method to locate last row.

so the trimming might not be inclusive to the first time point. You could try providing a time value just before your initial time to include the first time index.

I'm not sure we will change this functionality, but regardless we should expose trimToIndices so you have more control over the start time index.

from opensim-core.

mrrezaie avatar mrrezaie commented on June 2, 2024

Hi @nickbianco, thanks for your response, and exposing trimToIndices.

Uses getRowIndexAfterTime to locate first row and getNearestRowIndexForTime method to locate last row.
so the trimming might not be inclusive to the first time point. You could try providing a time value just before your initial time to include the first time index.

Not sure if trim is functioning as documented. In this example, it is including the first time.

import opensim as osim
import numpy as np

times = np.linspace(0,1,11)
# [0. 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9, 1. ]
col = np.arange(0,11, dtype=float)
# [0. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10.]

table = osim.TimeSeriesTable(times)
table.appendColumn('col', osim.Vector(col))

table.trim(0.1,0.9)
print(table.getDependentColumn('col').to_numpy())
# [1. 2. 3. 4. 5. 6. 7. 8. 9.]

And if some sort of rounding error occurs, the output might be unreliable:

error = 1e-12
times = np.linspace(0,1,11) - error
...
table.trim(0.1,0.9)
# [2. 3. 4. 5. 6. 7. 8. 9.]
times = np.linspace(0,1,11) + error
...
table.trim(0.1,0.9)
# [1. 2. 3. 4. 5. 6. 7. 8.]

But getNearestRowIndexForTime always returns the correct index. Thank you.

from opensim-core.

tkuchida avatar tkuchida commented on June 2, 2024

Not sure if trim is functioning as documented.

IMHO the behavior in your examples is correct: trimming based on time points will always be sensitive to numerical noise. The trim method guarantees that all returned points are within the specified range. If what you're trying to do is find the time point closest to a specified value, then getNearestRowIndexForTime is the right idea. As @nickbianco suggested, a trimToIndices method would be good if there's currently no way to do this. 🐴

from opensim-core.

mrrezaie avatar mrrezaie commented on June 2, 2024

Thanks for your explanation. So, I'll be looking forward to trimToIndices method. Thanks for your time.

from opensim-core.

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.