#17016: Implement naive algorithm for factor_set method of a finite word
-------------------------+-------------------------------------------------
Reporter: | Owner:
slabbe | Status: needs_review
Type: | Milestone: sage-6.4
enhancement | Resolution:
Priority: major | Merged in:
Component: | Reviewers:
combinatorics | Work issues:
Keywords: | Commit:
Authors: | 7ed2922be57b5e27c8e5508963c182b80e4fe3e5
Sébastien Labbé | Stopgaps:
Report Upstream: N/A |
Branch: |
u/slabbe/17016 |
Dependencies: |
-------------------------+-------------------------------------------------
Changes (by {'newvalue': u'S\xe9bastien Labb\xe9', 'oldvalue': ''}):
* status: needs_info => needs_review
* author: => Sébastien Labbé
Old description:
> Because it allows to compare the suffix tree implementation with the
> naive approach which simply uses a sliding window. Also because sometimes
> the naive approach is faster:
>
> Sometime a naive algorithm is faster::
>
> {{{
> sage: w = Word([randint(0,2) for _ in range(10000)],
> alphabet=[0,1,2])
> sage: %time L = [w.number_of_factors(i, algorithm='naive') for i in
> range(20)]
> CPU times: user 356 ms, sys: 34.9 ms, total: 391 ms
> Wall time: 389 ms
> sage: %time O = [w.number_of_factors(i, algorithm='suffix tree') for
> i in range(20)]
> CPU times: user 676 ms, sys: 25.7 ms, total: 701 ms
> Wall time: 694 ms
> }}}
>
> Sometimes the suffix tree is faster (for longer word)::
>
> {{{
> sage: w = Word([randint(0,2) for _ in range(100000)],
> alphabet=[0,1,2])
> sage: %time L = [w.number_of_factors(i, algorithm='naive') for i in
> range(20)]
> CPU times: user 6.9 s, sys: 294 ms, total: 7.2 s
> Wall time: 7.17 s
> sage: %time O = [w.number_of_factors(i, algorithm='suffix tree') for
> i in range(20)]
> CPU times: user 6.34 s, sys: 131 ms, total: 6.47 s
> Wall time: 6.52 s
> sage: %time O = [w.number_of_factors(i, algorithm='suffix tree') for
> i in range(20)]
> CPU times: user 3.64 s, sys: 28.3 ms, total: 3.67 s
> Wall time: 3.76 s
> sage: %time L = [w.number_of_factors(i, algorithm='naive') for i in
> range(20)]
> CPU times: user 6.64 s, sys: 302 ms, total: 6.94 s
> Wall time: 6.93 s
> }}}
New description:
Because it allows to compare the suffix tree implementation with the naive
approach which simply uses a sliding window. With #17013, the naive
approach might be faster...
Though, the following example shows the suffix tree is faster::
{{{
sage: w = Word([randint(0,2) for _ in range(100000)],
alphabet=[0,1,2])
sage: %time L = [w.number_of_factors(i, algorithm='naive') for i in
range(20)]
CPU times: user 6.9 s, sys: 294 ms, total: 7.2 s
Wall time: 7.17 s
sage: %time O = [w.number_of_factors(i, algorithm='suffix tree') for i
in range(20)]
CPU times: user 6.34 s, sys: 131 ms, total: 6.47 s
Wall time: 6.52 s
sage: %time O = [w.number_of_factors(i, algorithm='suffix tree') for i
in range(20)]
CPU times: user 3.64 s, sys: 28.3 ms, total: 3.67 s
Wall time: 3.76 s
sage: %time L = [w.number_of_factors(i, algorithm='naive') for i in
range(20)]
CPU times: user 6.64 s, sys: 302 ms, total: 6.94 s
Wall time: 6.93 s
}}}
--
Comment:
> I do not understand your timings... on my computer
You are right : I get similar timings as yours. My hypothesis is that I
did my timings tests on top of #17013 before doing `git stash` and
creating a specific branch for this actual ticket.
I moved the benchmark showing that sometime a naive algorithm is faster
(with #17013) from the description of the ticket above to here::
{{{
sage: w = Word([randint(0,2) for _ in range(10000)], alphabet=[0,1,2])
sage: %time L = [w.number_of_factors(i, algorithm='naive') for i in
range(20)]
CPU times: user 356 ms, sys: 34.9 ms, total: 391 ms
Wall time: 389 ms
sage: %time O = [w.number_of_factors(i, algorithm='suffix tree') for i
in range(20)]
CPU times: user 676 ms, sys: 25.7 ms, total: 701 ms
Wall time: 694 ms
}}}
--
Ticket URL: <http://trac.sagemath.org/ticket/17016#comment:3>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.