gov.sandia.cognition.framework.learning.converter.CogxelWeightedInputOutputPairConverter 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: CogxelWeightedInputOutputPairConverter.java
* Authors: Kevin R. Dixon
* Company: Sandia National Laboratories
* Project: Cognitive Framework Lite
*
* Copyright July 17, 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.framework.learning.converter;
import gov.sandia.cognition.framework.CogxelState;
import gov.sandia.cognition.framework.SemanticIdentifierMap;
import gov.sandia.cognition.learning.data.DefaultWeightedInputOutputPair;
import gov.sandia.cognition.learning.data.InputOutputPair;
import gov.sandia.cognition.learning.data.WeightedInputOutputPair;
/**
* A CogxelConverter for creating WeightedInputOutputPairs
*
* @param Type of input to convert into the inputs of the
* InputOutputPairs
* @param Type of outputs to convert into the outputs of the
* InputOutputPairs
* @author Kevin R. Dixon
* @since 2.0
*
*/
public class CogxelWeightedInputOutputPairConverter
implements CogxelConverter>
{
/**
* Creates the underlying InputOutputPair
*/
private CogxelInputOutputPairConverter pairConverter;
/**
* Adds the weight to the InputOutputPair
*/
private CogxelConverter weightConverter;
/** Creates a new instance of CogxelWeightedInputOutputPairConverter */
public CogxelWeightedInputOutputPairConverter()
{
this( null, null, null );
}
/**
* Creates a new instance of CogxelWeightedInputOutputPairConverter
* @param inputConverter
* Converts Cogxels for the input
* @param outputConverter
* Converts Cogxels for the output
* @param weightConverter
* Converts the Cogxel for the weight
*/
public CogxelWeightedInputOutputPairConverter(
CogxelConverter inputConverter,
CogxelConverter outputConverter,
CogxelConverter weightConverter )
{
this.setPairConverter(
new CogxelInputOutputPairConverter(
inputConverter, outputConverter ) );
this.setWeightConverter( weightConverter );
}
/**
* Copy constructor
* @param other Object to clone
*/
@SuppressWarnings("unchecked")
public CogxelWeightedInputOutputPairConverter(
CogxelWeightedInputOutputPairConverter other )
{
this( other.getPairConverter().getInputConverter().clone(),
other.getPairConverter().getOutputConverter().clone(),
other.getWeightConverter().clone() );
}
/**
* {@inheritDoc}
* @return {@inheritDoc}
*/
@Override
public CogxelWeightedInputOutputPairConverter clone()
{
return new CogxelWeightedInputOutputPairConverter( this );
}
/**
* Getter for weightConverter
* @return
* Adds the weight to the InputOutputPair
*/
public CogxelConverter getWeightConverter()
{
return this.weightConverter;
}
/**
* Setter for weightConverter
* @param weightConverter
* Adds the weight to the InputOutputPair
*/
public void setWeightConverter(
CogxelConverter weightConverter)
{
this.weightConverter = weightConverter;
}
/**
* {@inheritDoc}
* @param cogxels {@inheritDoc}
* @return {@inheritDoc}
*/
public WeightedInputOutputPair fromCogxels(
CogxelState cogxels)
{
InputOutputPair pair =
this.getPairConverter().fromCogxels( cogxels );
double weight = this.getWeightConverter().fromCogxels( cogxels );
return new DefaultWeightedInputOutputPair( pair, weight );
}
/**
* {@inheritDoc}
* @param data {@inheritDoc}
* @param cogxels {@inheritDoc}
*/
public void toCogxels(
WeightedInputOutputPair data,
CogxelState cogxels)
{
this.getPairConverter().toCogxels( data, cogxels );
this.getWeightConverter().toCogxels( data.getWeight(), cogxels );
}
/**
* Getter for pairConverter
* @return
* Creates the underlying InputOutputPair
*/
public CogxelInputOutputPairConverter getPairConverter()
{
return this.pairConverter;
}
/**
* Setter for pairConverter
* @param pairConverter
* Creates the underlying InputOutputPair
*/
public void setPairConverter(
CogxelInputOutputPairConverter pairConverter)
{
this.pairConverter = pairConverter;
}
/**
* {@inheritDoc}
* @return {@inheritDoc}
*/
public SemanticIdentifierMap getSemanticIdentifierMap()
{
return this.getPairConverter().getSemanticIdentifierMap();
}
/**
* {@inheritDoc}
* @param semanticIdentifierMap {@inheritDoc}
*/
public void setSemanticIdentifierMap(
SemanticIdentifierMap semanticIdentifierMap)
{
this.getPairConverter().setSemanticIdentifierMap( semanticIdentifierMap );
this.getWeightConverter().setSemanticIdentifierMap( semanticIdentifierMap );
}
}