本文整理汇总了Python中rpy2.robjects.numpy2ri.activate方法的典型用法代码示例。如果您正苦于以下问题:Python numpy2ri.activate方法的具体用法?Python numpy2ri.activate怎么用?Python numpy2ri.activate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rpy2.robjects.numpy2ri
的用法示例。
在下文中一共展示了numpy2ri.activate方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: activate
# 需要导入模块: from rpy2.robjects import numpy2ri [as 别名]
# 或者: from rpy2.robjects.numpy2ri import activate [as 别名]
def activate():
global original_converter
# If module is already activated, there is nothing to do.
if original_converter is not None:
return
original_converter = conversion.Converter(
'snapshot before pandas conversion',
template=conversion.converter)
numpy2ri.activate()
new_converter = conversion.Converter('snapshot before pandas conversion',
template=conversion.converter)
numpy2ri.deactivate()
for k, v in py2rpy.registry.items():
if k is object:
continue
new_converter.py2rpy.register(k, v)
for k, v in rpy2py.registry.items():
if k is object:
continue
new_converter.rpy2py.register(k, v)
conversion.set_conversion(new_converter)
示例2: setUp
# 需要导入模块: from rpy2.robjects import numpy2ri [as 别名]
# 或者: from rpy2.robjects.numpy2ri import activate [as 别名]
def setUp(self):
numpy2ri.activate()
ro.r('set.seed({})'.format(0))
np.random.seed(0)
示例3: check_rpy2
# 需要导入模块: from rpy2.robjects import numpy2ri [as 别名]
# 或者: from rpy2.robjects.numpy2ri import activate [as 别名]
def check_rpy2(self):
try:
from rpy2 import robjects
from rpy2.robjects import numpy2ri
numpy2ri.activate()
except ImportError:
return True, "WARNING: rpy2 is not installed correctly; SVs will not be visualized"
return True, "rpy2 detected and appears to be correctly installed"
示例4: _build
# 需要导入模块: from rpy2.robjects import numpy2ri [as 别名]
# 或者: from rpy2.robjects.numpy2ri import activate [as 别名]
def _build(self, **kwargs):
from rpy2.robjects import numpy2ri, pandas2ri
match_it = self.install_matchit()
self.num_treatments = kwargs["num_treatments"]
self.batch_size = kwargs["batch_size"]
self.match_it = match_it
numpy2ri.activate()
pandas2ri.activate()
return super(PSM, self)._build(**kwargs)
示例5: _build
# 需要导入模块: from rpy2.robjects import numpy2ri [as 别名]
# 或者: from rpy2.robjects.numpy2ri import activate [as 别名]
def _build(self, **kwargs):
from rpy2.robjects import numpy2ri
from sklearn import linear_model
grf = self.install_grf()
self.grf = grf
numpy2ri.activate()
num_treatments = kwargs["num_treatments"]
return [linear_model.Ridge(alpha=.5)] +\
[None for _ in range(num_treatments)]
示例6: _build
# 需要导入模块: from rpy2.robjects import numpy2ri [as 别名]
# 或者: from rpy2.robjects.numpy2ri import activate [as 别名]
def _build(self, **kwargs):
from rpy2.robjects import numpy2ri, pandas2ri
n_jobs = int(np.rint(kwargs["n_jobs"]))
bart = self.install_bart()
bart.set_bart_machine_num_cores(n_jobs)
self.bart = bart
numpy2ri.activate()
pandas2ri.activate()
return None
示例7: numpy_conversion
# 需要导入模块: from rpy2.robjects import numpy2ri [as 别名]
# 或者: from rpy2.robjects.numpy2ri import activate [as 别名]
def numpy_conversion():
rpyn.activate()
yield
rpyn.deactivate()
示例8: test_activate
# 需要导入模块: from rpy2.robjects import numpy2ri [as 别名]
# 或者: from rpy2.robjects.numpy2ri import activate [as 别名]
def test_activate(self):
rpyn.deactivate()
#FIXME: is the following still making sense ?
assert rpyn.py2rpy != conversion.py2rpy
l = len(conversion.py2rpy.registry)
k = set(conversion.py2rpy.registry.keys())
rpyn.activate()
assert len(conversion.py2rpy.registry) > l
rpyn.deactivate()
assert len(conversion.py2rpy.registry) == l
assert set(conversion.py2rpy.registry.keys()) == k
示例9: test_activate_twice
# 需要导入模块: from rpy2.robjects import numpy2ri [as 别名]
# 或者: from rpy2.robjects.numpy2ri import activate [as 别名]
def test_activate_twice(self):
rpyn.deactivate()
#FIXME: is the following still making sense ?
assert rpyn.py2rpy != conversion.py2rpy
l = len(conversion.py2rpy.registry)
k = set(conversion.py2rpy.registry.keys())
rpyn.activate()
rpyn.deactivate()
rpyn.activate()
assert len(conversion.py2rpy.registry) > l
rpyn.deactivate()
assert len(conversion.py2rpy.registry) == l
assert set(conversion.py2rpy.registry.keys()) == k
示例10: fitRCausalImpact
# 需要导入模块: from rpy2.robjects import numpy2ri [as 别名]
# 或者: from rpy2.robjects.numpy2ri import activate [as 别名]
def fitRCausalImpact(Y_pre, Y_post, treated_units):
import rpy2.robjects as ro #ro.r is the R instace
#Automatically convert numpy arrays to R vector/matrix
from rpy2.robjects import numpy2ri
numpy2ri.activate()
control_units = [u for u in range(Y_pre.shape[0]) if u not in treated_units]
#np.matrix is not automatically converted so use ndarray
if type(Y_pre).__name__=="matrix":
Y_pre = Y_pre.A
if type(Y_post).__name__=="matrix":
Y_post = Y_post.A
Y = np.hstack((Y_pre, Y_post))
Y_sc = np.full(Y.shape, np.nan)
Y_c = Y[control_units,:]
T0 = Y_pre.shape[1]
N,T = Y.shape
try:
CausalImpact = importr('CausalImpact')
except:
raise RuntimeError("Need the 'CausalImpact' package loaded in the rpy2 R environment. Use test.test_simulation.installRCausalImpact")
for unit in range(N): #
if unit in treated_units:
data = np.hstack((Y[unit,:].T, Y_c.T))
else:
data = np.hstack((Y[unit,:].T, np.delete(Y_c, unit, 0).T))
r_data = ro.r.matrix(data, nrow=df.shape[0], ncol=df.shape[1])
r_casaulimpact_out = CausalImpact.CausalImpact(data=r_data, pre_period=ro.IntVector([1, T0]), post_period=ro.IntVector([T0+1, T]))
#can't seem to get weights from impact$model$bsts.model
#r_summary = r_casaulimpact_out[r_casaulimpact_out.names.index('summary')]
#te = r_summary[r_summary.names.index('AbsEffect')]
#p = r_summary[r_summary.names.index('p')]
#te_ci_l = r_summary[r_summary.names.index('AbsEffect.lower')]
#te_ci_u = r_summary[r_summary.names.index('AbsEffect.upper')]
point_pred = np.array(r_casaulimpact_out[r_casaulimpact_out.names.index('series')])[:,2] #'point.pred' from 'zoo' object
Y_sc[unit,:] = point_pred
class RCausalImpact:
def __self__(self, Y_sc):
self.Y_sc = Y_sc
return RCausalImpact(Y_sc)