rpy2のSignatureTranslatedAnonymousPackage (STAP)を使用して、任意のRコードをPython環境で利用可能なパッケージとしてインポートすることを検討してください。 //:
R
# Loading required package: Rdtq
require(Rdtq)
# Assigning drift and diff functions
mydrift = function(x) { -x }
mydiff = function(x) { rep(1,length(x)) }
# Running rdtq()
test = rdtq(h=0.1, k=0.01, bigm=250, init=0, fT=1,
drift=mydrift, diffusion=mydiff, method="sparse")
# Plotting output
plot(test$xvec, test$pdf, type='l')
パイソン
from rpy2 import robjects
from rpy2.robjects.packages import STAP
from rpy2.robjects.packages import importr
# Loading required package: Rdtq
Rdtq = importr('Rdtq')
fct_string = """
my_drift <- function(x) { -x }
my_diff <- function(x) { rep(1,length(x)) }
"""
# Creating package with above drift and diff methods
my_fcts = STAP(fct_string, "my_fcts")
# Running rdtq() --notice per Python's model: all methods are period qualified
test = Rdtq.rdtq(h=0.1, k=0.01, bigm=250, init=0, fT=1,
drift=my_fcts.my_drift(), diffusion=my_fcts.my_diff(), method="sparse")
# Load plot function
plot = robjects.r.plot
# Plotting by name index
plot(test[test.names.index('xvec')], test[test.names.index('pdf')], type='l')
をこれは[XY問題](HTTPSである:以下のPythonにRで書かRdtq githubは
rpy2
を用いて変換し、実証しますmeta.stackexchange.com/questions/66377/what-is-the-xy-problem)。あなたは私たちにあなたのYの解決策だけを教えていますが、Xの問題は説明していません。特異性や再現性のある例で真の完全なシナリオを教えてください。あなたはそう考えるかもしれませんが、ラムダが必要かもしれません。 – Parfait十分に公正で、私は質問を調整しました。 – user56643