コード例 #1
0
ファイル: experiment.py プロジェクト: foton263/swarm
def test_loop(phenotypes, iteration):
    """Test the phenotypes in a completely different environment."""
    # Create a validation environment instance
    test = TestModel(100, width, height, 10, iter=iteration)
    # Build the environment
    test.build_environment_from_json()
    # Create the agents in the environment from the sampled behaviors
    test.create_agents(phenotypes=phenotypes)
    # Store the initial result
    testresults = SimulationResults(test.pname, test.connect,
                                    test.sn, test.stepcnt,
                                    test.foraging_percent(), phenotypes[0])
    # Save the phenotype to a json file
    testresults.save_phenotype()
    # Save the data in a result csv file
    testresults.save_to_file()
    # Save the phenotype of json file
    phenotype_to_json(test.pname, test.runid, phenotypes)
    # Execute the BT in the environment
    for i in range(iteration):
        test.step()

        testresults = SimulationResults(test.pname, test.connect,
                                        test.sn, test.stepcnt,
                                        test.foraging_percent(), phenotypes[0])
        testresults.save_to_file()

    # Plot the result in the graph
    graph = GraphACC(test.pname, 'simulation.csv')
    graph.gen_plot()
コード例 #2
0
ファイル: main.py プロジェクト: timmyhussain/cs230
                           xlabel='Episode',
                           ylabel='Cumulative delay (s)')
    viz.save_data_and_plot(data=sim._avg_queue_length_store,
                           filename='queue',
                           xlabel='Episode',
                           ylabel='Average queue length (vehicles)')

    #%% Testing Simulation

    config = import_train_configuration(config_file="training_settings.ini")
    sumo_cmd = set_sumo(False, config['sumocfg_file_name'],
                        config['max_steps'])
    TrafficGen = TrafficGenerator(config['max_steps'],
                                  config['n_cars_generated'])

    model = TestModel(config['num_states'], config['num_actions'],
                      config['models_path_name'])

    testsim = TestSimulation(TrafficGen, model, sumo_cmd, config['max_steps'],
                             config['green_duration'],
                             config['yellow_duration'], config['num_states'],
                             config['num_actions'])

    queues_episodes = []
    waits_episodes = []
    simulation_times_episodes = []
    episode = 5

    simulation_time, avg_queue_length, total_wait_times = testsim.run(
        episode, baseline=False)

    # while episode < config['total_episodes']:
コード例 #3
0
from testing_simulation import Simulation
from generator import TrafficGenerator
from model import TestModel
from visualization import Visualization
from utils import import_test_configuration, set_sumo, set_test_path

if __name__ == "__main__":

    config = import_test_configuration(config_file='testing_settings.ini')
    sumo_cmd = set_sumo(config['gui'], config['sumocfg_file_name'],
                        config['max_steps'])
    model_path, plot_path = set_test_path(config['models_path_name'],
                                          config['model_to_test'])

    Model = TestModel(input_dim=config['num_states'], model_path=model_path)

    TrafficGen = TrafficGenerator(config['max_steps'], config['n_v_generated'])

    Visualization = Visualization(plot_path, dpi=96)

    Simulation = Simulation(Model, TrafficGen, sumo_cmd, sumo_cmd,
                            config['max_steps'], config['green_duration'],
                            config['yellow_duration'], config['num_states'],
                            config['num_actions'])

    print('\n----- Test episode')
    simulation_time = Simulation.run(
        config['episode_seed'])  # run the simulation
    print('Simulation time:', simulation_time, 's')
from visualization import Visualization
from model import TestModel
from utils import import_test_configuration, set_sumo, set_test_path

import statistics

if __name__ == "__main__":

    config = import_test_configuration(config_file='testing_settings.ini')
    sumo_cmd = set_sumo(config['gui'], config['sumocfg_file_name'],
                        config['max_steps'])
    model_path, plot_path = set_test_path(config['models_path_name'],
                                          config['model_to_test'])

    Model_A1 = TestModel(input_dim=config['num_states'],
                         model_path=model_path,
                         num=1)

    Model_A2 = TestModel(input_dim=config['num_states'],
                         model_path=model_path,
                         num=2)

    TrafficGen = TrafficGenerator(config['max_steps'],
                                  config['n_cars_generated'], "EW")

    Visualization = Visualization(plot_path, dpi=96)

    Simulation = Simulation(Model_A1, Model_A2, TrafficGen, sumo_cmd,
                            config['max_steps'], config['green_duration'],
                            config['yellow_duration'], config['num_cells'],
                            config['num_states'], config['num_actions'],
コード例 #5
0
ファイル: test.py プロジェクト: stadlerism/quasiNewton_ML
                    help='Visualize training progress')
parser.add_argument(
    '--batchsize',
    '-b',
    default=1,
    help='Batch size for training the network (default: %(default)s)')
args = parser.parse_args()

np.random.seed(args.seed)

# loss = Rosenbrock() # optimum: (1,1)
loss = Rosenbrock()  # optimum: (3, 0.5)

n = 2
# model = TestModel(n, lr=0.00001, loss=loss, d=np.array([[0.0],[0.0]]))
model = TestModel(n, lr=0.00001, loss=loss, d=np.array([[-1.2], [1]]))

optimizer = None
if args.optimizer == 'ibfgs':
    optimizer = InverseBFGS(nparams=model.nparams, gamma=0.0001, eta=0.9)
elif args.optimizer == 'bfgs':
    optimizer = BFGS(nparams=model.nparams, gamma=0.0001, eta=0.9)
elif args.optimizer == 'armijo':
    optimizer = DescentMethod(nparams=model.nparams, beta=1 / 2, gamma=0.0001)
elif args.optimizer == 'bbv1' or args.optimizer == 'barzilaiborweinv1':
    optimizer = BarzilaiBorwein(nparams=model.nparams,
                                beta=1 / 2,
                                gamma=0.0001,
                                strategy='v1')
elif args.optimizer == 'bbv2' or args.optimizer == 'barzilaiborweinv2':
    optimizer = BarzilaiBorwein(nparams=model.nparams,
コード例 #6
0
    sumo_cmd = set_sumo(config['gui'], config['sumocfg_file_name'],
                        config['max_steps'])
    model_path, plot_path = set_test_path(config['models_path_name'],
                                          config['model_to_test'],
                                          config['scenario_number'])

    #SET STATE DIMENSION PARAMETERS
    number_of_cells_per_lane = 10
    conv_state_shape = (number_of_cells_per_lane, 8, 2)
    green_phase_state_shape = 4
    elapsed_time_state_shape = 1
    state_shape = [
        conv_state_shape, green_phase_state_shape, elapsed_time_state_shape
    ]

    Model = TestModel(model_path=model_path, state_shape=state_shape)

    TrafficGen = TrafficGenerator(config['max_steps'],
                                  config['penetration_rate'])

    Visualization = Visualization(plot_path, dpi=96)

    #make non-recurrent model
    if Model._recurrent == False:
        Simulation = VanillaTestSimulation(Model, TrafficGen, sumo_cmd,
                                           config['max_steps'],
                                           config['green_duration'],
                                           config['yellow_duration'],
                                           config['num_actions'],
                                           config['scenario_number'])
        # print("make vanilla simulation")
コード例 #7
0
    device = '/GPU:0'

    num_samples = 12800
    inputs = tf.random.uniform((num_samples, input_steps),
                               -0.1,
                               0.1,
                               dtype=tf.float32,
                               name="input")
    targets = tf.random.uniform((num_samples, intent_size),
                                -0.1,
                                0.1,
                                dtype=tf.float32,
                                name="output")

    with tf.device(device):
        model = TestModel(vocab_size, embedding_size, hidden_size, batch_size,
                          intent_size)
        optimizer = tf.keras.optimizers.Adam(learning_rate=1e-3)

        for epoch in range(epoch_num):
            for step, batch in enumerate(get_batch(batch_size, inputs,
                                                   targets)):
                encoder_inputs = batch[0]
                intent_targets = batch[1]

                with tf.GradientTape() as tape:
                    intent_logits = model(encoder_inputs)
                    cross_entropy = tf.nn.softmax_cross_entropy_with_logits(
                        intent_targets, intent_logits)
                    loss = tf.reduce_mean(cross_entropy)
                    if step % 50 == 0:
                        print('epoch:{}, step:{}, intent loss:{:.2f}'.format(
コード例 #8
0
ファイル: hello.py プロジェクト: kkkf1190/FlaskBlog
def user(username):
	item = TestModel(id='1')
	item.text=str(username)
	print(item.text)
	return '<h1>welcome! %s</h1>' % username
コード例 #9
0
ファイル: modeltest.py プロジェクト: kkkf1190/FlaskBlog
import sys
sys.path.append('D:\\PycharmProjects\\FlaskBlog')
from model import TestModel
test = TestModel(testid='1')
test.text='test1'
test.save()