Exemple #1
0
def getRepertoire():
    try:
        dict = jsonEditor.readDict(
            GeneticAlgorithm.Constants.repertoire_paths[0])
        return dict
    except Exception, e:
        print "error", e
Exemple #2
0
def plot2d_2_series_from_path(path):
    data_read = jsonEditor.readDict(path + "values")
    data = data_read["fitness"]
    data2 = data_read["novelty"]
    if len(data2.keys()) == 0:
        plot2d_2_series(data, data2, path + "values_graph", "generations",
                        "fitness")
    else:
        plot2d_2_series(data, data2, path + "values_graph", "generations",
                        "fitness and novelty")

    data_read2 = jsonEditor.readDict(path + "ncd_full")
    plot2d(data_read2, path + "ncd_full", "generations", "ncd_full")
    data_read3 = jsonEditor.readDict(path + "criterion_1")
    plot2d(data_read3, path + "criterion_1", "generations", "criterion 1")
    data_read4 = jsonEditor.readDict(path + "criterion_2")
    plot2d(data_read4, path + "criterion_2", "generations", "criterion 2")
Exemple #3
0
def mutation(movesList):
    for _ in range(
            random.randint(
                1, GeneticAlgorithm.Constants.max_number_of_mutations)):
        movesList[random.randint(
            0,
            len(movesList) - 1)] = jsonEditor.readDict(
                random.choice(GeneticAlgorithm.Constants.list_of_moves))
    return (movesList, )
Exemple #4
0
def getResults():
    try:
        dict = jsonEditor.readDict(GeneticAlgorithm.Constants.results_path)
        return dict
    except Exception, e:
        print "error", Exception, e
Exemple #5
0
def getRepertoireWithPath(path):
    try:
        dict = jsonEditor.readDict(path)
        return dict
    except Exception, e:
        print "error", Exception, e
Exemple #6
0
def loadListOfMoves():
    return jsonEditor.readDict(GeneticAlgorithm.Constants.list_of_moves_path)
Exemple #7
0
def getArchive():
    try:
        dict = jsonEditor.readDict(GeneticAlgorithm.Constants.archive_path)
        return dict
    except Exception, e:
        print "error", Exception, e
Exemple #8
0
def getres(path):
    try:
        dict = jsonEditor.readDict(path)
        return dict
    except Exception, e:
        print "error", Exception, e
Exemple #9
0
            repertoire = []
            repertoire_length = 0
            # calculate fitness generations
            gen_fitness = calculate_fitness_generations(path=path)
            gen_fitness_total.append(gen_fitness)

            # open the repertoire
            with open(os.path.join(path, "repertoire_serialized")) as fp:
                for line in fp:
                    if (line != "\n"):
                        repertoire_length = repertoire_length + 1
                        repertoire.append(line[:-1])
            fp.close()

            results_fitness_and_novelty = jsonEditor.readDict(
                os.path.join(path, "results"))
            fit = []
            ncd_local = []
            string_rep = concatenate_items_to_string(repertoire)
            nov_local = []
            for x in results_fitness_and_novelty["results"]:
                results_complete.append(x["ind"])
                avg_fit_results = avg_fit_results + x["value"][0]
                fit.append(x["value"][0])
                ncd_local.append(compute_ncd("".join(x["ind"]), string_rep))
                if "and" in path:
                    avg_nov = avg_nov + x["value"][1]
                    nov_local.append(x["value"][1])
            all_results["alg"] = fit
            full_ncd_total["alg"] = ncd_local
            avg_fit_results = avg_fit_results / results_length
Exemple #10
0
import bcolors

from NaoLibs.lib1 import angles_2 as angles
import os
from JsonEditor import jsonEditor
from NaoLibs.Common import sendToRobot
from Mathematical import plot3d

# filename = 'prova8maggio'
filename = 'provanoh1'
# filename = 'nohbasics'
dirName = "json/1/" + filename
data = jsonEditor.readKinectDict(filename)
t = 0
if not os.path.exists(dirName):
    os.mkdir(dirName)

for key in data['datafile']:
    value = key['data']
    print bcolors.ERRMSG + "number",key["coord"] + bcolors.ENDC
    listAngles = angles.anglesList(value)
    jsonEditor.dumpDict(dirName + "/" + str(t), listAngles)
    listAngles = jsonEditor.readDict(dirName + "/" + str(t))
    sendToRobot.sendrobot(listAngles,t)
    # plot3d.printplot(key)
    t = t + 1
Exemple #11
0
def readAndMove(filename, t):
    listAngles = jsonEditor.readDict(filename)
    sendToRobot.sendrobot(listAngles, t)
Exemple #12
0
def readAndMove(filename, t):
    listAngles = jsonEditor.readDict(filename)
    print (listAngles)
    # here can be added the balance
    sendToRobot.sendrobot(listAngles, t)