Code Monkey home page Code Monkey logo

Comments (6)

jeromekelleher avatar jeromekelleher commented on August 12, 2024 1

Since it's returning an iterator I don't think there's any point in trying to be clever, just a simple loop is the right way to go. From the stdpopsim perspective this is fine, because it wants to iterate over the intervals and do Python stuff to them.

from tskit.

petrelharp avatar petrelharp commented on August 12, 2024 1

Since it's returning an iterator I don't think there's any point in trying to be clever

I agree with this, but if you did want to be clever with numpy, here's how to pre-compute the relevant things:

rm1 = msprime.RateMap(position=[0, 10], rate=[1.0])
rm2 = msprime.RateMap(position=[0, 3, 10], rate=[4.0, 5])
rm_list = [rm1, rm2]
pos = np.unique(np.concatenate([rm.position for rm in rm_list]))
rates = np.array([rm.rate[np.searchsorted(rm.position[:-1], pos, side='right') - 1] for rm in rm_list])
for k in range(len(pos)-1):
  print(f"segment {k}: {pos[k]} to {pos[k+1]} - rates {rates[:,k]}")

from tskit.

jeromekelleher avatar jeromekelleher commented on August 12, 2024

cc @mufernando @grahamgower

from tskit.

mufernando avatar mufernando commented on August 12, 2024

I would volunteer to implement this, except I can't think of a clever way to do this in numpy. I've run across this exact problem many times and always end up doing a dumb/slow for loop. If anyone has any ideas on how to use numpy vectorized tricks to do that let me know and I can implement it.

from tskit.

mufernando avatar mufernando commented on August 12, 2024

It would be nice to be able to define a RateMap with left and right intervals so that it automatically converts to the breakpoints representation. Or is this sth we want to do within stdpopsim?

from tskit.

jeromekelleher avatar jeromekelleher commented on August 12, 2024

It would be nice to be able to define a RateMap with left and right intervals so that it automatically converts to the breakpoints representation. Or is this sth we want to do within stdpopsim?]

This is a separate issue - can you open one to track with an example of what you'd like to see?

from tskit.

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.