Skip to main content

Expand multi optional configuration to multiple configurations.

Project description

json-config-expander

Expand multi optional configuration to multiple configurations.

Example 1

base_config = {'param_1*': [12, 13]}
expand_configs(base_config)

Returns:

[{'param_1': 12}, {'param_1': 13})

Example 2

base_config = {'param_1': {'param_2*': [12, 13]}}
expand_configs(base_config)

Returns:

[
    {'param_1': {'param_2': 12}}, 
    {'param_1': {'param_2': 13}}
]

Example 3

base_config = {'param_1*': [12, 13], 'param_2*': ['a', 'b']}
expand_configs(base_config)

Returns:

[
    {'param_1': 12, 'param_2': 'a'}, 
    {'param_1': 12, 'param_2': 'b'}, 
    {'param_1': 13, 'param_2': 'a'}, 
    {'param_1': 13, 'param_2': 'b'}
]

Example 4

base_config = {
    'param_1*': [
        {'param_2*': [20, 30, 50]},
        {'param_3*': ['Big', 'Small']}
    ]
}
expand_configs(base_config)

Returns:

[
    {'param_1': {'param_2': 20}}, 
    {'param_1': {'param_2': 30}},
    {'param_1': {'param_2': 50}},  
    {'param_1': {'param_3': 'Big'}},
    {'param_1': {'param_3': 'Small'}}
]

Motivation Scenario

You would like to run a classification task on multiple parameters of multiple classifier types, and see which one performs better:
base_config = {
    'classifier*': [
        {'name': 'logistic_regression', 'max_iter*': [100, 200, 300]},
        {'name': 'xgboost', 'n_estimators*': [50, 100, 200], 'max_depth*': [3,4,5]}
    ]
}

To returns all the possible configurations of your setting:

expand_configs(base_config)

Returns:

[
    {'classifier': {'name': 'logistic_regression', 'max_iter': 100}}, 
    {'classifier': {'name': 'logistic_regression', 'max_iter': 200}}, 
    {'classifier': {'name': 'logistic_regression', 'max_iter': 300}}, 
    {'classifier': {'name': 'xgboost', 'n_estimators': 50, 'max_depth': 3}}, 
    {'classifier': {'name': 'xgboost', 'n_estimators': 50, 'max_depth': 4}}, 
    {'classifier': {'name': 'xgboost', 'n_estimators': 50, 'max_depth': 5}}, 
    {'classifier': {'name': 'xgboost', 'n_estimators': 100, 'max_depth': 3}}, 
    {'classifier': {'name': 'xgboost', 'n_estimators': 100, 'max_depth': 4}}, 
    {'classifier': {'name': 'xgboost', 'n_estimators': 100, 'max_depth': 5}}, 
    {'classifier': {'name': 'xgboost', 'n_estimators': 200, 'max_depth': 3}}, 
    {'classifier': {'name': 'xgboost', 'n_estimators': 200, 'max_depth': 4}}, 
    {'classifier': {'name': 'xgboost', 'n_estimators': 200, 'max_depth': 5}}
]

If you want to run evaluation on each configuration, you need to pass evaluation_function:

def evaluation_function(config):
    ...
results = expand_configs(base_config, evaluation_function)

The results list would have all the evaluation results on each config, then you can select the best result for your needs.

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

json-config-expander-0.6.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

json_config_expander-0.6-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file json-config-expander-0.6.tar.gz.

File metadata

  • Download URL: json-config-expander-0.6.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.8.0

File hashes

Hashes for json-config-expander-0.6.tar.gz
Algorithm Hash digest
SHA256 43a8f05a767711c01e6b931cb181b3248099e0de3798bf8c05e946da6a16dc0d
MD5 5257e4c5217438740fb95b586095db0e
BLAKE2b-256 e0c4ff131b7b468001c4aff29d72c2f93ad32fcf7cb6d91a6a6e807e05e40178

See more details on using hashes here.

File details

Details for the file json_config_expander-0.6-py3-none-any.whl.

File metadata

  • Download URL: json_config_expander-0.6-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.8.0

File hashes

Hashes for json_config_expander-0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 abcd3e0b8ea28a515f4a3253d2c88aef22f54bda85572696ca6e184b9c3d07b2
MD5 0cb1e2b83fac17c11d8679e68ef58296
BLAKE2b-256 16d524a05d14a76a471f4a5bbd77789593fde5224b1da7b46c2b01024156ec2b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page