New experimental Go programming language grammar
  • I wrote my first 5.0 grammar, and placed the file "go.Math.00.default.grm.xml" into the "grammars" directory and then started the tool.  I then created a new run, started it, stopped it, and then went to the Models section to save the code, but my new "Go" grammar didn't show up in the languages drop-down menu.

    If I recall correctly, in version 4.0 it was enough to copy my "d.Math.00.default.grm.xml" file into the directory for it to see my D language grammar, but I could be wrong.

    I searched the help files, but they said that copying the file was sufficient.

    Any ideas what I'm doing wrong?

    Thanks!
    -- Glenn
  • Hello Glenn,

    Copying the file and restarting GeneXproTools is enough (assuming you changed the name in the top node of the grammar) . If the grammar does not appear in the dropdown in the Model Panel then it is because it did not validate against grammar.dtd (the XML type definition that exists in the same folder as the grammars). I suggest that you open the grammar that you copied to the folder in Internet Explorer (from within that folder) and see if it shows any validation errors. If that fails then please send us the grammar to the support email and I will run it in the debug version of GeneXproTools and pinpoint the error for you.

  • Although I was unable to get IE to cooperate (it loaded and displayed the file but didn't show me any errors), I did find that "xmllint --valid file.xml" (on Ubuntu) showed me the section that had errors in it, and then I was able to see the problem.
    Thanks!

    When I test it out on a large number of test cases and I'm satisfied that it is working well, I would be happy to share it with the community and/or GepSoft if there is interest.  Would it be better to attach it to this forum post when it is ready, or should I email it to support@gepsoft.com?

    -- Glenn
  • That is a good tip Glenn, I will have a look at xmllint. Feel free to attach it here in the forum whenever you feel it is OK as I am sure others will be interested and may help in further testing.
  • I've put together my first version of the Go programming language grammars.

    I've run through all the test cases and have run into problems whenever TransformCategoricalInputs is needed.
    There are two problems: An extra import is needed whenever atof is used, and that import can not appear anywhere except at the top of the file.  Manual editing can fix this problem.  The second problem is that the if/else statement has mandatory curly braces around the "if" part as well as the "else" part, and I couldn't figure out how to wrangle the XML to get it to do that.
    Anyway, feel free to try this out... we can consider it to be an alpha version.

    -- Glenn
  • Hi Glenn,

    That is an awesome amount of work you put in there thanks!

    Regarding the two problems:

    First the atof's import. Is it strconv? I see that you added the import statement to the open node but I think that adding it to the headers solves the problem. There are headers for categorical (nominal) variants of the code and those can have the extended imports whereas the others only import math. Let me know if this is not correct.

    Second the mandatory curly braces. Why don't you use switch instead of ifs? The system was initially designed to work with switches and the ifs are a bit of a hard fit in there and unfortunately it does not support mandatory braces very well. We will consider that for the next version for sure. Still, the grammar I am attaching uses switch and appears to be ok although I did not compile/test it,  I just copied an example from Go's website.

    Finally, I am kicking myself for not telling you this earlier but I had forgotten myself since it has been a while since I had to do anything to the grammars. There is a parameter in the App.config file (ForceGrammarReloading) that when set to 1 reloads the grammars without restarting GeneXproTools, you only need to click the Models node to reload all the grammars. We also have an internal app that helps with the formatting of the code in the grammars but it only works in the development environment. If you think that would be useful I can have a go at trying to make it read the grammars from an installed version.

    Thanks!
    Jose

  • Thanks, Jose.

    Yes, you are right.  The import "strconv" is the problem.  In Go, it is a compile-time error if you import a package that you don't use... so I was thinking I would break every other model if it didn't use TransformCanonicalInputs.  But I just realized I can *always* put "atof" in the header and always import "strconv" even if no other function uses atof.  That would solve problem #1.

    As for problem #2, using switch is probably the correct solution.

    Also, for other people tuning in, http://play.golang.org/ is a great site to try out Go code without having to download and install the compiler.

    And for those people who would like to kick the Go tires, check this out: http://tour.golang.org/
    It has some interesting quirks, but when you start writing a lot of code, the quirks make sense and become your best friend.  :-)

    Thanks for the reloading tip, Jose!  Very cool.  I'll look for some switch examples.

    -- Glenn
  • Hi Glenn,

    Thanks for the Go Play tip. I has used the one in their homepage but this one is fullscreen and much nicer!

    I am not sure if I understand your post though :-) I already added the switches to the grammar you posted here and I also modified it so that strconv is only imported when there are categorical variables in the dataset.

    These changes are in the xml file appended to my previous post.

    Jose
  • Oh, wow!  I didn't even realize you had attached an XML file to the last post!  ...and there it is, staring right at me!

    Woohoo!  I'm going to try it out.

    Thanks, Jose!
    -- Glenn
  • Ah, very nice... your changes look great, Jose... thank you!
    -- Glenn

  • Just two slight tweaks are no necessary to get it all working...

    On line 361, I had to delete the extra "{CRLF}import "strconv"" that I had added immediately before the "func atof".

    And on line 363, I had to change the single quotes (') to double quotes (") because they mean different things in Go (runes versus strings).

    After that, the FuelCompsumption test I had compiled great with "go build FueldConsumption.go".

    Thanks again, Jose!
    -- Glenn


  • Thanks Glenn, 

    I am attaching to this post the corrected grammar for anyone else who wants to have a go (I know, I know :-).

    Cheers,
    Jose
  • Hi, Glenn!

    The grammars are great! Thank you so much! 

    I took a quick look at all the grammars and found just a small formatting inconsistency in the Boolean grammars: the word “func” doesn't show in blue.

    Again, many thanks! That’s a lot of work you put in there! Thank you also for sharing this with others!

    Candida

  • Thank you, Candida!

    I am having so much fun with your algorithm!  I am reading your book and attempting to write the whole thing in Go. 
    So far, I have the simple NAND example working and am randomly getting complete solutions in generation #0. This was so exciting!  My next step is to start implementing all the selection and mutation steps so that I can iterate past generation #0.  :-)

    My eventual goal is to embed this solver into a more complex robotics simulation environment so that the fitness function can be evaluated within the environment on every step. Big goals, but I am having so much fun thanks to you!

    -- Glenn

  • That’s great, Glenn! Seems to me the hardest part is already done :) Tying the loop is easy and really satisfying. Good luck with your project!

    Candida


  • Thanks!  Tonight I got the first two reproduction steps working: replication/selection (using the roulette wheel algorithm) and mutation.  I think my mutations are probably much more aggressive than they should be, but now the simple NAND example always finds a solution, usually within less than 10 generations.

    This is amazing and incredibly satisfying like you said!

    For my project, I will most likely be dealing with float64 inputs (sensor feedback) and outputs (servo controls), so I should probably move on to one of your linear regression examples and see if I can get that to work.  I will probably wait on the classification examples until I really demonstrate that I have a need for one.

    -- Glenn
  • Thank you, Jose!

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Tagged