📄 aggregationmeasure.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.
*/
/**
* <p>Title: XELOPES</p>
* <p>Description: Java Data Mining API. Supported standarts: <a href="http://www.dmg.org">Predictive Model Markup Language (PMML 2.0) </a>; <a href="http://www.omg.org/cwm">DataMining specification for Common Warehouse Metamodel (OMG)</a>.</p>
* <p>Copyright: Copyright (c) 2002-2004 prudsys AG</p>
* <p>Company: prudsys, ZSoft</p>
* @authorv Michael Thess
* @version 1.2
*/
package com.prudsys.pdm.Olap.Metadata.Measures;
import javax.olap.OLAPException;
import com.prudsys.pdm.Core.MiningAttribute;
import com.prudsys.pdm.Core.MiningException;
import com.prudsys.pdm.Models.Statistics.SimpleStats;
import com.prudsys.pdm.Olap.Metadata.Measure;
/**
* Measure which is aggregated over an attribute.
*/
public class AggregationMeasure extends Measure
{
// -----------------------------------------------------------------------
// Constants declarations
// -----------------------------------------------------------------------
/** Sum. */
public static final int SUM = 0;
/** Minimum. */
public static final int MIN = 1;
/** Maximum. */
public static final int MAX = 2;
/** Mean. */
public static final int MEAN = 3;
/** Mode. */
public static final int MODE = 4;
/** Count. */
public static final int COUNT = 5;
/** Missing Count. */
public static final int MISSING_COUNT = 6;
/** Entropy. */
public static final int ENTROPY = 7;
/** Variance. */
public static final int VARIANCE = 8;
/** Standard deviation. */
public static final int DEVIATION = 9;
// -----------------------------------------------------------------------
// Variables declarations
// -----------------------------------------------------------------------
/** Aggregation attribute. */
protected MiningAttribute attribute;
// -----------------------------------------------------------------------
// Constructors
// -----------------------------------------------------------------------
/**
* Empty constructor.
*/
public AggregationMeasure() {
}
/**
* Aggregation measure with given subtype and aggregation attribute.
*
* @param subtype measure subtype
* @param attribute aggregation attribute
*/
public AggregationMeasure(int subtype, MiningAttribute attribute) {
this.subtype = subtype;
this.attribute = attribute;
}
// -----------------------------------------------------------------------
// Getter and setter methods
// -----------------------------------------------------------------------
/**
* Returns aggregation attribute.
*
* @return aggregation attribute
*/
public MiningAttribute getAttribute() {
return attribute;
}
/**
* Sets new aggregation attribute.
*
* @param attribute new aggregation attribute
*/
public void setAttribute(MiningAttribute attribute) {
this.attribute = attribute;
}
// -----------------------------------------------------------------------
// Method of measure value calculation
// -----------------------------------------------------------------------
/**
* Calculates aggregated measure value.
*
* @return measure value
* @throws OLAPException unknwn subtype
*/
public double measureValue() throws OLAPException {
try {
SimpleStats stats = measureDimension.getStats();
if (subtype == SUM)
return stats.getCalculatedValue(attribute, SimpleStats.STAT_SUM);
else if (subtype == MIN)
return stats.getCalculatedValue(attribute, SimpleStats.STAT_MIN);
else if (subtype == MAX)
return stats.getCalculatedValue(attribute, SimpleStats.STAT_MAX);
else if (subtype == MEAN)
return stats.getCalculatedValue(attribute, SimpleStats.STAT_MEAN);
else if (subtype == MODE)
return stats.getCalculatedValue(attribute, SimpleStats.STAT_MODE);
else if (subtype == COUNT)
return stats.getCalculatedValue(attribute, SimpleStats.STAT_COUNT);
else if (subtype == MISSING_COUNT)
return stats.getCalculatedValue(attribute, SimpleStats.STAT_MISSING_COUNT);
else if (subtype == ENTROPY)
return stats.getCalculatedValue(attribute, SimpleStats.STAT_ENTROPY);
else if (subtype == VARIANCE)
return stats.getCalculatedValue(attribute, SimpleStats.STAT_VARIANCE);
else if (subtype == DEVIATION)
return stats.getCalculatedValue(attribute, SimpleStats.STAT_DEVIATION);
else
throw new OLAPException("unknown subtype");
}
catch (MiningException ex) {
throw new OLAPException( ex.toString() );
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -