Beispiel #1
0
def get_cxx_kernel(options):
    options_cxx = soap.Options()
    log << "Kernel:" << log.endl
    for k, v in options.iteritems():
        log << "- Setting %s=%s" % (k, str(v)) << log.endl
        options_cxx.set(k, v)
    kernel = soap.Kernel(options_cxx)
    return kernel
Beispiel #2
0
def evaluate_kernel(dset, options):
    kernel = soap.Kernel(options)
    symmetric = True
    K = kernel.evaluate(dset, dset, symmetric, "float64")
    z = 1. / np.sqrt(K.diagonal())
    K = K * np.outer(z, z)
    log << log.mg << "Kernel =" << log.endl
    log << K << log.endl
    return K
Beispiel #3
0
def evaluate_kernel(dset, options=None, kernel=None):
    assert not (options == kernel == None)
    if kernel is None: kernel = soap.Kernel(options)
    symmetric = True
    kernel.evaluateAll(dset, dset, symmetric)
    for slot in range(kernel.n_output):
        K = kernel.getOutput(slot, "float64")
        z = 1. / np.sqrt(K.diagonal())
        K = K * np.outer(z, z)
        log << "Kernel: Output slot" << slot << log.endl
        log << K << log.endl
Beispiel #4
0
def test_reduction_matrix_average(options):
    log << log.mg << "<test_reduction_matrix_average>" << log.flush
    kernel_options = soap.Options()
    kernel_options.set("basekernel_type", "dot")
    kernel_options.set("base_exponent", 3.)
    kernel_options.set("base_filter", False)
    kernel_options.set("topkernel_type", "average")
    kernel = soap.Kernel(kernel_options)
    for i in range(9):
        K_base = np.random.uniform(size=(i + 1, ((i + 2) % 4) + 1))
        k = kernel.evaluateTop(K_base, "float64")
        P = kernel.attributeTopGetReductionMatrix(K_base, "float64")
        k_red = np.sum(K_base * P)
        assert_equal(k - k_red, 0.0, 1e-6)
    log << log.endl
Beispiel #5
0
def test_attribution_average(dset, options):
    log << log.mg << "<test_attribution_average>" << log.flush
    kernel_options = soap.Options()
    kernel_options.set("basekernel_type", "dot")
    kernel_options.set("base_exponent", 3.)
    kernel_options.set("base_filter", False)
    kernel_options.set("topkernel_type", "average")
    kernel = soap.Kernel(kernel_options)
    K = kernel.evaluate(dset, dset, False, "float64")
    for i in range(len(dset)):
        KK = kernel.attributeLeft(dset[i], dset, "float64")
        KK_sum = np.sum(KK, axis=0)
        for j in range(len(dset)):
            assert_equal(KK_sum[j] - K[i, j], 0.0, 1e-6)
    log << log.endl
Beispiel #6
0
if __name__ == "__main__":
    configs = soap.tools.io.read('data/structures.xyz')

    # Compute SOAP descriptors
    options = soap.soapy.configure_default()
    dset = evaluate_soap(configs, options)

    # Multikernel: Variant A
    log << log.mg << "Variant A" << log.endl
    kernel_options = soap.Options()
    kernel_options.set("basekernel_type", "dot")
    kernel_options.set("base_exponent", 3.)
    kernel_options.set("base_filter", False)
    kernel_options.set("topkernel_type", "average;canonical;rematch")
    kernel_options.set("canonical_beta", 0.5)
    kernel_options.set("rematch_gamma", 0.05)
    kernel_options.set("rematch_eps", 1e-6)
    kernel_options.set("rematch_omega", 1.0)
    evaluate_kernel(dset, options=kernel_options)

    # Multikernel: Variant B
    log << log.mg << "Variant B" << log.endl
    kernel_options.set("topkernel_type", "")
    kernel = soap.Kernel(kernel_options)
    for beta in [0.01, 0.05, 0.1, 0.5, 1.0, 10.0, 100.0]:
        kernel_options.set("topkernel_type", "canonical")
        kernel_options.set("canonical_beta", beta)
        kernel.addTopkernel(kernel_options)
    evaluate_kernel(dset, kernel=kernel)
Beispiel #7
0
 def __init__(self, kernel_options_top, kernel_options_super):
     self.kernel_top = soap.Kernel(kernel_options_top)
     self.kernel_super = soap.Kernel(kernel_options_super)
     return