Skip to content

Correct choices function#299

Merged
gpampara merged 1 commit intociren:masterfrom
gpampara:choices-fix
Sep 7, 2018
Merged

Correct choices function#299
gpampara merged 1 commit intociren:masterfrom
gpampara:choices-fix

Conversation

@gpampara
Copy link
Copy Markdown
Member

@gpampara gpampara commented Sep 3, 2018

The function was returning invalid results due to referencing the
wrong data structure. Some additional logic is now also included to
make sure that the operation behaves a little more efficiently.

MetricSpace did not use the memoization scheme correctly, resulting
in no benefit actually being present. This is now correct, referencing
the memoization map structure.

The function was returning invalid results due to referencing the
wrong data structure. Some additional logic is now also included to
make sure that the operation behaves a little more efficiently.

`MetricSpace` did not use the memoization scheme correctly, resulting
in no benefit actually being present. This is now correct, referencing
the memoization map structure.
Copy link
Copy Markdown
Contributor

@KyleErwin KyleErwin left a comment

Choose a reason for hiding this comment

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

Just a comment on choices as a whole, should we not cater to cases where n is the greater than the list.size?

innerDropIndex(0, l)
}

def go(indexes: List[Int], current: List[A]): List[A] =
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What happens if, for example we have a List of size n and we generate random indices such as n-2 and n-1. And since the method go will remove indices already visited then the index n-1 will become invalid. Is this correct?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I don't follow your thinking here. The values in backsaw are based on a "reducing list size", so even if the same same value is randomly selected, the selected element will be within range and the elements will always be shrinking as selections take place.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm with you now. That's very cool. One final thought though, because backsaw uses the reducing list size to generate random indices do we not end up giving preference to indices 0 to n - 1 as they would have the most opportunities to be generated?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I understand now that since already visited elements are being removed that the elements closer to xs.length will also get a chance of selected fairly. Will Approve the PR

case _ => List.empty[A]
}

go(l, xs.toList).some
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Does choices now eliminate any duplicates generated?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The tests should be illustrating that fairly well.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Cool, I see that. Was just double checking.

@gpampara
Copy link
Copy Markdown
Member Author

gpampara commented Sep 5, 2018

What would the correct behaviour be? Request n values and then you get back m instead is wrong.

@KyleErwin
Copy link
Copy Markdown
Contributor

Was just wondering if n is greater than the list size should duplicates then be allowed. But that behavior is better off with something like

RVar.choose(NonEmptyList(...)).replicateM(n)

@gpampara
Copy link
Copy Markdown
Member Author

gpampara commented Sep 7, 2018

Yeah, I would be very hesitant to overload the behaviour like that. It seems very out of the functions scope.

@gpampara gpampara merged commit 5ca4090 into ciren:master Sep 7, 2018
@gpampara gpampara deleted the choices-fix branch September 7, 2018 14:42
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