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
# Target solutions depending on the kernel
target_rbf = np.array(sorted([
    [0.0,0.0],
    [1.0,1.0],
    [0.0,1.0]
]))

target_poly = np.array(sorted([
    [0.0,1.0],
    [1.0,1.0], 
    [1.0,1.0]
]))

# 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)