def JS_Swarm(docs, length_max, mfe=80000, number_locations=1000): sentences = [] for title, doc in docs: sentences.append(title) sentences.extend(doc) doc_freq = compute_tf(sentences) swarm_optimizer = SwarmOptimizer(fitness_fun=js_divergence, docs=docs, docs_representation = doc_freq, max_length=length_max, number_locations=number_locations, trial_limit=400, mfe=mfe, maximization=False) return swarm_optimizer.swarm_disperse()
def JS_Gen(docs, length_max, epoch, population_size=1000): sentences = [] for doc in docs: sentences.extend(doc) doc_freq = compute_tf(sentences) gen_optimizer = GeneticOptimizer(fitness_fun=js_divergence, docs=docs, docs_representation=doc_freq, max_length=length_max, population_size=population_size, survival_rate=0.5, mutation_rate=0.2, reproduction_rate=0.4, maximization=False) return gen_optimizer.evolve(epoch)