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

ufold causes unexpected results #24

Closed
mpickering opened this issue Dec 15, 2015 · 5 comments
Closed

ufold causes unexpected results #24

mpickering opened this issue Dec 15, 2015 · 5 comments

Comments

@mpickering
Copy link

I expected the following two functions to be equivalent but ufold gives strange answers. Specifically, the context was missing self-loops and incoming edges, am I misusing ufold here?

consistency :: DTMC -> Maybe Node
consistency dtmc =
  foldr (\n c ->
    if sum (map edgeLabel (out dtmc n)) == 1
      then c
      else (Just n)) Nothing
consistency :: DTMC -> Maybe (Context [String] Rational)
consistency =
  ufold (\context c ->
    if sum (map edgeLabel (out' context)) == 1)
      then c
      else (Just context)) Nothing
@ivan-m
Copy link
Contributor

ivan-m commented Dec 15, 2015

What is DTMC? It makes it difficult for me to tell what you're doing here.

Note that ufold removes the node each time it recurses, whereas I'm guessing that your first function considers the entire graph.

@mpickering
Copy link
Author

Why does ufold remove the node when it recurses? I think that is my problem.

type DTMC = Gr [String] Rational

@ivan-m
Copy link
Contributor

ivan-m commented Dec 16, 2015

Because it's a fold: just like foldr removes that list element as it recurses.

What are you trying to find? The last node that has an out-going weight of 1?

If so, I would use a variant of your first one:

consistency :: DTMC -> Maybe Node
consistency dtmc = listToMaybe . filter ((==1) . sum . map edgeLabel . out dtmc) 
                               $ nodes dtmc

Note that performance-wise, if all you want is the Node then this would be as performant as a Context-based approach, possibly even a tad better (no need to get the in-coming edges, delete the node from the graph, etc.).

@ivan-m
Copy link
Contributor

ivan-m commented May 24, 2016

Is this issue still relevant?

@mpickering
Copy link
Author

No.

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

No branches or pull requests

2 participants