Commit 8c6b3595 authored by Bharat Garhewal's avatar Bharat Garhewal
Browse files

Cleanup

parent a730c331
......@@ -12,11 +12,13 @@ pub enum AdsStatus {
pub trait AdaptiveDistinguishingSequence {
/// Given the previous output, returns the next input, or an [`AdsStatus`].
///
/// Initially, prev_output will be ``None``, but after that, it is
/// Initially, `prev_output` will be ``None``, but after that, it is
/// required to provide the previous output, wrapped in a ``Some``.
/// ## [`AdsStatus`]
/// 1. DONE ⇒ No more inputs to send, and
/// 2. UNEXPECTED ⇒ Previous output was not expected.
/// # Errors
/// None.
fn next_input(&mut self, prev_output: Option<OutputSymbol>) -> Result<InputSymbol, AdsStatus>;
fn get_print_tree(&self) -> Box<[u8]>;
......
......@@ -17,7 +17,7 @@ use std::{
cell::RefCell,
collections::{HashMap, HashSet, VecDeque},
fmt::Debug,
hash::BuildHasher,
hash::{BuildHasher, BuildHasherDefault},
rc::Rc,
};
......@@ -128,6 +128,9 @@ where
let rho = &ce_input[..idx];
let x = rho.len();
let y = ce_input.len();
#[allow(clippy::cast_possible_truncation)]
#[allow(clippy::cast_precision_loss)]
#[allow(clippy::cast_sign_loss)]
let h = ((x as f32 + y as f32) / 2_f32).floor() as usize;
let sigma_1 = &ce_input[..h];
......@@ -289,15 +292,13 @@ where
let temp = RefCell::borrow(&self.oq_oracle);
let o_tree = temp.borrow_tree();
let basis = self.basis.iter().copied().collect::<HashSet<_, _>>();
let hyp_input_alphabet = (0..self.input_size)
.into_iter()
.map(|x| x as u16)
.map(InputSymbol::from)
.collect_vec();
let hyp_input_alphabet = toolbox::inputs_iterator(self.input_size).collect_vec();
let func_size = basis.len() * hyp_input_alphabet.len();
let mut hyp_output_alphabet = HashSet::<_, _>::default();
let mut hyp_trans_fn = HashMap::with_capacity_and_hasher(func_size, Default::default());
let mut hyp_output_fn = HashMap::with_capacity_and_hasher(func_size, Default::default());
let mut hyp_trans_fn =
HashMap::with_capacity_and_hasher(func_size, BuildHasherDefault::default());
let mut hyp_output_fn =
HashMap::with_capacity_and_hasher(func_size, BuildHasherDefault::default());
log::debug!("Basis set: {:?}", self.basis);
log::debug!("Frontier-Basis sep: {:?}", self.frontier_to_basis_map);
......@@ -342,6 +343,7 @@ where
.expect("Safe")
}
#[allow(clippy::unused_self)]
fn run_ly_ads(&mut self, _ly_ads: &mut LyAds) {
todo!()
}
......@@ -367,13 +369,8 @@ where
let input_alph = self.input_size;
let temp = RefCell::borrow(&self.oq_oracle);
let o_tree = temp.borrow_tree();
let state_input_iterator = Itertools::cartesian_product(
basis_set.iter().copied(),
(0..input_alph)
.into_iter()
.map(|x| x as u16)
.map(InputSymbol::from),
);
let ia = toolbox::inputs_iterator(input_alph).collect_vec();
let state_input_iterator = Itertools::cartesian_product(basis_set.iter().copied(), ia);
let new_front = state_input_iterator
.filter_map(|(bs, i)| o_tree.get_succ(bs, &[i]))
.filter(|x| !self.basis.contains(x))
......@@ -404,11 +401,7 @@ where
queue.push_back((State::new(0), State::new(0)));
while !queue.is_empty() {
let (q, r) = queue.pop_front().expect("Always safe!");
for i in (0..self.input_size)
.into_iter()
.map(|x| x as u16)
.map(InputSymbol::from)
{
for i in toolbox::inputs_iterator(self.input_size) {
if let Some(((out_tree, dest_tree), (dest_hyp, out_hyp))) = o_tree
.get_out_succ(q, i)
.zip(Some(hypothesis.step_from(r, i)))
......@@ -426,6 +419,8 @@ where
}
None
}
#[allow(clippy::unused_self)]
pub fn get_ads_score(&self) -> f32 {
0.0
}
......
......@@ -15,7 +15,7 @@ use log4rs::{
encode::pattern::PatternEncoder,
};
use lsharp_ru::learner::learning::OptionsBuilder;
use lsharp_ru::*;
use lsharp_ru::{automatadefs, learner, util};
use rand::{prelude::StdRng, Rng, SeedableRng};
use std::{fs, io::Write, path::Path};
......
......@@ -59,11 +59,7 @@ where
}
let access_map = self.construct_access_map(hyp_states.clone()); // S -> Access Seq.
let input_size = hypothesis.input_alphabet().len();
let mut input_alphabet: Vec<_> = (0..input_size)
.into_iter()
.map(|x| x as u16)
.map(InputSymbol::from)
.collect_vec();
let mut input_alphabet = toolbox::inputs_iterator(input_size).collect_vec();
input_alphabet.shuffle(&mut self.rng);
let lookahead_range = (1..=lookahead + 1).into_iter().collect_vec();
let infix_closure = || {
......@@ -151,11 +147,7 @@ where
// since we are already in the initial state;
// Therefore, the only thing left is I<=(n+1)
let input_size = hyp.input_alphabet().len();
let mut input_alphabet: Vec<_> = (0..input_size)
.into_iter()
.map(|x| x as u16)
.map(InputSymbol::from)
.collect_vec();
let mut input_alphabet = toolbox::inputs_iterator(input_size).collect_vec();
input_alphabet.shuffle(&mut self.rng);
let lookahead_range = (0..=self.lookahead + 1).into_iter().collect_vec();
let infix_closure = || {
......
......@@ -5,7 +5,7 @@ use crate::{
traits::{FiniteStateMachine, ObservationTree},
},
oracles::membership::Oracle as OQOracle,
util::{learning_config::EqOracle, writers::overall as MealyWriter},
util::{learning_config::EqOracle, toolbox, writers::overall as MealyWriter},
};
use fnv::FnvHashMap;
use itertools::Itertools;
......@@ -180,11 +180,7 @@ impl<'a, T: ObservationTree + Send + Sync> SouchaOracle<'a, T> {
// since we are already in the initial state;
// Therefore, the only thing left is I<=(n+1)
let input_size = hyp.input_alphabet().len();
let input_alphabet: Vec<_> = (0..input_size)
.into_iter()
.map(|x| x as u16)
.map(InputSymbol::from)
.collect_vec();
let input_alphabet = toolbox::inputs_iterator(input_size).collect_vec();
let lookahead_range = (0..=self.config.lookahead() + 1).into_iter().collect_vec();
let infix_closure = || {
Iterator::flatten(lookahead_range.iter().map(|&n| {
......@@ -209,7 +205,7 @@ impl<'a, T: ObservationTree + Send + Sync> SouchaOracle<'a, T> {
if hyp_output == sut_output {
return None;
}
Some((input_seq.to_vec(), sut_output.to_vec()))
Some((input_seq.to_vec(), sut_output))
}
}
......@@ -266,8 +262,8 @@ where
.kill()
.expect("Could not manage to kill H-ADS process.");
let ce_input = input_vec.clone();
let ce_output = sut_output.to_vec();
let ret = Some((ce_input.to_vec(), ce_output));
let ce_output = sut_output;
let ret = Some((ce_input, ce_output));
return ret;
}
}
......
......@@ -58,11 +58,7 @@ where
}
let access_map = self.construct_access_map(hyp_states.clone()); // S -> Access Seq.
let input_size = hypothesis.input_alphabet().len();
let mut input_alphabet: Vec<_> = (0..input_size)
.into_iter()
.map(|x| x as u16)
.map(InputSymbol::from)
.collect_vec();
let mut input_alphabet = toolbox::inputs_iterator(input_size).collect_vec();
input_alphabet.shuffle(&mut self.rng);
let lookahead_range = (1..=lookahead + 1).into_iter().collect_vec();
let infix_closure = || {
......@@ -150,11 +146,7 @@ where
// since we are already in the initial state;
// Therefore, the only thing left is I<=(n+1)
let input_size = hyp.input_alphabet().len();
let mut input_alphabet = (0..input_size)
.into_iter()
.map(|x| x as u16)
.map(InputSymbol::from)
.collect_vec();
let mut input_alphabet = toolbox::inputs_iterator(input_size).collect_vec();
input_alphabet.shuffle(&mut self.rng);
let lookahead_range = (0..=self.lookahead + 1).into_iter().collect_vec();
let infix_closure = || {
......@@ -175,7 +167,7 @@ where
if hyp_output == sut_output {
return None;
}
Some((input_seq.to_vec(), sut_output.to_vec()))
Some((input_seq.to_vec(), sut_output))
}
/// Compute the access sequences for the states
......
......@@ -45,8 +45,8 @@ impl<T, P> ArenaTree<T, P> {
}
/// Get borrow for node at `idx`.
pub fn ref_at(&self, idx: usize) -> &T {
&self.arena[idx].val
pub fn ref_at(&self, idx: impl Into<usize>) -> &T {
&self.arena[idx.into()].val
}
pub fn apply_at<X>(&self, idx: usize, func: fn(&T) -> X) -> X {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment