gpt4 book ai didi

java - RCaller 抛出 java.io.IOException/ExecutionException

转载 作者:行者123 更新时间:2023-11-30 10:28:51 25 4
gpt4 key购买 nike

当我想通过 RCaller 运行一些代码时,Java 抛出以下异常:

Exception in thread "JavaFX Application Thread" com.github.rcaller.exception.ExecutionException: Can not send the source code to R file due to: java.io.IOException: The pipe is being closed Maximum number of retries exceeded.

这是我的代码:

protected void initialize(){
if (!System.getProperty("os.name").contains("Windows")){
rscript = rscript.replace("\\","/");
r = r.replace("\\","/");
}
out.println(rscript + "\n" + r);
caller = RCaller.create(RCallerOptions.create(rscript,r,FailurePolicy.RETRY_1,500,500,RProcessStartUpOptions.create()));
}

private void calculateIntegral(String newValue){
RCode rCode = RCode.create();
rCode.addRCode("func <- function (x) (" + newValue + ")");
rCode.addRCode("x <- integrate(func," + from.getValue() + "," + to.getValue() + ")");
caller.setRCode(rCode);
caller.runAndReturnResult("x"); <- This is where I get the Exception
value.setText(String.valueOf(caller.getParser().getAsDoubleArray("x")[0]));
}

我检查了我的 R 安装,它似乎没问题

编辑:
我还尝试将 rscript 和 r 与 "\""连接起来,如下所示:

rscript =  "\"" + rscript +  "\"";
r = "\"" + r + "\"";

它也没有用 :(

编辑 2:
当我尝试生成这样的图时:

rCode.addRCode("plot(func)");

Java 仍然会抛出异常,但也会生成一个包含绘图的 pdf

另外...我正在慢慢放弃 R...是否有另一种方法可以根据 Java 中作为字符串给出的数学函数计算积分?

最佳答案

您可以使用数值优化和符号优化对定积分使用最大值。例如

integrate(2 * x, x)

返回 x ^ 2。您可以定义数值计算的下限和上限(定积分的近似值)。您可以使用多个选项调用可执行文件 maxima。您可以在文本文件中发送积分(当然还有任何其他数学运算,包括极限和导数)以及命令外壳上的字符串。例如

maxima -q -r "integrate(2 * x, x);"

计算括号之间给出的积分并将结果返回到标准输出。

祝你好运。

关于java - RCaller 抛出 java.io.IOException/ExecutionException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44371257/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com