Giter Site home page Giter Site logo

Featurizing seems rather slow about elm2d HOT 4 CLOSED

sgbaird avatar sgbaird commented on August 29, 2024
Featurizing seems rather slow

from elm2d.

Comments (4)

SurgeArrester avatar SurgeArrester commented on August 29, 2024

That's a good point thanks for bringing it up, I'm afraid I haven't got the bandwidth to test out the best chunksizes for different sized datasets at the moment. I've added chunksize as a parameter to the ElM2D class in 0.3.15 which will be used in each of these lines if that's of use?

ElM2D(chunksize=64)

I'm afraid I haven't been able to fix the other spyder issue, but will leave it open for now.

from elm2d.

sgbaird avatar sgbaird commented on August 29, 2024

This is great, thanks! Also, no pressure on the Spyder issue.

from elm2d.

sgbaird avatar sgbaird commented on August 29, 2024

Something like the following seems to be a lot faster (probably because it only involves a single call to ElMD():

E = ElMD()

def gen_ratio_vector(comp):
    """Create a numpy array from a composition dictionary."""
    if isinstance(comp, str):
        comp = E._parse_formula(comp)
        comp = E._normalise_composition(comp)

    sorted_keys = sorted(comp.keys())
    comp_labels = [E._get_position(k) for k in sorted_keys]
    comp_ratios = [comp[k] for k in sorted_keys]

    indices = np.array(comp_labels, dtype=np.int64)
    ratios = np.array(comp_ratios, dtype=np.float64)

    numeric = np.zeros(shape=len(E.periodic_tab[E.metric]), dtype=np.float64)
    numeric[indices] = ratios

    return numeric

def gen_ratio_vectors(comps):
    return np.array([gen_ratio_vector(comp) for comp in comps])

U = gen_ratio_vectors(formulas)
V = gen_ratio_vectors(formulas2)

lookup, periodic_tab, metric = attrgetter("lookup", "periodic_tab", "metric")(E)
ptab_metric = periodic_tab[metric]

def get_mod_petti(x):
    return [ptab_metric[lookup[a]] if b > 0 else 0 for a, b in enumerate(x)]

def get_mod_pettis(X):
    return np.array([get_mod_petti(x) for x in X])

U_weights = get_mod_pettis(U)
V_weights = get_mod_pettis(V)

from elm2d.

SurgeArrester avatar SurgeArrester commented on August 29, 2024

It looks like this issue was introduced when the additional lookup tables were added. Because it was loading a big json from disk into ram for each composition it was slowing things down a lot. I've reduced the memory overhead of this function in ElMD and followed this suggestion a bit by caching the functions output to local memory which has significantly sped up parsing. That's now pushed to ElM2D==0.4.0 and ElMD==0.4.2

from elm2d.

Related Issues (11)

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.