嵌套字典结构对字典列表的排列在python中保持相同的结构

时间:2017-11-10 21:32:45

标签: python json dictionary permutation

我有以下JSON /字典结构。

{
    "layers": [{
            "type": "fc",
            "name": "fc1",
            "nodes": [100, 200],
            "activation": "relu",
            "dropout": false
        }, {
            "type": "fc",
            "name": "fc2",
            "nodes": 50,
            "activation": ["relu", "tanh"],
            "dropout": false
        }
    ],
    "hyper_parameters": {
        "dropout": [0.25, 0.30],
        "lr": [0.01, 0.002, 0.5],
        "lr_decay": 1,
        "epochs": 100,
        "epoch_no_imprv": 10,
        "batch_size": 100
    }
}

我想生成上述结构的所有排列,只要有列表,保留相同的结构。 所以上面的结构应该生成24个这样的结构列表。 显示下面的样本4结构。

[
    {
        "layers": [{
                "type": "fc",
                "name": "fc1",
                "nodes": 100,
                "activation": "relu",
                "dropout": false
            }, {
                "type": "fc",
                "name": "fc2",
                "nodes": 50,
                "activation": "relu",
                "dropout": false
            }
        ],
        "hyper_parameters": {
            "dropout": 0.25,
            "lr": 0.01,
            "lr_decay": 1,
            "epochs": 100,
            "epoch_no_imprv": 10,
            "batch_size": 100
        }
    },
    {
        "layers": [{
                "type": "fc",
                "name": "fc1",
                "nodes": 200,
                "activation": "relu",
                "dropout": false
            }, {
                "type": "fc",
                "name": "fc2",
                "nodes": 50,
                "activation": "relu",
                "dropout": false
            }
        ],
        "hyper_parameters": {
            "dropout": 0.25,
            "lr": 0.01,
            "lr_decay": 1,
            "epochs": 100,
            "epoch_no_imprv": 10,
            "batch_size": 100
        }
    },
    {
        "layers": [{
                "type": "fc",
                "name": "fc1",
                "nodes": 100,
                "activation": "relu",
                "dropout": false
            }, {
                "type": "fc",
                "name": "fc2",
                "nodes": 50,
                "activation": "tanh",
                "dropout": false
            }
        ],
        "hyper_parameters": {
            "dropout": 0.25,
            "lr": 0.01,
            "lr_decay": 1,
            "epochs": 100,
            "epoch_no_imprv": 10,
            "batch_size": 100
        }
    },
    {
        "layers": [{
                "type": "fc",
                "name": "fc1",
                "nodes": 200,
                "activation": "relu",
                "dropout": false
            }, {
                "type": "fc",
                "name": "fc2",
                "nodes": 50,
                "activation": "tanh",
                "dropout": false
            }
        ],
        "hyper_parameters": {
            "dropout": 0.25,
            "lr": 0.01,
            "lr_decay": 1,
            "epochs": 100,
            "epoch_no_imprv": 10,
            "batch_size": 100
        }
    }
]

这里,以下键可以有列表,但我更喜欢它是否可以通用

节点,激活,退出,lr。

“图层”列表可以包含任意数量的图层。

实现相同目标的任何其他简化结构也将起作用。

0 个答案:

没有答案