📄 numericattribute.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)
* @version 1.0
*/
package com.prudsys.pdm.Core;
import com.prudsys.pdm.Adapters.PmmlVersion20.DataField;
/**
* Attribute containing numbers, for which numeric operations are meaningful. <p>
*
* From CWM Data Mining. <p>
*
* Superclasses:
* <ul>
* <li> MiningAttribute
* </ul>
* Attributes:
* <ul>
* <li> <i>lowerBound</i>: Least non-outlier value. <br>
* - type: Float <br>
* - multiplicity: exactly one
* <li> <i>upperBound</i>: Greatest non-outlier value. <br>
* - type: Float <br>
* - multiplicity: exactly one
* <li> <i>isCyclic</i>: Indicates attributes with cyclic value range such as
* angles or numbers representing the day of the week. If true, lowerBound
* and upperBound define the base interval. <br>
* - type: Boolean <br>
* - multiplicity: exactly one
* <li> <i>isDiscrete</i>: Tells the algorithm whether to deal with the numbers
* as discrete values. <br>
* - type: Boolean <br>
* - multiplicity: exactly one
* </ul>
* Constraints:
* <ul>
* <li> lowerBound must be less or equal to upperBound.
* </ul>
*/
public class NumericAttribute extends MiningAttribute
{
// -----------------------------------------------------------------------
// Constants of data type of numeric attribute
// -----------------------------------------------------------------------
/** Double (default type). */
public static final int DOUBLE = 0;
/** Float. */
public static final int FLOAT = 1;
/** Integer. */
public static final int INTEGER = 2;
/** Boolean. */
public static final int BOOLEAN = 3;
/** prudsys-specific is same like Borland: days since 30.12.1899, decimal. */
public static final int DATETIME_PRUDSYS = 10;
/** Seconds since January 01, 1970, 00:00:00 GMT. */
public static final int DATETIME_UNIX = 11;
// -----------------------------------------------------------------------
// Variables declarations
// -----------------------------------------------------------------------
/** Interval specification object. */
private Interval interval = new Interval();
/** Is attribute cyclic? */
private boolean cyclic = false;
/** Is attribute discrete? */
private boolean discrete = false;
/** Is attribute of time type? */
private boolean time = false;
// -----------------------------------------------------------------------
// Constructors
// -----------------------------------------------------------------------
/**
* Empty constructor.
*/
public NumericAttribute()
{
}
/**
* A numeric attribute of given name.
*
* @param name name of numeric attribute
*/
public NumericAttribute( String name )
{
this.setName(name);
}
/**
* Numeric attribute with its parameters given.
*
* @param name name of numeric attribute
* @param lowerBound lower bound of its values
* @param upperBound upper bound of its values
* @param isCyclic cyclic attribute
* @param isDiscrete discrete attribute
* @param isTime time attribute
*/
public NumericAttribute( String name, float lowerBound, float upperBound, boolean isCyclic, boolean isDiscrete, boolean isTime )
{
this.setName(name);
this.interval.setLowerBound(lowerBound);
this.interval.setUpperBound(upperBound);
this.cyclic = isCyclic;
this.discrete = isDiscrete;
this.time = isTime;
}
// -----------------------------------------------------------------------
// Getter and setter methods
// -----------------------------------------------------------------------
/**
* Returns interval object.
*
* @return interval object
*/
public Interval getInterval()
{
return interval;
}
/**
* Sets interval object.
*
* @param interval new interval object
*/
public void setInterval(Interval interval)
{
this.interval = interval;
}
/**
* Returns lower bound (from interval object).
*
* @return lower bound
*/
public double getLowerBound()
{
return interval.getLowerBound();
}
/**
* Sets lower bound (to interval object).
*
* @param lowerBound new lower bound
*/
public void setLowerBound(double lowerBound)
{
this.interval.setLowerBound(lowerBound);
}
/**
* Returns upper bound (from interval object).
*
* @return upper bound
*/
public double getUpperBound()
{
return interval.getUpperBound();
}
/**
* Sets upper bound (to interval object).
*
* @param upperBound new upper bound
*/
public void setUpperBound(double upperBound)
{
this.interval.setUpperBound(upperBound);
}
/**
* Returns closure of interval (from interval object).
*
* @return closure of interval
*/
public int getClosure()
{
return interval.getClosure();
}
/**
* Sets closure of interval (to interval object).
*
* @param closure new closure of interval
*/
public void setClosure(int closure)
{
this.interval.setClosure(closure);
}
/**
* Is time attribute?
*
* @return true if time attribute, otherwise false
*/
public boolean isTime()
{
return time;
}
/**
* Set to time attribute.
*
* @param time time attribute
*/
public void setTime(boolean time)
{
this.time = time;
}
/**
* Is cyclic attribute?
*
* @return true if cyclic attribute, otherwise false
*/
public boolean isCyclic()
{
return cyclic;
}
/**
* Set to cyclic attribute.
*
* @param cyclic cyclic attribute
*/
public void setCyclic(boolean cyclic)
{
this.cyclic = cyclic;
}
/**
* Is discrete attribute?
*
* @return true if discrete attribute, otherwise false
*/
public boolean isDiscrete()
{
return discrete;
}
/**
* Set to discrete attribute.
*
* @param discrete discrete attribute
*/
public void setDiscrete(boolean discrete)
{
this.discrete = discrete;
}
/**
* Is nominal attribute? No!
*
* @return false
*/
public boolean isNominal()
{
return false;
}
/**
* Is numeric attribute? Yes!!
*
* @return true
*/
public boolean isNumeric()
{
return true;
}
// -----------------------------------------------------------------------
// Methods of PMML handling
// -----------------------------------------------------------------------
/**
* Create PMML object DataField for use in PMML documents.
*
* @return PMMLs DataField object
* @exception MiningException if there are some pmml creating errors
* @see com.prudsys.pdm.Adapters.PmmlVersion20.DataField
*/
public Object createPmmlObject() throws MiningException
{
DataField dataField = new DataField();
dataField.setName( getName() );
dataField.setDisplayName( getName() );
dataField.setOptype( "continuous" );
if (dataType == DOUBLE) dataField.setDataType("double");
else if (dataType == FLOAT) dataField.setDataType("float");
else if (dataType == INTEGER) dataField.setDataType("integer");
else if (dataType == BOOLEAN) dataField.setDataType("boolean");
else if (dataType == DATETIME_PRUDSYS) dataField.setDataType("datePrudsys");
else if (dataType == DATETIME_UNIX) dataField.setDataType("dateUnix");
if (! cyclic)
dataField.setIsCyclic( "0" );
else
dataField.setIsCyclic( "1" );
com.prudsys.pdm.Adapters.PmmlVersion20.Interval[] intervals
= new com.prudsys.pdm.Adapters.PmmlVersion20.Interval[1];
intervals[0] = (com.prudsys.pdm.Adapters.PmmlVersion20.Interval)
interval.createPmmlObject();
dataField.setInterval( intervals );
return dataField;
}
/**
* Reads from PMML object DataField.
*
* @param pmml PMMLs DataField object
* @exception MiningException cannot parse PMML object
* @see com.prudsys.pdm.Adapters.PmmlVersion20.DataField
*/
public void parsePmmlObject( Object pmml ) throws MiningException
{
DataField dataField = (DataField) pmml;
setName( dataField.getName() );
dataType = DOUBLE;
String dt = dataField.getDataType();
if (dt != null) {
if ( dt.equals("double") ) dataType = DOUBLE;
else if (dt.equals("float") ) dataType = FLOAT;
else if (dt.equals("integer") ) dataType = INTEGER;
else if (dt.equals("boolean") ) dataType = BOOLEAN;
else if (dt.equals("datePrudsys") ) dataType = DATETIME_PRUDSYS;
else if (dt.equals("dateUnix") ) dataType = DATETIME_UNIX;
}
discrete = false;
time = false;
cyclic = Boolean.getBoolean( dataField.getIsCyclic() );
interval = new Interval();
com.prudsys.pdm.Adapters.PmmlVersion20.Interval[] intervals = dataField.getInterval();
if (intervals != null && intervals.length > 0) {
interval.parsePmmlObject(intervals[0]);
};
}
// -----------------------------------------------------------------------
// Other export methods
// Frank Xu, 01/12/2004
// Add single quotation mark to the attribute and the data,
// when converting data from SQL data source into ARFF format.
// -----------------------------------------------------------------------
/**
* Returns attribute as ARFF format description of the popular
* WEKA library.
*
* @return attribute information as ARFF description
*/
public String createArffDescription()
{
return "@attribute" + " '" + name + "' " + "numeric";
}
// -----------------------------------------------------------------------
// java.lang.Object methods
// -----------------------------------------------------------------------
/**
* Copies numeric attribute.
*
* @return copy of numeric attribute
*/
public Object clone() {
NumericAttribute numAtt = new NumericAttribute();
numAtt.setName( this.getName() );
numAtt.dataType = this.dataType;
numAtt.cyclic = this.cyclic;
numAtt.discrete = this.discrete;
numAtt.time = this.time;
numAtt.interval = (Interval) this.interval.clone();
return numAtt;
}
/**
* Returns attribute as string.
*
* @return attribute information as string
*/
public String toString()
{
String description = name + ", ";
description = description + "type: numeric, " + interval.toString();
if (cyclic)
description = description + ", cyclic";
if (discrete)
description = description + ", discrete";
if (time)
description = description + ", time";
if (dataType != MiningAttribute.UNDEFINED) {
description = description + ", dataType: ";
if (dataType == DOUBLE) description = description + "double";
else if (dataType == FLOAT) description = description + "float";
else if (dataType == INTEGER) description = description + "integer";
else if (dataType == BOOLEAN) description = description + "boolean";
else if (dataType == DATETIME_PRUDSYS) description = description + "datePrudsys";
else if (dataType == DATETIME_UNIX) description = description + "dateUnix";
};
return description;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -