Ejemplo n.º 1
0
def _compute_pie (feats, params):
	"""Compute a kernel with PluginEstimate.

	@param feats kernel features
	@param params dict containing various kernel parameters
	"""

	output=fileop.get_output(category.KERNEL, params)

	lab, labels=dataop.get_labels(feats['train'].get_num_vectors())
	output['classifier_labels']=lab
	pie=PluginEstimate()
	pie.set_labels(labels)
	pie.set_features(feats['train'])
	pie.train()

	kfun=eval('kernel.'+params['name']+'Kernel')
	kern=kfun(feats['train'], feats['train'], pie)
	output['kernel_matrix_train']=kern.get_kernel_matrix()
	kern.init(feats['train'], feats['test'])
	pie.set_features(feats['test'])
	output['kernel_matrix_test']=kern.get_kernel_matrix()

	classified=pie.classify().get_labels()
	output['classifier_classified']=classified

	fileop.write(category.KERNEL, output)
Ejemplo n.º 2
0
def _compute_pie(feats, params):
    """Compute a kernel with PluginEstimate.

	@param feats kernel features
	@param params dict containing various kernel parameters
	"""

    output = fileop.get_output(category.KERNEL, params)

    lab, labels = dataop.get_labels(feats["train"].get_num_vectors())
    output["classifier_labels"] = lab
    pie = PluginEstimate()
    pie.set_labels(labels)
    pie.set_features(feats["train"])
    pie.train()

    kfun = eval("kernel." + params["name"] + "Kernel")
    kern = kfun(feats["train"], feats["train"], pie)
    output["kernel_matrix_train"] = kern.get_kernel_matrix()
    kern.init(feats["train"], feats["test"])
    pie.set_features(feats["test"])
    output["kernel_matrix_test"] = kern.get_kernel_matrix()

    classified = pie.apply().get_labels()
    output["classifier_classified"] = classified

    fileop.write(category.KERNEL, output)
Ejemplo n.º 3
0
def _evaluate_pie (indata, prefix):
	pie=PluginEstimate()
	feats=util.get_features(indata, prefix)
	labels=BinaryLabels(double(indata['classifier_labels']))
	pie.set_labels(labels)
	pie.set_features(feats['train'])
	pie.train()

	fun=eval(indata[prefix+'name']+'Kernel')
	kernel=fun(feats['train'], feats['train'], pie)
	km_train=max(abs(
		indata[prefix+'matrix_train']-kernel.get_kernel_matrix()).flat)

	kernel.init(feats['train'], feats['test'])
	pie.set_features(feats['test'])
	km_test=max(abs(
		indata[prefix+'matrix_test']-kernel.get_kernel_matrix()).flat)
	classified=max(abs(
		pie.apply().get_values()-indata['classifier_classified']))

	return util.check_accuracy(indata[prefix+'accuracy'],
		km_train=km_train, km_test=km_test, classified=classified)
Ejemplo n.º 4
0
def kernel_histogram_word_string_modular (fm_train_dna=traindat,fm_test_dna=testdat,label_train_dna=label_traindat,order=3,gap=0,reverse=False):

	from shogun.Features import StringCharFeatures, StringWordFeatures, DNA, BinaryLabels
	from shogun.Kernel import HistogramWordStringKernel
	from shogun.Classifier import PluginEstimate#, MSG_DEBUG

	reverse = reverse
	charfeat=StringCharFeatures(DNA)
	#charfeat.io.set_loglevel(MSG_DEBUG)
	charfeat.set_features(fm_train_dna)
	feats_train=StringWordFeatures(charfeat.get_alphabet())
	feats_train.obtain_from_char(charfeat, order-1, order, gap, reverse)

	charfeat=StringCharFeatures(DNA)
	charfeat.set_features(fm_test_dna)
	feats_test=StringWordFeatures(charfeat.get_alphabet())
	feats_test.obtain_from_char(charfeat, order-1, order, gap, reverse)

	pie=PluginEstimate()
	labels=BinaryLabels(label_train_dna)
	pie.set_labels(labels)
	pie.set_features(feats_train)
	pie.train()

	kernel=HistogramWordStringKernel(feats_train, feats_train, pie)
	km_train=kernel.get_kernel_matrix()
	kernel.init(feats_train, feats_test)
	pie.set_features(feats_test)
	pie.apply().get_labels()
	km_test=kernel.get_kernel_matrix()
	return km_train,km_test,kernel
Ejemplo n.º 5
0
def _compute_pie(feats, params):
    """Compute a kernel with PluginEstimate.

	@param feats kernel features
	@param params dict containing various kernel parameters
	"""

    output = fileop.get_output(category.KERNEL, params)

    lab, labels = dataop.get_labels(feats['train'].get_num_vectors())
    output['classifier_labels'] = lab
    pie = PluginEstimate()
    pie.set_labels(labels)
    pie.set_features(feats['train'])
    pie.train()

    kfun = eval('kernel.' + params['name'] + 'Kernel')
    kern = kfun(feats['train'], feats['train'], pie)
    output['kernel_matrix_train'] = kern.get_kernel_matrix()
    kern.init(feats['train'], feats['test'])
    pie.set_features(feats['test'])
    output['kernel_matrix_test'] = kern.get_kernel_matrix()

    classified = pie.classify().get_labels()
    output['classifier_classified'] = classified

    fileop.write(category.KERNEL, output)
def kernel_histogram_word_string_modular(
    fm_train_dna=traindat, fm_test_dna=testdat, label_train_dna=label_traindat, order=3, gap=0, reverse=False
):

    from shogun.Features import StringCharFeatures, StringWordFeatures, DNA, Labels
    from shogun.Kernel import HistogramWordStringKernel
    from shogun.Classifier import PluginEstimate  # , MSG_DEBUG

    reverse = reverse
    charfeat = StringCharFeatures(DNA)
    # charfeat.io.set_loglevel(MSG_DEBUG)
    charfeat.set_features(fm_train_dna)
    feats_train = StringWordFeatures(charfeat.get_alphabet())
    feats_train.obtain_from_char(charfeat, order - 1, order, gap, reverse)

    charfeat = StringCharFeatures(DNA)
    charfeat.set_features(fm_test_dna)
    feats_test = StringWordFeatures(charfeat.get_alphabet())
    feats_test.obtain_from_char(charfeat, order - 1, order, gap, reverse)

    pie = PluginEstimate()
    labels = Labels(label_train_dna)
    pie.set_labels(labels)
    pie.set_features(feats_train)
    pie.train()

    kernel = HistogramWordStringKernel(feats_train, feats_train, pie)
    km_train = kernel.get_kernel_matrix()
    kernel.init(feats_train, feats_test)
    pie.set_features(feats_test)
    pie.classify().get_labels()
    km_test = kernel.get_kernel_matrix()
    return km_train, km_test, kernel
def kernel_salzberg_word_string_modular(fm_train_dna=traindat,
                                        fm_test_dna=testdat,
                                        label_train_dna=label_traindat,
                                        order=3,
                                        gap=0,
                                        reverse=False):
    from shogun.Features import StringCharFeatures, StringWordFeatures, DNA, Labels
    from shogun.Kernel import SalzbergWordStringKernel
    from shogun.Classifier import PluginEstimate

    charfeat = StringCharFeatures(fm_train_dna, DNA)
    feats_train = StringWordFeatures(charfeat.get_alphabet())
    feats_train.obtain_from_char(charfeat, order - 1, order, gap, reverse)

    charfeat = StringCharFeatures(fm_test_dna, DNA)
    feats_test = StringWordFeatures(charfeat.get_alphabet())
    feats_test.obtain_from_char(charfeat, order - 1, order, gap, reverse)

    pie = PluginEstimate()
    labels = Labels(label_train_dna)
    pie.set_labels(labels)
    pie.set_features(feats_train)
    pie.train()

    kernel = SalzbergWordStringKernel(feats_train, feats_train, pie, labels)
    km_train = kernel.get_kernel_matrix()

    kernel.init(feats_train, feats_test)
    pie.set_features(feats_test)
    pie.apply().get_labels()
    km_test = kernel.get_kernel_matrix()
    return km_train, km_test, kernel
def kernel_salzberg_word_string_modular (fm_train_dna=traindat,fm_test_dna=testdat,label_train_dna=label_traindat,
order=3,gap=0,reverse=False):
	from shogun.Features import StringCharFeatures, StringWordFeatures, DNA, Labels
	from shogun.Kernel import SalzbergWordStringKernel
	from shogun.Classifier import PluginEstimate

	charfeat=StringCharFeatures(fm_train_dna, DNA)
	feats_train=StringWordFeatures(charfeat.get_alphabet())
	feats_train.obtain_from_char(charfeat, order-1, order, gap, reverse)

	charfeat=StringCharFeatures(fm_test_dna, DNA)
	feats_test=StringWordFeatures(charfeat.get_alphabet())
	feats_test.obtain_from_char(charfeat, order-1, order, gap, reverse)

	pie=PluginEstimate()
	labels=Labels(label_train_dna)
	pie.set_labels(labels)
	pie.set_features(feats_train)
	pie.train()

	kernel=SalzbergWordStringKernel(feats_train, feats_train, pie, labels)
	km_train=kernel.get_kernel_matrix()

	kernel.init(feats_train, feats_test)
	pie.set_features(feats_test)
	pie.apply().get_labels()
	km_test=kernel.get_kernel_matrix()
	return km_train,km_test,kernel
def plugin_estimate_salzberg ():
	print 'PluginEstimate w/ SalzbergWord'

	from shogun.Features import StringCharFeatures, StringWordFeatures, DNA, Labels
	from shogun.Kernel import SalzbergWordStringKernel
	from shogun.Classifier import PluginEstimate

	order=3
	gap=0
	reverse=False

	charfeat=StringCharFeatures(fm_train_dna, DNA)
	feats_train=StringWordFeatures(charfeat.get_alphabet())
	feats_train.obtain_from_char(charfeat, order-1, order, gap, reverse)

	charfeat=StringCharFeatures(fm_test_dna, DNA)
	feats_test=StringWordFeatures(charfeat.get_alphabet())
	feats_test.obtain_from_char(charfeat, order-1, order, gap, reverse)

	pie=PluginEstimate()
	labels=Labels(label_train_dna)
	pie.set_labels(labels)
	pie.set_features(feats_train)
	pie.train()

	kernel=SalzbergWordStringKernel(feats_train, feats_test, pie, labels)
	km_train=kernel.get_kernel_matrix()

	kernel.init(feats_train, feats_test)
	pie.set_features(feats_test)
	pie.classify().get_labels()
	km_test=kernel.get_kernel_matrix()
Ejemplo n.º 10
0
def _evaluate_pie(indata, prefix):
    pie = PluginEstimate()
    feats = util.get_features(indata, prefix)
    labels = BinaryLabels(double(indata['classifier_labels']))
    pie.set_labels(labels)
    pie.set_features(feats['train'])
    pie.train()

    fun = eval(indata[prefix + 'name'] + 'Kernel')
    kernel = fun(feats['train'], feats['train'], pie)
    km_train = max(
        abs(indata[prefix + 'matrix_train'] - kernel.get_kernel_matrix()).flat)

    kernel.init(feats['train'], feats['test'])
    pie.set_features(feats['test'])
    km_test = max(
        abs(indata[prefix + 'matrix_test'] - kernel.get_kernel_matrix()).flat)
    classified = max(
        abs(pie.apply().get_confidences() - indata['classifier_classified']))

    return util.check_accuracy(indata[prefix + 'accuracy'],
                               km_train=km_train,
                               km_test=km_test,
                               classified=classified)