kstaats / karoo_gp

A Genetic Programming platform for Python with TensorFlow for wicked-fast CPU and GPU support.
Other
157 stars 61 forks source link

Use Unicode-art for the tree display. #83

Open ezio-melotti opened 2 years ago

ezio-melotti commented 2 years ago

This PR is a proof of concept that updates the Branch.display_viz() method to use Unicode-art instead of ASCII-art.

This is an example of the new representation:

                       ╭────┤+├──────────────────────╮      
           ╭──────────┤+├──────────╮                 b      
     ╭────┤+├────╮           ╭────┤+├────╮                  
     b           b           c           a           

Or as a screenshot from my terminal: image

I also played around with a few different representations:

  1. without rounded corners and nothing around the operator:
     ┌───────────────────────*─────┐                        
     a                       ┌─────*─────────────────┐      
                 ┌───────────-─────┐                 a      
                 b           ┌─────-─────┐                  
                             a           a     
  2. with rounded corners and nothing around the operator:

                   ╭─────────/───────────────────╮          
              ╭────*──────────────╮         ╭────+────╮     
    ╭─────────-────╮              c         c         b     
    a         ╭────/────╮                                   
              a         c   
    
  3. with rounded corners and [ ] around the operators:
                        ╭───[+]───────────────────────╮     
    ╭──────────────────[-]───╮                        c     
    b              ╭────────[+]────────╮                    
              ╭───[-]───╮         ╭───[-]───╮               
              b         c         a         c  
  4. with rounded corners and ┤ ├ around the operators (the proposed one, shown at the top).

TODO:

There are also a few items that don't seem directly related to this PR, but should be fixed in a separate PR:

kstaats commented 2 years ago

I prefer #4

On 8/3/22 15:37, Ezio Melotti wrote:

This PR is a proof of concept that updates the Branch.display_viz() method to use Unicode-art instead of ASCII-art.

This is an example of the new representation:

                        ╭────┤+├──────────────────────╮
            ╭──────────┤+├──────────╮                 b
      ╭────┤+├────╮           ╭────┤+├────╮
      b           b           c           a

Or as a screenshot from my terminal: image

I also played around with a few different representations:

  1. without rounded corners and nothing around the operator:
      ┌───────────────────────*─────┐
      a                       ┌─────*─────────────────┐
                  ┌───────────-─────┐                 a
                  b           ┌─────-─────┐
                              a           a
  2. with rounded corners and nothing around the operator:

                    ╭─────────/───────────────────╮
               ╭────*──────────────╮         ╭────+────╮
     ╭─────────-────╮              c         c         b
     a         ╭────/────╮
               a         c
    
  3. with rounded corners and [ ] around the operators:
                         ╭───[+]───────────────────────╮
     ╭──────────────────[-]───╮                        c
     b              ╭────────[+]────────╮
               ╭───[-]───╮         ╭───[-]───╮
               b         c         a         c
  4. with rounded corners and ┤ ├ around the operators (the proposed one, shown at the top).

TODO:

  • [ ] decide which representation to adopt
  • [ ] fix tests accordingly
  • [ ] possibly add a unicode=True arg

There are also a few items that don't seem directly related to this PR, but should be fixed in a separate PR:

-- Commit Summary --

  • Use Unicode-art for the tree display.

-- File Changes --

 M karoo_gp/branch.py (15)

-- Patch Links --

https://github.com/kstaats/karoo_gp/pull/83.patch https://github.com/kstaats/karoo_gp/pull/83.diff

granawkins commented 2 years ago

I also like Number 4.

re: 'deep tree', I thought of adding an option to clip the display at the bottom and/or top, to guarantee readability. There are some details to work out, but here's an idea:

                        (+3 hidden)
                       ╭────┤+├──────────────────────╮      
           ╭──────────┤+├──────────╮                 b      
     ╭────┤+├────╮           ╭────┤+├────╮                  
     b           b          |+|         |-|
                        (+4 hidden)  (+2 hidden)       

Another useful feature would be to highlight one node, or a node + all nodes below it. I'm close to adding click for my work on the interactive mode, which I'm sure we can co-opt for this.

ezio-melotti commented 2 years ago

Another useful feature would be to highlight one node, or a node + all nodes below it.

Unicode provides a range of characters that can be used for that, e.g. this could be used to highlight the bottom-left operator:

                       ╭────┤+├──────────────────────╮      
           ╭──────────┤+├──────────╮                 b      
     ╭────╢+╟────╮           ╭────┤+├────╮                  
     b           b           c           a   

There are also double lines, but not for rounded corners.

We could also make it fancier: image however this is more complicated to achieve and takes 2x many lines compared to the other version: image

kstaats commented 1 year ago

Keep in mind that with larger datasets we'll employ much larger trees. This visualization works well for small trees, but when they have 100+ nodes, it will wrap on-screen, no?

On 8/3/22 19:44, Grant wrote:

I also like Number 4.

re: 'deep tree', I thought of adding an option to clip the display at the bottom and/or top, to guarantee readability. There are some details to work out, but here's an idea:

                         (+3 hidden)
                        ╭────┤+├──────────────────────╮
            ╭──────────┤+├──────────╮                 b
      ╭────┤+├────╮           ╭────┤+├────╮
      b           b          |+|         |-|
                         (+4 hidden)  (+2 hidden)

Another useful feature would be to highlight one node, or a node + all nodes below it. I'm close to adding click for my work on the interactive mode, which I'm sure we can co-opt for this.

ezio-melotti commented 1 year ago

Yes, this is the last item in the checklist in my first message -- this PR was mostly a proof of concept. We discussed a different tree-style representation for larger sets too. I can go back to this before the release of 3.0 and implement both.

granawkins commented 1 year ago

For Karoo 3.0:

Future updates: