<jupyter_start><jupyter_text>*ttgames*: Example UseThis notebook shows how to build a TT-compressed cooperative game and compute its semivalues with the package *ttgames*. For this, we will use the classic [*airport problem*](https://en.wikipedia.org/wiki/Airport_problem).We start out by loading *ttgames* as well as the library [*tntorch*](https://github.com/rballester/tntorch), which is used for [cross-approximation](https://www.sciencedirect.com/science/article/pii/S0024379509003747):<jupyter_code>import ttgames as tg
import tntorch as tn<jupyter_output><empty_output><jupyter_text>Let us create an instance of the airport problem with $30$ airlines (the runway lengths required by each airline are chosen uniformly at random between 0 and 1):<jupyter_code>game = tg.games.Airport(N=30)
print(game.ak)<jupyter_output>tensor([0.4963, 0.7682, 0.0885, 0.1320, 0.3074, 0.6341, 0.4901, 0.8964, 0.4556,
        0.6323, 0.3489, 0.4017, 0.0223, 0.1689, 0.2939, 0.5185, 0.6977, 0.8000,
        0.1610, 0.2823, 0.6816, 0.9152, 0.3971, 0.8742, 0.4194, 0.5529, 0.9527,
        0.0362, 0.1852, 0.3734])<jupyter_text>Next, we will learn a TT tensor out of the game's utility function:<jupyter_code>t = tn.cross(function=game.function, domain=game.domain(), function_arg='matrix', eps=1e-4)<jupyter_output>cross device is None
Cross-approximation over a 30D domain containing 1.07374e+09 grid points:
iter: 0  | eps: 4.452e-02 | time:   0.1747 | largest rank:   1
iter: 1  | eps: 2.118e-02 | time:   0.7138 | largest rank:   4
iter: 2  | eps: 9.352e-03 | time:   1.2719 | largest rank:   7
iter: 3  | eps: 6.396e-03 | time:   1.8051 | largest rank:  10
iter: 4  | eps: 4.224e-03 | time:   2.3234 | largest rank:  13
iter: 5  | eps: 1.057e-04 | time:   2.8560 | largest rank:  16
iter: 6  | eps: 1.980e-06 | time:   3.4420 | largest rank:  19 <- converged: eps < 0.0001
Did 89222 function evaluations, which took 0.1986s (4.491e+05 evals/s)<jupyter_text>As a result, `t` is a tensor train with 30 dimensions and shape 2 along each dimension (an has $2^{30} \approx 10^9$ entries). Let us visualize it (the shape are the numbers on top, while the lower numbers denote the *TT ranks*):<jupyter_code>t<jupyter_output><empty_output><jupyter_text>Finally, we are ready to compute the Shapley values for all players of this game:<jupyter_code>tg.semivalues.semivalues(t, ps='shapley')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12625, 'fraction_numerical': 0.12875, 'mean_word_length': 4.444444444444445, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 19, 'https://': 3, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '244441', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1110, 'n_tokens_neox': 903, 'n_words': 269, 'path': 'examples/airport.ipynb', 'repo_name': 'rballester/ttgames', 'size': '2400'}