最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - Copy Optuna study while slightly altering trial scores - Stack Overflow

programmeradmin3浏览0评论

I am using Optuna to optimize the parameters of a non-ML task. Now, each trial consists in processing several files in sequence, each of which gets a score. The scores are summed cumulatively in order to allow Optuna to prune unfavorable trials, and the final sum of all scores is reported.

In order to optimize pruning, I want to have the highest variance files be processed first, as those are the most relevant to determine whether a run should be stopped or not. However, in order to know which files have the highest variance, I first must run some trials without any pruning. Once I have done that, I can determine from the results the optimal order in which to process the files.

However, there is no reason to discard the previous results. So I have written a small script that extracts the existing scores, including the intermediate steps, and re-arranges them as if the best optimal file processing order had always been used. I'd now like to create a new study with some trials that report my newly "re-arranged" scores.

However, I can't figure out a way to also pass the original parameter values to the new trials. With my current code, I get a study that reports the correct score, but doesn't show any parameter at all (since I'm not currently copying them). Is there a way to do so?

Below is an excerpt of my script to give an idea of what I'm looking for.

    new_study = optuna.create_study(
            storage=new_storage,
            study_name=args.study_name,
            direction="maximize")

    for i, trial in enumerate(completed_trials):
        new_trial = new_study.ask()

        # How to actually copy these? What else should be copied?
        #
        # new_trial.distributions = cp.deepcopy(trial.distributions)
        # new_trial.params = cp.deepcopy(trial.params)

        new_trial_score = cum_reordered_scores[i]
        for i in range(len(new_trial_score)):
            new_trial.report(new_trial_score[i], i)

        new_study.tell(new_trial, new_trial_score[-1])
发布评论

评论列表(0)

  1. 暂无评论