def evaluate_network(network, corpus):
    scores = []
    for instance in corpus:
        process = FeedForwardProcess(network, instance)
        process.run_to_end()
        scores.append(process.calc_score())
    return np.mean(scores)
logging.info("Generating corpus")
corpus = NestedList.generate_corpus(settings.CORPUS_SIZE)


logging.info("Evaluating untrained network")
mean_f1_score = evaluate_network(network, corpus)
logging.info("Mean score: %f", mean_f1_score)


logging.info("Training the network")
for i in range(settings.NUM_EPOCHS):
    
    logging.info("Epoch %d", i)
    
    process = FeedForwardProcess(network)
    logging.debug("Initial input: %s", [process.input_struct])
    process.run_to_end()
    logging.debug("Initial output: %s", process.output_struct.root)
    score = process.calc_score()
    logging.debug("Initial score: %f", score)
    
    if score != 1:
        
        fork_score = 0
        fork_count = 0
        
        while fork_score <= score and fork_count < settings.MAX_FORK_ATTEMPTS:
            logging.debug("Fork attempt %d", fork_count)
            fork, fork_step_index = process.get_random_fork()
            logging.debug("Running feed forward")