Yes, JUnit tests passed on my machine, if others do encounter problems, let me know and I'll debug further.

Al, there is no lost of efficiency (in fact theres a minor improvement). The previous path of action on calculating any statistic in AbstractUnivariate was basically like the following:

Univariate.getVariance(){
     return variance.evaluate(
          this.getValues(),
          this.getStart(),
          this.getNumElements()
          );
}

protected double[] internalValues() {
    return storage == null ? null : storage.getValues();
}

protected int start() {
    return storage.start();
}

protected int size() {
    return storage.getNumElements();
}

where these methods were used to expose the internal double[] of data (if possible) or generate a double[] of data in the case of ListUnivariateImpl and BeanListUnivariateImpl. The above example was what existed in UnivariateImpl and basically ends up delegating to the "storage" DoubleArray methods. So this equates to about 7 method calls (1*evaluate, 2*internalValues, 2*start, 2*size).

The using the "applicable" strategy we get the following path of action instead:

Univariate.getVariance(){
     return this.apply(variance);
}

public double apply(UnivariateStatistic stat) {
       return stat.evaluate(
           storage.getValues(),
           storage.start(),
           storage.getNumElements()
       );
}

which is more direct and only equates to about 4 method calls for the same process to occur (1*evaluate, 1*getValues, 1*start, 1*size).. Not that this is really a significant improvement, but its just added benefit on top of the following:

(1) It frees up the implementation not to have to expose its internal storage to apply a statistic against it.

(2) If you write your own "UnivariateStatistic" you can easily apply it against the same contents as the internally defined stats (mean,var,...).

I'd like to propose we add the apply method to the Univariate Interface, or create a generic Interface called "Applicable" that Univariate can extend to allow the User to see the apply method from the Univariate interface.

-Mark

Al Chou wrote:
--- [EMAIL PROTECTED] wrote:

mdiggory 2003/07/14 20:45:10

 Modified:    math/src/java/org/apache/commons/math/stat
                       UnivariateImpl.java AbstractStoreUnivariate.java
                       ListUnivariateImpl.java AbstractUnivariate.java
                       StoreUnivariateImpl.java
 Log:
 Application of "apply(Functor x)" strategy (thank you Al Chou) for
evaluating UnivariateStatistics against the internal storage collection
without exposing the collection or its bounds.


Mark,

I assume all the existing unit tests passed.  I don't think you mentioned
performance testing in your last message.  I'm curious what effect the
"applyable" strategy has on efficiency.


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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to