import numpy as np
from sklearn import svm
from sklearn import linear_model
from sklearn import metrics
from sklearn import preprocessing
import threading as td
import pickle
import copy

import nus_trainer

sem = td.Semaphore(1)
def need_lock(func):
	def wrapper(*args, **kvargs):
		sem.acquire()
		func(*args, **kvargs)
		sem.release()
	return wrapper

@need_lock
def trainer(traindata, trainlabel):
	clf = BaggingClassifier(linear_model.LogisticRegression())
	clf = clf.fit(traindata, trainlabel)
	return clf

def predictor(clf, testdata, label):
	result = clf.predict_proba(testdata)
	return label

def relat_calc(la, lb):
	if la.ndim == 4:
		# 由于 LogisticRegression 返回两个数
		#       n:1:10
		la = la[:,:,:,1]
		#       1:m:10
		lb = lb[:,:,:,1]

	res = np.zeros((la.shape[0], lb.shape[1]))
	for i in range(la.shape[0]):
		res[i] = np.sum(la[i] * lb, axis=2)
	return res

def relat_calc2(la, lb):
	if la.ndim == 4:
		la = la[:,:,:,1]
		lb = lb[:,:,:,1]

	res = np.zeros((la.shape[0], lb.shape[1]))
	for i in range(la.shape[0]):
		res[i] = 1 - np.prod(1 - la[i] * lb, axis=2)
	return res

nus_trainer.run(trainer, predictor, relat_calc, "lr_bs.bin")

5af2ff0c7ffd28283274e08dd3653be5fb8f3cbd
<mask token>


def need_lock(func):

    def wrapper(*args, **kvargs):
        sem.acquire()
        func(*args, **kvargs)
        sem.release()
    return wrapper


@need_lock
def trainer(traindata, trainlabel):
    clf = BaggingClassifier(linear_model.LogisticRegression())
    clf = clf.fit(traindata, trainlabel)
    return clf


<mask token>


def relat_calc(la, lb):
    if la.ndim == 4:
        la = la[:, :, :, 1]
        lb = lb[:, :, :, 1]
    res = np.zeros((la.shape[0], lb.shape[1]))
    for i in range(la.shape[0]):
        res[i] = np.sum(la[i] * lb, axis=2)
    return res


def relat_calc2(la, lb):
    if la.ndim == 4:
        la = la[:, :, :, 1]
        lb = lb[:, :, :, 1]
    res = np.zeros((la.shape[0], lb.shape[1]))
    for i in range(la.shape[0]):
        res[i] = 1 - np.prod(1 - la[i] * lb, axis=2)
    return res


<mask token>

<mask token>


def need_lock(func):

    def wrapper(*args, **kvargs):
        sem.acquire()
        func(*args, **kvargs)
        sem.release()
    return wrapper


@need_lock
def trainer(traindata, trainlabel):
    clf = BaggingClassifier(linear_model.LogisticRegression())
    clf = clf.fit(traindata, trainlabel)
    return clf


def predictor(clf, testdata, label):
    result = clf.predict_proba(testdata)
    return label


def relat_calc(la, lb):
    if la.ndim == 4:
        la = la[:, :, :, 1]
        lb = lb[:, :, :, 1]
    res = np.zeros((la.shape[0], lb.shape[1]))
    for i in range(la.shape[0]):
        res[i] = np.sum(la[i] * lb, axis=2)
    return res


def relat_calc2(la, lb):
    if la.ndim == 4:
        la = la[:, :, :, 1]
        lb = lb[:, :, :, 1]
    res = np.zeros((la.shape[0], lb.shape[1]))
    for i in range(la.shape[0]):
        res[i] = 1 - np.prod(1 - la[i] * lb, axis=2)
    return res


nus_trainer.run(trainer, predictor, relat_calc, 'lr_bs.bin')

<mask token>
sem = td.Semaphore(1)


def need_lock(func):

    def wrapper(*args, **kvargs):
        sem.acquire()
        func(*args, **kvargs)
        sem.release()
    return wrapper


@need_lock
def trainer(traindata, trainlabel):
    clf = BaggingClassifier(linear_model.LogisticRegression())
    clf = clf.fit(traindata, trainlabel)
    return clf


def predictor(clf, testdata, label):
    result = clf.predict_proba(testdata)
    return label


def relat_calc(la, lb):
    if la.ndim == 4:
        la = la[:, :, :, 1]
        lb = lb[:, :, :, 1]
    res = np.zeros((la.shape[0], lb.shape[1]))
    for i in range(la.shape[0]):
        res[i] = np.sum(la[i] * lb, axis=2)
    return res


def relat_calc2(la, lb):
    if la.ndim == 4:
        la = la[:, :, :, 1]
        lb = lb[:, :, :, 1]
    res = np.zeros((la.shape[0], lb.shape[1]))
    for i in range(la.shape[0]):
        res[i] = 1 - np.prod(1 - la[i] * lb, axis=2)
    return res


nus_trainer.run(trainer, predictor, relat_calc, 'lr_bs.bin')

import numpy as np
from sklearn import svm
from sklearn import linear_model
from sklearn import metrics
from sklearn import preprocessing
import threading as td
import pickle
import copy
import nus_trainer
sem = td.Semaphore(1)


def need_lock(func):

    def wrapper(*args, **kvargs):
        sem.acquire()
        func(*args, **kvargs)
        sem.release()
    return wrapper


@need_lock
def trainer(traindata, trainlabel):
    clf = BaggingClassifier(linear_model.LogisticRegression())
    clf = clf.fit(traindata, trainlabel)
    return clf


def predictor(clf, testdata, label):
    result = clf.predict_proba(testdata)
    return label


def relat_calc(la, lb):
    if la.ndim == 4:
        la = la[:, :, :, 1]
        lb = lb[:, :, :, 1]
    res = np.zeros((la.shape[0], lb.shape[1]))
    for i in range(la.shape[0]):
        res[i] = np.sum(la[i] * lb, axis=2)
    return res


def relat_calc2(la, lb):
    if la.ndim == 4:
        la = la[:, :, :, 1]
        lb = lb[:, :, :, 1]
    res = np.zeros((la.shape[0], lb.shape[1]))
    for i in range(la.shape[0]):
        res[i] = 1 - np.prod(1 - la[i] * lb, axis=2)
    return res


nus_trainer.run(trainer, predictor, relat_calc, 'lr_bs.bin')

import numpy as np
from sklearn import svm
from sklearn import linear_model
from sklearn import metrics
from sklearn import preprocessing
import threading as td
import pickle
import copy

import nus_trainer

sem = td.Semaphore(1)
def need_lock(func):
	def wrapper(*args, **kvargs):
		sem.acquire()
		func(*args, **kvargs)
		sem.release()
	return wrapper

@need_lock
def trainer(traindata, trainlabel):
	clf = BaggingClassifier(linear_model.LogisticRegression())
	clf = clf.fit(traindata, trainlabel)
	return clf

def predictor(clf, testdata, label):
	result = clf.predict_proba(testdata)
	return label

def relat_calc(la, lb):
	if la.ndim == 4:
		# 由于 LogisticRegression 返回两个数
		#       n:1:10
		la = la[:,:,:,1]
		#       1:m:10
		lb = lb[:,:,:,1]

	res = np.zeros((la.shape[0], lb.shape[1]))
	for i in range(la.shape[0]):
		res[i] = np.sum(la[i] * lb, axis=2)
	return res

def relat_calc2(la, lb):
	if la.ndim == 4:
		la = la[:,:,:,1]
		lb = lb[:,:,:,1]

	res = np.zeros((la.shape[0], lb.shape[1]))
	for i in range(la.shape[0]):
		res[i] = 1 - np.prod(1 - la[i] * lb, axis=2)
	return res

nus_trainer.run(trainer, predictor, relat_calc, "lr_bs.bin")
