Esempio n. 1
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. 2
0
        "fig": fig,
        "ax": axs[1][0]
    }).colorMap(
        ResultVisualizer().readAsMatrix(_file, "arduino", _sX, _sY) / 1000,
        "Atmega Program Memory Occupation [kB]")
    PlotTool({
        "fig": fig,
        "ax": axs[1][1]
    }).colorMap(ResultVisualizer().readAsMatrix(_file, "esp", _sX, _sY) / 1000,
                "ESP32 Program Memory Occupation [kB]")

    for ax in axs.flat:
        ax.set_xticks(range(4, _sX + 1, 5))
        ax.set_xticklabels(range(5, _sX + 1, 5))
        ax.set_yticks(range(0, _sY, 5))
        ax.set_yticklabels(np.flipud(range(5, _sY + 1, 5)))
        ax.set(xlabel='Number of Trees', ylabel='Maximum Depth')

    fig.tight_layout()
    fig.set_size_inches(8, 5)
    fig.savefig('example_rf_sweet_spot.png', format='png')
    plt.show()


#
e = Experiment("", "example_rf_sweet_spot")
trees = 30
depth = 15
resultFile = e.path("rf_regression_mem.csv")
regressionRF("../examples/mnoA.csv", trees, depth, resultFile)
plotSweetSpot(resultFile, trees, depth)
Esempio n. 3
0
from models.randomforest.RandomForest import RandomForest
from experiment.Experiment import Experiment
from code.CodeGenerator import CodeGenerator
from data.CSV import CSV
from data.ResultMatrix import ResultMatrix
import numpy as np
import matplotlib.pyplot as plt
from plot.PlotTool import PlotTool
from plot.ResultVisualizer import ResultVisualizer

# define the training data set and set up the model
training = "../examples/mnoA.csv"
model = RandomForest()
model.config.trees = 10
model.config.depth = 5

# perform a 10-fold cross validation
e = Experiment(training, "example_rf_mdi")
e.regression([model], 10)

#
M = CSV(e.path("features_0.csv")).toMatrix()
M.normalizeRows()
M.sortByMean()
M.save(e.path("rf_features.csv"))

#
ResultVisualizer().barchart(e.path("rf_features.csv"), xlabel="Feature", ylabel="Relative Feature Importance", savePNG=e.path(e.id+".png"))
Esempio n. 4
0
from models.m5.M5 import M5
from experiment.Experiment import Experiment
from code.CodeGenerator import CodeGenerator
from data.CSV import CSV
from code.Arduino import Arduino

# define the training data set and set up the model
training = "../examples/mnoA.csv"
model = M5()

# perform a 10-fold cross validation
e = Experiment(training, "example_arduino")
e.regression([model], 10)

# export the raw C++ code
codeFile = e.path("arduino.cpp")
CodeGenerator().export(training, model, codeFile)

# create a dummy Arduino project which executes the model
csv = CSV()
csv.load(training)
attributes = csv.findAttributes(0)

mem = Arduino().run(codeFile, "float", len(attributes) - 1)
print(mem)

# all results are written to results/example_arduino/
Esempio n. 5
0
from code.CodeEvaluator import CodeEvaluator
from data.FileHandler import FileHandler
from data.ResultMatrix import ResultMatrix

# define the training data set and set up the model
training = "../examples/mnoA.csv"
model = RandomForest()
model.config.trees = 10
model.config.depth = 10

csv = CSV(training)
attributes = csv.findAttributes(0)

# perform a 10-fold cross validation
e = Experiment(training, "example_model_reapplication")
e.regression([model], 10)

#
ce = CodeEvaluator()
R, C = ce.crossValidation(model, training, attributes, e.tmp())
R.printAggregated()

#
ResultVisualizer().scatter(
    [e.tmp() + "predictions_" + str(i) + ".csv" for i in range(10)],
    "prediction",
    "label",
    xlabel='Predicted Data Rate [MBit/s]',
    ylabel='Measured Data Rate [MBit/s',
    savePNG=e.path("example_model_reapplication.png"))
Esempio n. 6
0
from plot.ResultVisualizer import ResultVisualizer

# define the training data set and set up the model
training = "../examples/mnoA.csv"
model = ANN()

# perform a 10-fold cross validation
e = Experiment(training, "example_ann_feature_importance")
e.regression([model], 10)

#
M = ResultMatrix()
csv = CSV(training)
attributes = csv.findAttributes(0)

for i in range(10):
    training = e.tmp() + "training_mnoA_" + str(i) + ".csv"
    data = "\n".join(FileHandler().read(e.tmp() + "raw0_" + str(i) + ".txt"))

    ANN_WEKA(model).initModel(data, csv, attributes, training)
    M.add(csv.header[1:], model.computeInputLayerRanking())
M.normalizeRows()
M.sortByMean()
M.save(e.path("ann_features.csv"))

#
ResultVisualizer().barchart(e.path("ann_features.csv"),
                            xlabel="Feature",
                            ylabel="Relative Feature Importance",
                            savePNG=e.path(e.id + ".png"))
Esempio n. 7
0
        yStd = S[:, i]
        x = range(len(y))

        ax = axs[0, 0]
        ax.errorbar(x, y, yerr=yStd, capsize=7)
        ax.set_title('Model Performance')
        ax.set(xlabel='#Nodes on Hidden Layer', ylabel='Accuracy')

    plot(ResultVisualizer().readAsMatrix(_file, "msp", _layers, _nodes) / 1000,
         axs[0, 1], "MSP430", _nodes)
    plot(
        ResultVisualizer().readAsMatrix(_file, "arduino", _layers, _nodes) /
        1000, axs[1, 0], "Atmega", _nodes)
    plot(ResultVisualizer().readAsMatrix(_file, "esp", _layers, _nodes) / 1000,
         axs[1, 1], "ESP32", _nodes)

    fig.tight_layout()
    fig.set_size_inches(8, 5)
    fig.savefig(_example.path("example_ann_sweet_spot.png"), format="png")

    plt.show()


e = Experiment("", "example_ann_sweet_spot")
layers = 3
nodes = 26

resultFile = e.path("ann_classification_mem.csv")
classificationANN("../examples/vehicleClassification.csv", layers, nodes,
                  resultFile)
plotSweetSpot(resultFile, layers, nodes)
Esempio n. 8
0
from data.CSV import CSV

# define the training data set and set up the model
training = "../examples/mnoA.csv"
training = "../examples/vehicleClassification.csv"

csv = CSV(training)
attributes = csv.findAttributes(0)
d = csv.discretizeData()


model = RandomForest()
model.config.trees = 10
model.config.depth = 5

# perform a 10-fold cross validation
e = Experiment(training, "example_rf_disc")
e.classification([model], 10)

# export the C++ code 
CodeGenerator().export(training, model, e.path("rf.cpp"), d)

#
ce = CodeEvaluator()
R, C = ce.crossValidation(model, training, attributes, e.tmp(), d)
R.printAggregated()

# all results are written to results/example_rf_disc/


Esempio n. 9
0
from models.svm.SVM import SVM

from experiment.Experiment import Experiment
from plot.ResultVisualizer import ResultVisualizer
import matplotlib.pyplot as plt

# define the training data set and set up the model
training = "../examples/mnoA.csv"
models = [ANN(), M5(), RandomForest(), SVM()]

# perform a 10-fold cross validation
e = Experiment(training, "example_experiment")
e.regression(models, 10)

# visualize
files = [e.path("cv_" + str(i) + ".csv") for i in range(len(models))]
fig, axs = plt.subplots(2, 2)
fig.set_size_inches(8, 5)
xticks = [model.modelName for model in models]
ResultVisualizer().boxplots(files,
                            "r2",
                            xticks,
                            ylabel='R2',
                            fig=fig,
                            ax=axs[0][0],
                            show=False)
ResultVisualizer().boxplots(files,
                            "mae",
                            xticks,
                            ylabel='MAE [MBit/s]',
                            fig=fig,
from models.randomforest.RandomForest import RandomForest
from experiment.Experiment import Experiment
from data.CSV import CSV
from plot.ResultVisualizer import ResultVisualizer

# define the training data set and set up the model
training = "../examples/mnoA.csv"
csv = CSV(training)
model = RandomForest()

# perform a 10-fold cross validation
e = Experiment(training, "example_feature_reduction")
e.regression([model], 10)
CSV(e.path("cv_0.csv")).save(e.path("subset_0.csv"))
xTicks = ["None"]

# obtain a feature ranking
M = CSV(e.path("features_0.csv")).toMatrix()
M.normalizeRows()
M.sortByMean()

# sequentially remove the least important feature from the training data and retrain the model
subset = e.path("subset.csv")
for i in range(len(M.header) - 1):
    key = M.header[-1]
    M.header = M.header[0:-1]
    csv.removeColumnWithKey(key)
    csv.save(subset)

    e = Experiment(subset, "example_feature_reduction")
    e.regression([model], 10)
from models.ann.ANN import ANN
from experiment.Experiment import Experiment
from code.CodeGenerator import CodeGenerator
from data.FileHandler import FileHandler
from data.CSV import CSV

# define the training data set and set up the model
training = "../examples/mnoA.csv"
model = ANN()
model.hiddenLayers = [10, 10]

# perform a 10-fold cross validation
e = Experiment(training, "example_ann_visualization")
e.regression([model], 10)

# export the C++ code
CodeGenerator().export(training, model, e.path("ann.cpp"))
model.exportEps(e.path("ann_vis.eps"))
Esempio n. 12
0
from models.m5.M5 import M5
from experiment.Experiment import Experiment
from code.CodeGenerator import CodeGenerator

# define the training data set and set up the model
training = "../examples/mnoA.csv"
model = M5()

# perform a 10-fold cross validation
e = Experiment(training, "example_m5")
e.regression([model], 10)

# export the C++ code
CodeGenerator().export(training, model, e.path("m5.cpp"))

# all results are written to results/example_m5/
Esempio n. 13
0
from models.m5.M5 import M5
from experiment.Experiment import Experiment
from code.CodeGenerator import CodeGenerator
from data.CSV import CSV
from code.ESP32 import ESP32

# define the training data set and set up the model
training = "../examples/mnoA.csv"
model = M5()

# perform a 10-fold cross validation
e = Experiment(training, "example_esp")
e.regression([model], 10)

# export the raw C++ code 
codeFile = e.path("esp.cpp")
CodeGenerator().export(training, model, codeFile)

# create a dummy ESP32 project which executes the model
csv = CSV()
csv.load(training)
attributes = csv.findAttributes(0)

mem = ESP32().run(codeFile, "float", len(attributes)-1)
print(mem)

# all results are written to results/example_esp/