我试图在没有互联网连接的CentOS Linux机器上安装R包nloptr,如下所示:
install.packages("/home/ravi/nloptr_1.0.4.tar.gz", repos = NULL, type="source")
Run Code Online (Sandbox Code Playgroud)
此命令依次在线查找以下文件
http://ab-initio.mit.edu/nlopt/nlopt-2.4.2.tar.gz
Run Code Online (Sandbox Code Playgroud)
但是,由于没有与计算机的Internet连接,因此失败.
我尝试了以下stackoverflow帖子中的建议:
我更改了configure和configure.ac文件中的URL,如下所示:
NLOPT_URL="file:///home//ravi//${NLOPT_TGZ}"
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试再次安装包时出现以下错误:
> install.packages("/home/ravi/nloptr_1.0.4.tar.gz", repos = NULL, type="source")
* installing *source* package 'nloptr' ...
files 'configure', 'configure.ac' have the wrong MD5 checksums
ERROR: 'configure' exists but is not executable -- see the 'R Installation and Administration Manual'
* removing '/opt/vertica/R/library/nloptr'
Warning message:
In install.packages("/home/ravi/nloptr_1.0.4.tar.gz", :
installation of package '/home/ravi/nloptr_1.0.4.tar.gz' had non-zero exit status
Run Code Online (Sandbox Code Playgroud)
有人可以指导我如何在本地安装这个R包吗?
更新1
根据Dirk关于首先安装nlopt的建议,我按照以下页面中的说明进行操作:
http://ab-initio.mit.edu/wiki/index.php/NLopt_Installation
我按如下方式安装了nlopt:
./configure --enable-shared
make
make install
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/local/lib …Run Code Online (Sandbox Code Playgroud) 我无法在 R 3.3.0 上安装包 nloptr 1.0.4。消息如下:
> install.packages("nloptr")
Installing package into ‘/Users/fgomesbarros/Library/R/3.3/library
(as ‘lib’ is unspecified)
trying URL 'https://cran.revolutionanalytics.com/src/contrib/nloptr_1.0.4.tar.gz'
Content type 'application/octet-stream' length 353942 bytes (345 KB)
==================================================
downloaded 345 KB
* installing *source* package ‘nloptr’ ...
** package ‘nloptr’ successfully unpacked and MD5 sums checked
checking for g++... g++
checking whether the C++ compiler works... yes
checking for C++ compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for …Run Code Online (Sandbox Code Playgroud) 另一个帮助在Linux 上安装nloptr包(Ubuntu 14.04.4 LTS).我查看了许多问题,但没有找到解决方案.
我无法在R(版本3.3.1/Rstudio版本0.99.902)作为安装的安装包lme4 nloptr具有非零退出状态.当我尝试
install.package("nloptr")
Run Code Online (Sandbox Code Playgroud)
我得到以下内容:
Installing package into ‘/home/rd14/R/x86_64-pc-linux-gnu-library/3.3’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/src/contrib/nloptr_1.0.4.tar.gz'
Content type 'unknown' length 353942 bytes (345 KB)
==================================================
downloaded 345 KB
* installing *source* package ‘nloptr’ ...
** package ‘nloptr’ successfully unpacked and MD5 sums checked
checking for g++... g++
checking whether the C++ compiler works... yes
checking for C++ compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... …Run Code Online (Sandbox Code Playgroud) 我需要H在以下等式中最小化:
哪里H是3x3矩阵.
Pn是3x1矩阵(点).
Euclidean()给出2点之间的距离.
Dn是实际距离.
我有一个初始估计H和m点(P0到Pm)
我需要优化值,H使得所有m点误差最小化.(表达式中的所有值都是已知的)如何使用opencv或dlib(或使用boost/NLopt)实现此功能.
我难住了。我在 R 中为 NLOPT 制定了一个问题。当前问题解决了 180 个具有 28 个等式约束的变量
该代码是从一个更简单的问题版本中重用的,在我的脚本的早期,有 36 个变量和 20 个等式约束,可以立即使用 NLOPT_LD_SLSQP作为算法。
使用 180 个变量的问题的较大版本会立即产生以下结果NLOPT_LD_SLSQP:
NLopt solver status: -4 ( NLOPT_ROUNDOFF_LIMITED: Roundoff errors led
to a breakdown of the optimization algorithm. In this case, the
returned minimum may
still be useful. (e.g. this error occurs in NEWUOA if one tries to
achieve a tolerance too close to machine precision.) )
Run Code Online (Sandbox Code Playgroud)
这让我感到困惑,因为它可以解决问题的较小版本。同样,它返回起始值并且实际上并不完成任何迭代。所以我实现了,NLOPT_AUGLAG_LD_EQ作为主要算法,NLOPT_LD_SLSQP作为本地算法。现在问题无法解决并产生:
NLopt solver status: -1 ( NLOPT_FAILURE: Generic failure code. …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用nloptrR中的程序包解决优化问题。我不确定以下代码有什么问题,因为我不断收到此错误:
Error: nlopt_add_equality_mconstraint returned NLOPT_INVALID_ARGS.
这是问题所在(请注意,(A +)^ T是矩阵A的Moore-Penrose逆的转置)

和代码:
library( MASS ) ## for the Moore-Penrose inverse ginv()
library( zoo )
library( nloptr )
A = matrix(runif(27, -0.5, 0.5), nc = 3)
sigma = diag(runif(3,0.001,0.002))
M = ncol(A)
b = 1 / M
n = nrow(A)
init_y = rep(1/M, M)
c = -ncol(A)*log(ncol(A))
#### Objective function
eval_f <- function(y)
{
return( sqrt( as.numeric( t(y) %*% sigma %*% y ) ) )
}
#### Gradient of objective function
eval_grad_f …Run Code Online (Sandbox Code Playgroud) 是否可以nloptr在R 中的函数中指定多个相等约束?我尝试运行的代码如下:
eval_f <- function( x ) {
return( list( "objective" = x[3]^2+x[4]^2,
"gradient" = c( 0,
0,
2*x[3],
2*x[4] ) ) )
}
# constraint functions
# equalities
eval_g_eq <- function( x ) {
constr <- c( x[1] + x[2] + x[3] - 4,
x[1]^2 + x[2]^2 + x[4] - 15
)
grad <- c( c(1, 1, 1, 0),
c(2*x[1], 2*x[2], 0, 1)
)
return( list( "constraints"=constr, "jacobian"=grad ) )
}
# initial values
x0 <- c( …Run Code Online (Sandbox Code Playgroud) 当我在 python 中运行以下简单的 NLOPT 示例时:
import numpy as np
import nlopt
n = 2
localopt_feval_max = 10
lb = np.array([-1, -1])
ub = np.array([1, 1])
def myfunc(x, grad):
return -1
opt = nlopt.opt(nlopt.LN_NELDERMEAD, n)
opt.set_lower_bounds(lb)
opt.set_upper_bounds(ub)
opt.set_maxeval(localopt_feval_max)
opt.set_min_objective(myfunc)
opt.set_xtol_rel(1e-8)
x0 = np.array([0,0])
x = opt.optimize(x0)
Run Code Online (Sandbox Code Playgroud)
我收到错误:
"ValueError: nlopt invalid argument"
Run Code Online (Sandbox Code Playgroud)
这里参考给出的唯一建议:
http://ab-initio.mit.edu/wiki/index.php/NLopt_Python_Reference
是下限可能大于上限,或者存在未知算法(这里都不是这种情况)。我正在运行以下版本的 Python、NLOPT 和 NumPy
>>> sys.version
'3.4.0 (default, Apr 11 2014, 13:05:11) \n[GCC 4.8.2]'
>>> nlopt.__version__
'2.4.2'
>>> np.__version__
'1.8.2'
Run Code Online (Sandbox Code Playgroud) 任何人都知道NLopt是否适用于单变量优化.试图运行以下代码:
using NLopt
function myfunc(x, grad)
x.^2
end
opt = Opt(:LD_MMA, 1)
min_objective!(opt, myfunc)
(minf,minx,ret) = optimize(opt, [1.234])
println("got $minf at $minx (returned $ret)")
Run Code Online (Sandbox Code Playgroud)
但是得到以下错误消息:
> Error evaluating untitled
LoadError: BoundsError: attempt to access 1-element Array{Float64,1}:
1.234
at index [2]
in myfunc at untitled:8
in nlopt_callback_wrapper at /Users/davidzentlermunro/.julia/v0.4/NLopt/src/NLopt.jl:415
in optimize! at /Users/davidzentlermunro/.julia/v0.4/NLopt/src/NLopt.jl:514
in optimize at /Users/davidzentlermunro/.julia/v0.4/NLopt/src/NLopt.jl:520
in include_string at loading.jl:282
in include_string at /Users/davidzentlermunro/.julia/v0.4/CodeTools/src/eval.jl:32
in anonymous at /Users/davidzentlermunro/.julia/v0.4/Atom/src/eval.jl:84
in withpath at /Users/davidzentlermunro/.julia/v0.4/Requires/src/require.jl:37
in withpath at /Users/davidzentlermunro/.julia/v0.4/Atom/src/eval.jl:53
[inlined code] from /Users/davidzentlermunro/.julia/v0.4/Atom/src/eval.jl:83 …Run Code Online (Sandbox Code Playgroud) 我想使用一个库(nlopt),它有一个函数set_min_objective,它接受一个指向数值函数myfunc的指针并找到它的最小值.我想创建一个包含适当初始化成员函数的类.然后set_min_objective将在特定实例中找到最佳值(下例中的myP).呼叫顺序是:
opt.set_min_objective(myfunc, NULL);
Run Code Online (Sandbox Code Playgroud)
我想使用类似的东西:
opt.set_min_objective(myP.f, NULL);
Run Code Online (Sandbox Code Playgroud)
编译时得到的错误是:
main.cpp: In function 'int main()':
main.cpp:79:34: error: no matching function for call to 'nlopt::opt::set_min_objective(<unresolved overloaded function type>, NULL)'
../lib/nlopt.hpp:335:10: note: candidates are: void nlopt::opt::set_min_objective(double (*)(unsigned int, const double*, double*, void*), void*)
../lib/nlopt.hpp:342:10: note: void nlopt::opt::set_min_objective(double (*)(const std::vector<double>&, std::vector<double>&, void*), void*)
../lib/nlopt.hpp:368:10: note: void nlopt::opt::set_min_objective(double (*)(unsigned int, const double*, double*, void*), void*, void* (*)(void*), void* (*)(void*))
Run Code Online (Sandbox Code Playgroud)
set_min_objective接受myP.f作为函数的普通指针最简单的解决方案是什么?请注意,myP.f和myfunc具有相同的参数和返回值类型.
谢谢,
JD
在网上找不到在F#中使用NLopt的例子,我一直试图将NLoptNet上给出的例子从C#转换为F#.对C#不熟悉,对F#不太熟悉,我一直在屠杀它.
这是我到目前为止:
open NLoptNet
open System
let solver = new NLoptSolver(NLoptAlgorithm.LN_COBYLA, uint32(1), 0.001, 100)
solver.SetLowerBounds([|-10.0|])
solver.SetUpperBounds([|100.0|])
let objfunc (variables : float array) =
Math.Pow(variables.[0] - 3.0, 2.0) + 4.0
solver.SetMinObjective(objfunc)
let initial_val = [|2.|]
let finalscore = ref System.Nullable() // ERROR
let result = solver.Optimize(initial_val, finalscore)
Run Code Online (Sandbox Code Playgroud)
以下是错误的描述:
连续的参数应该用空格或元组分隔,涉及函数或方法应用程序的参数应该用括号括起来
更具体地说,我正在尝试将以下三行C#转换为F#:
double? finalScore;
var initialValue = new[] { 2.0 };
var result = solver.Optimize(initialValue, out finalScore);
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?