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

gov.sandia.cognition.learning.function.kernel.ProductKernel Maven / Gradle / Ivy

There is a newer version: 4.0.1
Show newest version
/*
 * File:                ProductKernel.java
 * Authors:             Justin Basilico
 * Company:             Sandia National Laboratories
 * Project:             Cognitive Foundry
 *
 * Copyright September 18, 2007, 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.learning.function.kernel;

import gov.sandia.cognition.annotation.CodeReview;
import gov.sandia.cognition.util.ObjectUtil;
import java.util.Collection;

/**
 * The {@code ProductKernel} class implements a kernel that takes the product
 * of applying multiple kernels to the same pair of inputs.
 *
 * @param   The type of the input to the Kernel. For example, Vector.
 * @author Justin Basilico
 * @since  2.0
 */
@CodeReview(
    reviewer="Kevin R. Dixon",
    date="2009-07-08",
    changesNeeded=false,
    comments={
        "Made clone call super.clone.",
        "Looks fine otherwise."
    }
)
public class ProductKernel
    extends DefaultKernelsContainer
    implements Kernel
{
    /**
     * Creates a new instance of ProductKernel.
     */
    public ProductKernel()
    {
        super();
    }
    
    /**
     * Creates a new instance of ProductKernel with the given collection of
     * kernels.
     *
     * @param  kernels The collection of kernels to use.
     */
    public ProductKernel(
        final Collection> kernels)
    {
        super(kernels);
    }
    
    @Override
    public ProductKernel clone()
    {
        return (ProductKernel) super.clone();
    }

    /**
     * The addition kernel applies multiple kernels to the given inputs and
     * returns their product.
     *
     * @param  x The first item.
     * @param  y The second item.
     * @return The kernel evaluated on the two given objects.
     */
    public double evaluate(
        final InputType x, 
        final InputType y)
    {
        double result = 1.0;
        
        for ( Kernel kernel : this.getKernels() )
        {
            result *= kernel.evaluate(x, y);
        }
        
        return result;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy