From 17cf3637d6e6b2297ee297f68d3c57f251f8d3aa Mon Sep 17 00:00:00 2001 From: sikai zhang Date: Tue, 4 Nov 2025 10:55:41 +0800 Subject: [PATCH] ASV add benchmark for beam search --- asv_benchmarks/benchmarks/fastcan.py | 10 ++++++++-- pixi.toml | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/asv_benchmarks/benchmarks/fastcan.py b/asv_benchmarks/benchmarks/fastcan.py index 121038f..c9ddb12 100644 --- a/asv_benchmarks/benchmarks/fastcan.py +++ b/asv_benchmarks/benchmarks/fastcan.py @@ -16,7 +16,7 @@ class FastCanBenchmark(Benchmark): """ param_names = ["task", "alg"] - params = (["classif", "reg"], ["h", "eta"]) + params = (["classif", "reg"], ["h", "eta", "beam"]) def setup_cache(self): """Pickle a fitted estimator for all combinations of parameters""" @@ -30,11 +30,17 @@ def setup_cache(self): if alg == "h": eta = False - else: + beam_width = 1 + elif alg == "eta": eta = True + beam_width = 1 + else: + eta = False + beam_width = 10 estimator = FastCan( n_features_to_select=20, eta=eta, + beam_width=beam_width ) estimator.fit(X, y) diff --git a/pixi.toml b/pixi.toml index dc1f756..be5376c 100644 --- a/pixi.toml +++ b/pixi.toml @@ -88,6 +88,7 @@ time-eta = "python -m timeit -n 5 -s 'import numpy as np; from fastcan import Fa profile-minibatch = { cmd = '''python -c "import cProfile; import numpy as np; from fastcan import minibatch; X = np.random.rand(100, 3000); y = np.random.rand(100, 20); cProfile.run('minibatch(X, y, 1000, 10, verbose=0)', sort='{{ SORT }}')"''', args = [{ arg = "SORT", default = "cumtime" }] } time-narx = '''python -m timeit -n 1 -s "import numpy as np; from fastcan.narx import make_narx; rng = np.random.default_rng(5); X = rng.random((1000, 10)); y = rng.random((1000, 2)); m = make_narx(X, y, 10, max_delay=2, poly_degree=2, verbose=0)" "m.fit(X, y, coef_init='one_step_ahead', verbose=1)"''' profile-narx = { cmd = '''python -c "import cProfile; import numpy as np; from fastcan.narx import make_narx; rng = np.random.default_rng(8); X = rng.random((3000, 3)); y = rng.random((3000, 3)); m = make_narx(X, y, 10, max_delay=10, poly_degree=2, verbose=0); cProfile.run('m.fit(X, y, coef_init=[0]*33)', sort='{{ SORT }}')"''', args = [{ arg = "SORT", default = "tottime" }] } +time-beam = "python -m timeit -n 5 -s 'import numpy as np; from fastcan import FastCan; X = np.random.rand(3000, 100); y = np.random.rand(3000, 20)' 's = FastCan(20, beam_width=3, verbose=0).fit(X, y)'" [feature.asv.tasks] asv-build = { cmd = "python -m asv machine --machine {{ MACHINE }} --yes && python -m asv run --show-stderr -v --machine {{ MACHINE }} {{ EXTRA_ARGS }}", cwd = "asv_benchmarks", args = [{ arg = "MACHINE", default = "MacOS-M1" }, { arg = "EXTRA_ARGS", default = "" }] }