📄 metadataoperations.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 Valentine Stepanenko (valentine.stepanenko@zsoft.ru)
* @author Michael Thess
* @version 1.2
*/
package com.prudsys.pdm.Core;
import com.prudsys.pdm.Input.MiningVector;
import com.prudsys.pdm.Transform.MiningTransformer;
import com.prudsys.pdm.Utils.IntVector;
/**
* Performs comparisons and basis transformations of meta data (e.g. mining
* data specification). <p>
*
* From PDM CWM extension.
*
* @see MiningDataSpecification
* @see MiningAttribute
*/
public class MetaDataOperations extends com.prudsys.pdm.Cwm.Core.Class implements MiningTransformer
{
// -----------------------------------------------------------------------
// Constants of basis treatment
// -----------------------------------------------------------------------
/** Just use attribute names in comparisons and transformations. */
public static final int USE_ATT_NAMES = 0;
/** Use attributes names and types in comparisons and transformations. */
public static final int USE_ATT_NAMES_AND_TYPES = 1;
/** Use attributes names, types, and categories in comparisons and transformations. */
public static final int USE_ATT_NAMES_AND_TYPES_AND_CATEGORIES = 2;
// -----------------------------------------------------------------------
// Variables declarations
// -----------------------------------------------------------------------
/** Reference to meta data owning this object. */
protected MiningDataSpecification thisMetaData;
/** Specifies usage level in comparisons and transformations. */
protected int usageType = USE_ATT_NAMES;
/** Previous usage type. Used for caching. */
private int prevUsageType = -1;
/** Pretransformed meta data. Used for caching. */
private MiningDataSpecification pretransMetaData = null;
/** Transformed meta data. Used for caching. */
private MiningDataSpecification transMetaData = null;
/** Indexes of coordinate assignemnt. */
private IntVector indexAssign = new IntVector();
// -----------------------------------------------------------------------
// Protected constructor
// -----------------------------------------------------------------------
/**
* Protected constructor with meta data object.
*
* @param metaData meta data owning this object
*/
protected MetaDataOperations(MiningDataSpecification metaData)
{
this.thisMetaData = metaData;
}
// -----------------------------------------------------------------------
// Getter and setter methods
// -----------------------------------------------------------------------
/**
* Returns reference to meta data object owning this object.
*
* @return meta data object owning this object
*/
public MiningDataSpecification getThisMetaData()
{
return thisMetaData;
}
/**
* Returns usage type for comparisons and transformations.
*
* @return usage type
*/
public int getUsageType()
{
return usageType;
}
/**
* Sets usage type for comparisons and transformations.
*
* @param usageType new usage type
*/
public void setUsageType(int usageType)
{
this.usageType = usageType;
}
// -----------------------------------------------------------------------
// Basis transformation methods
// -----------------------------------------------------------------------
/**
* Transforms mining vector depending on the basis transformation type.
*
* Notice that this method can also be applied to a mining vector without
* own meta data. In this case the last meta data basis transformation is used
* as transformation ressource (if the basis transformation type was the same).
* Such last meta data transformation could have been done either explicitly,
* applying transform to some meta data, or implicitely, when a mining vactor
* with meta data was transformed. If none of both cases has ever happened,
* for the mining vector (without meta data) an exception is thrown.
*
* @param vector mining vector to transform
* @return transformed mining vector, with meta data
* @exception MiningException cannot transform mining vector
*/
public MiningVector transform(MiningVector vector) throws MiningException {
// Transform meta data:
MiningDataSpecification vecMetaData = vector.getMetaData();
if (vecMetaData != null) {
// Use caching if possible:
if (vecMetaData != pretransMetaData || prevUsageType != usageType)
transform(vecMetaData);
}
else {
if (transMetaData == null || prevUsageType != usageType)
throw new MiningException("No meta data ressource for basis trafo available");
}
// Transform mining vector:
int nAtt = indexAssign.size();
double[] vec = new double[nAtt];
for (int i = 0; i < nAtt; i++) {
int ind = indexAssign.IntegerAt(i);
double val = vector.getValue(ind);
// Transform key of categorical attribute:
if (usageType != USE_ATT_NAMES && transMetaData.getMiningAttribute(i) instanceof CategoricalAttribute) {
CategoricalAttribute catTransAtt = (CategoricalAttribute) transMetaData.getMiningAttribute(i);
CategoricalAttribute catAtt = (CategoricalAttribute) vecMetaData.getMiningAttribute(ind);
val = catTransAtt.getCatAttOp().transform(catAtt, val);
};
vec[i] = val;
}
MiningVector transMiningVector = new MiningVector(vec);
transMiningVector.setMetaData(transMetaData);
return transMiningVector;
}
/**
* Transforms meta data depending on the basis transformation type.
*
* @param metaData meta data to transform
* @return transformed meta data
* @exception MiningException cannot transform meta data
*/
public MiningDataSpecification transform(MiningDataSpecification metaData) throws MiningException {
// Transformation of meta data:
indexAssign.clear();
MiningDataSpecification mds = new MiningDataSpecification( metaData.getName() );
for (int i = 0; i < thisMetaData.getAttributesNumber(); i++) {
MiningAttribute thisAtt = thisMetaData.getMiningAttribute(i);
MiningAttribute att = metaData.getMiningAttribute( thisAtt.getName() );
if (att != null) {
indexAssign.addElement( metaData.getAttributeIndex(att) );
// Transform basis of categorical attribute:
if (usageType != USE_ATT_NAMES && thisAtt instanceof CategoricalAttribute &&
att instanceof CategoricalAttribute) {
att = ((CategoricalAttribute) thisAtt).getCatAttOp().transform( (CategoricalAttribute) att);
}
mds.addMiningAttribute(att);
}
else {
};
};
// Copy remaining variables of catAtt:
mds.setFileName( metaData.getFileName() );
mds.setTransformed( metaData.isTransformed() );
mds.setPretransformedMetaData( metaData.getPretransformedMetaData() );
mds.setMiningTransformationActivity( metaData.getMiningTransformationActivity() );
transMetaData = mds;
// For caching:
pretransMetaData = metaData;
prevUsageType = usageType;
return transMetaData;
}
// -----------------------------------------------------------------------
// Other transformations
// -----------------------------------------------------------------------
/**
* For all categorical attributes which are of unboundedCategories but
* not of unstoredCategories type, the type is set to bounded (i.e.
* unboundedCategories = false).
*/
public void unboundedToBoundedCategories() {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -