[Root Pointer] Ultimate test - Neural Network

Hi, I wrote a small utility that reads PDFs over the Internet and converts the text into a tree of regular expressions. The goal here is to test root_ptr<> and see if it will stand up to this complexity. The code is very simple for the moment as you can see: https://github.com/philippeb8/root_ptr/blob/master/example/t100_test1.cpp Because it makes use of Bash utilities. I am also using libpstreams and "indent_facet.hpp". So anyway apparently it works fine and please let me know if you do not think the code is clean enough. Regards, -Phil

Phil Bouchard wrote:
Hi,
I wrote a small utility that reads PDFs over the Internet and converts the text into a tree of regular expressions. The goal here is to test root_ptr<> and see if it will stand up to this complexity.
The code is very simple for the moment as you can see: https://github.com/philippeb8/root_ptr/blob/master/example/t100_test1.cpp
I'm probably missing something... but isn't this kind of use enabled much more easily by using list<node> for the root and ordinary node* for the internal pointers? Once the list is destroyed everything is swept away, no need for smart pointers of any kind?

On 03/18/2016 09:49 PM, Peter Dimov wrote:
Phil Bouchard wrote:
Hi,
I wrote a small utility that reads PDFs over the Internet and converts the text into a tree of regular expressions. The goal here is to test root_ptr<> and see if it will stand up to this complexity.
The code is very simple for the moment as you can see: https://github.com/philippeb8/root_ptr/blob/master/example/t100_test1.cpp
I'm probably missing something... but isn't this kind of use enabled much more easily by using list<node> for the root and ordinary node* for the internal pointers? Once the list is destroyed everything is swept away, no need for smart pointers of any kind?
neuron_base got sub lists that will need to be explicitly destroyed as well in this case. I will make it even more complex & cyclic tomorrow.

On 03/18/2016 10:13 PM, Phil Bouchard wrote:
On 03/18/2016 09:49 PM, Peter Dimov wrote:
Phil Bouchard wrote:
Hi,
I wrote a small utility that reads PDFs over the Internet and converts the text into a tree of regular expressions. The goal here is to test root_ptr<> and see if it will stand up to this complexity.
The code is very simple for the moment as you can see: https://github.com/philippeb8/root_ptr/blob/master/example/t100_test1.cpp
I'm probably missing something... but isn't this kind of use enabled much more easily by using list<node> for the root and ordinary node* for the internal pointers? Once the list is destroyed everything is swept away, no need for smart pointers of any kind?
neuron_base got sub lists that will need to be explicitly destroyed as well in this case.
I will make it even more complex & cyclic tomorrow.
In implementing a search functionality I realized that there is no easy way to make a node_ptr<> from this. In my example I am forced to create a copy of *this so that I can create a note_ptr<> to it: node_ptr<neuron_base> search(std::string const & input) { std::string res; boost::match_results<std::string::const_iterator> what; if (boost::regex_match(input, what, exp_, boost::match_default | boost::match_partial)) if (what[0].matched) for (unsigned k = 1; k < what.size(); ++ k) if (what[k].matched) if (sub_.size() <= 1) return node_ptr<neuron_base>(x_, new node<neuron_base>(* this)); //< *** Copy of *this else for (std::list<std::list<neuron_base::pointer> >::const_iterator i = sub_.begin(); i != sub_.end(); ++ i) for (std::list<neuron_base::pointer>::const_iterator j = i->begin(); j != i->end(); ++ j) if (node_ptr<neuron_base> p = search(input)) return p; return node_ptr<neuron_base>(x_); } That's a caveat but the copy of *this is done quickly. Although search() could easily use neuron_base * because it is a read only function.

On 03/19/2016 03:22 PM, Phil Bouchard wrote:
On 03/19/2016 01:53 PM, Phil Bouchard wrote:
return node_ptr<neuron_base>(x_, new node<neuron_base>(* this)); //< *** Copy of *this
It is always possible to create a new helper function:
make_node_from_this(x_, * this);
Actually just using: return make_node<neuron_base>(x_, * this); Is okay.

On 03/18/2016 10:13 PM, Phil Bouchard wrote:
I will make it even more complex & cyclic tomorrow.
Its usage is pretty neat now: https://github.com/philippeb8/root_ptr/blob/master/example/t100.h#L73 root_ptr<> is pretty solid. I am not sure what else can possibly be done.

On 03/19/2016 07:26 PM, Phil Bouchard wrote:
On 03/18/2016 10:13 PM, Phil Bouchard wrote:
I will make it even more complex & cyclic tomorrow.
Its usage is pretty neat now: https://github.com/philippeb8/root_ptr/blob/master/example/t100.h#L73
root_ptr<> is pretty solid. I am not sure what else can possibly be done.
It's really fun to program with. Here I am returning complex r-values recursively and it works fine: https://github.com/philippeb8/root_ptr/blob/master/example/t100.h#L152

On 03/20/2016 01:35 PM, Phil Bouchard wrote:
It's really fun to program with.
Here I am returning complex r-values recursively and it works fine: https://github.com/philippeb8/root_ptr/blob/master/example/t100.h#L152
I've cleaned up the example again and now a simple: cout << "Mind dump:" << endl; cout << * t100 << endl; cout << "Searching for: \"einstein\"" << endl; if (node_ptr<neuron_base> p = t100->search("einstein")) cout << p->sort().unique() << endl; cout << "Searching for: \"graviton\"" << endl; if (node_ptr<neuron_base> p = t100->search("graviton")) cout << p->sort().unique() << endl; Will dump you the atomic sentence fragments related to your search.

Hi Phil,
I wrote a small utility that reads PDFs over the Internet and converts the text into a tree of regular expressions.
The subject line says "neural network", and although I see a few names like "neuron" in your code, I can't actually see a neural network implementation. It all seems to be about regular expressions. What have I missed? Regards, Phil.

On 03/23/2016 10:48 AM, Phil Endecott wrote:
The subject line says "neural network", and although I see a few names like "neuron" in your code, I can't actually see a neural network implementation. It all seems to be about regular expressions.
What have I missed?
It's a general neural network with each neuron being represented by a regular expression. I said "tree" but it is really a graph of neurons randomly interconnected with each other: https://github.com/philippeb8/root_ptr/blob/master/example/t100.h#L72 I still need to work on the network but the goal is to test the memory manager and it seems to work perfectly fine up to now.

Phil Bouchard wrote:
On 03/23/2016 10:48 AM, Phil Endecott wrote:
The subject line says "neural network", and although I see a few names like "neuron" in your code, I can't actually see a neural network implementation. It all seems to be about regular expressions.
What have I missed?
It's a general neural network with each neuron being represented by a regular expression. I said "tree" but it is really a graph of neurons randomly interconnected with each other: https://github.com/philippeb8/root_ptr/blob/master/example/t100.h#L72
It's not a "neural network" at all; it's a graph. Which might be what you need to test your smart pointer, but it's confusing to call it something that it isn't. Regards, Phil.
participants (3)
-
Peter Dimov
-
Phil Bouchard
-
Phil Endecott