Пример #1
0
def steels_uniwersal_basic_experiment(num_iter, agents,
        interaction, classifier=SteelsClassifier, topology=None,
        inc_category_treshold=None, dump_freq=50, stimuli=None, chooser=None):

    topology = topology or generate_simple_network(agents)

#       if stimuli == None:
#               stimuli = def_value(None, default_stimuli())

    if inc_category_treshold is not None:
        interaction.__class__.def_inc_category_treshold = inc_category_treshold

    chooser = chooser or RandomStimuliChooser(use_distance=True, distance=50.)
    env = Environment(stimuli, chooser)
    for agent in agents:
        agent.env = env

    s = Simulation(topology, interaction, agents)
    res = s.run(num_iter, dump_freq)

#       import pprint
#       print pprint.pprint(error_counter)
    try:
#               s = sum(error_counter.values())
#               for k,v in error_counter.iteritems():
#                       print "%s: %s" % (k, float(v)/s)
        for a in agents:
            print "[%s]:%s" % (len(a.state.lexicon.known_words()),
                                                    a.state.lexicon.known_words())
        print "OK"
    except:
        pass

    return res
Пример #2
0
def steels_uniwersal_basic_experiment(num_iter,
                                      agents,
                                      environments,
                                      interaction,
                                      classifier=SteelsClassifier,
                                      topology=None,
                                      inc_category_treshold=None,
                                      dump_freq=50,
                                      stimuli=None):

    from cog_abm.core import Environment, Simulation
    from cog_abm.core.environment import RandomStimuliChooser
    from pygraph.algorithms.generators import generate

    num_agents = len(agents)
    topology = def_value(
        topology, generate(num_agents,
                           num_agents * (num_agents - 1) / 2))

    #       if stimuli == None:
    #               stimuli = def_value(None, default_stimuli())

    if inc_category_treshold is not None:
        interaction.__class__.def_inc_category_treshold = inc_category_treshold

    chooser = RandomStimuliChooser(use_distance=True, distance=50.)
    env = Environment(stimuli, chooser)

    for key in environments.keys():
        Simulation.environments[key] =\
                                                Environment(environments[key].stimuli, chooser)
    #TODO: think about this all...
    glob = Simulation.environments["global"]

    Simulation.global_environment = def_value(glob, env)

    s = Simulation(topology, interaction, agents)
    res = s.run(num_iter, dump_freq)

    #       import pprint
    #       print pprint.pprint(error_counter)
    try:
        #               s = sum(error_counter.values())
        #               for k,v in error_counter.iteritems():
        #                       print "%s: %s" % (k, float(v)/s)
        for a in agents:
            print "[%s]:%s" % (len(
                a.state.lexicon.known_words()), a.state.lexicon.known_words())
        print "OK"
    except:
        pass

    return res
Пример #3
0
def steels_uniwersal_basic_experiment(num_iter, agents, environments,
			interaction, classifier=SteelsClassifier, topology=None,
			inc_category_treshold=None, dump_freq=50, stimuli=None):
				
	from cog_abm.core import Environment, Simulation
	from cog_abm.core.environment import RandomStimuliChooser
	from pygraph.algorithms.generators import generate

	num_agents = len(agents)
	topology = def_value(topology, 
	                     generate(num_agents, num_agents*(num_agents-1)/2))
	
#	if stimuli == None:
#		stimuli = def_value(None, default_stimuli())
	
	if inc_category_treshold is not None:
		interaction.__class__.def_inc_category_treshold = inc_category_treshold

	chooser = RandomStimuliChooser(use_distance=True, distance=50.)
	env = Environment(stimuli, chooser)

	for key in environments.keys():
		Simulation.environments[key] =\
							Environment(environments[key].stimuli, chooser)
	#TODO: think about this all...
	glob = Simulation.environments["global"]

		
	Simulation.global_environment = def_value(glob , env)

	s = Simulation(topology, interaction, agents)
	res = s.run(num_iter, dump_freq)
	
#	import pprint
#	print pprint.pprint(error_counter)
	try:
#		s = sum(error_counter.values())
#		for k,v in error_counter.iteritems():
#			print "%s: %s" % (k, float(v)/s)
		for a in agents:
			print "[%s]:%s" % (len(a.state.lexicon.known_words()), 
								a.state.lexicon.known_words())
		print "OK"
	except:
		pass

	return res
Пример #4
0
def steels_uniwersal_basic_experiment(num_iter,
                                      agents,
                                      interaction,
                                      classifier=SteelsClassifier,
                                      topology=None,
                                      inc_category_treshold=None,
                                      dump_freq=50,
                                      stimuli=None,
                                      chooser=None):

    topology = topology or generate_simple_network(agents)

    #       if stimuli == None:
    #               stimuli = def_value(None, default_stimuli())

    if inc_category_treshold is not None:
        interaction.__class__.def_inc_category_treshold = inc_category_treshold

    chooser = chooser or RandomStimuliChooser(use_distance=True, distance=50.)
    env = Environment(stimuli, chooser)
    for agent in agents:
        agent.env = env

    s = Simulation(topology, interaction, agents)
    res = s.run(num_iter, dump_freq)

    #       import pprint
    #       print pprint.pprint(error_counter)
    try:
        #               s = sum(error_counter.values())
        #               for k,v in error_counter.iteritems():
        #                       print "%s: %s" % (k, float(v)/s)
        for a in agents:
            print "[%s]:%s" % (len(
                a.state.lexicon.known_words()), a.state.lexicon.known_words())
        print "OK"
    except:
        pass

    return res
Пример #5
0
def flu_experiment(num_agents, num_doctors, num_ill, iters):
    agents = prepare_agents(num_agents, num_doctors, num_ill)
    topology = generate_simple_network(agents)
    s = Simulation(topology, FluInteraction(), agents)
    return s.run(iters, DUMP_FREQ)