Beispiel #1
0
def test_generate_by_line2():

    pm = ParameterHelper(verbose="DEBUG")
    pm.define_group("specie", "O", ["O"])
    pm.define_group("specie", "rest", ["C", "H"])
    pm.define_group("twobody", "**", ["*", "*"])
    pm.define_group("twobody", "OO", ["O", "O"])
    pm.define_group("threebody", "***", ["*", "*", "*"])
    pm.define_group("threebody", "Oall", ["O", "O", "O"])
    pm.set_parameters("**", [1, 0.5])
    pm.set_parameters("OO", [1, 0.5])
    pm.set_parameters("Oall", [1, 0.5])
    pm.set_parameters("***", [1, 0.5])
    pm.set_parameters("cutoff_twobody", 5)
    pm.set_parameters("cutoff_threebody", 4)
    hm = pm.as_dict()
    Parameters.check_instantiation(hm["hyps"], hm["cutoffs"], hm["kernels"], hm)
Beispiel #2
0
def test_generate_by_line2():

    pm = ParameterHelper(verbose="DEBUG")
    pm.define_group('specie', 'O', ['O'])
    pm.define_group('specie', 'rest', ['C', 'H'])
    pm.define_group('twobody', '**', ['*', '*'])
    pm.define_group('twobody', 'OO', ['O', 'O'])
    pm.define_group('threebody', '***', ['*', '*', '*'])
    pm.define_group('threebody', 'Oall', ['O', 'O', 'O'])
    pm.set_parameters('**', [1, 0.5])
    pm.set_parameters('OO', [1, 0.5])
    pm.set_parameters('Oall', [1, 0.5])
    pm.set_parameters('***', [1, 0.5])
    pm.set_parameters('cutoff_twobody', 5)
    pm.set_parameters('cutoff_threebody', 4)
    hm = pm.as_dict()
    Parameters.check_instantiation(
        hm['hyps'], hm['cutoffs'], hm['kernels'], hm)
Beispiel #3
0
def generate_hm(ntwobody,
                nthreebody,
                nmanybody=1,
                constraint=False,
                multihyps=True):

    cutoff = 0.8
    if multihyps is False:
        kernels = []
        parameters = {}
        if ntwobody > 0:
            kernels += ["twobody"]
            parameters["cutoff_twobody"] = cutoff
        if nthreebody > 0:
            kernels += ["threebody"]
            parameters["cutoff_threebody"] = cutoff
        if nmanybody > 0:
            kernels += ["manybody"]
            parameters["cutoff_manybody"] = cutoff
        pm = ParameterHelper(kernels=kernels,
                             random=True,
                             parameters=parameters)
        hm = pm.as_dict()
        hyps = hm["hyps"]
        cut = hm["cutoffs"]
        return hyps, hm, cut

    pm = ParameterHelper(species=["H", "He"], parameters={"noise": 0.05})
    if ntwobody > 0:
        pm.define_group("twobody", "b1", ["*", "*"], parameters=random(2))
        pm.set_parameters("cutoff_twobody", cutoff)
    if nthreebody > 0:
        pm.define_group("threebody",
                        "t1", ["*", "*", "*"],
                        parameters=random(2))
        pm.set_parameters("cutoff_threebody", cutoff)
    if nmanybody > 0:
        pm.define_group("manybody",
                        "manybody1", ["*", "*"],
                        parameters=random(2))
        pm.set_parameters("cutoff_manybody", cutoff)
    if ntwobody > 1:
        pm.define_group("twobody", "b2", ["H", "H"], parameters=random(2))
    if nthreebody > 1:
        pm.define_group("threebody",
                        "t2", ["H", "H", "H"],
                        parameters=random(2))

    if constraint is False:
        hm = pm.as_dict()
        hyps = hm["hyps"]
        cut = hm["cutoffs"]
        return hyps, hm, cut

    pm.set_constraints("b1", opt=[True, False])
    pm.set_constraints("t1", opt=[False, True])
    hm = pm.as_dict()
    hyps = hm["hyps"]
    cut = hm["cutoffs"]
    return hyps, hm, cut
Beispiel #4
0
def generate_hm(ntwobody, nthreebody, nmanybody=1, constraint=False, multihyps=True):

    cutoff = 0.8
    if (multihyps is False):
        kernels = []
        parameters = {}
        if (ntwobody > 0):
            kernels += ['twobody']
            parameters['cutoff_twobody'] = cutoff
        if (nthreebody > 0):
            kernels += ['threebody']
            parameters['cutoff_threebody'] = cutoff
        if (nmanybody > 0):
            kernels += ['manybody']
            parameters['cutoff_manybody'] = cutoff
        pm = ParameterHelper(kernels=kernels, random=True,
                parameters=parameters)
        hm = pm.as_dict()
        hyps = hm['hyps']
        cut = hm['cutoffs']
        return hyps, hm, cut

    pm = ParameterHelper(species=['H', 'He'], parameters={'noise':0.05})
    if (ntwobody > 0):
        pm.define_group('twobody', 'b1', ['*', '*'], parameters=random(2))
        pm.set_parameters('cutoff_twobody', cutoff)
    if (nthreebody > 0):
        pm.define_group('threebody', 't1', ['*', '*', '*'], parameters=random(2))
        pm.set_parameters('cutoff_threebody', cutoff)
    if (nmanybody > 0):
        pm.define_group('manybody', 'manybody1', ['*', '*'], parameters=random(2))
        pm.set_parameters('cutoff_manybody', cutoff)
    if (ntwobody > 1):
        pm.define_group('twobody', 'b2', ['H', 'H'], parameters=random(2))
    if (nthreebody > 1):
        pm.define_group('threebody', 't2', ['H', 'H', 'H'], parameters=random(2))

    if (constraint is False):
        hm = pm.as_dict()
        hyps = hm['hyps']
        cut = hm['cutoffs']
        return hyps, hm, cut

    pm.set_constraints('b1', opt=[True, False])
    pm.set_constraints('t1', opt=[False, True])
    hm = pm.as_dict()
    hyps = hm['hyps']
    cut = hm['cutoffs']
    return hyps, hm, cut
Beispiel #5
0
def generate_diff_hm(kernels, diff_cutoff=False, constraint=False):

    pm = ParameterHelper(species=["H", "He"], parameters={"noise": 0.05})

    if "twobody" in kernels:
        para1 = 2.5 + 0.1 * random(3)
        para2 = 2.5 + 0.1 * random(3)
        pm.set_parameters("cutoff_twobody", para1[-1])
        pm.define_group("twobody", "twobody0", ["*", "*"])
        pm.set_parameters("twobody0", para1[:-1], not constraint)
        pm.define_group("twobody", "twobody1", ["H", "H"], para2[:-1])

        if diff_cutoff:
            pm.set_parameters("twobody0", para1, not constraint)
            pm.set_parameters("twobody1", para2)

    if "threebody" in kernels:
        para1 = 1.2 + 0.1 * random(3)
        para2 = 1.2 + 0.1 * random(3)
        pm.set_parameters("cutoff_threebody", para1[-1])
        pm.define_group("threebody", "threebody0", ["*", "*", "*"], para1[:-1])
        pm.set_parameters("threebody0", para1[:-1], not constraint)
        pm.define_group("threebody", "threebody1", ["H", "H", "H"], para2[:-1])

        if diff_cutoff:
            pm.define_group("cut3b", "c1", ["*", "*"], parameters=para1)
            pm.define_group("cut3b", "c2", ["H", "H"], parameters=para2)

    if "manybody" in kernels:
        para1 = 1.2 + 0.1 * random(3)
        para2 = 1.2 + 0.1 * random(3)

        pm.set_parameters("cutoff_manybody", para1[-1])
        pm.define_group("manybody", "manybody0", ["*", "*"])
        pm.set_parameters("manybody0", para1[:-1], not constraint)
        pm.define_group("manybody", "manybody1", ["H", "H"], para2[:-1])

        if diff_cutoff:
            pm.set_parameters("manybody0", para1, not constraint)
            pm.set_parameters("manybody1", para2)

    hm = pm.as_dict()
    hyps = hm["hyps"]
    cut = hm["cutoffs"]

    return cut, hyps, hm
Beispiel #6
0
def generate_same_hm(kernels, multi_cutoff=False):
    """
    generate hyperparameter and masks that are effectively the same
    but with single or multi group expression
    """
    pm1 = ParameterHelper(species=["H", "He"], parameters={"noise": 0.05})

    pm2 = ParameterHelper(species=["H", "He"], parameters={"noise": 0.05})

    if "twobody" in kernels:
        para = 2.5 + 0.1 * random(3)
        pm1.set_parameters("cutoff_twobody", para[-1])
        pm1.define_group("twobody", "twobody0", ["*", "*"], para[:-1])

        pm2.set_parameters("cutoff_twobody", para[-1])
        pm2.define_group("twobody", "twobody0", ["*", "*"], para[:-1])
        pm2.define_group("twobody", "twobody1", ["H", "H"], para[:-1])

        if multi_cutoff:
            pm2.set_parameters("twobody0", para)
            pm2.set_parameters("twobody1", para)

    if "threebody" in kernels:
        para = 1.2 + 0.1 * random(3)
        pm1.set_parameters("cutoff_threebody", para[-1])
        pm1.define_group("threebody", "threebody0", ["*", "*", "*"], para[:-1])

        pm2.set_parameters("cutoff_threebody", para[-1])
        pm2.define_group("threebody", "threebody0", ["*", "*", "*"], para[:-1])
        pm2.define_group("threebody", "threebody1", ["H", "H", "H"], para[:-1])

        if multi_cutoff:
            pm2.define_group("cut3b", "c1", ["*", "*"], parameters=para)
            pm2.define_group("cut3b", "c2", ["H", "H"], parameters=para)

    if "manybody" in kernels:
        para = 1.2 + 0.1 * random(3)

        pm1.set_parameters("cutoff_manybody", para[-1])
        pm1.define_group("manybody", "manybody0", ["*", "*"], para[:-1])

        pm2.set_parameters("cutoff_manybody", para[-1])
        pm2.define_group("manybody", "manybody0", ["*", "*"], para[:-1])
        pm2.define_group("manybody", "manybody1", ["H", "H"], para[:-1])

        if multi_cutoff:
            pm2.set_parameters("manybody0", para)
            pm2.set_parameters("manybody1", para)

    hm1 = pm1.as_dict()
    hyps1 = hm1["hyps"]
    cut = hm1["cutoffs"]

    hm2 = pm2.as_dict()
    hyps2 = hm2["hyps"]
    cut = hm2["cutoffs"]

    return cut, hyps1, hyps2, hm1, hm2
Beispiel #7
0
def test_generate_by_line():

    pm = ParameterHelper(verbose="DEBUG")
    pm.define_group('specie', 'O', ['O'])
    pm.define_group('specie', 'C', ['C'])
    pm.define_group('specie', 'H', ['H'])
    pm.define_group('twobody', '**', ['C', 'H'])
    pm.define_group('twobody', 'OO', ['O', 'O'], atomic_str=True)
    pm.define_group('threebody', '***', ['O', 'O', 'C'])
    pm.define_group('threebody', 'OOO', ['O', 'O', 'O'])
    pm.define_group('manybody', '1.5', ['C', 'H'])
    pm.define_group('manybody', '1.5', ['C', 'O'])
    pm.define_group('manybody', '1.5', ['O', 'H'])
    pm.define_group('manybody', '2', ['O', 'O'])
    pm.define_group('manybody', '2', ['H', 'O'])
    pm.define_group('manybody', '2.8', ['O', 'O'])
    pm.set_parameters('**', [1, 0.5])
    pm.set_parameters('OO', [1, 0.5])
    pm.set_parameters('***', [1, 0.5])
    pm.set_parameters('OOO', [1, 0.5])
    pm.set_parameters('1.5', [1, 0.5, 1.5])
    pm.set_parameters('2', [1, 0.5, 2])
    pm.set_parameters('2.8', [1, 0.5, 2.8])
    pm.set_constraints('2', [True, False])
    pm.set_constraints('2.8', False)
    pm.set_parameters('cutoff_twobody', 5)
    pm.set_parameters('cutoff_threebody', 4)
    pm.set_parameters('cutoff_manybody', 3)
    hm = pm.as_dict()
    Parameters.check_instantiation(
        hm['hyps'], hm['cutoffs'], hm['kernels'], hm)
Beispiel #8
0
def test_generate_by_line():

    pm = ParameterHelper(verbose="DEBUG")
    pm.define_group("specie", "O", ["O"])
    pm.define_group("specie", "C", ["C"])
    pm.define_group("specie", "H", ["H"])
    pm.define_group("twobody", "**", ["C", "H"])
    pm.define_group("twobody", "OO", ["O", "O"], atomic_str=True)
    pm.define_group("threebody", "***", ["O", "O", "C"])
    pm.define_group("threebody", "OOO", ["O", "O", "O"])
    pm.define_group("manybody", "1.5", ["C", "H"])
    pm.define_group("manybody", "1.5", ["C", "O"])
    pm.define_group("manybody", "1.5", ["O", "H"])
    pm.define_group("manybody", "2", ["O", "O"])
    pm.define_group("manybody", "2", ["H", "O"])
    pm.define_group("manybody", "2.8", ["O", "O"])
    pm.set_parameters("**", [1, 0.5])
    pm.set_parameters("OO", [1, 0.5])
    pm.set_parameters("***", [1, 0.5])
    pm.set_parameters("OOO", [1, 0.5])
    pm.set_parameters("1.5", [1, 0.5, 1.5])
    pm.set_parameters("2", [1, 0.5, 2])
    pm.set_parameters("2.8", [1, 0.5, 2.8])
    pm.set_constraints("2", [True, False])
    pm.set_constraints("2.8", False)
    pm.set_parameters("cutoff_twobody", 5)
    pm.set_parameters("cutoff_threebody", 4)
    pm.set_parameters("cutoff_manybody", 3)
    hm = pm.as_dict()
    Parameters.check_instantiation(hm["hyps"], hm["cutoffs"], hm["kernels"], hm)
Beispiel #9
0
def generate_diff_hm(kernels, diff_cutoff=False, constraint=False):

    pm = ParameterHelper(species=['H', 'He'], parameters={'noise': 0.05})

    if ('twobody' in kernels):
        para1 = 2.5 + 0.1 * random(3)
        para2 = 2.5 + 0.1 * random(3)
        pm.set_parameters('cutoff_twobody', para1[-1])
        pm.define_group('twobody', 'twobody0', ['*', '*'])
        pm.set_parameters('twobody0', para1[:-1], not constraint)
        pm.define_group('twobody', 'twobody1', ['H', 'H'], para2[:-1])

        if (diff_cutoff):
            pm.set_parameters('twobody0', para1, not constraint)
            pm.set_parameters('twobody1', para2)

    if ('threebody' in kernels):
        para1 = 1.2 + 0.1 * random(3)
        para2 = 1.2 + 0.1 * random(3)
        pm.set_parameters('cutoff_threebody', para1[-1])
        pm.define_group('threebody', 'threebody0', ['*', '*', '*'], para1[:-1])
        pm.set_parameters('threebody0', para1[:-1], not constraint)
        pm.define_group('threebody', 'threebody1', ['H', 'H', 'H'], para2[:-1])

        if (diff_cutoff):
            pm.define_group('cut3b', 'c1', ['*', '*'], parameters=para1)
            pm.define_group('cut3b', 'c2', ['H', 'H'], parameters=para2)

    if ('manybody' in kernels):
        para1 = 1.2 + 0.1 * random(3)
        para2 = 1.2 + 0.1 * random(3)

        pm.set_parameters('cutoff_manybody', para1[-1])
        pm.define_group('manybody', 'manybody0', ['*', '*'])
        pm.set_parameters('manybody0', para1[:-1], not constraint)
        pm.define_group('manybody', 'manybody1', ['H', 'H'], para2[:-1])

        if (diff_cutoff):
            pm.set_parameters('manybody0', para1, not constraint)
            pm.set_parameters('manybody1', para2)

    hm = pm.as_dict()
    hyps = hm['hyps']
    cut = hm['cutoffs']

    return cut, hyps, hm
Beispiel #10
0
def generate_same_hm(kernels, multi_cutoff=False):
    """
    generate hyperparameter and masks that are effectively the same
    but with single or multi group expression
    """
    pm1 = ParameterHelper(species=['H', 'He'], parameters={'noise': 0.05})

    pm2 = ParameterHelper(species=['H', 'He'], parameters={'noise': 0.05})

    if ('twobody' in kernels):
        para = 2.5 + 0.1 * random(3)
        pm1.set_parameters('cutoff_twobody', para[-1])
        pm1.define_group('twobody', 'twobody0', ['*', '*'], para[:-1])

        pm2.set_parameters('cutoff_twobody', para[-1])
        pm2.define_group('twobody', 'twobody0', ['*', '*'], para[:-1])
        pm2.define_group('twobody', 'twobody1', ['H', 'H'], para[:-1])

        if (multi_cutoff):
            pm2.set_parameters('twobody0', para)
            pm2.set_parameters('twobody1', para)

    if ('threebody' in kernels):
        para = 1.2 + 0.1 * random(3)
        pm1.set_parameters('cutoff_threebody', para[-1])
        pm1.define_group('threebody', 'threebody0', ['*', '*', '*'], para[:-1])

        pm2.set_parameters('cutoff_threebody', para[-1])
        pm2.define_group('threebody', 'threebody0', ['*', '*', '*'], para[:-1])
        pm2.define_group('threebody', 'threebody1', ['H', 'H', 'H'], para[:-1])

        if (multi_cutoff):
            pm2.define_group('cut3b', 'c1', ['*', '*'], parameters=para)
            pm2.define_group('cut3b', 'c2', ['H', 'H'], parameters=para)

    if ('manybody' in kernels):
        para = 1.2 + 0.1 * random(3)

        pm1.set_parameters('cutoff_manybody', para[-1])
        pm1.define_group('manybody', 'manybody0', ['*', '*'], para[:-1])

        pm2.set_parameters('cutoff_manybody', para[-1])
        pm2.define_group('manybody', 'manybody0', ['*', '*'], para[:-1])
        pm2.define_group('manybody', 'manybody1', ['H', 'H'], para[:-1])

        if (multi_cutoff):
            pm2.set_parameters('manybody0', para)
            pm2.set_parameters('manybody1', para)

    hm1 = pm1.as_dict()
    hyps1 = hm1['hyps']
    cut = hm1['cutoffs']

    hm2 = pm2.as_dict()
    hyps2 = hm2['hyps']
    cut = hm2['cutoffs']

    return cut, hyps1, hyps2, hm1, hm2