commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tobr...@transolutions.net (O'brien, Tim)
Subject Re: [math][patch] New RollingUnivariateImpl
Date Fri, 16 May 2003 05:27:14 GMT
Mark, take a look at ListStoreUnivariateImpl, StoreUnivariateImpl, and
UnivariateImpl.  The last two use ContractableDoubleArray as an
underlying storage mechanism which allows us the luxury of ignoring the
maintenance of the storage array.   

I tend to avoid committing code without heavy unit tests, but this was
an exception.  We'll need to get all classes to 100% testing in Clover.

Tim

On Thu, 2003-05-15 at 18:32, Mark R. Diggory wrote:
> Ughh, sorry about the copyright that got dumped in there, feel free to 
> replace it with the Apaches.
> 
> Mark R. Diggory wrote:
> 
> > Well the latest changes to the cvs made the implementation of the 
> > RollingUnivariate quite simple indeed. Tell me what you think.
> >
> > -Mark
> >
> >------------------------------------------------------------------------
> >
> >Index: .classpath
> >===================================================================
> >RCS file: .classpath
> >diff -N .classpath
> >--- /dev/null	1 Jan 1970 00:00:00 -0000
> >+++ .classpath	15 May 2003 23:22:10 -0000
> >@@ -0,0 +1,6 @@
> >+<?xml version="1.0" encoding="UTF-8"?>
> >+<classpath>
> >+    <classpathentry kind="src" path="src/java"/>
> >+    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
> >+    <classpathentry kind="output" path="target/classes"/>
> >+</classpath>
> >Index: .project
> >===================================================================
> >RCS file: .project
> >diff -N .project
> >--- /dev/null	1 Jan 1970 00:00:00 -0000
> >+++ .project	15 May 2003 23:22:10 -0000
> >@@ -0,0 +1,17 @@
> >+<?xml version="1.0" encoding="UTF-8"?>
> >+<projectDescription>
> >+	<name>math</name>
> >+	<comment></comment>
> >+	<projects>
> >+	</projects>
> >+	<buildSpec>
> >+		<buildCommand>
> >+			<name>org.eclipse.jdt.core.javabuilder</name>
> >+			<arguments>
> >+			</arguments>
> >+		</buildCommand>
> >+	</buildSpec>
> >+	<natures>
> >+		<nature>org.eclipse.jdt.core.javanature</nature>
> >+	</natures>
> >+</projectDescription>
> >Index: src/java/org/apache/commons/math/RollingUnivariate.java
> >===================================================================
> >RCS file: src/java/org/apache/commons/math/RollingUnivariate.java
> >diff -N src/java/org/apache/commons/math/RollingUnivariate.java
> >--- /dev/null	1 Jan 1970 00:00:00 -0000
> >+++ src/java/org/apache/commons/math/RollingUnivariate.java	15 May 2003 23:22:10
-0000
> >@@ -0,0 +1,43 @@
> >+package org.apache.commons.math;
> >+import org.apache.commons.math.StoreUnivariate;
> >+
> >+/*
> >+ * Created on May 15, 2003
> >+ *
> >+ * Copyright (C) 2002-2003, Mark Diggory 
> >+ *
> >+ * This program is free software; you can redistribute it and/or modify
> >+ * it under the terms of the GNU General Public License as published by
> >+ * the Free Software Foundation; either version 2 of the License, or
> >+ * (at your option) any later version.
> >+ *
> >+ * This program is distributed in the hope that it will be useful,
> >+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
> >+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> >+ * GNU General Public License for more details.
> >+ *
> >+ * You should have received a copy of the GNU General Public License
> >+ * along with this program; if not, write to the Free Software
> >+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. License 
> >+ * information is also available at http://www.gnu.org.
> >+ *
> >+ */
> >+
> >+/**
> >+ * @author administrator
> >+ *
> >+ * To change the template for this generated type comment go to
> >+ * Window>Preferences>Java>Code Generation>Code and Comments
> >+ */
> >+public interface RollingUnivariate extends StoreUnivariate {
> >+
> >+	/**
> >+	 * @return
> >+	 */
> >+	public int getWindow();
> >+
> >+	/**
> >+	 * @param i
> >+	 */
> >+	public void setWindow(int window);
> >+}
> >Index: src/java/org/apache/commons/math/RollingUnivariateImpl.java
> >===================================================================
> >RCS file: src/java/org/apache/commons/math/RollingUnivariateImpl.java
> >diff -N src/java/org/apache/commons/math/RollingUnivariateImpl.java
> >--- /dev/null	1 Jan 1970 00:00:00 -0000
> >+++ src/java/org/apache/commons/math/RollingUnivariateImpl.java	15 May 2003 23:22:10
-0000
> >@@ -0,0 +1,140 @@
> >+/* ====================================================================
> >+ * The Apache Software License, Version 1.1
> >+ *
> >+ * Copyright (c) 2003 The Apache Software Foundation.  All rights
> >+ * reserved.
> >+ *
> >+ * Redistribution and use in source and binary forms, with or without
> >+ * modification, are permitted provided that the following conditions
> >+ * are met:
> >+ *
> >+ * 1. Redistributions of source code must retain the above copyright
> >+ *    notice, this list of conditions and the following disclaimer.
> >+ *
> >+ * 2. Redistributions in binary form must reproduce the above copyright
> >+ *    notice, this list of conditions and the following disclaimer in
> >+ *    the documentation and/or other materials provided with the
> >+ *    distribution.
> >+ *
> >+ * 3. The end-user documentation included with the redistribution, if
> >+ *    any, must include the following acknowlegement:
> >+ *       "This product includes software developed by the
> >+ *        Apache Software Foundation (http://www.apache.org/)."
> >+ *    Alternately, this acknowlegement may appear in the software itself,
> >+ *    if and wherever such third-party acknowlegements normally appear.
> >+ *
> >+ * 4. The names "The Jakarta Project", "Commons", and "Apache Software
> >+ *    Foundation" must not be used to endorse or promote products derived
> >+ *    from this software without prior written permission. For written
> >+ *    permission, please contact apache@apache.org.
> >+ *
> >+ * 5. Products derived from this software may not be called "Apache"
> >+ *    nor may "Apache" appear in their names without prior written
> >+ *    permission of the Apache Software Foundation.
> >+ *
> >+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
> >+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
> >+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
> >+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
> >+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
> >+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
> >+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
> >+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
> >+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
> >+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
> >+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
> >+ * SUCH DAMAGE.
> >+ * ====================================================================
> >+ *
> >+ * This software consists of voluntary contributions made by many
> >+ * individuals on behalf of the Apache Software Foundation.  For more
> >+ * information on the Apache Software Foundation, please see
> >+ * <http://www.apache.org/>.
> >+ */
> >+package org.apache.commons.math;
> >+
> >+/**
> >+ *
> >+ * Accumulates univariate statistics for values fed in 
> >+ * through the addValue() method.  Stores only the data 
> >+ * over the designated window of interest.
> >+ *
> >+ * @author Phil Steitz
> >+ * @author Mark Diggory
> >+ * @version
> >+ * 
> >+*/
> >+public class RollingUnivariateImpl extends AbstractStoreUnivariate implements RollingUnivariate{
> >+
> >+	/** Array of values for rolling */ 
> >+	private double[] values = null;
> >+	
> >+	/** Array of values for rolling */ 
> >+	private int index = 0;
> >+		
> >+	/** Window on which to calculate */
> >+	private int window = 2;
> >+	
> >+	/** Creates new univariate */
> >+	public RollingUnivariateImpl(int window){
> >+		if(window < 2) throw new java.lang.IndexOutOfBoundsException("window must be
greater than 2");
> >+		values = new double[window];
> >+	}
> >+		
> >+
> >+	/* (non-Javadoc)
> >+	 * @see org.apache.commons.math.StoreUnivariate#getValues()
> >+	 */
> >+	public double[] getValues() {
> >+		double[] copiedArray = new double[window];
> >+		System.arraycopy( values, 0, copiedArray, 0, copiedArray.length);
> >+		return  copiedArray;
> >+	}
> >+
> >+	/* (non-Javadoc)
> >+	 * @see org.apache.commons.math.StoreUnivariate#getElement(int)
> >+	 */
> >+	public double getElement(int index) {
> >+		return values[index];
> >+	}
> >+	
> >+	/* (non-Javadoc)
> >+	 * @see org.apache.commons.math.Univariate#getN()
> >+	 */
> >+	public double getN() {
> >+		return values.length;
> >+	}
> >+	
> >+	/* (non-Javadoc)
> >+	 * @see org.apache.commons.math.Univariate#addValue(double)
> >+	 */
> >+	public void addValue(double v) {
> >+		values[index] = v;
> >+		index = (index + 1) % values.length;			
> >+	}
> >+
> >+	/* (non-Javadoc)
> >+	 * @see org.apache.commons.math.Univariate#clear()
> >+	 */
> >+	public void clear() {
> >+		values = new double[window];
> >+		this.index = 0;
> >+	}
> >+	
> >+	/**
> >+	 * @return
> >+	 */
> >+	public int getWindow() {
> >+		return window;
> >+	}
> >+
> >+	/**
> >+	 * @param i
> >+	 */
> >+	public void setWindow(int window){
> >+		if(window < 2) throw new java.lang.IndexOutOfBoundsException("window must be
greater than 2");
> >+		this.window = window;
> >+		clear();
> >+	}
> >+
> >+}
> >
> >  
> >
> >------------------------------------------------------------------------
> >
> >---------------------------------------------------------------------
> >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


Mime
View raw message