问题描述
我在<!DOCTYPE html>
<html lang="en">
<head>
<style>
body{
padding: 0;
margin: 0;
}
.navigation-bar {
width: 100%;
height: 53px; /
background-color: black;
}
.logo {
display: inline-block;
vertical-align: top;
height: 50px;
margin-left: 30px;
margin-top: 2px;
}
.navigation-bar> a {
float:right;
display: inline-block;
vertical-align: top;
margin-right: 25px;
height: 60px;
color: white;
line-height: 70px;
font-weight: bolder;
font-size: 12px;
text-decoration: none;
font-family: sans-serif;
position: relative;
padding: 3px;
}
.navigation-bar> a:hover:before {
content: "";
position: absolute;
top: 40px;
left: 50%;
margin-left: -5px;
width: 0px;
height: 7px;
xxmargin: 0px auto;
border-left: 5px solid transparent;
border-right: 5px solid transparent;
border-bottom: 5px solid #fff;
}
</style>
</head>
<body>
<nav class="navigation-bar">
<img class="logo" src="C:\Users\sahan\Downloads\logo.png">
<a href="#">Contact</a>
<a href="#">Us</a>
<a href="#">Work</a>
<a href="#">Home</a>
</nav>
中遇到最小方差优化问题,但有一个附加约束:
scipy
如果我使用以下命令运行此优化器:
def min_variance_scipy(initial_point: np.array,covariance_matrix: np.array):
start = time.time()
n = covariance_matrix.shape[0]
objective_function = lambda w,c: 1000 * w.dot(c).dot(w)
A = np.array([[1] * n])
ub = [1]
lb = [1]
bounds = Bounds([0] * n,[1] * n)
diversification_target = {
'type': 'ineq','fun': lambda weights: (2 / n) - np.sum(weights**2)
}
constraints = [LinearConstraint(A,lb,ub),diversification_target]
solution = minimize(fun=objective_function,x0=initial_point,method='trust-constr',bounds=bounds,constraints=constraints,args=(covariance_matrix,),tol=1e-6,jac=lambda x,c: 2000 * x.T.dot(c.T),hess=lambda x,c: 2000 * c.T,options={'gtol': 1e-6})
# options={'verbose': 3,'finite_diff_rel_step': 1e-5,})
return solution.x
执行时间为+100段。我想加快性能。我测试了initial_point: np.array of shape == (600,).
covariance_matrix: matrix of shape == (600,600)
,但是如果我们使用DCCP优化器,则某些约束不是DCP或DCCP。 (我还有更多要测试的约束条件。)
我还将方法参数更改为cvxpy
,但是没有满足SLSQP
约束。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)