-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '484-configuration-remove-combined-config' of https://gi…
…thub.com/hpi-epic/BP2021 into 484-configuration-remove-combined-config
- Loading branch information
Showing
27 changed files
with
387 additions
and
327 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from recommerce.configuration.utils import get_class | ||
|
||
from .utils import convert_python_type_to_input_type | ||
|
||
|
||
def get_agent_hyperparameter(agent: str, formdata: dict) -> list: | ||
|
||
# get all fields that are possible for this agent | ||
agent_class = get_class(agent) | ||
agent_specs = agent_class.get_configurable_fields() | ||
|
||
# we want to keep values already inside the html, so we need to parse existing html | ||
parameter_values = _convert_form_to_value_dict(formdata) | ||
# convert parameter into special list format for view | ||
all_parameter = [] | ||
for spec in agent_specs: | ||
this_parameter = {} | ||
this_parameter['name'] = spec[0] | ||
this_parameter['input_type'] = convert_python_type_to_input_type(spec[1]) | ||
this_parameter['prefill'] = _get_value_from_dict(spec[0], parameter_values) | ||
all_parameter += [this_parameter] | ||
return all_parameter | ||
|
||
|
||
def get_rl_parameter_prefill(prefill: dict, error: dict) -> list: | ||
# returns list of dictionaries | ||
all_parameter = [] | ||
for key, value in prefill.items(): | ||
this_parameter = {} | ||
this_parameter['name'] = key | ||
this_parameter['prefill'] = value if value else '' | ||
this_parameter['error'] = error[key] if error[key] else '' | ||
all_parameter += [this_parameter] | ||
return all_parameter | ||
|
||
|
||
def _convert_form_to_value_dict(config_form) -> dict: | ||
final_values = {} | ||
for index in range((len(config_form) - 2) // 2): | ||
current_name = config_form[f'formdata[{index}][name]'] | ||
current_value = config_form[f'formdata[{index}][value]'] | ||
if 'hyperparameter-rl' in current_name: | ||
final_values[current_name.replace('hyperparameter-rl-', '')] = current_value | ||
return final_values | ||
|
||
|
||
def _get_value_from_dict(key, value_dict) -> dict: | ||
try: | ||
return value_dict[key] | ||
except KeyError: | ||
return '' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
...usiness_app/migrations/0013_rlconfig_stable_baseline_test_rlconfig_testvalue2_and_more.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# Generated by Django 4.0.1 on 2022-06-01 18:36 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('alpha_business_app', '0012_config_user_container_user'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='rlconfig', | ||
name='stable_baseline_test', | ||
field=models.FloatField(default=None, null=True), | ||
), | ||
migrations.AddField( | ||
model_name='rlconfig', | ||
name='testvalue2', | ||
field=models.FloatField(default=None, null=True), | ||
), | ||
migrations.AlterField( | ||
model_name='rlconfig', | ||
name='batch_size', | ||
field=models.IntegerField(default=None, null=True), | ||
), | ||
migrations.AlterField( | ||
model_name='rlconfig', | ||
name='epsilon_decay_last_frame', | ||
field=models.IntegerField(default=None, null=True), | ||
), | ||
migrations.AlterField( | ||
model_name='rlconfig', | ||
name='epsilon_final', | ||
field=models.FloatField(default=None, null=True), | ||
), | ||
migrations.AlterField( | ||
model_name='rlconfig', | ||
name='epsilon_start', | ||
field=models.FloatField(default=None, null=True), | ||
), | ||
migrations.AlterField( | ||
model_name='rlconfig', | ||
name='gamma', | ||
field=models.FloatField(default=None, null=True), | ||
), | ||
migrations.AlterField( | ||
model_name='rlconfig', | ||
name='learning_rate', | ||
field=models.FloatField(default=None, null=True), | ||
), | ||
migrations.AlterField( | ||
model_name='rlconfig', | ||
name='replay_size', | ||
field=models.IntegerField(default=None, null=True), | ||
), | ||
migrations.AlterField( | ||
model_name='rlconfig', | ||
name='replay_start_size', | ||
field=models.IntegerField(default=None, null=True), | ||
), | ||
migrations.AlterField( | ||
model_name='rlconfig', | ||
name='sync_target_frames', | ||
field=models.IntegerField(default=None, null=True), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
webserver/alpha_business_app/tests/test_adjustable_fields.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from django.test import TestCase | ||
|
||
from ..adjustable_fields import get_rl_parameter_prefill | ||
|
||
|
||
class AdjustableFieldsTests(TestCase): | ||
def test_rl_hyperparameter_with_prefill(self): | ||
prefill_dict = {'gamma': 0.9, 'learning_rate': 0.4, 'test': None} | ||
error_dict = {'gamma': 'test', 'learning_rate': None, 'test': None} | ||
expected_list = [ | ||
{'name': 'gamma', 'prefill': 0.9, 'error': 'test'}, | ||
{'name': 'learning_rate', 'prefill': 0.4, 'error': ''}, | ||
{'name': 'test', 'prefill': '', 'error': ''} | ||
] | ||
actual_list = get_rl_parameter_prefill(prefill_dict, error_dict) | ||
assert actual_list == expected_list |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.