-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
A new Region for plots in C++ (for C++ and C# apps) #748
Comments
My first impression was to search for plot library package written entirely in standard C++11 that can be linked into the htm.core library. However, the downside (in addition to license issues) is that it blots the library. We are not looking for a super fast package, just something that can provide the capability enjoyed by Python users with Matplotlib. So, why not just call Matplotlib from C++?
For inspiration I looked at this package: https://github.com/lava/matplotlib-cpp Before I start in on this... does anyone have a better idea? |
I agree on the matplotlib based package. Do we even need this in c++? PyRegion would be much simpler, and yes it would require python to be installed on the machine (but for machines that will do graphical outputs, I think it's an OK requirement for on optional functionality) |
Good point. That would be much easier... I got to thinking about how we would link up a .py Region for an app that its main is in C++. In order to do embedded python we need the python library to be linked in. The C++ app would also need PyBindRegion and RegisteredRegionImplPy classes. And to be general it would also need all of the python bindings so that the .py classes it calls can call back into htm.core; so basically it would need the 5 extension libraries. The extension libraries are basically shared libraries. I wonder if a C++ app could link with those directly. I guess that is something to investigate. |
I think what you're trying to figure is if c++ only app could use our code written in py (with python statically linked etc). |
@dkeeney I do not know what kind of plot/visualization this region should have? @marty1995 and I usually use SFML library for visualizing some important visualization tasks related to HTM (ploting curves, Cells/Layers-Visualization). I think it is good for all we need... |
Another way would be to get in touch with @Zbysekz and But I think the 2 projects are about something else, HTMpandaVis plots the connections etc, while we want simple graphs here and maybe a visualization of a SDR. |
I was trying to keep it all within one C++ process...as a plugin for NetworkAPI. Spawning out to the shell to call python would work I guess. Is that what you are suggesting? |
Currently, i am working on revamp of the HTMpanda interface. Now it works through TCP sockets. But we got stuck with some execution order problems, and also execution speed is not so good for larger projects. So i decided to change this.
Not really. I would like to incorporate also "universal data plot window". User configurable window, choosing what variable from database you want to plot. Up to let's say 10 or so graphs in one window so the state of the simulation can be seen. I am imagining just using matplotlib. I could create C++ "data feeder" which could simply contains method like
What do you think? Is this what is wanted? |
so there are 2 stages?
We have serialization for Connections, can you just use that? Or it stores too much data and you need to be storage-savvy?
so this will include the raw data? (sequence of float, or an image, ...) ?
sounds exactly like how I imagined things for this 👏 |
Repost the API draft: |
Yes exactly. Separated from htm.core code completely. The SQLite3 database has file with *.db extension.
If i use the If yes, then that's too much as i need to store thousands of iterations...
yes it will create the table with the given name if not exists and put there the data. Two columns, one is iteration number, second is the value. Image also could be stored, because it supports "blob" datatype (i am using that for storing whole numpy array) (P.S. funny fact, sqlite3 has limit for one database file 140 TB 👍 ) |
yes, but it's a bit smart. Stores only sparse synapses, also in binary format (possibly can even compress?). So, I quick test:
I think that is a good idea 👍 We're storing the "raw inputs" anyway, right? So given encoders are deterministic, we could compute the distal if needed.
we're good for a while :) |
I've ended up with these plots as result: (there are 13 plots on one page in this case) This uses the python plotly dash library. Very nice interactive graphs. In web browser All plots have iteration on x axis. There is small cfg text file, where you can specify what you want to plot from the database and set labels. To have just line plots with x axis as iteration is now enough for pandaVis. Should i write C++ feeder to be able to fill data into database? Or this is for no use regarding this PR? |
wow! The image looks really great! I'm looking forward to the interactive plots.
I'd like to hear from @dkeeney . But for me, if it's not too complicated, it'll surely be nice way to achieve the visualizations. |
@breznak 's response is the same as mine... wow! We would love to have such a feeder for C++. Such a module was on my 'back burner' to do and this is wonderful that you have taken on this project. What I envisioned as a feeder from NetworkAPI was a new built-in Region Implementation which accepts a link and displays the data interactively. Much like FileOutputRegion except rather than sending the data to a file it sends it to the plot. To add a plot into a project, a user would connect a link from any output to this new PlotRegion and like magic there is a plot available in a browser. This would work with the REST api as well. |
To be honest, i don't know the Network API, nor how to use it. I can't find API doc for the FileOutputRegion but it shouldn't be so hard to use. @dkeeney do we have some minimal example that i can see how FileOutputRegion is used and run it? I found this, but it uses just fileoutput stream. |
There's atleast A minimal example should be in the region's test:
@dkeeney could you please look at these 2 things?
|
Yes, we can do that. Although it does not sound like a high priority issue.
I was trying to strip down the example to simplify it as much as possible. But sure, that would be reasonable.
I have that on my back burner as a low priority project that I never got to. Not sure it is really important. |
I would look at FileOutputRegion object as an example. Make a copy of it and edit it from there. Any configuration you need would be passed in params in the constructor.
This will fetch the incoming data for that cycle. This is an Array object which is a container for array data. On that container, dataIn_.getCount( ) is the elements in the array, dataIn_.getBuffer( ) gets a C style pointer to the beginning of the array. The data type of each element is set in the spec. The value NTA_BasicType_Real32 means it is a float. The link object will have already converted the data to this type if necessary. So you can cast the pointer to Real32 and use it for the plot. |
Thanks for advice @dkeeney. I made simple few line modif of napi_hello to use the fileoutput region https://github.com/Zbysekz/htm.core/tree/RegionForPlots |
When the net.link( ... ) function is called it sets up the connections of output to input. This can be configured by calling the net.link( ) function or by setting up links in the JSON string that is passed to net.configure( ... ).
The 'anomaly' output on the TM should be connected to the input of your PlotRegion with a link.
That is a leftover from Numenta's implementation. The link has no parameters other than the delay so those two parameters are not used. I left them there because I did not want to break the API. I will write up something that describes how to build a new region module for NetworkAPI. This information exist in the numenta's old documentation but its a little hard to extract. |
See PR #853 which describes how to create a region for NetworkAPI. What I was thinking was that your PlotRegion would control one plot. An app could configure multiple PlotRegion instances to handle different data. Let us know how it is going. |
I stuck little bit on the compilation with sqlite3 library. I added the new region into CMakeLists.txt in the src folder and also put sqlite3.c & sqlite3.h into utils folder.
It seems that it is because sqlite3.c is missing in build/scripts/src/Makefile |
I don't think we make a regexp now, but explicitely name all the files.
|
sqlite3 is a third party package. But for now you do need to explicitly name the .h and .c files or sqlite3 in src/CMakeLists.txt |
Yes i already put them in the src/CMakeLists. Today i tried just for test renaming sqlite3.c to sqlite3.cpp and sqlite3.h to sqlite3.hpp and it showed up in build/scripts/src/Makefile ! so it seems that it is really because of the extension. Here is my branch https://github.com/Zbysekz/htm.core/tree/RegionForPlots |
Oh, good find.. it's probably due to our project being specified as CXX in said CMakeFile.
|
Oh great, i added |
I don-t know if the non-original cpp sqlite implementation would work for you? (as the db readable in python, etc) or if that's a good idea (bugs fixed in db) but here's some list: https://srombauts.github.io/SQLiteCpp/#see-also---some-other-simple-c-sqlite-wrappers the |
we have strict |
nit, once it works, can you try doing that only for the cmake unit, not globally? |
This grows over my head, the cmake language is spanish village for me, i have put the sqlite in ThirdParty, created the sqlite3.cmake to automatically download tar, but how to build it to create .a library and link it to the project i don't know.. Can one of you help me to setup this? this branch is what i have now. My goal is just to compile it. Note: i think compiling sqlite3.c & sqlite3.h into static library or object file will be enough, but which is better i have no idea |
Yes, I can help you with CMake. I was expecting that you could get it to compile "any way it works" for this PR and I will then I would fold sqlite3 into the ThirdParty build with a second PR. Would it be easier if I just did sqlite3 first and then you can add your project using sqlite3 library which would already be there? |
Yes that would be wonderful, thanks. |
I just checked in PR #857 which folds sqlite3 into the htm.core library. In your code reference the .h as sqlite3/sqlite3.h |
hmmm, sqlite3 package did not build on Linux so I have more work to do. |
I've tried build PR #857 on my linux machine and passed. (.a file was created) |
Ok, that should have worked. Let me look into it further. #857 is now in the main but I want to be sure this is right. |
Now we can continue in NAB, where it all started EDIT: |
The objective is to have a Region that is accessible by C++ (and eventually C#) users that can perform plots, much like Matplotlib which we have for Python.
The text was updated successfully, but these errors were encountered: