TheodoreEhrenborg / mercantilism

MIT License
0 stars 0 forks source link

Speed #22

Closed TheodoreEhrenborg closed 5 years ago

TheodoreEhrenborg commented 5 years ago

I need to make the algorithms faster so that I can get statistically significant data. I think I'll split up aux_stochastic and aux_abridged_game among their users. I'll focus on making aux_stochastic faster with Cython and numpy Remember to set the array's length beforehand; appending takes time. See https://stackoverflow.com/questions/50171246/how-to-define-a-list-in-cython

Here's the profile data on running 5 copies of neural_nash against each other. Using profile slowed the program down by a factor of 10.

Mon Feb 25 17:16:25:mercantilism jtae$ python Python 2.7.10 (default, Oct 6 2017, 22:29:07) [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.31)] on darwin Type "help", "copyright", "credits" or "license" for more information.

import algorithms algorithms.Neural_Evolver.evolve(generations = 10**9, trials_per_generation = 1000, population = 100) 2019-02-25 17:17:01.102140: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA ^CTraceback (most recent call last): File "", line 1, in File "algorithms.py", line 256, in evolve g = Game( playing_players, copy.copy(TOKENS) ) File "algorithms.py", line 614, in init this_move = player_list[0].choose_token( copy.deepcopy(self.tokens), copy.deepcopy(data), self.name ) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 163, in deepcopy y = copier(x, memo) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 230, in _deepcopy_list y.append(deepcopy(a, memo)) KeyboardInterrupt import random random.choice <bound method Random.choice of <random.Random object at 0x7fbad19abc20>> quit() Tue Feb 26 15:36:33:mercantilism jtae$ python Python 2.7.10 (default, Oct 6 2017, 22:29:07) [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.31)] on darwin Type "help", "copyright", "credits" or "license" for more information. import profile temp = inspect.getmembers( algorithms, inspect.isfunction) Traceback (most recent call last): File "", line 1, in NameError: name 'inspect' is not defined import inspect temp = inspect.getmembers( algorithms, inspect.isfunction) Traceback (most recent call last): File "", line 1, in NameError: name 'algorithms' is not defined import algorithms temp = inspect.getmembers( algorithms, inspect.isfunction) temp [('aux_abridged_game', <function aux_abridged_game at 0x114602d70>), ('aux_exp', <function aux_exp at 0x1145cbc80>), ('aux_list_total', <function aux_list_total at 0x1146055f0>), ('aux_power', <function aux_power at 0x1145cbde8>), ('aux_stochastic', <function aux_stochastic at 0x114605938>), ('best_human_strategy', <function best_human_strategy at 0x1145f9e60>), ('exp_2', <function exp_2 at 0x1145cbcf8>), ('neural_evolve', <function neural_evolve at 0x1146022a8>), ('neural_nash', <function neural_nash at 0x114602758>), ('play_highest', <function play_highest at 0x1145fd320>), ('power_1', <function power_1 at 0x1145f9de8>), ('power_2', <function power_2 at 0x1145d4848>), ('power_3', <function power_3 at 0x1145d4e60>), ('quick_evolve', <function quick_evolve at 0x114602230>), ('round_diff', <function round_diff at 0x114605758>), ('round_points', <function round_points at 0x114605668>), ('round_winner', <function round_winner at 0x114605848>), ('total_diff', <function total_diff at 0x1146057d0>), ('total_points', <function total_points at 0x1146056e0>), ('total_winner', <function total_winner at 0x1146058c0>), ('uniform', <function uniform at 0x1145cbc08>)] temp[7] ('neural_evolve', <function neural_evolve at 0x1146022a8>) temp[8] ('neural_nash', <function neural_nash at 0x114602758>) x = temp[8] x ('neural_nash', <function neural_nash at 0x114602758>) import api 2019-02-26 15:37:39.017657: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA w = api.Wrapper(x) w Wrapper(('neural_nash', <function neural_nash at 0x114602758>)) api.API.TOKENS Traceback (most recent call last): File "", line 1, in AttributeError: class API has no attribute 'TOKENS' tokens = range(1,15) tokens = range(1,16) tokens [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15] import copy algorithm_tuple = (w,w,w,w,w) g = Game( copy.copy(algorithm_tuple), copy.copy(tokens) ) Traceback (most recent call last): File "", line 1, in NameError: name 'Game' is not defined g = api.Game( copy.copy(algorithm_tuple), copy.copy(tokens) ) help(g)

g.get_results() Traceback (most recent call last): File "", line 1, in TypeError: get_results() takes no arguments (1 given) help(g)

profile.run( g2 = api.Game( copy.copy(algorithm_tuple), copy.copy(tokens) ) ) ^CTraceback (most recent call last): File "", line 1, in File "api.py", line 482, in init this_move = Game.Neural_Nash_Instance.actually_choose_token( copy.deepcopy(self.tokens), copy.deepcopy(data), self.name ) File "algorithms.py", line 549, in actually_choose_token return aux_stochastic(tokens, data, game_name, self) File "algorithms.py", line 839, in aux_stochastic my_utilities[l].append( temp_utilities[i] ) KeyboardInterrupt profile.run( 2+2 ) Traceback (most recent call last): File "", line 1, in File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/profile.py", line 61, in run prof = prof.run(statement) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/profile.py", line 438, in run return self.runctx(cmd, dict, dict) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/profile.py", line 444, in runctx exec cmd in globals, locals TypeError: exec: arg 1 must be a string, file, or code object profile.run( print 2+2 ) File "", line 1 profile.run( print 2+2 ) ^ SyntaxError: invalid syntax profile.run( "print 2+2" ) 4 3 function calls in 0.003 seconds

Ordered by: standard name

ncalls tottime percall cumtime percall filename:lineno(function) 1 0.003 0.003 0.003 0.003 :0(setprofile) 1 0.000 0.000 0.000 0.000 :1() 1 0.000 0.000 0.003 0.003 profile:0(print 2+2) 0 0.000 0.000 profile:0(profiler)

profile.run( "print 2**100" ) 1267650600228229401496703205376 3 function calls in 0.000 seconds

Ordered by: standard name

ncalls tottime percall cumtime percall filename:lineno(function) 1 0.000 0.000 0.000 0.000 :0(setprofile) 1 0.000 0.000 0.000 0.000 :1() 1 0.000 0.000 0.000 0.000 profile:0(print 2**100) 0 0.000 0.000 profile:0(profiler)

profile.run( "print 2+2" ) 4 3 function calls in 0.000 seconds

Ordered by: standard name

ncalls tottime percall cumtime percall filename:lineno(function) 1 0.000 0.000 0.000 0.000 :0(setprofile) 1 0.000 0.000 0.000 0.000 :1() 1 0.000 0.000 0.000 0.000 profile:0(print 2+2) 0 0.000 0.000 profile:0(profiler)

profile.run( "g2 = api.Game( copy.copy(algorithm_tuple), copy.copy(tokens) )" ) 32030683 function calls (31381333 primitive calls) in 662.242 seconds

Ordered by: standard name

ncalls tottime percall cumtime percall filename:lineno(function) 32400 0.574 0.000 0.574 0.000 :0(Flatten) 32400 0.288 0.000 0.288 0.000 :0(TFE_Py_TapeSetRestartOnThread) 32400 0.299 0.000 0.299 0.000 :0(TFE_Py_TapeSetStopOnThread) 32400 0.293 0.000 0.293 0.000 :0(TF_DeleteStatus) 32400 0.307 0.000 0.307 0.000 :0(TF_GetCode) 32400 0.350 0.000 0.350 0.000 :0(TF_NewStatus) 32400 14.968 0.000 14.968 0.000 :0(TF_SessionRunCallable) 97200 0.801 0.000 0.801 0.000 :0(new) 32400 0.238 0.000 0.238 0.000 :0(add) 97200 1.173 0.000 4.316 0.000 :0(any) 11436865 121.231 0.000 121.231 0.000 :0(append) 32400 0.609 0.000 0.609 0.000 :0(arange) 97200 2.078 0.000 2.078 0.000 :0(array) 69 0.002 0.000 0.002 0.000 :0(asctime) 69 0.020 0.000 0.020 0.000 :0(close) 732 0.008 0.000 0.008 0.000 :0(count) 471636 3.549 0.000 3.549 0.000 :0(get) 778338 6.410 0.000 6.410 0.000 :0(getattr) 1134000 10.384 0.000 20.577 0.000 :0(hasattr) 2380 0.018 0.000 0.018 0.000 :0(id) 26400 0.332 0.000 0.332 0.000 :0(index) 1491900 14.239 0.000 20.644 0.000 :0(isinstance) 1626069 15.276 0.000 15.276 0.000 :0(len) 27132 0.375 0.000 0.375 0.000 :0(max) 58800 0.569 0.000 0.569 0.000 :0(min) 69 0.006 0.000 0.006 0.000 :0(open) 226830 1.803 0.000 1.803 0.000 :0(pop) 1248721 8.620 0.000 8.620 0.000 :0(random) 1515336 17.637 0.000 17.637 0.000 :0(range) 32400 0.252 0.000 0.252 0.000 :0(remove) 5 0.000 0.000 0.000 0.000 :0(repr) 32400 0.275 0.000 0.275 0.000 :0(setdefault) 1 0.000 0.000 0.000 0.000 :0(setprofile) 3 0.000 0.000 0.000 0.000 :0(time) 32400 0.289 0.000 0.289 0.000 :0(tolist) 69 0.001 0.000 0.001 0.000 :0(write) 32400 0.497 0.000 0.497 0.000 :0(zeros) 97200 1.092 0.000 1.092 0.000 :0(zip) 1 0.000 0.000 662.241 662.241 :1() 97200 1.472 0.000 2.273 0.000 :8(new) 32400 0.259 0.000 0.259 0.000 _weakrefset.py:16(init) 32400 0.506 0.000 0.744 0.000 _weakrefset.py:20(enter) 32400 0.988 0.000 1.531 0.000 _weakrefset.py:26(exit) 32400 0.501 0.000 0.501 0.000 _weakrefset.py:36(init) 32400 0.291 0.000 0.291 0.000 _weakrefset.py:52(_commit_removals) 680400 6.134 0.000 8.669 0.000 _weakrefset.py:58(iter) 195876 1.859 0.000 1.859 0.000 _weakrefset.py:70(contains) 97938 3.753 0.000 6.405 0.000 abc.py:128(instancecheck) 33132 17.208 0.001 330.318 0.010 algorithms.py:512(aux_evaluate_position) 30 0.040 0.001 662.046 22.068 algorithms.py:548(actually_choose_token) 33132 17.061 0.001 368.784 0.011 algorithms.py:697(aux_abridged_game) 198000 3.940 0.000 3.940 0.000 algorithms.py:779(aux_list_total) 30 148.376 4.946 662.006 22.067 algorithms.py:796(aux_stochastic) 1 0.011 0.011 662.241 662.241 api.py:449(init) 65 0.000 0.000 0.000 0.000 api.py:569(get_name) 5 0.000 0.000 0.000 0.000 api.py:573(get_tuple) 5 0.000 0.000 0.000 0.000 api.py:575(repr) 35 0.001 0.000 0.001 0.000 api.py:577(str) 32400 0.550 0.000 0.844 0.000 backend.py:2938(_call_fetch_callbacks) 32400 8.261 0.000 97.749 0.003 backend.py:2943(call) 32400 2.509 0.000 88.647 0.003 backend.py:359(learning_phase) 32400 2.205 0.000 53.857 0.002 backend.py:442(get_session) 64800 0.949 0.000 1.475 0.000 backend.py:586(is_sparse) 32400 1.616 0.000 4.828 0.000 backend.py:711(_get_variables) 32400 11.397 0.000 32.048 0.001 backend.py:720(_initialize_variables) 32400 0.451 0.000 0.702 0.000 base.py:702(isspmatrix) 194400 1.441 0.000 1.441 0.000 base_layer.py:236(trainable_weights) 194400 1.426 0.000 1.426 0.000 base_layer.py:240(non_trainable_weights) 194400 4.534 0.000 7.401 0.000 base_layer.py:255(weights) 194400 2.791 0.000 10.192 0.000 base_layer.py:264(variables) 32400 0.496 0.000 0.847 0.000 c_api_util.py:32(init) 32400 0.494 0.000 0.787 0.000 c_api_util.py:35(del) 65538 2.173 0.000 17.469 0.000 collections.py:446(init) 246846 1.682 0.000 1.682 0.000 collections.py:467(missing) 65538 5.740 0.000 14.847 0.000 collections.py:516(update) 97200 2.522 0.000 5.591 0.000 context.py:122(push) 97200 1.463 0.000 2.189 0.000 context.py:138(pop) 194400 2.011 0.000 2.011 0.000 context.py:343(_mode) 356400 2.884 0.000 2.884 0.000 context.py:364(executing_eagerly) 194400 1.378 0.000 1.378 0.000 context.py:606(context_switches) 648000 4.569 0.000 4.569 0.000 context.py:628(context) 324000 7.111 0.000 12.050 0.000 context.py:655(executing_eagerly) 97200 2.213 0.000 5.158 0.000 context.py:671(graph_mode) 388800 2.813 0.000 2.813 0.000 contextlib.py:12(init) 388800/64800 6.285 0.000 69.946 0.001 contextlib.py:15(enter) 388800/64800 8.077 0.000 28.599 0.000 contextlib.py:21(exit) 388800 6.713 0.000 9.526 0.000 contextlib.py:82(helper) 1 0.000 0.000 0.000 0.000 copy.py:101(_copy_immutable) 31 0.000 0.000 0.000 0.000 copy.py:113(_copy_with_constructor) 1110/60 0.051 0.000 0.144 0.002 copy.py:145(deepcopy) 490 0.003 0.000 0.003 0.000 copy.py:198(_deepcopy_atomic) 360/60 0.024 0.000 0.137 0.002 copy.py:226(_deepcopy_list) 850 0.018 0.000 0.029 0.000 copy.py:267(_keep_alive) 32 0.001 0.000 0.001 0.000 copy.py:66(copy) 32400 0.764 0.000 3.987 0.000 data_utils.py:97(is_generator_or_sequence) 64800 0.508 0.000 0.508 0.000 dtypes.py:125(as_numpy_dtype) 64800 1.038 0.000 1.518 0.000 dtypes.py:661(as_dtype) 32400 0.603 0.000 1.449 0.000 errors_impl.py:518(enter) 32400 1.130 0.000 2.224 0.000 errors_impl.py:522(exit) 32400 1.708 0.000 2.238 0.000 generic_utils.py:457(make_batches) 32400 2.623 0.000 3.933 0.000 generic_utils.py:472(slice_arrays) 32400 0.475 0.000 0.719 0.000 inspect.py:164(isgenerator) 194400 5.300 0.000 21.221 0.000 layer_utils.py:25(is_layer) 32400 3.268 0.000 25.922 0.001 layer_utils.py:40(filter_empty_layer_containers) 32400 0.807 0.000 1.281 0.000 network.py:441(uses_learning_phase) 32400 2.170 0.000 31.267 0.001 network.py:446(stateful) 32400 0.587 0.000 26.510 0.001 network.py:514(layers) 64800 1.013 0.000 2.234 0.000 numeric.py:469(asarray) 162000 2.284 0.000 3.844 0.000 ops.py:156(is_dense_tensor_like) 32400 0.251 0.000 0.251 0.000 ops.py:3022(_get_control_flow_context) 64800 0.470 0.000 0.470 0.000 ops.py:3030(_set_control_flow_context) 162000 1.164 0.000 1.164 0.000 ops.py:3187(building_function) 64800 0.478 0.000 0.478 0.000 ops.py:341(dtype) 97200 1.619 0.000 4.096 0.000 ops.py:3706(as_default) 64800 0.990 0.000 1.478 0.000 ops.py:3895(_name_stack) 64800 0.523 0.000 0.523 0.000 ops.py:3902(_name_stack) 64800 1.344 0.000 2.605 0.000 ops.py:3907(name_scope) 32400 0.511 0.000 1.252 0.000 ops.py:4074(get_name_scope) 32400 0.457 0.000 0.457 0.000 ops.py:4323(init) 32400 1.624 0.000 3.780 0.000 ops.py:4358(enter) 32400 1.115 0.000 3.377 0.000 ops.py:4368(exit) 32400 0.725 0.000 1.193 0.000 ops.py:4386(_push_control_dependencies_controller) 32400 1.010 0.000 1.749 0.000 ops.py:4389(_pop_control_dependencies_controller) 32400 0.596 0.000 1.053 0.000 ops.py:4443(control_dependencies) 64800 0.514 0.000 0.514 0.000 ops.py:4782(_device_function_stack) 64800 0.493 0.000 0.493 0.000 ops.py:4820(_device_function_stack) 129600 0.917 0.000 0.917 0.000 ops.py:4858(_control_dependencies_stack) 64800 0.514 0.000 0.514 0.000 ops.py:4870(_control_dependencies_stack) 32400 1.043 0.000 5.081 0.000 ops.py:4975(control_dependencies) 259200 3.878 0.000 5.612 0.000 ops.py:5015(get_default) 194400 3.084 0.000 4.587 0.000 ops.py:5032(get_controller) 32400 0.544 0.000 1.238 0.000 ops.py:5102(get_default_session) 226800 4.223 0.000 9.388 0.000 ops.py:5202(get_default) 32400 0.248 0.000 0.248 0.000 ops.py:5209(_GetGlobalDefaultGraph) 194400 12.833 0.000 45.151 0.000 ops.py:5222(get_controller) 64800 7.333 0.000 80.491 0.001 ops.py:5240(init_scope) 226800 3.500 0.000 12.888 0.000 ops.py:5545(get_default_graph) 32400 1.125 0.000 4.817 0.000 ops.py:5603(_get_graph_from_inputs) 32400 0.841 0.000 1.305 0.000 ops.py:5968(init) 32400 1.842 0.000 21.062 0.001 ops.py:5982(enter) 32400 0.957 0.000 8.383 0.000 ops.py:6033(exit) 1 0.000 0.000 662.242 662.242 profile:0(g2 = api.Game( copy.copy(algorithm_tuple), copy.copy(tokens) )) 0 0.000 0.000 profile:0(profiler) 32400 0.488 0.000 1.062 0.000 pywrap_tensorflow_internal.py:2124(Flatten) 1 0.000 0.000 0.000 0.000 random.py:175(randrange) 1 0.000 0.000 0.000 0.000 random.py:238(randint) 3780 0.082 0.000 0.131 0.000 random.py:273(choice) 26430 11.167 0.000 19.962 0.001 random.py:277(shuffle) 32400 0.979 0.000 27.716 0.001 sequential.py:110(layers) 32400 2.473 0.000 21.391 0.001 session.py:1429(call) 32400 0.234 0.000 0.234 0.000 session.py:746(graph) 64800 0.988 0.000 1.576 0.000 tape.py:68(stop_recording) 162000 4.980 0.000 11.698 0.000 tensor_util.py:941(is_tensor) 32400 0.775 0.000 1.422 0.000 tf_decorator.py:104(unwrap) 32400 0.845 0.000 2.986 0.000 tf_inspect.py:328(isgenerator) 32400 2.252 0.000 292.620 0.009 training.py:1778(predict) 32400 0.527 0.000 0.780 0.000 training.py:731(_make_predict_function) 32400 2.433 0.000 60.882 0.002 training.py:861(_standardize_user_data) 32400 2.501 0.000 46.948 0.001 training.py:995(_standardize_weights) 32400 9.064 0.000 224.220 0.007 training_arrays.py:246(predict_loop) 32400 2.892 0.000 5.738 0.000 training_utils.py:1018(init) 32400 0.224 0.000 0.224 0.000 training_utils.py:1100(as_list) 32400 0.886 0.000 10.080 0.000 training_utils.py:173(check_num_samples) 32400 0.542 0.000 0.762 0.000 training_utils.py:215(standardize_single_array) 32400 4.291 0.000 10.378 0.000 training_utils.py:226(standardize_input_data) 64800 1.464 0.000 12.648 0.000 training_utils.py:739(has_symbolic_tensors) 64800 1.786 0.000 8.696 0.000 training_utils.py:745(has_tensors) 64800 0.764 0.000 3.142 0.000 training_utils.py:747() 64800 2.783 0.000 17.017 0.000 training_utils.py:860(check_steps_argument) 32400 0.274 0.000 0.274 0.000 weakref.py:314(getitem) 32400 0.494 0.000 0.726 0.000 weakref.py:342(get) 32400 0.350 0.000 0.350 0.000 weakref.py:352(contains) 32400 0.540 0.000 0.815 0.000 weakref.py:432(setdefault)

TheodoreEhrenborg commented 5 years ago

Here's the profile of total_winner:

profile.run( "g22 = api.Game( copy.copy(algorithm_tuple2), copy.copy(tokens) )") 28264916 function calls (28261306 primitive calls) in 655.511 seconds

Ordered by: standard name

ncalls tottime percall cumtime percall filename:lineno(function) 19894748 215.765 0.000 215.765 0.000 :0(append) 140 0.004 0.000 0.004 0.000 :0(asctime) 140 0.035 0.000 0.035 0.000 :0(close) 54680 0.474 0.000 0.474 0.000 :0(count) 278332 2.069 0.000 2.069 0.000 :0(get) 54692 0.438 0.000 0.438 0.000 :0(getattr) 5650 0.043 0.000 0.043 0.000 :0(id) 52800 0.625 0.000 0.625 0.000 :0(index) 54752 1.024 0.000 4.533 0.000 :0(isinstance) 1597388 17.108 0.000 17.108 0.000 :0(len) 107480 1.214 0.000 1.214 0.000 :0(max) 52800 0.631 0.000 0.631 0.000 :0(min) 140 0.013 0.000 0.013 0.000 :0(open) 61 0.001 0.000 0.001 0.000 :0(pop) 2497441 17.494 0.000 17.494 0.000 :0(random) 2813104 33.329 0.000 33.329 0.000 :0(range) 5 0.000 0.000 0.000 0.000 :0(repr) 1 0.000 0.000 0.000 0.000 :0(setprofile) 3 0.000 0.000 0.000 0.000 :0(time) 140 0.003 0.000 0.003 0.000 :0(write) 1 0.000 0.000 655.511 655.511 :1() 109384 1.019 0.000 1.019 0.000 _weakrefset.py:70(contains) 54692 2.052 0.000 3.509 0.000 abc.py:128(instancecheck) 54680 26.856 0.000 62.762 0.001 algorithms.py:697(aux_abridged_game) 404800 4.291 0.000 4.291 0.000 algorithms.py:779(aux_list_total) 60 0.037 0.001 655.058 10.918 algorithms.py:794(total_winner) 60 301.901 5.032 655.021 10.917 algorithms.py:796(aux_stochastic) 1 0.024 0.024 655.511 655.511 api.py:449(init) 185 0.001 0.000 0.001 0.000 api.py:569(get_name) 60 0.000 0.000 0.000 0.000 api.py:571(get_function) 5 0.000 0.000 0.000 0.000 api.py:573(get_tuple) 5 0.000 0.000 0.000 0.000 api.py:575(repr) 65 0.001 0.000 0.001 0.000 api.py:577(str) 54692 1.757 0.000 13.266 0.000 collections.py:446(init) 54692 4.146 0.000 11.143 0.000 collections.py:516(update) 1 0.000 0.000 0.000 0.000 copy.py:101(_copy_immutable) 61 0.001 0.000 0.001 0.000 copy.py:113(_copy_with_constructor) 3130/120 0.128 0.000 0.353 0.003 copy.py:145(deepcopy) 960 0.006 0.000 0.006 0.000 copy.py:198(_deepcopy_atomic) 720/120 0.064 0.000 0.339 0.003 copy.py:226(_deepcopy_list) 1680 0.036 0.000 0.058 0.000 copy.py:267(_keep_alive) 62 0.002 0.000 0.003 0.000 copy.py:66(copy) 1 0.000 0.000 655.511 655.511 profile:0(g22 = api.Game( copy.copy(algorithm_tuple2), copy.copy(tokens) )) 0 0.000 0.000 profile:0(profiler) 1 0.000 0.000 0.000 0.000 random.py:175(randrange) 1 0.000 0.000 0.000 0.000 random.py:238(randint) 7560 0.170 0.000 0.270 0.000 random.py:273(choice) 52860 22.747 0.000 40.599 0.001 random.py:277(shuffle)

TheodoreEhrenborg commented 5 years ago

See https://hplgit.github.io/teamods/MC_cython/main_MC_cython.html https://cython.readthedocs.io/en/latest/src/tutorial/numpy.html

TheodoreEhrenborg commented 5 years ago

It doesn't seem to be working.

TheodoreEhrenborg commented 5 years ago

It's working slowly.

TheodoreEhrenborg commented 5 years ago

See https://docs.scipy.org/doc/numpy/reference/generated/numpy.bincount.html for a Collections alternative

TheodoreEhrenborg commented 5 years ago

This is important and useful: https://cython.readthedocs.io/en/latest/src/userguide/numpy_tutorial.html

TheodoreEhrenborg commented 5 years ago

The problem is that the computer has to look in the dictionary at least 100000 times. Using Cython does not speed this up, and replacing the Python dictionary with a custom array makes the program even slower. This problem also affects the stochastic programs besides neural_nash.