You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Al Chou <ho...@yahoo.com> on 2003/07/13 08:09:54 UTC

[math] food for thought concerning interfaces

I wonder, with all the design consideration going on, whether the "Applyable"
interface idea from the following article would be at all valuable in
commons-math:

http://www.pragmaticprogrammer.com/ppllc/papers/1998_05.html


Al

=====
Albert Davidson Chou

    Get answers to Mac questions at http://www.Mac-Mgrs.org/ .

__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Re: [math] food for thought concerning interfaces

Posted by "Mark R. Diggory" <md...@latte.harvard.edu>.
I experimented with using the "apply" strategy instead of exposing the 
internal array, its start and length via protected methods in the 
Univariate Facade implementations. This works so much "cleaner" now.

Each Univariate implementation simply implements a

public double apply(UnivariateStatistic stat)

method which implements the evaluation of the UnivariateStatistic 
against its internal array or a double array generated off of its list. 
Each getXXX bean property simple calls this polymorphic 
apply(UnivariateStatistic stat) method, handing it an instance of the 
applicable stat.

The cool thing is, with this approach, Univariates are not restricted to 
only calculating just their internal stats, they can also receive and 
calculate external UnivariateStatistic objects to complete the calculation


Univariate u = new StoreUniviariateImpl();
UnivariateStatistic stat = new MySpecialStat();

double result = u.apply(stat);

-M.

Mark R. Diggory wrote:
> A tasty meal indeed,
> 
> I like his discussion about how iterators are invariants and how 
> functors can help the design avoid such invariants. For example, by 
> making it the Containers job to apply the the "Applyable" object to its 
> storage.
> 
> I think this would also map well to our ideas of UnivariateStatistics 
> (US) and DoubleArrays, instead of DoubleArrays exposing the internal 
> double[], or providing an iterator over that state, its possible that we 
> could approach more of an "applyable" approach where the data object 
> implements its own iteration mechanism internally and "applies" the 
> appropriate UnivariateStatistic to it.
> 
> DoubleArray array = ...
> ...
> 
> UnivariateStatistic stat = ...
> ...
> 
> double result = array.apply(stat);
> 
> 
> the apply method could look as simple as this in cases where we are 
> working with a double[] internal store:
> 
> public double apply(UnivariateStatistic stat){
>    return stat.evaluate(internalArray,start,length);
> }
> 
> or for iterative approaches over non-double[] stores:
> 
> public double apply(UnivariateStatistic stat){
>     DoubleIterator iter = new MyDoubleIterator();
>     while (iter.hasNext()) {
>        stat.increment(iter.next());
>     }
>     return stat.getResult();
> }
> 
> Although I've not yet determined which is more efficient in cases where 
> the store is not a double[]:
> 
> 1.) building a double[] off the store and calling 
> UnivariateStatistic.evaluate.
> 
> 2.) iterating over the store (i.e. if its a java.util.Collection) and 
> calling StorelessUnivariateStatistic.increment.
> 
> -Mark
> 
> Al Chou wrote:
> 
>> I wonder, with all the design consideration going on, whether the 
>> "Applyable"
>> interface idea from the following article would be at all valuable in
>> commons-math:
>>
>> http://www.pragmaticprogrammer.com/ppllc/papers/1998_05.html
>>
>>
>> Al
>>
>> =====
>> Albert Davidson Chou
>>
>>     Get answers to Mac questions at http://www.Mac-Mgrs.org/ .
>>
>> __________________________________
>> Do you Yahoo!?
>> SBC Yahoo! DSL - Now only $29.95 per month!
>> http://sbc.yahoo.com
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
>>
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Re: [math] food for thought concerning interfaces

Posted by "Mark R. Diggory" <md...@latte.harvard.edu>.
A tasty meal indeed,

I like his discussion about how iterators are invariants and how 
functors can help the design avoid such invariants. For example, by 
making it the Containers job to apply the the "Applyable" object to its 
storage.

I think this would also map well to our ideas of UnivariateStatistics 
(US) and DoubleArrays, instead of DoubleArrays exposing the internal 
double[], or providing an iterator over that state, its possible that we 
could approach more of an "applyable" approach where the data object 
implements its own iteration mechanism internally and "applies" the 
appropriate UnivariateStatistic to it.

DoubleArray array = ...
...

UnivariateStatistic stat = ...
...

double result = array.apply(stat);


the apply method could look as simple as this in cases where we are 
working with a double[] internal store:

public double apply(UnivariateStatistic stat){
    return stat.evaluate(internalArray,start,length);
}

or for iterative approaches over non-double[] stores:

public double apply(UnivariateStatistic stat){
     DoubleIterator iter = new MyDoubleIterator();
     while (iter.hasNext()) {
        stat.increment(iter.next());
     }
     return stat.getResult();
}

Although I've not yet determined which is more efficient in cases where 
the store is not a double[]:

1.) building a double[] off the store and calling 
UnivariateStatistic.evaluate.

2.) iterating over the store (i.e. if its a java.util.Collection) and 
calling StorelessUnivariateStatistic.increment.

-Mark

Al Chou wrote:
> I wonder, with all the design consideration going on, whether the "Applyable"
> interface idea from the following article would be at all valuable in
> commons-math:
> 
> http://www.pragmaticprogrammer.com/ppllc/papers/1998_05.html
> 
> 
> Al
> 
> =====
> Albert Davidson Chou
> 
>     Get answers to Mac questions at http://www.Mac-Mgrs.org/ .
> 
> __________________________________
> Do you Yahoo!?
> SBC Yahoo! DSL - Now only $29.95 per month!
> http://sbc.yahoo.com
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org