diff --git a/Benchmarking/json_lbt.py b/Benchmarking/json_lbt.py index 45c7d62dc03..a12fbdb5885 100644 --- a/Benchmarking/json_lbt.py +++ b/Benchmarking/json_lbt.py @@ -234,9 +234,9 @@ def corrupt_json(symbols): ) -def generate_dataset(num_sequances): +def generate_dataset(num_sequences): dataset = set() - while len(dataset) <= num_sequances: + while len(dataset) <= num_sequences: ts, tt = generate_random_json(max_depth=2, max_elements=3) assert is_valid_json(ts), ts dataset.add((tuple(tt), True)) @@ -287,7 +287,7 @@ def validate_string_with_json_parser(json_str, json_parser): model_learning_dataset = [] if not use_learned_model: - model_learning_dataset = generate_dataset(num_sequances=20000) + model_learning_dataset = generate_dataset(num_sequences=20000) learned_json_model = run_PAPNI(model_learning_dataset, vpa_alphabet) # learned_json_model.visualize() @@ -307,10 +307,10 @@ def validate_string_with_json_parser(json_str, json_parser): for _ in range(num_learning_iterations): disagreements.clear() - test_dataset = generate_input_output_data_from_vpa(learned_json_model, num_sequances=10000, max_seq_len=16) + test_dataset = generate_input_output_data_from_vpa(learned_json_model, num_sequences=10000, max_seq_len=16) print(f"Num well-matched tests: {len([x for x in test_dataset if learned_json_model.is_balanced(x[0])])}") - num_new_sequances = 0 + num_new_sequences = 0 for seq, label in test_dataset: @@ -330,9 +330,9 @@ def validate_string_with_json_parser(json_str, json_parser): if (seq, label) in model_learning_dataset: model_learning_dataset.remove((seq, label)) model_learning_dataset.add((seq, not label)) - num_new_sequances += 1 + num_new_sequences += 1 - print(f'Added {num_new_sequances} to learning set, total size {len(model_learning_dataset)}') + print(f'Added {num_new_sequences} to learning set, total size {len(model_learning_dataset)}') learned_json_model = run_PAPNI(model_learning_dataset, vpa_alphabet, print_info=False) print(f'Current model size: {learned_json_model.size}') diff --git a/Benchmarking/passive_vpa_vs_rpni.py b/Benchmarking/passive_vpa_vs_rpni.py index a5cbc41a94c..5ba012d8a47 100644 --- a/Benchmarking/passive_vpa_vs_rpni.py +++ b/Benchmarking/passive_vpa_vs_rpni.py @@ -8,7 +8,7 @@ from statistics import mean, stdev all_data = dict() -with open('papni_sequances.pickle', 'rb') as handle: +with open('papni_sequences.pickle', 'rb') as handle: all_data = pickle.load(handle) @@ -59,21 +59,21 @@ def evaluate_model(learned_model, test_data): return [rpni_model.size, papni_model.size, rpni_error, papni_error] -def get_sequances_from_active_sevpa(model): +def get_sequences_from_active_sevpa(model): from aalpy import SUL, run_KV, RandomWordEqOracle, SevpaAlphabet class CustomSUL(SUL): def __init__(self, automatonSUL): super(CustomSUL, self).__init__() self.sul = automatonSUL - self.sequances = [] + self.sequences = [] def pre(self): self.tc = [] self.sul.pre() def post(self): - self.sequances.append(self.tc) + self.sequences.append(self.tc) self.sul.post() def step(self, letter): @@ -91,7 +91,7 @@ def step(self, letter): # eq_oracle = BreadthFirstExplorationEqOracle(vpa_alphabet.get_merged_alphabet(), sul, 7) _ = run_KV(alphabet, sul, eq_oracle, automaton_type='vpa', print_level=3) - return convert_i_o_traces_for_RPNI(sul.sequances) + return convert_i_o_traces_for_RPNI(sul.sequences) def split_data_to_learning_and_testing(data, learning_to_test_ratio=0.5): @@ -104,20 +104,20 @@ def split_data_to_learning_and_testing(data, learning_to_test_ratio=0.5): # sorted(data, key=lambda x: len(x[0])) shuffle(data) - learning_sequances, test_sequances = [], [] + learning_sequences, test_sequences = [], [] l_pos, l_neg = 0, 0 for seq, label in data: if label and l_pos <= num_learning_positive_seq: - learning_sequances.append((seq, label)) + learning_sequences.append((seq, label)) l_pos += 1 elif not label and l_neg <= num_learning_negative_seq: - learning_sequances.append((seq, label)) + learning_sequences.append((seq, label)) l_neg += 1 else: - test_sequances.append((seq, label)) + test_sequences.append((seq, label)) - return learning_sequances, test_sequances + return learning_sequences, test_sequences def run_experiment(experiment_id, @@ -128,7 +128,7 @@ def run_experiment(experiment_id, learning_to_test_ratio=0.5): if random_data_generation: data = generate_input_output_data_from_vpa(ground_truth_model, - num_sequances=num_of_learning_seq, + num_sequences=num_of_learning_seq, max_seq_len=max_learning_seq_len, ) else: @@ -150,7 +150,7 @@ def run_experiment(experiment_id, # wm_negative += 1 # print(wm_negative) - # data = get_sequances_from_active_sevpa(ground_truth_model) + # data = get_sequences_from_active_sevpa(ground_truth_model) vpa_alphabet = ground_truth_model.get_input_alphabet() diff --git a/Benchmarking/rpni_papni_memory_footrpint.py b/Benchmarking/rpni_papni_memory_footrpint.py index 70fd9477ac8..88d574bb517 100644 --- a/Benchmarking/rpni_papni_memory_footrpint.py +++ b/Benchmarking/rpni_papni_memory_footrpint.py @@ -49,7 +49,7 @@ # for size in range(5000, 50001, 5000): # print(size) # data = generate_input_output_data_from_vpa(gt, -# num_sequances=size, +# num_sequences=size, # max_seq_len=randint(6, 30)) # # y = run_RPNI(data, automaton_type='dfa', print_info=False) diff --git a/Examples.py b/Examples.py index 79f2c0e220c..132cd64307b 100644 --- a/Examples.py +++ b/Examples.py @@ -869,7 +869,7 @@ def rpni_check_model_example(): input_al = model.get_input_alphabet() - data = generate_input_output_data_from_automata(model, num_sequances=2000, + data = generate_input_output_data_from_automata(model, num_sequences=2000, min_seq_len=1, max_seq_len=12) data = convert_i_o_traces_for_RPNI(data) @@ -1149,7 +1149,7 @@ def passive_vpa_learning_on_lists(): def passive_vpa_learning_arithmetics(): from aalpy.learning_algs import run_PAPNI from aalpy.utils.BenchmarkVpaModels import gen_arithmetic_data - arithmetic_data, vpa_alphabet = gen_arithmetic_data(num_sequances=4000, min_seq_len=2, max_seq_len=10) + arithmetic_data, vpa_alphabet = gen_arithmetic_data(num_sequences=4000, min_seq_len=2, max_seq_len=10) print(f"Alphabet: {vpa_alphabet}") @@ -1168,7 +1168,7 @@ def passive_vpa_learning_on_all_benchmark_models(): for gt in [vpa_L1(), vpa_L12(), vpa_for_odd_parentheses()]: vpa_alphabet = gt.input_alphabet - data = generate_input_output_data_from_vpa(gt, num_sequances=2000, max_seq_len=16) + data = generate_input_output_data_from_vpa(gt, num_sequences=2000, max_seq_len=16) papni = run_PAPNI(data, vpa_alphabet, algorithm='gsm', print_info=True) @@ -1336,7 +1336,7 @@ def k_tails_example(): input_alphabet_size=3, output_alphabet_size=3) - data = generate_input_output_data_from_automata(model, num_sequances=2000, + data = generate_input_output_data_from_automata(model, num_sequences=2000, min_seq_len=1, max_seq_len=12, sequance_type='io_traces') diff --git a/aalpy/learning_algs/deterministic_passive/RPNI.py b/aalpy/learning_algs/deterministic_passive/RPNI.py index 04bbead8076..ef42366e55b 100644 --- a/aalpy/learning_algs/deterministic_passive/RPNI.py +++ b/aalpy/learning_algs/deterministic_passive/RPNI.py @@ -80,7 +80,7 @@ def run_PAPNI(data, vpa_alphabet, algorithm='edsm', print_info=True): assert algorithm in {'gsm', 'classic', 'edsm'} - # preprocess input sequances to keep track of stack + # preprocess input sequences to keep track of stack papni_data = [] for input_seq, label in data: # if input sequance is not balanced we do not consider it (it would lead to error state anyway) diff --git a/aalpy/learning_algs/non_deterministic/OnfsmLstar.py b/aalpy/learning_algs/non_deterministic/OnfsmLstar.py index 223cb363c4b..02e5135ac5c 100644 --- a/aalpy/learning_algs/non_deterministic/OnfsmLstar.py +++ b/aalpy/learning_algs/non_deterministic/OnfsmLstar.py @@ -28,7 +28,7 @@ def run_non_det_Lstar(alphabet: list, sul: SUL, eq_oracle: Oracle, n_sampling=5, n_sampling: number of times that each cell has to be updated. If this number is to low, all-weather condition will not hold and learning will not converge to the correct model. (Default value = 50) - samples: input output sequances provided to learning algorithm. List of ((input sequence), (output sequence)). + samples: input output sequences provided to learning algorithm. List of ((input sequence), (output sequence)). stochastic: if True, non deterministic learning will be performed but probabilities will be added to the returned model, making it a stochastic Mealy machine diff --git a/aalpy/learning_algs/stochastic_passive/FPTA.py b/aalpy/learning_algs/stochastic_passive/FPTA.py index 0393b868be0..08b0dac446b 100644 --- a/aalpy/learning_algs/stochastic_passive/FPTA.py +++ b/aalpy/learning_algs/stochastic_passive/FPTA.py @@ -60,7 +60,7 @@ def create_fpta(data, automaton_type): for seq in data: if automaton_type != 'smm' and seq[0] != root_node.output: - print('All sequances passed to Alergia should have the same initial output!') + print('All sequences passed to Alergia should have the same initial output!') assert False curr_node = root_node diff --git a/aalpy/utils/BenchmarkVpaModels.py b/aalpy/utils/BenchmarkVpaModels.py index b49c89aab28..62b8d701ed7 100644 --- a/aalpy/utils/BenchmarkVpaModels.py +++ b/aalpy/utils/BenchmarkVpaModels.py @@ -350,7 +350,7 @@ def vpa_for_even_parentheses(): return vpa -def gen_arithmetic_data(num_sequances=3000, min_seq_len=2, max_seq_len=8): +def gen_arithmetic_data(num_sequences=3000, min_seq_len=2, max_seq_len=8): import ast from aalpy.base import SUL from aalpy.utils import convert_i_o_traces_for_RPNI @@ -388,7 +388,7 @@ def step(self, letter): alphabet = VpaAlphabet(internal_alphabet=['1', '+', ], call_alphabet=['(', ], return_alphabet=[')', ]) merged_alphabet = alphabet.get_merged_alphabet() data = [] - while len(data) < num_sequances: + while len(data) < num_sequences: seq = [] for _ in range(random.randint(min_seq_len, max_seq_len)): seq.append(random.choice(merged_alphabet)) diff --git a/aalpy/utils/HelperFunctions.py b/aalpy/utils/HelperFunctions.py index fb52c0bb208..9aa78a06952 100644 --- a/aalpy/utils/HelperFunctions.py +++ b/aalpy/utils/HelperFunctions.py @@ -340,14 +340,14 @@ def is_balanced(input_seq, vpa_alphabet): return counter == 0 -def generate_input_output_data_from_automata(model, num_sequances=4000, min_seq_len=1, max_seq_len=16, +def generate_input_output_data_from_automata(model, num_sequences=4000, min_seq_len=1, max_seq_len=16, sequance_type='io_traces'): assert sequance_type in {'io_traces', 'labeled_sequences'} alphabet = model.get_input_alphabet() dataset = [] - while len(dataset) < num_sequances: + while len(dataset) < num_sequences: sequance = [] for _ in range(random.randint(min_seq_len, max_seq_len)): sequance.append(random.choice(alphabet)) @@ -363,18 +363,18 @@ def generate_input_output_data_from_automata(model, num_sequances=4000, min_seq_ return dataset -def generate_input_output_data_from_vpa(vpa, num_sequances=1000, max_seq_len=16, max_attempts=None): +def generate_input_output_data_from_vpa(vpa, num_sequences=1000, max_seq_len=16, max_attempts=None): alphabet = vpa.input_alphabet.get_merged_alphabet() data_set, in_set = [], set() - num_nominal_tries = num_sequances // 2 + num_nominal_tries = num_sequences // 2 num_generation_attempts = 0 - max_attempts = max_attempts if max_attempts is not None else num_sequances * 50 + max_attempts = max_attempts if max_attempts is not None else num_sequences * 50 - while len(data_set) < num_sequances: + while len(data_set) < num_sequences: num_generation_attempts += 1 - # it can happen that it is not possible to generate num_sequances balanced words of lenght <= max_seq_len + # it can happen that it is not possible to generate num_sequences balanced words of lenght <= max_seq_len if num_generation_attempts == max_attempts: break