Beispiel #1
0
def main():
    bench = Benchmark()

    for num_function in range(INITIAL_FUNCTION, LAST_FUNCTION + 1):
        info = bench.get_info(num_function)
        print(f'\nFunction {num_function}: {info}')

        for i in range(INITIAL_EJECUTION, LAST_EJECUTION + 1):
            BKS = info['best']
            D = info['dimension']
            NP = 30
            N_Gen = 5000
            A = 0.95
            r = 0.1
            alpha = 0.9
            gamma = 0.5
            fmin = 0
            fmax = 1
            Lower = info['lower']
            Upper = info['upper']
            ObjetiveFunction = bench.get_function(num_function)

            name_ejecution_file = f'function{num_function}_{i}.csv'
            name_logs_file = 'Logs/' + name_ejecution_file
            name_cluster_file = 'Logs/clusters/' + name_ejecution_file

            bats = BatAlgorithm(num_function, i, BKS, D, NP, N_Gen, A, r,
                                alpha, gamma, fmin, fmax, Lower, Upper,
                                ObjetiveFunction)
            bats.move_bats(name_logs_file, name_cluster_file, ORIGINAL_MH, 100)
Beispiel #2
0
def CC_exe(Dim, func_num, NIND, Max_iteration, scale_range, groups, method):
    bench = Benchmark()
    function = bench.get_function(func_num)
    name = 'f' + str(func_num)
    print(name, 'Optimization with', method)

    """The next is DE optimization"""
    best_indexes, best_obj_trace = DE.CC(Dim, NIND, Max_iteration, function, scale_range, groups)
    help.write_obj_trace(name, method, best_obj_trace)
Beispiel #3
0
def DECC_CL_exe(Dim, func_num, NIND, Max_iteration, scale_range, groups_One, groups_Lasso, Lasso_cost, candidate, method):
    bench = Benchmark()
    function = bench.get_function(func_num)
    EFs = 3000000
    name = 'f' + str(func_num)
    print(name, 'Optimization with', method)

    """The next is DE optimization"""
    best_indexes, best_obj_trace_CC, Population, up, down, cost = DE.DECC_CL_CCDE(Dim, NIND, Max_iteration, function,
                                                                                  scale_range, groups_One, candidate)
Beispiel #4
0
def go_lsgo(func_id):

    from cec2013lsgo.cec2013 import Benchmark

    bench = Benchmark()

    bench_info = bench.get_info(func_id)

    dim = bench_info['dimension']

    return bench.get_function(func_id), None, [bench_info['lower']] * dim, [
        bench_info['upper']
    ] * dim
Beispiel #5
0
def DECC_CL_exe(Dim, func_num, NIND, scale_range, groups_One, groups_Lasso, Lasso_cost, method):
    bench = Benchmark()
    function = bench.get_function(func_num)
    EFs = 3000000
    name = 'f' + str(func_num)
    print(name, 'Optimization with', method)

    """The next is DE optimization"""
    best_indexes, best_obj_trace_CC, cost, up, down = DE.DECC_CL_CCDE(Dim, NIND, int((EFs - Lasso_cost) / (NIND * Dim)),
                                                                      function, scale_range, groups_One)

    central_point = best_indexes[len(best_indexes)-1]

    best_indexes, best_obj_trace_CL = DE.DECC_CL_DECC_L(Dim, NIND, int((EFs-Lasso_cost-cost)/(NIND*Dim)), function, up, down, groups_Lasso, central_point)
    help.write_obj_trace(name, method, best_obj_trace_CC+best_obj_trace_CL)
Beispiel #6
0
def DECC_D(func_num, groups_num=10, max_number=100):

    bench = Benchmark()
    function = bench.get_function(func_num)
    benchmark_summary = bench.get_info(func_num)
    scale_range = [benchmark_summary['lower'], benchmark_summary['upper']]
    Dim = 1000
    groups = k_s(10, max_number)
    delta = [0] * Dim
    NIND = 10000
    for i in range(len(groups)):
        delta[i * max_number:(i + 1) * max_number] = DE.OptTool(
            Dim, NIND, 1, function, groups[i], scale_range, -1)
    sort_index = np.argsort(delta).tolist()
    groups = []
    for i in range(groups_num):
        groups.append(sort_index[i * max_number:(i + 1) * max_number])
    return groups
Beispiel #7
0
def main():
    dims = 30
    pop_size = 20
    num_funcs = 23
    forces = [gsa.basicForce, bh.BHForce(1e5), bh.BHForce(0.5), bh.BHForce(1e-5), bh.BHForce(0)]
    columns = ["FUNCTION","SOLVER","BEST","ITERATIONS","TIME"]
    repetitions = 20
    
    condition = gsa.iterationCondition
    
    result = pd.DataFrame(columns = columns)

    #Run 23 original functions
    for prob_num in range(1,num_funcs + 1):
        func = functions.getFunction(prob_num,dims)
        for force in forces:
            func.desc = str(prob_num) + "-" + force.desc
            print("Processing problem {0} with {1}".format(prob_num, force.desc))
            for i in range(repetitions):
                result = result.append(gsa.gsa(func,pop_size,force,condition, columns, outputProgress=True, suffix = "-" + str(i)), ignore_index = True)
        
    result.to_csv("out-" + condition.desc + ".csv", index = False)
    
    #Run 15 CEC2013 functions
    result = pd.DataFrame(columns = columns)

    for prob_num in range(1,Benchmark().get_num_functions() + 1):
        info = Benchmark().get_info(prob_num)
        dims = info['dimension']
        cec_func = Benchmark().get_function(prob_num)
        func = functions.FunctionMaker("cec-" + str(prob_num), [info['upper']]*dims, [info['lower']]*dims, dims, 
                                       False, lambda sol: cec_func(sol))
        for force in forces:
            func.desc = "cec-" + str(prob_num) + "-" + force.desc
            print("Processing problem {0} with {1}".format(prob_num, force.desc))
            for i in range(repetitions):
                result = result.append(gsa.gsa(func,pop_size,force,condition, columns, outputProgress=True, suffix = "-" + str(i)), ignore_index = True)
        
    result.to_csv("cec-" + condition.desc + ".csv", index = False)
Beispiel #8
0
def DECC_DG(func_num):
    cost = 2
    bench = Benchmark()
    function = bench.get_function(func_num)
    groups = CCDE(1000)
    intercept = function(np.zeros((1, 1000))[0])

    for i in range(len(groups) - 1):
        if i < len(groups) - 1:
            cost += 2
            index1 = np.zeros((1, 1000))[0]
            index1[groups[i][0]] = 1
            delta1 = function(index1) - intercept

            for j in range(i + 1, len(groups)):
                cost += 2
                if i < len(groups) - 1 and j < len(
                        groups) and not help.DG_Differential(
                            groups[i][0], groups[j][0], delta1, function,
                            intercept):
                    groups[i].extend(groups.pop(j))
                    j -= 1

    return groups, cost
from Asy_DECC_CL.DimensionReductionForSparse.main_interface import f
from Asy_DECC_CL.DimensionReductionForSparse.util import help
from Asy_DECC_CL.DimensionReductionForSparse.main_interface.grouping_main import LASSOCC, DECC_DG, DECC_D, DECC_G, CCDE, Normal
from cec2013lsgo.cec2013 import Benchmark
import time

if __name__ == '__main__':

    Dim = 1000
    NIND = 30
    bench = Benchmark()
    EFs = 3000000
    for func_num in [10]:
        test_time = 1
        name = 'f' + str(func_num)
        benchmark_summary = bench.get_info(func_num)
        scale_range = [benchmark_summary['lower'], benchmark_summary['upper']]

        # base_time = time.time()
        # groups_One = CCDE(Dim)
        # O_group_time = time.time()
        #
        # groups_DECC_DG, DECC_DG_cost = DECC_DG(func_num)
        # DG_group_time = time.time()

        # help.write_EFS_cost(name, 'DECC_DG_EFS', str(DECC_DG_cost))
        # [[0, 1, 2, 4, 5, 6, 7, 8, 9, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 25, 26, 28, 29, 31, 32, 33, 35, 36, 37, 38, 39, 40, 41, 42, 45, 46, 48], [3], [10, 30], [11], [24], [27], [34], [43], [47], [49], [44], [50], [51], [52], [53], [54], [55], [56], [57], [58, 75], [59], [60], [98, 61], [62], [63], [64], [65], [66], [67], [68], [69], [70], [77, 71], [72], [73], [74], [76], [78], [79], [80], [81], [82], [83], [84], [85], [86], [87], [88], [90], [91], [92], [93], [94], [95], [96], [97], [99], [89], [100], [101], [102], [103], [104], [105], [106], [107], [108], [109], [110], [111], [112], [113], [114], [115], [116], [117], [118], [119], [120], [121], [122], [123], [124], [125], [126], [127], [128], [129], [130], [131], [132], [133], [134], [135], [136], [137], [138], [139], [140], [141], [142], [143], [144], [145], [146], [147], [148], [149], [150], [151], [152], [153], [154], [155], [156], [157], [158], [159], [160], [161], [162], [163], [164], [165], [166], [167], [168], [169], [170], [171], [172], [173], [174], [175], [176], [177], [178], [179], [180], [181], [182], [183], [184], [185], [186], [187], [188], [189], [190], [191], [192], [193], [194], [195], [196], [197], [198], [199], [200], [201], [202], [203], [204], [205], [206], [207], [208], [209], [210], [211], [212], [213], [214], [215], [216], [217], [218], [219], [220], [221], [222], [223], [224], [225], [226], [227], [228], [229], [230], [231], [232], [233], [234], [235], [236], [237], [238], [239], [240], [241], [242], [243], [244], [245], [246], [247], [248], [249], [250], [251], [252], [253], [254], [255], [256], [257], [258], [259], [260], [261], [262], [263], [264], [265], [266], [267], [268], [269], [270], [271], [272], [273], [274], [275], [276], [277], [278], [279], [280], [281], [282], [283], [284], [285], [286], [287], [288], [289], [290], [291], [292], [293], [294], [295], [296], [297], [298], [299], [300], [301], [302], [303], [304], [305], [306], [307], [308], [309], [310], [311], [312], [313], [314], [315], [316], [317], [318], [319], [320], [321], [322], [323], [324], [325], [326], [327], [328], [329], [330], [331], [332], [333], [334], [335], [336], [337], [338], [339], [340], [341], [342], [343], [344], [345], [346], [347], [348], [349], [350], [351], [352], [354], [356], [357], [358], [359], [360], [361], [362], [363], [364], [365], [366], [367], [368], [369], [370], [371], [372], [373], [374], [375], [376], [377], [378], [379], [380], [381], [382], [383], [384], [385], [386], [387], [388], [389], [390], [391], [392], [393], [394], [395], [396], [397], [398], [399], [353, 355], [400], [401], [402], [403], [404], [405], [406], [407], [408], [409], [410], [411], [412], [413], [414], [415], [416], [417], [418], [419], [420], [421], [422], [423], [424], [425], [426], [427], [428], [429], [430], [431], [432], [433], [434], [435], [436], [437], [438], [439], [440], [441], [442], [443], [444], [445], [446], [447], [448], [449], [450], [451], [452], [453], [454], [455], [456], [457], [458], [459], [460], [461], [462], [463], [464], [465], [466], [467], [468], [470], [471], [472], [474], [475], [476], [477], [478], [479], [480], [481], [482], [483], [484], [485], [486], [487], [488], [489], [490], [491], [492], [493], [494], [495], [496], [497], [498], [499], [469, 473], [500], [501], [502], [503], [506], [507], [508], [509], [510], [511], [513], [514], [515], [516], [517], [518], [519], [520], [521], [522], [523], [524], [525], [526], [529], [530], [531], [533], [535], [536], [537], [538], [539], [540], [541], [543], [544], [545], [546], [547], [549], [504, 505, 512, 527, 528, 532, 534, 542, 548], [551], [552], [553], [555], [556], [557], [559], [560], [563], [564], [565], [566], [567], [568], [569], [570], [571], [575], [576], [577], [578], [579], [581], [582], [583], [585], [586], [588], [589], [590], [591], [592], [594], [596], [597], [550, 554, 558, 561, 562, 572, 573, 574, 580, 584, 587, 593, 595, 598, 599], [600], [602], [604], [606], [607], [608], [615], [616], [619], [620], [621], [623], [624], [625], [626], [628], [629], [630], [631], [633], [635], [636], [638], [639], [640], [641], [642], [643], [644], [645], [646], [647], [649], [601, 603, 605, 609, 610, 611, 612, 613, 614, 617, 618, 622, 627, 632, 634, 637, 648], [650], [651], [654], [655], [659], [660], [662], [664], [666], [667], [670], [671], [672], [673], [676], [677], [678], [680], [681], [682], [683], [684], [685], [688], [690], [692], [693], [694], [695], [696], [697], [652, 653, 656, 657, 658, 661, 663, 665, 668, 669, 674, 675, 679, 686, 687, 689, 691, 698, 699], [700], [701], [704], [706], [707], [709], [711], [712], [714], [716], [717], [718], [722], [723], [724], [726], [730], [731], [732], [733], [736], [738], [741], [742], [744], [702, 703, 705, 708, 710, 713, 715, 719, 720, 721, 725, 727, 728, 729, 734, 735, 737, 739, 740, 743, 745, 746, 747, 748, 749], [751], [756], [760], [761], [763], [768], [771], [772], [773], [776], [779], [781], [782], [784], [785], [787], [788], [790], [794], [795], [796], [797], [798], [750, 752, 753, 754, 755, 757, 758, 759, 762, 764, 765, 766, 767, 769, 770, 774, 775, 777, 778, 780, 783, 786, 789, 791, 792, 793, 799], [802], [803], [807], [809], [810], [811], [814], [815], [817], [820], [821], [822], [823], [826], [834], [835], [837], [839], [841], [842], [844], [845], [847], [800, 801, 804, 805, 806, 808, 812, 813, 816, 818, 819, 824, 825, 827, 828, 829, 830, 831, 832, 833, 836, 838, 840, 843, 846, 848, 849], [851], [852], [855], [857], [858], [861], [864], [866], [870], [871], [873], [875], [876], [881], [882], [884], [887], [888], [890], [895], [896], [898], [850, 853, 854, 856, 859, 860, 862, 863, 865, 867, 868, 869, 872, 874, 877, 878, 879, 880, 883, 885, 886, 889, 891, 892, 893, 894, 897, 899], [901], [902], [904], [908], [914], [916], [917], [918], [919], [920], [922], [924], [927], [931], [932], [940], [942], [943], [944], [945], [948], [900, 903, 905, 906, 907, 909, 910, 911, 912, 913, 915, 921, 923, 925, 926, 928, 929, 930, 933, 934, 935, 936, 937, 938, 939, 941, 946, 947, 949], [950], [952], [958], [959], [960], [961], [965], [968], [969], [972], [974], [976], [977], [978], [980], [981], [982], [984], [986], [987], [988], [989], [991], [992], [994], [995], [996], [997], [998], [951, 953, 954, 955, 956, 957, 962, 963, 964, 966, 967, 970, 971, 973, 975, 979, 983, 985, 990, 993, 999]]
        # [[550, 551, 552, 553, 554, 555, 556, 557, 558, 559, 560, 561, 562, 563, 564, 565, 566, 567, 568, 569, 570, 571, 572, 573, 574, 575, 576, 577, 578, 579, 580, 581, 582, 583, 584, 585, 586, 587, 588, 589, 590, 591, 592, 593, 594, 595, 596, 597, 598, 599, 600, 601, 602, 603, 604, 605, 606, 607, 608, 609, 610, 611, 612, 613, 614, 615, 616, 617, 618, 619, 620, 621, 622, 623, 624, 625, 626, 627, 628, 629, 630, 631, 632, 633, 634, 635, 636, 637, 638, 639, 640, 641, 642, 643, 644, 645, 646, 647, 648, 649, 800, 801, 802, 803, 804, 805, 806, 807, 808, 809, 810, 811, 812, 813, 814, 815, 816, 817, 818, 819, 820, 821, 822, 823, 824, 825, 826, 827, 828, 829, 830, 831, 832, 833, 834, 835, 836, 837, 838, 839, 840, 841, 842, 843, 844, 845, 846, 847, 848, 849, 950, 951, 952, 953, 954, 955, 956, 957, 958, 959, 960, 961, 962, 963, 964, 965, 966, 967, 968, 969, 970, 971, 972, 973, 974, 975, 976, 977, 978, 979, 980, 981, 982, 983, 984, 985, 986, 987, 988, 989, 990, 991, 992, 993, 994, 995, 996, 997, 998, 999], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49], [50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99], [100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149], [150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199], [200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249], [250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299], [300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, 323, 324, 325, 326, 327, 328, 329, 330, 331, 332, 333, 334, 335, 336, 337, 338, 339, 340, 341, 342, 343, 344, 345, 346, 347, 348, 349], [350, 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, 362, 363, 364, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, 381, 382, 383, 384, 385, 386, 387, 388, 389, 390, 391, 392, 393, 394, 395, 396, 397, 398, 399], [400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, 420, 421, 422, 423, 424, 425, 426, 427, 428, 429, 430, 431, 432, 433, 434, 435, 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, 446, 447, 448, 449], [450, 451, 452, 453, 454, 455, 456, 457, 458, 459, 460, 461, 462, 463, 464, 465, 466, 467, 468, 469, 470, 471, 472, 473, 474, 475, 476, 477, 478, 479, 480, 481, 482, 483, 484, 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, 497, 498, 499], [500, 501, 502, 503, 504, 505, 506, 507, 508, 509, 510, 511, 512, 513, 514, 515, 516, 517, 518, 519, 520, 521, 522, 523, 524, 525, 526, 527, 528, 529, 530, 531, 532, 533, 534, 535, 536, 537, 538, 539, 540, 541, 542, 543, 544, 545, 546, 547, 548, 549], [650, 651, 652, 653, 654, 655, 656, 657, 658, 659, 660, 661, 662, 663, 664, 665, 666, 667, 668, 669, 670, 671, 672, 673, 674, 675, 676, 677, 678, 679, 680, 681, 682, 683, 684, 685, 686, 687, 688, 689, 690, 691, 692, 693, 694, 695, 696, 697, 698, 699], [700, 701, 702, 703, 704, 705, 706, 707, 708, 709, 710, 711, 712, 713, 714, 715, 716, 717, 718, 719, 720, 721, 722, 723, 724, 725, 726, 727, 728, 729, 730, 731, 732, 733, 734, 735, 736, 737, 738, 739, 740, 741, 742, 743, 744, 745, 746, 747, 748, 749], [750, 751, 752, 753, 754, 755, 756, 757, 758, 759, 760, 761, 762, 763, 764, 765, 766, 767, 768, 769, 770, 771, 772, 773, 774, 775, 776, 777, 778, 779, 780, 781, 782, 783, 784, 785, 786, 787, 788, 789, 790, 791, 792, 793, 794, 795, 796, 797, 798, 799], [850, 851, 852, 853, 854, 855, 856, 857, 858, 859, 860, 861, 862, 863, 864, 865, 866, 867, 868, 869, 870, 871, 872, 873, 874, 875, 876, 877, 878, 879, 880, 881, 882, 883, 884, 885, 886, 887, 888, 889, 890, 891, 892, 893, 894, 895, 896, 897, 898, 899], [900, 901, 902, 903, 904, 905, 906, 907, 908, 909, 910, 911, 912, 913, 914, 915, 916, 917, 918, 919, 920, 921, 922, 923, 924, 925, 926, 927, 928, 929, 930, 931, 932, 933, 934, 935, 936, 937, 938, 939, 940, 941, 942, 943, 944, 945, 946, 947, 948, 949]]
        for i in range(test_time):

            # groups_Normal = Normal(Dim)
Beispiel #10
0
    maxFEs = 3e6
    checkpoints = (
        np.array([0.04, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0]) *
        maxFEs).astype(int)  #array

    for fid in Functions:
        #print("Processing f" + str(fid))
        filename = "myresults_" + str(popsize1) + "pop1_" + str(
            popsize2) + "pop2_f" + str(fid) + ".csv"
        outputfile = open(filename, "w+")
        outputfile.write("FEs,Value,Seed,Function\n")
        for Rseed in seeds:
            '''
			Set objective function: the CEC'13 LSGO Benchmark presents 15 minimization problems.  
			'''
            bench = Benchmark()
            fobj = bench.get_function(fid)  #objective function
            info = bench.get_info(
                fid
            )  #info is a dictionary which keys are lower, upper, dimension, threshold and best.
            '''
			Set parameters
			'''
            np.random.seed(Rseed)
            currentFEs = 0
            results = [
            ]  #list of tuples. Each tuple will be of the form (checkpoint,decision_vector,value_of_decision_vector)
            '''
			Set components
			'''
            DE1 = shade(fobj,
def main(args):
    global SR_MTS, SR_global_MTS
    """
    Main program. It uses
    Run DE for experiments. F, CR must be float, or 'n' as a normal
    """
    description = "SHADEILS"
    parser = argparse.ArgumentParser(description)
    parser.add_argument("-f",
                        default=16,
                        type=int,
                        dest="function",
                        help='function')
    # Argument for problem type: D4, D12 or D19, both with or without noise
    parser.add_argument("-pr",
                        required=True,
                        type=str,
                        choices=list(
                            ("D4", "D12", "D19", "D4N", "D12N", "D19N")),
                        dest="problem",
                        help='problem type')
    parser.add_argument("-v",
                        default=False,
                        dest="verbose",
                        action='store_true',
                        help='verbose mode')
    parser.add_argument("-s",
                        default=1,
                        type=int,
                        dest="seed",
                        choices=range(1, 6),
                        help='seed (1 - 5)')
    parser.add_argument("-r", default=1, type=int, dest="run", help='runs')
    parser.add_argument("-e",
                        required=False,
                        type=int,
                        dest="maxevals",
                        help='maxevals')
    # Argument for index of evals, that is [1,2,3] -> [1.2e5, 6e5,3e6]
    parser.add_argument("-i",
                        default=1,
                        type=int,
                        dest="index",
                        choices=range(1, 4),
                        help="index of evals")
    parser.add_argument("-t",
                        default=0.001,
                        type=float,
                        dest="threshold",
                        help='threshold')
    parser.add_argument("-p",
                        default=100,
                        type=int,
                        dest="popsize",
                        help='population size')
    parser.add_argument("-H",
                        default=3,
                        type=int,
                        dest="shade_h",
                        help='SHADE history size')
    parser.add_argument("-d",
                        default="results",
                        type=str,
                        dest="dir_output",
                        help='directory output')

    # Time stamp for comparative study
    time0 = time.clock()

    #seeds
    seeds = [24, 45689, 97232447, 96793335, 12345679]
    args = parser.parse_args(args)
    fun = args.function
    problem = args.problem

    # Noise problem, False by default
    noise = False

    if (problem in ["D4", "D4N"]):
        dim = 1024
    elif (problem in ["D12", "D12N"]):
        dim = 3072
    elif (problem in ["D19", "D19N"]):
        dim = 4864

    if ("N" in problem):
        print("Problem with noise")
        noise = True

    print("EEG Problem: {0}".format(problem))
    print("Problem: {0}".format(problem))
    print("Dimension: {0}".format(dim))
    print("Seed: {0}".format(args.seed))
    print("Treshold: {0}".format(args.threshold))
    print("Popsize: {0}".format(args.popsize))

    if args.shade_h is None:
        args.shade_h = min(args.popsize, 100)

    print("SHADE_H: {0}".format(args.shade_h))

    if (args.maxevals):
        evals = list(map(int, [1.0e5, 6e5, 3e6])[:args.maxevals])
    else:
        evals = list(map(int, [1.0e5, 6e5, 3e6]))

    evals_index = args.index

    bench = Benchmark()
    maxfuns = bench.get_num_functions()
    funinfo = bench.get_info(fun, dim)

    if not (1 <= fun <= maxfuns and 1 <= args.seed <= 5):
        parser.print_help()
        sys.exit(1)

    name = "SHADEILS"

    fname = name + "_EEGProblem_" + problem + "_" + str(
        evals[evals_index - 1]) + ".txt"

    output = path.join(args.dir_output, fname)

    if not args.verbose and isfile(output):
        fin = open(output, 'rb')
        lines = fin.readlines()
        fin.close()

        if lines:
            print("Experiment already exists. Check results folder")
            return

    if not args.verbose:
        fid = open(output, 'w')
    else:
        fid = sys.stdout

    # Parameter commons
    #bench.set_algname("shadeils_restart0.1_pos")
    fitness_fun = bench.get_function(fun, dim, noise)

    seed(seeds[args.seed - 1])

    for _ in range(args.run):
        SR_MTS = []
        SR_global_MTS = []
        SHADEILS.ihshadels(fitness_fun,
                           funinfo,
                           dim,
                           evals,
                           evals_index,
                           fid,
                           time0,
                           threshold=args.threshold,
                           popsize=args.popsize,
                           info_de=args.shade_h)
        bench.next_run()

    fid.close()
def main(args):
    global SR_MTS, SR_global_MTS

    """
    Main program. It uses
    Run DE for experiments. F, CR must be float, or 'n' as a normal
    """
    description = "IHDELS"
    parser = argparse.ArgumentParser(description)
    parser.add_argument("-f", required=True, type=int, choices=range(1, 16), dest="function", help='function')
    parser.add_argument("-v", default=False, dest="verbose", action='store_true', help='verbose mode')
    parser.add_argument("-s", default=1, type=int, dest="seed", choices=range(1, 6), help='seed (1 - 5)')
    parser.add_argument("-r", default=5, type=int, dest="run", help='runs')
    parser.add_argument("-e", required=False, type=int, dest="maxevals", help='maxevals')
    parser.add_argument("-t", default=0.01, type=float, dest="threshold", help='threshold')
    parser.add_argument("-p", default=100, type=int, dest="popsize", help='population size')
    parser.add_argument("-H", default=None, type=int, dest="shade_h", help='SHADE history size')
    parser.add_argument("-d", default="results", type=str, dest="dir_output", help='directory output')
    #seeds
    seeds = [23, 45689, 97232447, 96793335, 12345679]
    args = parser.parse_args(args)
    fun = args.function
    dim = 1000

    print("Function: {0}".format(fun))
    print("Seed: {0}".format(args.seed))
    print("Treshold: {0}".format(args.threshold))
    print("Popsize: {0}".format(args.popsize))

    if args.shade_h is None:
        args.shade_h = min(args.popsize, 100)

    print("SHADE_H: {0}".format(args.shade_h))

    if (args.maxevals):
        evals = list(map(int, [1.2e5, 6e5, 3e6])[:args.maxevals])
    else:
        evals = list(map(int, [1.2e5, 6e5, 3e6]))

    print(evals)
    bench = Benchmark()
    maxfuns = bench.get_num_functions()
    funinfo = bench.get_info(fun)

    if not (1 <= fun <= maxfuns and 1 <= args.seed <= 5):
        parser.print_help()
        sys.exit(1)

    name = "SHADEILS"

    fname = name +"_pop{args.popsize}_H{args.shade_h}_t{args.threshold:.2f}_F{args.function}_{args.seed}r{args.run}.txt".format(args=args);

    output = path.join(args.dir_output, fname)

    if not args.verbose and isfile(output):
        fin = open(output, 'rb')
        lines = fin.readlines()
        fin.close()

        if lines:
            print("Experiment already exists. Check results folder")
            return

    if not args.verbose:
        fid = open(output, 'w')
    else:
        fid = sys.stdout


    # Parameter commons
    #bench.set_algname("shadeils_restart0.1_pos")
    fitness_fun = bench.get_function(fun)

    seed(seeds[args.seed-1])

    for _ in range(args.run):
        SR_MTS = []
        SR_global_MTS = []
        SHADEILS.ihshadels(fitness_fun, funinfo, dim, evals, fid, threshold=args.threshold, popsize=args.popsize, info_de=args.shade_h)
        bench.next_run()

    fid.close()
Beispiel #13
0
def LASSOCC(func_num):
    Dim = 1000
    group_dim = 20
    size = group_dim * 100
    degree = 3
    bench = Benchmark()
    max_variables_num = group_dim

    function = bench.get_function(func_num)
    benchmark_summary = bench.get_info(func_num)
    scale_range = [benchmark_summary['lower'], benchmark_summary['upper']]
    verify_time = 0
    All_groups = []

    intercept = function(np.zeros((1, 1000))[0])
    one_bias = []
    for i in range(1000):
        index = np.zeros((1, 1000))[0]
        index[i] = 1
        one_bias.append(function(index) - intercept)
    verify_time += 1001

    for current_index in range(0, int(Dim / group_dim)):
        # print(current_index)
        Lasso_model, Feature_names = SparseModel.Regression(
            degree, size, Dim, group_dim, current_index, scale_range, function)

        # Grouping
        coef, Feature_names = help.not_zero_feature(
            Lasso_model.coef_, help.feature_names_normalization(Feature_names))

        groups = help.group_DFS(group_dim, Feature_names, max_variables_num)
        # print(groups)
        bias = current_index * group_dim
        for g in groups:
            for i in range(len(g)):
                g[i] += bias

        for g in groups:
            if not g or g is None:
                groups.remove(g)
        # We need to check the relationship between new groups and previous groups

        temp_groups = []
        for i in range(len(All_groups)):
            for j in range(len(groups)):
                if i < len(All_groups) and j < len(groups):
                    verify_time += 1

                    if not help.Differential(All_groups[i][0], groups[j][0],
                                             function, intercept, one_bias):
                        g1 = All_groups.pop(i)
                        g2 = groups.pop(j)
                        temp_groups.append(g1 + g2)
                        i -= 1
                        j -= 1
                        break

        for g in All_groups:
            temp_groups.append(g)
        for g in groups:
            temp_groups.append(g)
        All_groups = temp_groups.copy()

    return All_groups, verify_time + 100000
Beispiel #14
0
from Sy_DECC_CL.DimensionReductionForSparse.DE import DE
from Sy_DECC_CL.DimensionReductionForSparse.util import help
from Sy_DECC_CL.DimensionReductionForSparse.main_interface.grouping_main import CCDE
from cec2013lsgo.cec2013 import Benchmark
import os.path as path


if __name__ == '__main__':
    # func_num = 11
    Dim = 1000
    NIND = 30
    bench = Benchmark()
    EFs = 3000000
    for func_num in range(2, 16):
        test_time = 1
        name = 'f' + str(func_num)
        benchmark_summary = bench.get_info(func_num)
        scale_range = [benchmark_summary['lower'], benchmark_summary['upper']]
        function = bench.get_function(func_num)

        groups_One = CCDE(Dim)
        for iteration in range(1, 2):

            EFs = 3000000
            name = 'f' + str(func_num)

            """The next is DE optimization"""
            best_indexes, best_obj_trace_CC, up, down = DE.DECC_CL_CCDE(Dim, NIND, iteration, function, scale_range, groups_One)
            delta = []
            for i in range(len(up)):
                delta.append((up[i]-down[i])/(scale_range[1]-scale_range[0]))
Beispiel #15
0
#!/usr/bin/env python3
import scipy.optimize as opt
from cec2013lsgo.cec2013 import Benchmark
from des import DEStrategy, randomizePopulation
import multiprocessing
import plotUtils
import numpy as np

bench = Benchmark()

MAX_ITERATIONS = 5
#CEC_TO_RUN = [1,2,6,7]
# CEC_TO_RUN = [10,11,12,13]
CEC_TO_RUN = [2, 5, 7, 14]
THREADS_COUNT = 4


def runDEOneFunc(funcId):
    info = bench.get_info(funcId)
    fun = bench.get_function(funcId)
    print(f"Test info: {info}")

    boundaries = [(info['lower'], info['upper'])] * info['dimension']

    result = []
    curIteration = 0

    def callback(best, **kwargs):
        nonlocal curIteration
        result.append(fun(best))
        curIteration += 1