示例#1
0
def survival_stat(filename, thresholds = None):
    data = np.array(read_data_file(filename, ","))
    D, t = parse_data(data, inputcols = (2, 3, 4, 5, 6, 7, 8, 9, 10), ignorerows = [0], normalize = False)

    T = D[:, (2, 3)]
    outputs = D[:, (-1, 3)]
    C = get_C_index(T, outputs)

    print("C-index: " + str(C))
    print("Genetic error: " + str(1 / C))

    th = kaplanmeier(D, 2, 3, -1, threshold = thresholds)
    print("Threshold dividing the set in two equal pieces: " + str(th))
    if plt:
        plt.show()
示例#2
0
Created on Jun 7, 2011

@author: jonask
'''
from kalderstam.neural.error_functions.sum_squares import total_error
from kalderstam.neural.network import build_feedforward
from kalderstam.util.filehandling import parse_data
from kalderstam.neural.training.gradientdescent import traingd
from kalderstam.neural.training.davis_genetic import train_evolutionary
import numpy

xor_set = [[0, 0, 0],
           [0, 1, 1],
           [1, 0, 1],
           [1, 1, 0]]

xor_set = numpy.array(xor_set)

P, T = parse_data(xor_set, targetcols = 2, inputcols = [0, 1], normalize = False)

net = build_feedforward(2, 4, 1)

print("Error before training: " + str(total_error(T, net.sim(P))))
net = traingd(net, (P, T), (None, None), epochs = 1000, learning_rate = 0.1, block_size = 0)
print("Error after training: " + str(total_error(T, net.sim(P))))

net = build_feedforward(2, 4, 1)
print("Error before genetic training: " + str(total_error(T, net.sim(P))))
net = train_evolutionary(net, (P, T), (None, None), epochs = 100, population_size = 100)
print("Error after genetic training: " + str(total_error(T, net.sim(P))))