<jupyter_start><jupyter_text>*Load classes:*<jupyter_code>os.chdir(d['py'])
from GmsPy import Group
os.chdir(d['curr'])<jupyter_output><empty_output><jupyter_text>Model components  Grouping of variables The class ```GmsPy.Group``` specifies how to define groupings of variables. We can define groups of variables using four attributes:* ```self.v```: List of tuples. Each tuple is length 2, with first element indicating the variable, the second indicating the condition on that variable.* ```self.g```: Ordered set. Each element is a string referencing other groups to be included.* ```self.neg_v```: List of tuples akin to ```self.v```. Each element is subtracted from the group.* ```sef.neg_g```: Ordered set. Each element is a string referencing another group that is subtracted.When specifying variables, the conditions should conform to the form used in ```DBWheels_rc``` and ```GmsPyWheels_write```.*NB: As groups can depend on other groups, it can be important to process groups in the right order.*<jupyter_code>groups = {}<jupyter_output><empty_output><jupyter_text>Add a group specified as a list of tuples Specify the list of tuples and initialize a group:<jupyter_code>g1 = Group('g1', v = [('theta',db['V01_T']), 
                      ('mu', ('and', [db['V01_inp2T'], ('not', db['V01_dur'])])),
                      ('sigma', db['V01_T2ESNorm'])])<jupyter_output><empty_output><jupyter_text>Compile:<jupyter_code>groups[g1.name] = g1.compile(groups)
g1.out<jupyter_output><empty_output><jupyter_text>Add a group specified by referencing a group and variables Specify list of variables + reference group 'g1'. This adds a variable 'mu' and the conditional of the mapping 'V01_NT_inp' that has been aliased with 'n','nn'. A preview of what will eventually be written:<jupyter_code>c = {'s': db['V01_NT_inp'], 'alias': {'n':'nn'}}
write_gpy(**c)
g2 = Group('g2', v = [('mu',c)], g=['g1'])<jupyter_output><empty_output><jupyter_text>Compile:<jupyter_code>groups[g2.name] = g2.compile(groups)
groups[g2.name].out<jupyter_output><empty_output><jupyter_text>Subtract a group Define a group as the group 'g2', but extract 'g1':<jupyter_code>g3 = Group('g3', g = ['g2'], neg_g = ['g1'])<jupyter_output><empty_output><jupyter_text>Compile:<jupyter_code>groups[g3.name] = g3.compile(groups)
groups[g3.name].out
groups[g3.name].out_neg<jupyter_output><empty_output><jupyter_text>Subtract a group and a variable:<jupyter_code>g4 = Group('g4', g = ['g2'], neg_g = ['g1'], neg_v = [('mu', db['V01_NT_inp'])])<jupyter_output><empty_output><jupyter_text>Compile:<jupyter_code>groups[g4.name] = g4.compile(groups)
groups[g4.name].out, g4.out_neg<jupyter_output><empty_output><jupyter_text>Collect conditions from a group: The ```self.compile``` creates a dictionary of conditions to apply (```self.out```) and conditions to negate and apply (```self.out_neg```). The two are combined into one dictionary of nested conditions using the ```self.conditions``` property. These can be processed using e.g. the ```write_gpy``` method:<jupyter_code>for g in groups.values():
    print(f"Text for group {g.name}:")
    for k,v in g.conditions.items():
        print(f"\t{write_gpy(db[k],c=v)}")<jupyter_output>Text for group g1:
	theta[s,n]$(V01_T[s,n])
	mu[s,n,nn]$((V01_inp2T[s,n,nn] and ( not (V01_dur[s,n]))))
	sigma[s,n]$(V01_T2ESNorm[s,n,nn])
Text for group g2:
	mu[s,n,nn]$((V01_NT_inp[s,nn] or (V01_inp2T[s,n,nn] and ( not (V01_dur[s,n])))))
	theta[s,n]$(V01_T[s,n])
	sigma[s,n]$(V01_T2ESNorm[s,n,nn])
Text for group g3:
	mu[s,n,nn]$(V01_NT_inp[s,nn])
Text for group g4:
	mu[s,n,nn]$((V01_NT_inp[s,nn] and ( not (V01_NT_inp[s,n]))))
{'fraction_non_alphanumeric': 0.16556473829201102, 'fraction_numerical': 0.021763085399449034, 'mean_word_length': 6.564583333333333, 'pattern_counts': {'":': 0, '<': 44, '<?xml version=': 0, '>': 44, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '11', 'dir': 'jupyter-structured-clean-dedup', 'id': '186453', 'license': 'MIT', 'n_tokens_mistral': 1408, 'n_tokens_neox': 1363, 'n_words': 337, 'path': 'Class_GmsPy_Group.ipynb', 'repo_name': 'ChampionApe/GPM_v06', 'size': '3630'}