python Ubuntu dlib 人臉識別9-輔助函式

純潔的程式碼發表於2020-04-02

全域性優化函式:

import dlib
from math import sin,cos,pi,exp,sqrt

# This is a standard test function for these kinds of optimization problems.
# It has a bunch of local minima, with the global minimum resulting in
# holder_table()==-19.2085025679.
def holder_table(x0,x1):
return -abs(sin(x0)*cos(x1)*exp(abs(1-sqrt(x0*x0+x1*x1)/pi)))

# Find the optimal inputs to holder_table(). The print statements that follow
# show that find_min_global() finds the optimal settings to high precision.
x,y = dlib.find_min_global(holder_table,
[-10,-10], # Lower bound constraints on x0 and x1 respectively
[10,10], # Upper bound constraints on x0 and x1 respectively
80) # The number of times find_min_global() will call holder_table()

print("optimal inputs: {}".format(x));
print("optimal output: {}".format(y));
最佳分配問題:

假設需要為N個工作分配N個人。另外,每個工人會得到相應報酬,但每一份工作都需要有不同的技能,所以他們在某些工作中表現更好或更糟糕
其他。您希望找到將人員分配到這些工作的最佳方式,並希望報酬最大化。對於這樣的問題模型,可以直接呼叫max_cost_assignment來實現,輸入為一給矩陣,第N行為第N個工人所得到的報酬。如第1個工人做3分工作的報酬為1,2,6;第2個工人是5,3,6;第3個為4,5,0。這個函式可以用於高效的計算最大損失。
cost = dlib.matrix([[1, 2, 6],
[5, 3, 6],
[4, 5, 0]])

# To find out the best assignment of people to jobs we just need to call this
# function.
assignment = dlib.max_cost_assignment(cost)

# This prints optimal assignments: [2, 0, 1]
# which indicates that we should assign the person from the first row of the
# cost matrix to job 2, the middle row person to job 0, and the bottom row
# person to job 1.
print("Optimal assignments: {}".format(assignment))

# This prints optimal cost: 16.0
# which is correct since our optimal assignment is 6+5+5.
print("Optimal cost: {}".format(dlib.assignment_cost(cost, assignment)))

---------------------
作者:_iorilan
來源:CSDN
原文:blog.csdn.net/lan_liang/a…
版權宣告:本文為博主原創文章,轉載請附上博文連結!

更多學習資料可關注:gzitcast


相關文章