question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Conditional param's

See original GitHub issue

I just wanted to confirm how one deals with a parameter which has a different distribution depending on the value of another parameter, i.e. in the case below (using CatBoost), I have to limit max_depth between 1 and 8 when using Depthwise or Symmetric grow_policy but can use 1 to 16 for Lossguide

Can I use the same param name for both branches? In the case below I named it differently as I was getting a warning. The problem then though is at the end of training trial.params contains the name arguments of suggest_* not the hparams keys.

    if hparams['grow_policy']=='Lossguide':
        # Max leaves is only used for Lossguide grow_policy
        hparams['max_leaves'] = int(trial.suggest_loguniform("max_leaves", 2, 64))
        hparams['max_depth'] = trial.suggest_int("max_depth_16", 1, 16) # or trial.suggest_int("max_depth", 1, 16) ?
    else:
        hparams['max_depth'] = trial.suggest_int("max_depth_8", 1, 8) # or trial.suggest_int("max_depth", 1, 8) ?

Also, in the case below grow_policy must be ‘SymmetricTree’ when ‘boosting_type’ == ‘Plain’, so I didn’t sample grow_policy in the else branch. Problem then is it’s not part of the trial.params and I have to apply the same logic to infer the correct hparams for the best trial. Should I use suggest_categorical with a single category as per the comment?

    hparams['boosting_type'] = trial.suggest_categorical('boosting_type', ['Plain', 'Ordered'])
    if hparams['boosting_type'] == 'Plain':
        hparams['grow_policy'] = trial.suggest_categorical('grow_policy', ['SymmetricTree', 'Depthwise', 'Lossguide'])
    else:
        # On GPU grow policy Depthwise can't be used with ordered boosting
        # On GPU grow policy Lossguide can't be used with ordered boosting
        hparams['grow_policy'] = 'SymmetricTree' # or trial.suggest_categorical('grow_policy', ['SymmetricTree' ])
        hparams['has_time'] = bool(trial.suggest_int("has_time", 0, 1))

Or am I just doing it wrong, should I be attaching hparams to each trial somehow, since trialparams isn’t what I’m actually training the model with? I’m used to hyperopt which had a way of recreating the hparams from the space and params.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
HideakiImamuracommented, Jul 3, 2020

[FYI] We are planning that we make FrozenTrial can be used as FrozenTrial.suggest_* samely as Trial.suggest_*. Ongoing at Issue https://github.com/optuna/optuna/issues/1251.

1reaction
david-waterworthcommented, Jul 3, 2020

Thanks I was just about to ask that, I’ll close now and follow that issue!

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - how to have conditional params arguments to a function
1 Answer 1 ; var parameters = new List< ; object> { a, b }; if (x == ; 42) parameters.Add(c); Foo("yo", parameters);....
Read more >
Conditionally pass params to a script - bash
I have a script running on Linux that accepts some parameters. I would like to do something like: if [[ $CONDITION == "true"...
Read more >
Conditions - AWS CloudFormation
Declare conditions to conditionally create resources by using intrinsic functions in the Conditions section of a template.
Read more >
Conditional deployment with Bicep - Azure Resource Manager
Describes how to conditionally deploy a resource in Bicep. ... param deployZone bool resource dnsZone 'Microsoft.
Read more >
Conditions reference | Dialogflow CX - Google Cloud
This reference describes the syntax for using conditions in routes. When a condition evaluates to true, the associated route is called when the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found