All Downloads are FREE. Search and download functionalities are using the official Maven repository.

gov.sandia.cognition.math.WeightedRingAverager Maven / Gradle / Ivy

There is a newer version: 4.0.1
Show newest version
/*
 * File:                WeightedRingAverager.java
 * Authors:             Kevin R. Dixon
 * Company:             Sandia National Laboratories
 * Project:             Cognitive Foundry
 * 
 * Copyright Feb 4, 2010, Sandia Corporation.
 * Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive
 * license for use of this work by or on behalf of the U.S. Government.
 * Export of this program may require a license from the United States
 * Government. See CopyrightHistory.txt for complete details.
 * 
 */

package gov.sandia.cognition.math;

import gov.sandia.cognition.util.AbstractCloneableSerializable;
import gov.sandia.cognition.util.Summarizer;
import gov.sandia.cognition.util.WeightedValue;
import java.util.Collection;

/**
 * A type of Summarizer for Rings (Matrices, Vectors, ComplexNumbers). Returns
 * the arithmetic weighted mean of a Collection of Rings.
 * @param  Type of Ring to average.
 * @author Kevin R. Dixon
 * @since 3.0
 */
public class WeightedRingAverager>
    extends AbstractCloneableSerializable
    implements Summarizer, RingType>
{

    /** 
     * Creates a new instance of WeightedRingAverager 
     */
    public WeightedRingAverager()
    {
    }

    public RingType summarize(
        Collection> data)
    {

        double weightSum = 0.0;
        RingAccumulator weightedSum =
            new RingAccumulator();
        for( WeightedValue value : data )
        {
            final double w = value.getWeight();
            weightSum += w;
            weightedSum.accumulate( value.getValue().scale( w ) );
        }

        return weightedSum.getSum().scale( 1.0/weightSum );
        
    }
    
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy