Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling the optimizer is unnecessarily complicated #10

Open
foolnotion opened this issue Feb 3, 2024 · 0 comments
Open

Calling the optimizer is unnecessarily complicated #10

foolnotion opened this issue Feb 3, 2024 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@foolnotion
Copy link
Member

Right now, optimizing a tree with pyoperon requires a lot of ugly code:

def evaluate_with_pyoperon(pdata, tree, range_train, range_test):
    a, b = range_train
    c, d = range_test

    # pyoperon
    pyop_dataset  = op.Dataset(pdata.values)
    pyop_dataset.VariableNames = pdata.columns
    pyop_range_tr = op.Range(a, b)
    pyop_range_te = op.Range(c, d)
    pyop_vars     = sorted(pyop_dataset.Variables, key=lambda v: v.Index)
    pyop_hashes   = [v.Hash for v in pyop_vars[:-1]]
    pyop_target   = pyop_vars[-1]
    pyop_problem  = op.Problem(pyop_dataset, pyop_range_tr, pyop_range_te)
    pyop_problem.InputHashes = pyop_hashes
    pyop_problem.Target = pyop_target
    pyop_dt       = op.DispatchTable()
    pyop_opt      = op.LMOptimizer(pyop_dt, pyop_problem, max_iter=20)
    rng = op.RomuTrio(np.random.randint(1, 1_000_000))

    summary = pyop_opt.Optimize(rng, tree)

    if summary.Success:
        pyop_tree.SetCoefficients(summary.FinalParameters)

    range_full = op.Range(0, pyop_dataset.Rows)
    return op.Evaluate(pyop_dt, pyop_tree, pyop_dataset, range_full)

This should not be so complicated. At the very least, if pdata is a dataframe, we should hide the construction of the dataset and problem and offer a simplified API.

@foolnotion foolnotion added the enhancement New feature or request label Feb 3, 2024
@foolnotion foolnotion self-assigned this Feb 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant