# AUTOGENERATED! DO NOT EDIT! File to edit: densityRatioSugiyama.ipynb (unless otherwise specified).

__all__ = ['r', 'ulsif', 'clsif', 'eval_basis', 'estimate']

# Cell
import rpy2

import rpy2.robjects as robjects

import os


import numpy as np
import scipy.stats as ss
import matplotlib.pyplot as plt

r = robjects.r

import rpy2.robjects.numpy2ri
rpy2.robjects.numpy2ri.activate()

for f in os.listdir("R/densityratiosugiyama/R"):
    r.source("R/densityratiosugiyama/R/{}".format(f))

ulsif = robjects.globalenv["ulsif"]

clsif = robjects.globalenv["clsif"]

eval_basis = robjects.globalenv["eval.basis"]

# Cell
def estimate(x,y,lambda_=1):
    x0 = x[~y]
    x1 = x[y]
    m0 = r.matrix(x0.T,nrow=x0.shape[1],ncol=x0.shape[0])
    m1 = r.matrix(x1.T,nrow=x1.shape[1],ncol=x1.shape[0])
    results = ulsif(m1,m0,lambda_)
    ratios = np.array(eval_basis(results,
                          r.matrix(x.T,
                                   nrow=x.shape[1],
                                   ncol=x.shape[0])))
    return ratios