Пример #1
0
def _get_filename(catID, out):
    """
	Return filename for testcase data's output.

	@param catID ID of the category
	@param out data to be written into file
	@return string with the filename
	"""

    params = []

    name = category.get_name(catID)
    for key, val in out.iteritems():
        if _is_excluded_from_filename(key):
            continue
        if key == name:
            continue

        cname = val.__class__.__name__
        if cname == 'bool' or cname == 'float' or cname == 'int' or cname == 'str':
            val = str(val)
            val = val.replace('-', 'n')
            val = val.replace('+', 'p')
            params.append(val)

    params = '_'.join(params).replace('.', '')
    if len(params) > 0:
        params = '_' + params
    else:  # otherwise problems with one interface (FIXME: find out which)
        params = '_fnord'

    dir = DIR_OUTPUT + os.sep + category.get_as_string(catID) + os.sep
    return dir + out[name] + params + EXT_OUTPUT
Пример #2
0
def write(catID, out):
    """
	Write given testcase data to a file.

	@param cat ID of the category, like category.KERNEL
	@param out data to be written into file
	@return Success of operation
	"""

    fnam = _get_filename(catID, out)
    print 'Writing for '+category.get_as_string(catID).upper()+': '+ \
     os.path.basename(fnam)

    dirname = os.path.dirname(fnam)
    if not os.path.isdir(dirname):
        os.mkdir(dirname)

    mfile = open(fnam, mode='w')
    for key, val in out.iteritems():
        cname = val.__class__.__name__
        if cname == 'bool' or cname == 'str':
            mfile.write("%s = '%s';\n" % (key, val))
        elif cname == 'ndarray' or cname == 'matrix':
            mfile.write("%s;\n" % _get_matrix(key, val))
        else:
            mfile.write("%s = %s;\n" % (key, val))
    mfile.close()

    return True
Пример #3
0
def _get_filename (catID, out):
	"""
	Return filename for testcase data's output.

	@param catID ID of the category
	@param out data to be written into file
	@return string with the filename
	"""

	params=[]

	name=category.get_name(catID)
	for key, val in out.iteritems():
		if _is_excluded_from_filename(key):
			continue
		if key==name:
			continue

		cname=val.__class__.__name__
		if cname=='bool' or cname=='float' or cname=='int' or cname=='str':
			val=str(val)
			val=val.replace('-', 'n')
			val=val.replace('+', 'p')
			params.append(val)

	params='_'.join(params).replace('.', '')
	if len(params)>0:
		params='_'+params
	else: # otherwise problems with one interface (FIXME: find out which)
		params='_fnord'

	dir=DIR_OUTPUT+os.sep+category.get_as_string(catID)+os.sep
	return dir+out[name]+params+EXT_OUTPUT
Пример #4
0
def write (catID, out):
	"""
	Write given testcase data to a file.

	@param cat ID of the category, like category.KERNEL
	@param out data to be written into file
	@return Success of operation
	"""

	fnam=_get_filename(catID, out)
	print 'Writing for '+category.get_as_string(catID).upper()+': '+ \
		os.path.basename(fnam)

	dirname=os.path.dirname(fnam)
	if not os.path.isdir(dirname):
		os.mkdir(dirname)

	mfile=open(fnam, mode='w')
	for key, val in out.iteritems():
		cname=val.__class__.__name__
		if cname=='bool' or cname=='str':
			mfile.write("%s = '%s';\n"%(key, val))
		elif cname=='ndarray' or cname=='matrix':
			mfile.write("%s;\n"%_get_matrix(key, val))
		else:
			mfile.write("%s = %s;\n"%(key, val))
	mfile.close()

	return True
Пример #5
0
def get_output(catID, params, prefix=''):
    """
	Return output data to be written into the testcase's file.

	After computations, the gathered data is structured and
	put into one data structure which can conveniently be written to a
	file that will represent the testcase.
	
	@param catID ID of entity's category, e.g. category.DISTANCE
	@param params hash with parameters to entity
	@param prefix prefix for parameter's name, e.g. 'subkernel'
	@return Dict containing testcase data ready to be written to file
	"""

    out = {}
    prefix = category.get_as_string(catID) + '_' + prefix
    if catID == category.CLASSIFIER:
        out = _get_output_classifier(params, prefix)
    elif catID == category.CLUSTERING:
        out = _get_output_distribution(params, prefix)
    elif catID == category.DISTANCE:
        out = _get_output_distance(params, prefix)
    elif catID == category.DISTRIBUTION:
        out = _get_output_distribution(params, prefix)
    elif catID == category.KERNEL:
        out = _get_output_kernel(params, prefix)
    elif catID == category.PREPROC:
        out = _get_output_preproc(params, prefix)
    elif catID == category.REGRESSION:
        out = _get_output_regression(params, prefix)
    else:
        return out

    out[prefix + 'name'] = params['name']
    if params.has_key('accuracy'):
        out[prefix + 'accuracy'] = params['accuracy']

    # example data
    if params.has_key('data'):
        out[prefix + 'data_train'] = matrix(params['data']['train'])
        out[prefix + 'data_test'] = matrix(params['data']['test'])

    # params wrt feature class & type
    if params.has_key('feature_class'):
        fclass = params['feature_class']
        ftype = params['feature_type']
        out[prefix + 'feature_class'] = fclass
        out[prefix + 'feature_type'] = ftype

        if fclass == 'string' or (fclass == 'simple' and ftype == 'Char'):
            if params.has_key('alphabet'):
                out[prefix + 'alphabet'] = params['alphabet']
            else:
                out[prefix + 'alphabet'] = 'DNA'
            out[prefix + 'seqlen'] = dataop.LEN_SEQ

        elif fclass == 'simple' and ftype == 'Byte':
            out[prefix + 'alphabet'] = 'RAWBYTE'
            out[prefix + 'seqlen'] = dataop.LEN_SEQ

        elif fclass == 'string_complex':
            if params.has_key('alphabet'):
                out[prefix + 'alphabet'] = params['alphabet']
            else:
                out[prefix + 'alphabet'] = 'DNA'
            if params.has_key('order'):
                out[prefix + 'order'] = params['order']
            else:
                out[prefix + 'order'] = featop.WORDSTRING_ORDER
            if params.has_key('gap'):
                out[prefix + 'gap'] = params['gap']
            else:
                out[prefix + 'gap'] = featop.WORDSTRING_GAP
            if params.has_key('reverse'):
                out[prefix + 'reverse'] = params['reverse']
            else:
                out[prefix + 'reverse'] = featop.WORDSTRING_REVERSE
            if params.has_key('seqlen'):
                out[prefix + 'seqlen'] = params['seqlen']
            else:
                out[prefix + 'seqlen'] = dataop.LEN_SEQ

    out['init_random'] = dataop.INIT_RANDOM

    return out
Пример #6
0
def get_output (catID, params, prefix=''):
	"""
	Return output data to be written into the testcase's file.

	After computations, the gathered data is structured and
	put into one data structure which can conveniently be written to a
	file that will represent the testcase.

	@param catID ID of entity's category, e.g. category.DISTANCE
	@param params hash with parameters to entity
	@param prefix prefix for parameter's name, e.g. 'subkernel'
	@return Dict containing testcase data ready to be written to file
	"""

	out={}
	prefix=category.get_as_string(catID)+'_'+prefix
	if catID==category.CLASSIFIER:
		out=_get_output_classifier(params, prefix)
	elif catID==category.CLUSTERING:
		out=_get_output_distribution(params, prefix)
	elif catID==category.DISTANCE:
		out=_get_output_distance(params, prefix)
	elif catID==category.DISTRIBUTION:
		out=_get_output_distribution(params, prefix)
	elif catID==category.KERNEL:
		out=_get_output_kernel(params, prefix)
	elif catID==category.PREPROC:
		out=_get_output_preproc(params, prefix)
	elif catID==category.REGRESSION:
		out=_get_output_regression(params, prefix)
	else:
		return out

	out[prefix+'name']=params['name']
	if params.has_key('accuracy'):
		out[prefix+'accuracy']=params['accuracy']

	# example data
	if params.has_key('data'):
		out[prefix+'data_train']=matrix(params['data']['train'])
		out[prefix+'data_test']=matrix(params['data']['test'])


	# params wrt feature class & type
	if params.has_key('feature_class'):
		fclass=params['feature_class']
		ftype=params['feature_type']
		out[prefix+'feature_class']=fclass
		out[prefix+'feature_type']=ftype

		if fclass=='string' or (fclass=='simple' and ftype=='Char'):
			if params.has_key('alphabet'):
				out[prefix+'alphabet']=params['alphabet']
			else:
				out[prefix+'alphabet']='DNA'
			out[prefix+'seqlen']=dataop.LEN_SEQ

		elif fclass=='simple' and ftype=='Byte':
			out[prefix+'alphabet']='RAWBYTE'
			out[prefix+'seqlen']=dataop.LEN_SEQ

		elif fclass=='string_complex':
			if params.has_key('alphabet'):
				out[prefix+'alphabet']=params['alphabet']
			else:
				out[prefix+'alphabet']='DNA'
			if params.has_key('order'):
				out[prefix+'order']=params['order']
			else:
				out[prefix+'order']=featop.WORDSTRING_ORDER
			if params.has_key('gap'):
				out[prefix+'gap']=params['gap']
			else:
				out[prefix+'gap']=featop.WORDSTRING_GAP
			if params.has_key('reverse'):
				out[prefix+'reverse']=params['reverse']
			else:
				out[prefix+'reverse']=featop.WORDSTRING_REVERSE
			if params.has_key('seqlen'):
				out[prefix+'seqlen']=params['seqlen']
			else:
				out[prefix+'seqlen']=dataop.LEN_SEQ

	out['init_random']=dataop.INIT_RANDOM

	return out