コード例 #1
0
ファイル: sheets.py プロジェクト: JamesEarle/GPP
ws['E1'] = "ENS_MAX"
ws['F1'] = "AVG-DJIA"
ws['G1'] = "MED-DJIA"
ws['H1'] = "AVG-STDFIT"
ws['I1'] = "MED-STDFIT"

# Get the abs difference between expected and actual value
for x in range(2, 80):
    ws['F' + str(x)] = "=ABS(B" + str(x) + "-A" + str(x) + ")^2"
    ws['G' + str(x)] = "=ABS(C" + str(x) + "-A" + str(x) + ")^2"  

# Sum of Squared Residuals for Ensembles
ws['H2'] = "=SUM(F2:F79)" # Avg
ws['I2'] = "=SUM(G2:G79)" # Median

activeDirectory = active.listActiveDirectory()
files = listdir(activeDirectory)

input = "D:/Development/GitHub/GPP/GeneticProgrammingPortfolio/input/DJIA/djia_close_12-16_testing_90.txt"
input_arr = []

# Read and write Dow Jones Index
for line in open(input, 'r'):
    input_arr.append(float(line))
for x in range(0, len(input_arr)):
    ws['A' + str(x+2)] = input_arr[x]

# All ensemble statistics
ensembleToSpreadsheet(activeDirectory + "/ensemble-avg.txt", 'B', ws)
ensembleToSpreadsheet(activeDirectory + "/ensemble-med.txt", 'C', ws)
ensembleToSpreadsheet(activeDirectory + "/ensemble-min.txt", 'D', ws)
コード例 #2
0
ファイル: sort_runs.py プロジェクト: JamesEarle/GPP
import operator
from os import listdir

## Author: James Earle.
##
## This script parses the output files from 20 separate GPP runs
## and creates a file, 'sorted_inds.txt' displaying all the runs 
## ordered by fitness in terms of their performance on testing data.
## We don't want to graph all of them, so we will not automate that 
## process. Rather, we'd like to hand pick the best, and then 1-2 
## that are average.

# Init an empty dictionary
best_of_run_inds = {}

outHourDir = active.listActiveDirectory()

# Append run number to the beginning of this pattern
pattern = "_best_ind_tree.txt"

# List and search through all the files.
allRunFiles = listdir(active.listActiveDirectory())

# Iterate the 20 necessary files  
for x in range(0, 20):
    patternWithRunNumber = str(x) + pattern
    if((patternWithRunNumber) in allRunFiles):
        with open(outHourDir + "/" + patternWithRunNumber, 'r') as file:
            std_test_fitness = file.readline() # it is the first line in the file
            # Add a float representation to the dictionary. Use string slicing.
            std_test_fitness = float(std_test_fitness[5:len(std_test_fitness)-1])