示例#1
0
	hyper_parameters = None
	for key in ['learning_rate', 'beta', 'gamma', 'dense_sizes']:
		if args.__dict__[key] == None:
			if hyper_parameters == None:
				tuning_file = os.path.join(ROOT_DIR, 'experiments', 'tuning', 'results', 'smad', args.antipattern, args.test_system + '.csv')
				hyper_parameters = detection_utils.get_optimal_hyperparameters(tuning_file)
			args.__dict__[key] = hyper_parameters[' '.join(key.split('_')).capitalize()]

	# Remove the test system from the training set
	systems = data_utils.getSystems()
	systems.remove(args.test_system)
	systems = list(systems)

	# Get training data
	x_train = reduce(lambda x1, x2: np.concatenate((x1, x2), axis=0), [detection_utils.getInstances(args.antipattern, s) for s in systems])
	y_train = reduce(lambda x1, x2: np.concatenate((x1, x2), axis=0), [detection_utils.getLabels(args.antipattern, s) for s in systems])
	
	# Get test data
	x_test = detection_utils.getInstances(args.antipattern, args.test_system)
	y_test = detection_utils.getLabels(args.antipattern, args.test_system)

	# Create model
	model = md.SMAD(
		shape=args.dense_sizes, 
		input_size=x_train.shape[-1])

	# To save and restore a trained model
	saver = tf.train.Saver(max_to_keep=args.n_net)

	# Train several neural networks
	all_losses_train = []
示例#2
0
		else:
			core_metrics[system] = hist_cm.getFECoreMetrics(system)

	params = np.arange(0.0, 20.0, 0.5)/100. if args.antipattern == 'god_class' else np.arange(100., 300., 5)/100.

	# Initialize progressbar
	bar = progressbar.ProgressBar(maxval=len(params), \
		widgets=['Tuning HIST parameters for ' + args.test_system + ': ' ,progressbar.Percentage()])
	bar.start()

	perfs = []
	for i, alpha in enumerate(params):
		bar.update(i)
		overall_prediction = np.empty(shape=[0, 1])
		overall_labels = np.empty(shape=[0, 1])
		for system in systems:
			smells = [entityName for entityName, ratio in core_metrics[system].items() if ratio[0]>alpha]
			prediction = detection_utils.predictFromDetect(args.antipattern, system, smells)
			overall_prediction = np.concatenate((overall_prediction, prediction), axis=0)
			overall_labels = np.concatenate((overall_labels, detection_utils.getLabels(args.antipattern, system)), axis=0)
		
		perfs.append(detection_utils.mcc(overall_prediction, overall_labels))
	bar.finish()
	output_file_path = os.path.join(ROOT_DIR, 'experiments', 'tuning', 'results', 'hist', args.antipattern, args.test_system + '.csv')

	indexes = np.argsort(np.array(perfs))
	with open(output_file_path, 'w') as file:
		file.write("Alpha;MCC\n")
		for i in reversed(indexes):
			file.write("{0:.3f};{1}\n".format(params[i], perfs[i]))
示例#3
0
		session.run(model.learning_step, feed_dict=feed_dict_train)

if __name__ == "__main__":
	args = parse_args()

	# Remove the test system from the set of systems
	systems = data_utils.getSystems()
	systems.remove(args.test_system)

	# Store instances and labels for each system
	instances = {}
	labels    = {}
	for system in systems:
		instances[system] = detection_utils.getInstances(args.antipattern, system, True)
		labels[system]    = detection_utils.getLabels(args.antipattern, system)

	# Initialize progress bar
	bar = progressbar.ProgressBar(maxval=args.n_test, \
		widgets=['Performing cross validation for ' + args.test_system + ': ' ,progressbar.Percentage()])
	bar.start()

	output_file_path = os.path.join(ROOT_DIR, 'experiments', 'tuning', 'results', 'smad', args.antipattern, args.test_system + '.csv')

	params = []
	perfs  = []
	for i in range(args.n_test):
		learning_rate, beta, gamma, dense_sizes = generateRandomHyperParameters()
		params.append([learning_rate, beta, gamma, dense_sizes])

		pred_overall   = np.empty(shape=[0, 1])
示例#4
0
import numpy as np

systems = data_utils.getSystems()

overall_prediction_incode = np.empty(shape=[0, 1])
overall_prediction_hist = np.empty(shape=[0, 1])
overall_prediction_jd = np.empty(shape=[0, 1])
overall_prediction_vote = np.empty(shape=[0, 1])
overall_prediction_asci = np.empty(shape=[0, 1])
overall_prediction_smad = np.empty(shape=[0, 1])

overall_labels = np.empty(shape=[0, 1])
for system in systems:
    # Get labels
    labels = detection_utils.getLabels('feature_envy', system)
    overall_labels = np.concatenate((overall_labels, labels), axis=0)

    # Compute performances for InCode
    prediction_incode = incode.predict(system)
    overall_prediction_incode = np.concatenate(
        (overall_prediction_incode, prediction_incode), axis=0)

    # Compute performances for HIST
    prediction_hist = hist_fe.predict(system)
    overall_prediction_hist = np.concatenate(
        (overall_prediction_hist, prediction_hist), axis=0)

    # Compute performances for JDeodorant
    prediction_jd = jdeodorant_fe.predict(system)
    overall_prediction_jd = np.concatenate(
示例#5
0
import numpy as np

systems = data_utils.getSystems()

overall_prediction_decor = np.empty(shape=[0, 1])
overall_prediction_hist = np.empty(shape=[0, 1])
overall_prediction_jd = np.empty(shape=[0, 1])
overall_prediction_vote = np.empty(shape=[0, 1])
overall_prediction_asci = np.empty(shape=[0, 1])
overall_prediction_smad = np.empty(shape=[0, 1])

overall_labels = np.empty(shape=[0, 1])
for system in systems:
    # Get labels
    labels = detection_utils.getLabels('god_class', system)
    overall_labels = np.concatenate((overall_labels, labels), axis=0)

    # Compute performances for DECOR
    prediction_decor = decor.predict(system)
    overall_prediction_decor = np.concatenate(
        (overall_prediction_decor, prediction_decor), axis=0)

    # Compute performances for HIST
    prediction_hist = hist_gc.predict(system)
    overall_prediction_hist = np.concatenate(
        (overall_prediction_hist, prediction_hist), axis=0)

    # Compute performances for JDeodorant
    prediction_jd = jdeodorant_gc.predict(system)
    overall_prediction_jd = np.concatenate(
示例#6
0
    return parser.parse_args()


if __name__ == '__main__':
    args = parse_args()

    # Remove the test system from the training set and build dataset
    systems = data_utils.getSystems()
    systems.remove(args.test_system)
    systems = list(systems)

    # Get overall labels
    overall_labels = np.empty(shape=[0, 1])
    for system in systems:
        overall_labels = np.concatenate(
            (overall_labels, detection_utils.getLabels('feature_envy',
                                                       system)),
            axis=0)

    params = [(atfd, laa, fdp) for atfd in range(1, 6) for laa in range(1, 6)
              for fdp in range(1, 6)]

    # Initialize progressbar
    bar = progressbar.ProgressBar(maxval=len(params), \
     widgets=['Tuning InCode parameters for ' + args.test_system + ': ' ,progressbar.Percentage()])
    bar.start()

    perfs = []
    count = 0
    for atfd, laa, fdp in params:
        count += 1
        bar.update(count)
示例#7
0
    # Remove the test system from the training set
    systems = data_utils.getSystems()
    systems.remove(args.test_system)
    systems = list(systems)

    # Get training instances
    x_train = reduce(
        lambda x1, x2: np.concatenate((x1, x2), axis=0),
        [detection_utils.getInstances(args.antipattern, s) for s in systems])

    # Get ASCI training labels
    tools_predictions_list = [
        asci_utils.get_tools_predictions(args.antipattern, s) for s in systems
    ]
    labels_list = [
        detection_utils.getLabels(args.antipattern, s) for s in systems
    ]
    y_train_asci = asci_utils.get_asci_labels(tools_predictions_list,
                                              labels_list)

    # Get test data, note that here y_test contains the real labels while y_train_asci contains ASCI labels, i.e., tools' indexes
    x_test = detection_utils.getInstances(args.antipattern, args.test_system)
    y_test = detection_utils.getLabels(args.antipattern, args.test_system)
    tools_predictions_test = asci_utils.get_tools_predictions(
        args.antipattern, args.test_system)

    # Train and compute ensemble prediction on test set
    predictions = np.zeros((args.n_tree, x_test.shape[0], 1))
    for i in range(args.n_tree):
        clf = tree.DecisionTreeClassifier(
            min_samples_split=args.min_samples_split,