📄 multisimplepredicate.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.2
*/
package com.prudsys.pdm.Input.Multidimensional;
import java.util.Vector;
import com.prudsys.pdm.Core.CategoricalAttribute;
import com.prudsys.pdm.Core.Category;
import com.prudsys.pdm.Core.MiningAttribute;
import com.prudsys.pdm.Core.MiningDataSpecification;
import com.prudsys.pdm.Core.MiningException;
import com.prudsys.pdm.Core.NumericAttribute;
import com.prudsys.pdm.Input.Predicates.SimplePredicate;
import com.prudsys.pdm.Utils.IntVector;
/**
* SimplePredicate for evaluations on multidimensional stream.
*/
public class MultiSimplePredicate extends SimplePredicate implements MultiPredicate
{
// -----------------------------------------------------------------------
// Constructors
// -----------------------------------------------------------------------
/**
* Empty constructor.
*/
public MultiSimplePredicate()
{
}
/**
* Simple predicate with given condition.
*
* @param attribute attribute to be evaluated
* @param value attribute's value for evaluation
* @param op evaluation operator
*/
public MultiSimplePredicate(MiningAttribute attribute, String value, int op) {
super(attribute, value, op);
}
// -----------------------------------------------------------------------
// Evaluate predicate
// -----------------------------------------------------------------------
/**
* Evaluates predicates for all mining vectors of MultidimensionalStream.
*
* @param multidimStream multidimensional stream for predicate evaluations
* @return evaluation result as array for each mining vector
* @exception MiningException can't evaluate mining vector
*/
public boolean[] evaluate(MultidimensionalStream multidimStream)
throws MiningException {
int nVec = multidimStream.nVec;
boolean[] vecBool = new boolean[nVec];
MiningDataSpecification metaData = multidimStream.getMetaData();
if (metaData == null)
throw new MiningException("multidimStream has no meta data");
MiningAttribute ma = metaData.getMiningAttribute(name);
if (ma == null)
throw new MiningException("MiningAttribute "+name+" not found in multidimStream");
int ind = metaData.getAttributeIndex(ma);
if (ma instanceof CategoricalAttribute)
{
CategoricalAttribute cAtt = (CategoricalAttribute) ma;
if ( cAtt.isUnstoredCategories() )
throw new MiningException("SimplePredicate: categorical attribute can't be of unstoredCategories type");
if (op != SimplePredicate.EQUAL && op != SimplePredicate.NOT_EQUAL)
throw new MiningException("SimplePredicate: categorical attribute - equal operators are supported only");
Category catValue = new Category(value);
Vector categs = new Vector();
if (op == EQUAL)
categs.addElement(catValue);
else {
for (int i = 0; i < cAtt.getCategoriesNumber(); i++) {
Category cat = cAtt.getCategory(i);
if ( !cat.equals(catValue) )
categs.addElement(cat);
};
}
for (int i = 0; i < categs.size(); i++) {
double key = cAtt.getKey( (Category) categs.elementAt(i) );
if ( Category.isMissingValue(key) )
throw new MiningException("SimplePredicate: unknown category");
int ikey = (int) key;
IntVector vecs = (IntVector) multidimStream.dimVec[ind].elementAt(ikey);
for (int k = 0; k < vecs.size(); k++) {
vecBool[ vecs.IntegerAt(k) ] = true;
};
};
return vecBool;
}
else if (ma instanceof NumericAttribute)
{
throw new MiningException("selection attribute can't be numeric");
}
else throw new MiningException("SimplePredicate: unknown attribute type");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -