Esempio n. 1
0
    def initModel(self, _data, _csv, _attributes, _fileIn=""):
        self.model.clear()

        N = []
        O = []
        L = []
        csv = CSV()
        csv.load(_fileIn)
        self.model.inputLayerKeys = csv.header[1:]
        self.model.training = _fileIn

        if not "{" in _attributes[0].type:
            N, O = self.parseNodes(_data, 1)
            L = self.parseLayers(self.model.config.hiddenLayers, N, O)
            self.model.modelType = Type.REGRESSION
            self.model.outputLayerKeys.append(csv.header[0])
        else:
            classes = self.extractClasses(_attributes)
            N, O = self.parseNodes(_data, len(classes))
            L = self.parseLayers(self.model.config.hiddenLayers, N, O)
            self.model.modelType = Type.CLASSIFICATION
            self.model.outputLayerKeys = classes

        for i in range(len(L)):
            W, T = self.generateWeightMatrix(L[i])
            self.model.weights.append(W)
            self.model.thresholds.append(T)

        W, T = self.generateWeightMatrix(O)
        self.model.weights.append(W)
        self.model.thresholds.append(T)
        self.model.L = L
Esempio n. 2
0
def initExperiment(_args):
	FileHandler().createFolder("results")

	resultFolder = "results/" + args.name + "/"
	FileHandler().createFolder(resultFolder)
	resultFile = resultFolder + "result.csv"	

	if _args.classification:
		e = Experiment(args.classification, args.name)
		models = initModels(_args, Type.CLASSIFICATION)
		e.classification(models, 10)

		if _args.gen_code:
			exportCode(_args, resultFolder, _args.classification, models)

		if _args.visualize:
			files = [e.path("cv_" + str(i) + ".csv") for i in range(len(models))] 
			xTicks = [model.modelName for model in models]
			ResultVisualizer().boxplots(files, _args.visualize, xTicks,  ylabel=_args.visualize)

	elif _args.correlation:
		csv = CSV()
		csv.load(args.correlation)
		csv.computeCorrelationMatrix(resultFile)

		if _args.visualize:
			ResultVisualizer().colorMap(resultFile)

	elif _args.regression:
		e = Experiment(args.regression, args.name)
		models = initModels(_args, Type.REGRESSION)
		e.regression(models, 10)

		if _args.gen_code:
			exportCode(_args, resultFolder, _args.regression, models)

		if _args.visualize:
			files = [e.path("cv_" + str(i) + ".csv") for i in range(len(models))] 
			xTicks = [model.modelName for model in models]
			ResultVisualizer().boxplots(files, _args.visualize, xTicks,  ylabel=_args.visualize)

	print("[LIMITS]: results written to src/" + resultFolder)
Esempio n. 3
0
    def run(self, _models, _folds, _type):
        if self.genDataSets:
            csv = CSV()
            csv.load(self.training)
            csv.randomize(self.seed)

            if _type == Type.REGRESSION:
                csv.createFolds(_folds, self.resultFolder + "tmp/")
            elif _type == Type.CLASSIFICATION:
                classes = csv.stratify(_folds, self.resultFolder + "tmp/")

        R = ResultMatrix()
        for i in range(0, len(_models)):
            model = _models[i]
            model.modelType = _type
            config = Configuration(self.training, model, _folds)
            config.resultFolder = self.resultFolder
            config.tmpFolder = self.resultFolder + "tmp/"

            cv = CrossValidation(config, str(i))
            r = cv.run(csv.id, csv.id)
            results = np.hstack([r.data.mean(0),
                                 r.data.std(0)])  # TUDO: mean only if size>1 !
            R.add(r.header + [x + "_std" for x in r.header], results)

            if self.verbose:
                if i == 0:
                    r.printHeader()
                r.printAggregated()

        FileHandler().saveMatrix(R.header, R.data,
                                 self.resultFolder + "results.csv")

        if self.clear:
            FileHandler().clearFolder(self.resultFolder + "tmp/")

        return R.header, R.data
Esempio n. 4
0
	def run(self, _training, _models, _platforms):
		R = ResultMatrix()
		M = [];
		for model in _models:
			# run the cross validation to compute the model performance
			M.append(model.toString())
			e = Experiment(_training)
			header, result = e.regression([model], 10)
			R.add(header, result)

			# train with the global training data and export code
			training_arff = "tmp/recommend.arff"

			csv = CSV()
			csv.load(_training)
			csv.convertToARFF(training_arff, False)
			attributes = csv.findAttributes(0)
			lAtt = len(attributes)-1
			WEKA().train(model, training_arff, "0")
			
			data = "\n".join(FileHandler().read("tmp/raw0.txt"))
			codeFile = "recommend.c"

			model.exportCode(data, csv, attributes, codeFile)

			# complile platform-specific code
			for platform in _platforms:
				""





				#print(model.toString() + " : " + platform.toString())
		print(R.header, R.data)
		print(M)
Esempio n. 5
0
from data.CSV import CSV
from plot.ResultVisualizer import ResultVisualizer

# define the training data set
training = "../examples/mnoA.csv"

# compute amd export the correlation matrix
csv = CSV()
csv.load(training)

resultFolder = "results/example_correlation/"
resultFile = resultFolder + "corr.csv"
csv.computeCorrelationMatrix(resultFile)

ResultVisualizer().colorMap(resultFile,
                            savePNG=resultFolder + 'example_correlation.png')

# all results are written to results/example_correlation/