我的初始问题可以在这里找到:R中的任意约束优化
它引发了另一个问题,如何传递参数nloptr.
我需要最小化函数F(x,y,A),其中x和y是向量并且A是矩阵,同时具有约束sum(x * y) >= sum(y/3)和sum(x)=1.我试过用nloptr:
F <- function(x,y,A){
...
}
Gc <- function(x,y){
return(sum(y/3) - sum(x*y))
}
Hc <- function(x){
retunr(1-sum(x))
}
nloptr(x0=rep(1/3,3), eval_f=F, lb = 0.05, ub = 1, eval_g_ineq = Gc, eval_g_eq = Hc, opts = list(), y=y, A=A)
Run Code Online (Sandbox Code Playgroud)
我收到一个错误:
'A' passed to (...) in 'nloptr' but this is not required in the eval_g_ineq function.
如果我说 nloptr( ... , y, A) …
我正在尝试保存一张大图片(实际上大于我的显示器的分辨率),但是当增加Figsize时我得到了相同大小的png图片。因此,对于下面的两个示例,我得到完全相同的文件:
import matplotlib.pylab as plt
fig, ax = plt.subplots(nrows=2, ncols=1, figsize=(10, 100))
ax[0].plot([0, 1], [0, 1])
ax[1].plot([0, 1], [0, 1])
fig.savefig('test1.png')
plt.close()
Run Code Online (Sandbox Code Playgroud)
第二:
fig, ax = plt.subplots(nrows=2, ncols=1, figsize=(10, 150))
ax[0].plot([0, 1], [0, 1])
ax[1].plot([0, 1], [0, 1])
fig.savefig('test2.png')
plt.close()
Run Code Online (Sandbox Code Playgroud)
请问有什么方法可以制作更大的图片吗?
我有一个非常大的pandas数据帧/系列,有数百万个元素.我需要找到时间戳<小于t0的所有元素.通常我会做的是:
selected_df = df[df.index < t0]
Run Code Online (Sandbox Code Playgroud)
这需要很长时间.据我所知,当pandas搜索时,它会遍历数据帧的每个元素.但是我知道我的数据帧已经排序,因此我可以在时间戳> t0后立即中断循环.我假设pandas不知道数据帧已排序并搜索所有时间戳.
我试过用pandas.Series代替 - 仍然很慢.我试着编写自己的循环,如:
boudery = 0
ticks_time_list = df.index
tsearch = ticks_time_list[0]
while tsearch < t0:
tsearch = ticks_time_list[boudery]
boudery += 1
selected_df = df[:boudery]
Run Code Online (Sandbox Code Playgroud)
这需要比熊猫搜索更长的时间.我能看到的唯一解决方案就是使用Cython.任何想法如何在没有C参与的情况下进行排序?