Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Topic/inverse evaluate proposer #8

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

na2021
Copy link

@na2021 na2021 commented Apr 10, 2019

Code to be reviewed, not necessarily merged yet, I have still to finish the documentation and tests.

Copy link
Owner

@joshrule joshrule left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know you're not entirely finished with this PR, but here are a few comments on what you've done so far. This is going to be a really cool search move, so I'm glad you're working on it. Looking forward to seeing the completed product!

src/trs/rewrite.rs Outdated Show resolved Hide resolved
src/trs/rewrite.rs Outdated Show resolved Hide resolved
}
/// Selects two Rules from the TRS at random and atempts to inverse evaluate one rule on the other, if it
/// succeeds it takes that new rule and inserts it imediately after the background.
pub fn inverse_evaluate<R: Rng>(&self, rng: &mut R) -> Result<TRS, SampleError> {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because this is pub, let's make sure to have an example here.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still need an example here.

src/trs/rewrite.rs Outdated Show resolved Hide resolved
src/trs/rewrite.rs Outdated Show resolved Hide resolved
src/trs/rewrite.rs Show resolved Hide resolved
Copy link
Owner

@joshrule joshrule left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool - you're making progress! I've added a few new comments below. What's the biggest barrier between where you are now and being finished with this feature?

pub fn inverse_evaluate<R: Rng>(&self, rng: &mut R) -> Result<TRS, SampleError> {

/// Extracts a sngle rule from the TRS selecting only 1 rhs
fn sample_rule<R: Rng>(&self, rng: &mut R) -> Result<Rule, SampleError> {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Funny - I forgot that I'd put this in the last review and just wrote a similar function, TRS::choose_clause, a couple days ago. I suppose we have a strong use case for it! I'm not sure why this one is quite so long, though. Here's my implementation:

    fn choose_clause<R: Rng>(&self, rng: &mut R) -> Result<Rule, SampleError> {
        let rules = {
            let num_rules = self.len();
            let background = &self.lex.0.read().expect("poisoned lexicon").background;
            let num_background = background.len();
            &self.utrs.rules[0..(num_rules - num_background)]
        };
        let mut clauses = rules.iter().flat_map(Rule::clauses).collect_vec();
        let idx = (0..clauses.len())
            .choose(rng)
            .ok_or(SampleError::OptionsExhausted)?;
        Ok(clauses.swap_remove(idx))
    }

Am I missing something?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I was reading some of the lines you'd deleted as part of the current function. They're pretty similar in length.

}
trs.utrs.remove_idx(target_idx).expect("removing old rule");
trs.utrs
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can use ? here instead of expect. That way, you return the error rather than panic. Something like this:

trs.utrs.remove_clauses(&ref_rule)?;

}
let mut target_idx: usize = rng.gen_range(num_background, num_rules);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of sampling a rule by index, would it work just to sample another clause? Also, we write so much boilerplate to figure out how many rules we've learned. Perhaps that could also be extracted into a helper function, say, pub fn learned_rules<'a>(&'a self) -> &'a [Rule] or something similar.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants