📄 onetoonemapping.java
字号:
/*
* 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.
*/
/**
* Title: XELOPES Data Mining Library
* Description: The XELOPES library is an open platform-independent and data-source-independent library for Embedded Data Mining.
* Copyright: Copyright (c) 2002 Prudential Systems Software GmbH
* Company: ZSoft (www.zsoft.ru), Prudsys (www.prudsys.com)
* @author Michael Thess
* @version 1.0
*/
package com.prudsys.pdm.Transform;
import com.prudsys.pdm.Adapters.PmmlVersion20.DerivedField;
import com.prudsys.pdm.Core.MiningAttribute;
import com.prudsys.pdm.Core.MiningDataSpecification;
import com.prudsys.pdm.Core.MiningException;
import com.prudsys.pdm.Core.PmmlPresentable;
import com.prudsys.pdm.Cwm.Transformation.FeatureMap;
import com.prudsys.pdm.Models.Statistics.StatisticsMiningModel;
/**
* Transforms one attribute into one other attribute.
*/
public abstract class OneToOneMapping extends FeatureMap implements PmmlPresentable
{
// -----------------------------------------------------------------------
// Variables declarations
// -----------------------------------------------------------------------
/** Name of source attribute. */
protected String sourceName;
/** Name of target attribute. */
protected String targetName;
/** Remove source attribute after transformation? */
protected boolean removeSourceAttribute = true;
/** Statistics model required by some extensions. */
protected StatisticsMiningModel statisticsMiningModel;
/** Directly assigned source attribute. */
protected MiningAttribute sourceAttribute = null;
// -----------------------------------------------------------------------
// Constructor
// -----------------------------------------------------------------------
/**
* Empty constructor.
*/
public OneToOneMapping()
{
}
// -----------------------------------------------------------------------
// Getter and setter methods
// -----------------------------------------------------------------------
/**
* Sets new name of source attribute.
*
* @param sourceName new name of source attribute
*/
public void setSourceName(String sourceName)
{
this.sourceName = sourceName;
}
/**
* Returns name of source attribute.
*
* @return source attribute name
*/
public String getSourceName()
{
return sourceName;
}
/**
* Sets new name of target attribute.
*
* @param targetName new name of target attribute
*/
public void setTargetName(String targetName)
{
this.targetName = targetName;
}
/**
* Returns name of target attribute.
*
* @return name of target attribute
*/
public String getTargetName()
{
return targetName;
}
/**
* Set remove all source attribute after transformation (default: no).
*
* @param removeSourceAttribute set remove source attribute after transformation
*/
public void setRemoveSourceAttribute(boolean removeSourceAttribute)
{
this.removeSourceAttribute = removeSourceAttribute;
}
/**
* Remove source attribute after transformation (default: no)?
*
* @return true if remove source attribute after trafo, otherwise false
*/
public boolean isRemoveSourceAttribute()
{
return removeSourceAttribute;
}
/**
* Sets statistics mining model required for some transformations.
*
* @param statisticsMiningModel new statistics mining model
*/
public void setStatisticsMiningModel(StatisticsMiningModel statisticsMiningModel)
{
this.statisticsMiningModel = statisticsMiningModel;
}
/**
* Returns statistics mining model required for some transformations.
*
* @return statistics mining model
*/
public StatisticsMiningModel getStatisticsMiningModel()
{
return statisticsMiningModel;
}
/**
* Returns source attribute name.
*
* @return dynamic source attributes
*/
protected String getSourceNameDynamic() {
return sourceName;
}
/**
* Returns target attribute name. If not target attribute name is defined,
* the target attribute name is defined as
* "t_" + <dynamic source attribute name>.
*
* @return dynamic target attributes
*/
protected String getTargetNameDynamic() {
String tname = targetName;
if (tname == null && sourceName != null)
tname = "t_" + getSourceNameDynamic();
return tname;
}
/**
* Allows to directly assign a source attribute which is used
* instead of the meta data. This should be done when the ono-to-one mapping
* is used separately from the multiple-to-multiple mapping, e.g. in
* Neural Network's input and output units.
*
* @param sourceAttribute source attribute of the transformation
*/
public void setSourceAttribute(MiningAttribute sourceAttribute) {
this.sourceAttribute = sourceAttribute;
}
/**
* Returns source attribute. If the source attribute is defined
* directly through the method setSourceAttribute, this one is used.
* Otherwise the meta data is accessed from the multiple-to-multiple
* mapping it is assigned to and the attribute with sourceName is found.
*
* @return source attribute, null if not found
*/
public MiningAttribute getSourceAttribute() {
if (sourceAttribute != null)
return sourceAttribute;
MiningDataSpecification metaData = getSourceMetaData();
MiningAttribute attribute = metaData.getMiningAttribute(sourceName);
return attribute;
}
/**
* Returns meta data of sources, i.e. the pretransformed meta data
* from the assigned multiple-to-multiple mapping.
*
* @return source meta data
*/
protected MiningDataSpecification getSourceMetaData() {
return ((MultipleToMultipleMapping) classifierMap).pretransformedMetaData;
}
// -----------------------------------------------------------------------
// Transformation methods
// -----------------------------------------------------------------------
/**
* Transforms the source attribute. The result is the target attribute.
*
* @return transformed attribute
* @exception MiningException cannot transform attribute
*/
public abstract MiningAttribute transformAttribute() throws MiningException;
/**
* Transforms attribute value. The result is also a value.
*
* @param attributeValue value of attribute to be transformed
* @return tranformed value
* @exception MiningException cannot transform attribute value
*/
public abstract double transformAttributeValue( double attributeValue ) throws MiningException;
// -----------------------------------------------------------------------
// Methods of PMML handling
// -----------------------------------------------------------------------
/**
* Creates PMML object DerivedField and sets target attribute
* and removeSourceAttribute option.
*
* @return DerivedField element
* @see com.prudsys.pdm.Adapters.PmmlVersion20.Root
* @exception MiningException could not create PMML object
*/
public Object createPmmlObject() throws MiningException
{
DerivedField field = new DerivedField();
field.setName( getTargetNameDynamic() );
field.setDisplayName( "Transformed " + sourceName );
if ( isRemoveSourceAttribute() )
field.setRemoveSourceAtt("1");
return field;
}
/**
* Parse PMML object DerivedField obtaining target attribute and
* remove source attribute option.
*
* @param pmml DerivedField element
* @see com.prudsys.pdm.Adapters.PmmlVersion20.Root
* @exception MiningException could not parse PMML object
*/
public void parsePmmlObject(Object pmml) throws MiningException
{
DerivedField field = (DerivedField) pmml;
targetName = field.getName();
setRemoveSourceAttribute(false);
if ( field.getRemoveSourceAtt()!= null && field.getRemoveSourceAtt().equals("1") )
setRemoveSourceAttribute(true);
}
/**
* Creates one-to-one mapping object from PMML DerivedField.
*
* @param pmml DerivedField object
* @return one-to-one mapping of corresponding class, else null
*/
public static OneToOneMapping createOneToOneMappingFromPmml(Object pmml) {
OneToOneMapping one2oneMap = null;
DerivedField field = (DerivedField) pmml;
if ( field.getFieldRef() != null )
one2oneMap = new com.prudsys.pdm.Transform.OneToOne.Copy();
else if ( field.getNormContinuous() != null )
one2oneMap = new com.prudsys.pdm.Transform.OneToOne.LinearNormal();
else if ( field.getDiscretize() != null )
one2oneMap = new com.prudsys.pdm.Transform.OneToOne.Discretization();
else if ( field.getNumerization() != null )
one2oneMap = new com.prudsys.pdm.Transform.OneToOne.Numerization();
else if ( field.getCategorization() != null )
one2oneMap = new com.prudsys.pdm.Transform.OneToOne.Categorization();
else if ( field.getMapValues() != null )
one2oneMap = new com.prudsys.pdm.Transform.OneToOne.CategMapping();
else if ( field.getMapValuesNum() != null )
one2oneMap = new com.prudsys.pdm.Transform.OneToOne.CategNumMapping();
else if ( field.getExponential() != null )
one2oneMap = new com.prudsys.pdm.Transform.OneToOne.Exponential();
else if ( field.getLogarithmic() != null )
one2oneMap = new com.prudsys.pdm.Transform.OneToOne.Logarithmic();
else if ( field.getReciprocal() != null )
one2oneMap = new com.prudsys.pdm.Transform.OneToOne.Reciprocal();
else if ( field.getRoot() != null )
one2oneMap = new com.prudsys.pdm.Transform.OneToOne.Root();
else if ( field.getSquare() != null )
one2oneMap = new com.prudsys.pdm.Transform.OneToOne.Square();
else if ( field.getCreateVirtualAttribute() != null )
one2oneMap = new com.prudsys.pdm.Transform.OneToOne.CreateVirtualAttribute();
return one2oneMap;
}
// -----------------------------------------------------------------------
// Other methods
// -----------------------------------------------------------------------
/**
* Returns string representation of one-to-one map.
*
* @return onoe-to-one map string representation
*/
public String toString() {
String res = "----------Ono-to-one map. " + "\n";
res = res + "Source name: " + sourceName + "\n";
res = res + "Target name: " + targetName + "\n";
res = res + "removeSourceAttribute: " + removeSourceAttribute + "\n";
res = res + "class name: " + this.getClass().toString();
return res;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -