Algorithm to find the set of K solutions candidates based on two criteria

The context is the initialization of optimization algorithms (for example, differential evolution), where we generate a random population of vectors that represent the solution’s parameters.

We are trying to devise new initialization methods that are better than random.
Regardless of the initialization method itself, in the end, we have M possible solutions from which we want only N (usually, they have more than 100 samples, and we want to select only 30).

In simple terms, the main idea is to find a set of dimensions N drawn from M that maximizes the distance between solutions while the overall fitness value is high (for our algorithm the lower the fitness value the better the performance of the solution).

What we are using right now is quite simple, we generate all the combinations of solution sets and measure their overall distance and fitness. From all of the points, we draw the Pareto frontier and select one of those points.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>import math
import itertools
import numpy as np
import matplotlib.pyplot as plt
from paretoset import paretoset
def distance_matrix(a):
b = a.reshape(a.shape[0], 1, a.shape[1])
dist = np.sqrt(np.einsum('ijk, ijk->ij', a-b, a-b))
return dist
samples = np.random.random([10, 2])*10.0
fitness = [math.dist(p, [0,0]) for p in samples]
n_pop = 3
for s,f in zip(samples, fitness):
print(f'{s}({f})')
# additional code - get best n_pop points that are far away from each other
# compute distance matrix
dist = distance_matrix(samples)
print(f'{dist})')
# compute the cost (fitness + distance) of all solutions
aggregated_distances = []
aggregated_fitness = []
solutions = []
combs = itertools.combinations(range(len(samples)), n_pop)
print('main loop')
for c in combs:
# store current solution
solutions.append(c)
# compute the aggregated distance
agg_dist = 0.0
for i in c:
for j in c:
agg_dist += dist[i][j]
aggregated_distances.append(agg_dist)
# compute the aggregated fitness
agg_fit = 0.0
for s in c:
agg_fit += fitness[s]
aggregated_fitness.append(agg_fit)
aggregated_distances = np.array(aggregated_distances)
aggregated_fitness = np.array(aggregated_fitness)
solutions = np.array(solutions)
plt.plot(aggregated_distances, aggregated_fitness, 'o')
for s,d,f in zip(solutions, aggregated_distances, aggregated_fitness):
print(f'{s} {d} {f})')
#https://github.com/tommyod/paretoset
objective_values_array = np.vstack([aggregated_distances, aggregated_fitness]).T
print(f'{objective_values_array.shape}')
mask = paretoset(objective_values_array, sense=['max', 'min'])
print(f'{mask}')
print(solutions[mask])
plt.plot(aggregated_distances[mask], aggregated_fitness[mask], 'o')
plt.show()
</code>
<code>import math import itertools import numpy as np import matplotlib.pyplot as plt from paretoset import paretoset def distance_matrix(a): b = a.reshape(a.shape[0], 1, a.shape[1]) dist = np.sqrt(np.einsum('ijk, ijk->ij', a-b, a-b)) return dist samples = np.random.random([10, 2])*10.0 fitness = [math.dist(p, [0,0]) for p in samples] n_pop = 3 for s,f in zip(samples, fitness): print(f'{s}({f})') # additional code - get best n_pop points that are far away from each other # compute distance matrix dist = distance_matrix(samples) print(f'{dist})') # compute the cost (fitness + distance) of all solutions aggregated_distances = [] aggregated_fitness = [] solutions = [] combs = itertools.combinations(range(len(samples)), n_pop) print('main loop') for c in combs: # store current solution solutions.append(c) # compute the aggregated distance agg_dist = 0.0 for i in c: for j in c: agg_dist += dist[i][j] aggregated_distances.append(agg_dist) # compute the aggregated fitness agg_fit = 0.0 for s in c: agg_fit += fitness[s] aggregated_fitness.append(agg_fit) aggregated_distances = np.array(aggregated_distances) aggregated_fitness = np.array(aggregated_fitness) solutions = np.array(solutions) plt.plot(aggregated_distances, aggregated_fitness, 'o') for s,d,f in zip(solutions, aggregated_distances, aggregated_fitness): print(f'{s} {d} {f})') #https://github.com/tommyod/paretoset objective_values_array = np.vstack([aggregated_distances, aggregated_fitness]).T print(f'{objective_values_array.shape}') mask = paretoset(objective_values_array, sense=['max', 'min']) print(f'{mask}') print(solutions[mask]) plt.plot(aggregated_distances[mask], aggregated_fitness[mask], 'o') plt.show() </code>
import math
import itertools
import numpy as np
import matplotlib.pyplot as plt

from paretoset import paretoset


def distance_matrix(a):
    b = a.reshape(a.shape[0], 1, a.shape[1])
    dist = np.sqrt(np.einsum('ijk, ijk->ij', a-b, a-b))
    return dist

samples = np.random.random([10, 2])*10.0
fitness = [math.dist(p, [0,0]) for p in samples]
n_pop = 3

for s,f in zip(samples, fitness):
    print(f'{s}({f})')

# additional code - get best n_pop points that are far away from each other
# compute distance matrix
dist = distance_matrix(samples)
print(f'{dist})')

# compute the cost (fitness + distance) of all solutions
aggregated_distances = []
aggregated_fitness = []
solutions = []
combs = itertools.combinations(range(len(samples)), n_pop)
print('main loop')
for c in combs:
    # store current solution
    solutions.append(c)
    # compute the aggregated distance
    agg_dist = 0.0
    for i in c:
        for j in c:
            agg_dist += dist[i][j]
    aggregated_distances.append(agg_dist)
    # compute the aggregated fitness
    agg_fit = 0.0
    for s in c:
        agg_fit += fitness[s]
    aggregated_fitness.append(agg_fit)

aggregated_distances = np.array(aggregated_distances)
aggregated_fitness = np.array(aggregated_fitness)
solutions = np.array(solutions)

plt.plot(aggregated_distances, aggregated_fitness, 'o')

for s,d,f in zip(solutions, aggregated_distances, aggregated_fitness):
    print(f'{s} {d} {f})')

#https://github.com/tommyod/paretoset
objective_values_array = np.vstack([aggregated_distances, aggregated_fitness]).T
print(f'{objective_values_array.shape}')
mask = paretoset(objective_values_array, sense=['max', 'min'])
print(f'{mask}')
print(solutions[mask])
plt.plot(aggregated_distances[mask], aggregated_fitness[mask], 'o')
plt.show()

The issue is that this code is quite slow when the population is reasonably large.
Is there a better method? Ideally, something that is linear in complexity.
Linear programming could be a solution?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật