def orderscatter(outputs, T, filename = "", marker = '+'): if plt: c_index = get_cC_index(T, outputs) T_copy = T.copy() T_copy[:, 0] = outputs[:, 0] plt.figure() plt.title('Scatter between the indices of the sorted target and sorted output arrays\n' + str(filename) + "\nC index = " + str(c_index) + "\nEvents in green, Censored in red.") plt.xlabel('Target index') plt.ylabel('Network index') largest = 0 for x_index in xrange(len(T)): index_t = 0 #index in T index_o = 0 #index in outputs color = 'g' if not T[x_index, 1]: color = 'r' for cmp_index in xrange(len(T)): if T[x_index, 0] > T[cmp_index, 0]: index_t += 1 if index_t > largest: largest = index_t if T_copy[x_index, 0] > T_copy[cmp_index, 0]: index_o += 1 plt.plot(index_t, index_o, color + marker) plt.plot(range(largest), range(largest), 'r-')
def epoch_func(net, test_inputs, test_targets, block_size, epoch, timeslots = None, risk_groups = None, **pre_loop_kwargs): outputs = net.sim(test_inputs) sigma = calc_sigma(outputs) if block_size != 0 and block_size != len(test_targets): timeslots = generate_timeslots(test_targets) risk_groups = get_risk_groups(test_targets, timeslots) beta, beta_risk, part_func, weighted_avg = calc_beta(outputs, timeslots, risk_groups) error = cox_error(beta, sigma) c_index = get_cC_index(test_targets, outputs) logger.info("C index = " + str(c_index)) glogger.debugPlot('Total error', error, style = 'b-') glogger.debugPlot('C index vs Epochs', c_index, style = 'b-') glogger.debugPlot('Sigma * Beta vs Epochs', beta * sigma, style = 'g-') #glogger.debugPlot('Sigma vs Epochs', sigma, style = 'b-') #glogger.debugPlot('Beta vs Epochs', beta, style = 'b-') logger.info('Beta*Sigma = ' + str(sigma * beta)) return {'error': error}