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

Cereal for TMRegion #472

Merged
merged 5 commits into from
May 21, 2019
Merged

Cereal for TMRegion #472

merged 5 commits into from
May 21, 2019

Conversation

dkeeney
Copy link

@dkeeney dkeeney commented May 14, 2019

Adds Cereal for TMRegion

Replaces #421

@dkeeney
Copy link
Author

dkeeney commented May 14, 2019

This is a new clean branch. The other one was so messed up I could not trust it.
This should be a simple PR. But nothing seems to be simple.

The Network class has two STL objects being serialized. One for regions and one for links. Whichever one is first is ok but the second one seems to be out of synch with the stream and crashes. I tried putting just a simple int field deserialized after the first STL object and it came up with the wrong value.
This is similar to (and may be the same) problem I was having when I tried to do my own iterations but I thought Cereal was doing them correctly. Apparently not.

This did not show up with the SPRegion PR because I did not happen to have any Links in the test. Well, I am out of time so I will have to finish this when I get back.

Copy link
Member

@breznak breznak 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 question to the TM. reset, otherwise looks good

if (args_.init) {
// Restore algorithm state
nupic::algorithms::temporal_memory::TemporalMemory* tm = new nupic::algorithms::temporal_memory::TemporalMemory();
tm_.reset(tm);
Copy link
Member

Choose a reason for hiding this comment

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

the TM::reset() is questionable here, since it didnt have to be called prior to saving

Copy link
Author

Choose a reason for hiding this comment

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

The reset just assigns the raw TM pointer to the shared_ptr. Perhaps I should use a make_shared( ) here in this case since this is a simple allocation.

Copy link
Member

Choose a reason for hiding this comment

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

Perhaps I should use a make_shared( ) here in this case since this is a simple allocation.

ok, the name confused me into a TM.reset. Maybe rename the method to resetTMPointer or something? but it can stay as is

@breznak
Copy link
Member

breznak commented May 14, 2019

CI simple problem:

/Users/distiller/numenta/nupic.core/src/nupic/engine/Network.hpp:151:9: error: unused variable 'marker' [-Werror,-Wunused-variable]
int marker;

@dkeeney
Copy link
Author

dkeeney commented May 14, 2019

I pushed again without the marker field :) That was the field I serialized after the first STL. I missed the declaration when I took it back out.

breznak
breznak previously approved these changes May 14, 2019
Copy link
Member

@breznak breznak left a comment

Choose a reason for hiding this comment

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

This looks good, thank you David!

@dkeeney
Copy link
Author

dkeeney commented May 21, 2019

Funny how problems look so much simpler after coming back from a vacation.

  • We can do sequences in Cereal. You have to be sure to use the correct size in make_size_tag( ) for the variable holding the iteration count. It must be cereal::size_type, not size_t. Also, for each iteration of a sequence you can output only one object. ar(a, b, c) is three objects and it will mess up the sequence count. So if you have more than one object for each sequence iteration, put them in a container and add save_ar( ) and load_ar( ) to the container. For an example, see TemporalMemory.hpp line 455.
  • The regions_ member variable in the Network class is now a std::map( ) so it is easier to serialize. But this map is only seen inside the class. Outside the Network class regions is a Collection, obtained via the getRegions( ) call so this does not change the API.

Copy link
Member

@breznak breznak left a comment

Choose a reason for hiding this comment

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

Wow, this looks real good now! Thank you 👍

Funny how problems look so much simpler after coming back from a vacation.

indeed, sometimes we just need to take a rest from the problems.

So if you have more than one object for each sequence iteration, put them in a container and add save_ar( ) and load_ar( ) to the container. For an example, see TemporalMemory.hpp line 455.

this is great finding!

The regions_ member variable in the Network class is now a std::map( ) so it is easier to serialize. But this map is only seen inside the class. Outside the Network class regions is a Collection, obtained via the getRegions( ) call so this does not change the API.

Cool! The better API would use std::map instead, and internally Collection could have extended from std::map. Good as is now, do you want to break the API for the sake of getting rid of Collection, or leave things stable as is now?

* The list of regions registered with the Network.
* Internally this is a map so it is easy to serialize
* but externally this is a Collection object so it
* retains API compatability.
Copy link
Member

Choose a reason for hiding this comment

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

this is perferct! Thanks 👍

Copy link
Author

Choose a reason for hiding this comment

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

The better API would use std::map instead, and internally Collection could have extended from std::map.

Collection contains both a vector of pairs and a map of indexes into the vector. It would be difficult to extend from map and get a class that can also be indexed like a vector to get a pair.

... for the sake of getting rid of Collection, ...

The Collection is still being used in several other places as well so it will take a while before we can get rid of it. Lets let it live in the API for now.

Copy link
Author

Choose a reason for hiding this comment

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

@breznak approved these changes

Thanks for doing the review for me.

@breznak breznak merged commit dd6d06a into master May 21, 2019
@breznak breznak deleted the cereal-TMRegion2 branch May 21, 2019 09:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants