Giter VIP home page Giter VIP logo

Comments (3)

basnijholt avatar basnijholt commented on August 11, 2024

originally posted by Bas Nijholt (@basnijholt) at 2018-11-19T13:32:18.497Z on GitLab

This is explained in https://gitlab.kwant-project.org/qt/adaptive/merge_requests/118.

from adaptive.

basnijholt avatar basnijholt commented on August 11, 2024

originally posted by Joseph Weston (@jbweston) at 2018-11-19T13:45:33.747Z on GitLab

I still don't really see why it's necessary. BalancingLearner.load could take something additional that maps learners to filenames, for example. The API for 'BalancingLearner.load' is already not the same as for the other learners, because it expects a path to a directory rather than to a regular file, so it doesn't seem bad to have it also differ in other ways.

For example, for BalancingLearner, 'fname' could expect a callable that takes a learner and gives back a filename where the data can be got.

This means that your example from gitlab:!118:

def combo_fname(val):
    return '__'.join([f'{k}_{v}' for k, v in val.items()])

combos = adaptive.utils.named_product(a=[1, 2], b=[1])
learners = []
for combo in combos:
    l = Learner(partial(f, combo=combo))
    l.fname = combo_fname(combo)
    learners.append(l)
learner = BalancingLearner(learners)
learner.load(folder='data_folder')

becomes:

combos = adaptive.utils.named_product(a=[1, 2], b=[1])
learners = {Learner(partial(f, combo=combo)): combo for combo in combos}

def combo_fname(learner):
    val = learners[learner]
    return 'data_folder/' + '__'.join([f'{k}_{v}' for k, v in val.items()])

learner = BalancingLearner(list(learners.keys()))
learner.load(fname=combo_fname)

from adaptive.

basnijholt avatar basnijholt commented on August 11, 2024

originally posted by Joseph Weston (@jbweston) at 2018-11-19T16:15:02.731Z on GitLab

In fact it can be even simpler because BalancingLearner.from_product uses functools:

def combo_fname(learner):  # this function is pure
    val = learner.function.keywords  # from functools.partial
    return 'data_folder/' + '__'.join([f'{k}_{v}' for k, v in val.items()])

combos = dict(a=[1, 2], b=[1])
learner = BalancingLearner.from_product(f, Learner1D, dict(bounds=(-1, 1)), combos)
learner.load(fname=combo_fname)

from adaptive.

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.