Exemplo n.º 1
0
def pre(cfg):
    name = cfg["method"]
    sigma = cfg["sigma"]
    scale = cfg["scale"]
    K = cfg["K"]

    kernel = RBFKernel(sigma=sigma,scale=scale)
    fastLogDet = FastIVM(K, kernel, 1.0)

    if name == "Greedy":
        opt = Greedy(K, fastLogDet)
    if name == "IndependentSetImprovement":
        opt = IndependentSetImprovement(K, fastLogDet)
    elif name == "Random":
        opt = Random(K, fastLogDet, cfg["run_id"])
    elif name == "SieveStreaming":
        e = cfg["epsilon"]
        opt = SieveStreaming(K, fastLogDet, 1.0, e)
    elif name == "SieveStreaming++":
        e = cfg["epsilon"]
        opt = SieveStreamingPP(K, fastLogDet, 1.0, e)
    elif name == "Salsa":
        e = cfg["epsilon"]
        opt = Salsa(K, fastLogDet, 1.0, e)
    elif name == "ThreeSieves":
        e = cfg["epsilon"]
        T = cfg["T"]
        opt = ThreeSieves(K, fastLogDet, 1.0, e, "sieve", T)
    return opt
# Define all the kernel / submodular function combinations
kernel = RBFKernel(sigma=1,scale=1)
ivm_rbf = FastIVM(K, kernel = kernel, sigma = 1.0)

kernel = PolyKernel()
ivm_custom_kernel_class = FastIVM(K, kernel = kernel, sigma = 1.0)
ivm_custom_kernel_function = FastIVM(K, kernel = poly_kernel, sigma = 1.0)

ivm_custom_class = FastLogdet(K)
ivm_custom_function = ivm

optimizers = {}

### GREEDY ### 
optimizers["Greedy with IVM + RBF"] = Greedy(K, ivm_rbf)
optimizers["Greedy with IVM + poly kernel class"] = Greedy(K, ivm_custom_kernel_class)
optimizers["Greedy with IVM + poly kernel function"] = Greedy(K, ivm_custom_kernel_function)
optimizers["Greedy with custom IVM class"] = Greedy(K, ivm_custom_class)
optimizers["Greedy with custom IVM function"] = Greedy(K, ivm_custom_function)

### Random ### 
# We "optimize" over the random seeds so that the solution matches the target solution and we do not need to distinguish 
# between Random and the other optimizers
optimizers["Random with IVM + RBF"] = Random(K, ivm_rbf, 12345)
optimizers["Random with IVM + poly kernel class"] = Random(K, ivm_custom_kernel_class, 22222)
optimizers["Random with IVM + poly kernel function"] = Random(K, ivm_custom_kernel_function, 22222)
optimizers["Random with custom IVM class"] = Random(K, ivm_custom_class, 12345)
optimizers["Random with custom IVM function"] = Random(K, ivm_custom_function, 12345)

### IndependentSetImprovement ###