gov.sandia.cognition.statistics.bayesian.DefaultBayesianParameter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cognitive-foundry Show documentation
Show all versions of cognitive-foundry Show documentation
A single jar with all the Cognitive Foundry components.
/*
* File: DefaultBayesianParameter.java
* Authors: Kevin R. Dixon
* Company: Sandia National Laboratories
* Project: Cognitive Foundry
*
* Copyright Feb 27, 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.statistics.bayesian;
import gov.sandia.cognition.statistics.DefaultDistributionParameter;
import gov.sandia.cognition.statistics.ClosedFormDistribution;
import gov.sandia.cognition.statistics.Distribution;
import gov.sandia.cognition.util.ObjectUtil;
import java.util.Random;
/**
* Default implementation of BayesianParameter using reflection.
* @param Type of parameters.
* @param
* Type of parameterized distribution that generates observations.
* @param
* Assumed underlying distribution of parameters of the conditional distribution.
* @author Kevin R. Dixon
* @since 3.0
*/
public class DefaultBayesianParameter,PriorType extends Distribution>
extends DefaultDistributionParameter
implements BayesianParameter
{
/**
* Distribution of values that the parameter is assumed to take.
*/
private PriorType parameterPrior;
/**
* Creates a new instance of DefaultBayesianParameter
* @param conditionalDistribution
* Distribution from which to pull the parameters.
* @param parameterName
* Name of the parameter
*/
public DefaultBayesianParameter(
ConditionalType conditionalDistribution,
String parameterName )
{
this( conditionalDistribution, parameterName, null );
}
/**
* Creates a new instance of DefaultBayesianParameter
* @param conditionalDistribution
* Distribution from which to pull the parameters.
* @param parameterName
* Name of the parameter
* @param parameterPrior
* Distribution of values that the parameter is assumed to take.
*/
public DefaultBayesianParameter(
ConditionalType conditionalDistribution,
String parameterName,
PriorType parameterPrior )
{
super( conditionalDistribution, parameterName );
this.setParameterPrior(parameterPrior);
}
@Override
public DefaultBayesianParameter clone()
{
@SuppressWarnings("unchecked")
DefaultBayesianParameter clone =
(DefaultBayesianParameter) super.clone();
clone.setParameterPrior(
ObjectUtil.cloneSafe( this.getParameterPrior() ) );
clone.setName( this.getName() );
return clone;
}
@Override
public PriorType getParameterPrior()
{
return this.parameterPrior;
}
/**
* Sets the Distribution of values that the parameter is assumed to take.
* @param parameterPrior
* Distribution of values that the parameter is assumed to take.
*/
public void setParameterPrior(
PriorType parameterPrior)
{
this.parameterPrior = parameterPrior;
}
@Override
public void updateConditionalDistribution(
Random random)
{
ParameterType parameter = this.parameterPrior.sample(random);
this.setValue(parameter);
}
/**
* Creates a new instance of DefaultBayesianParameter
* @param conditionalDistribution
* Distribution from which to pull the parameters.
* @param parameterName
* Name of the parameter
* @param parameterPrior
* Distribution of values that the parameter is assumed to take.
* @param Type of parameters.
* @param
* Type of parameterized distribution that generates observations.
* @param
* Assumed underlying distribution of parameters of the conditional distribution.
* @return
* Creates a new instance of DefaultBayesianParameter
*/
public static ,PriorType extends Distribution> DefaultBayesianParameter create(
ConditionalType conditionalDistribution,
String parameterName,
PriorType parameterPrior )
{
return new DefaultBayesianParameter(
conditionalDistribution, parameterName, parameterPrior);
}
}