On 27 October 2011 23:22, Satrajit Ghosh <[email protected]> wrote:
> hi robert,
>
>
>> I had a way of doing it that would be really robust, but really slow.
>> Expand each of the factorials on the denominator and numerator separately
>> and store as separate lists. Then remove all terms common to both lists and
>> multiply the results. However, this heavily uses append and would be too
>> slow for large value of N.
>>
>
> another exact solution would be to do an accumulator trick (treating every
> factorial as a factor):
>
> def run_accumulate(all_factors):
> a = np.zeros((all_factors.max()+1))
> b = np.arange(all_factors.max()+1)
> for factor in all_factors:
> a[:(abs(factor)+1)] += np.sign(factor)
> return np.exp(np.dot(a[2:], np.log(b[2:])))
>
> seems to run pretty quickly
>
> %timeit run_accumulate(np.array([50, 10, -30, -20])) # numerator factors
> are +ve, denominator is -ve
>
> 10000 loops, best of 3: 98.3 us per loop
>
> cheers,
>
> satra
>
>
>
> ------------------------------------------------------------------------------
> The demand for IT networking professionals continues to grow, and the
> demand for specialized networking skills is growing even more rapidly.
> Take a complimentary Learning@Cisco Self-Assessment and learn
> about Cisco certifications, training, and career opportunities.
> http://p.sf.net/sfu/cisco-dev2dev
> _______________________________________________
> Scikit-learn-general mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/scikit-learn-general
>
>
I haven't seen this pattern before - that should probably work well.
I'll have some time this weekend, so I think I'll be implementing three
different versions!
- Robert
--
My public key can be found at: http://pgp.mit.edu/
Search for this email address and select the key from "2011-08-19" (key id:
54BA8735)
Older keys can be used, but please inform me beforehand (and update when
possible!)
------------------------------------------------------------------------------
The demand for IT networking professionals continues to grow, and the
demand for specialized networking skills is growing even more rapidly.
Take a complimentary Learning@Cisco Self-Assessment and learn
about Cisco certifications, training, and career opportunities.
http://p.sf.net/sfu/cisco-dev2dev
_______________________________________________
Scikit-learn-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/scikit-learn-general