📄 retrospectivecallback.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.Automat;
import java.io.Serializable;
import java.util.Vector;
import com.prudsys.pdm.Core.MiningAlgorithmSpecification;
import com.prudsys.pdm.Core.MiningException;
import com.prudsys.pdm.Core.MiningSettings;
/**
* A retrospective callback is characterized by the fact that the calculation
* of the new parameters depends not only on the current parameters
* and the current assessment value but on the parameters and assessment
* values of all previous steps.
*
* This type of callbacks is most often used. The initial parameters
* are set at the beginning and are the current parameters of
* the first step. Every call of calculateNewMiningParameters
* adds one new step to the callback history and the former new
* parameters become the current one. The user cannot modify
* the current parameters (in contrast to the sister class
* SlidingCallback) since they are implecitely defined through
* the data of their predecessor.<p>
*
* The history of all parameters is contained in the vectors
* allMiningSettings for the mining settings and
* allMiningAlgorithmSpecifications for all mining algorithm
* specifications of all steps as well as the vector allAssessments
* for all assessment values. Obviously, these three vectors
* all have the same length which can also be retrieved via
* the method getNumberOfCallbackSteps.
*
* @see SlidingCallback
*/
public abstract class RetrospectiveCallback extends MiningAutomationCallback implements Serializable
{
// -----------------------------------------------------------------------
// Variables declarations
// -----------------------------------------------------------------------
/** Mining settings before first callback step. */
protected MiningSettings initialMiningSettings;
/** Mining algorithm specification before first callback step. */
protected MiningAlgorithmSpecification initialMiningAlgorithmSpecification;
/** Mining settings of all callback steps. */
protected Vector allMiningSettings = new Vector();
/** Mining algorithm specifications of all callback steps. */
protected Vector allMiningAlgorithmSpecifications = new Vector();
/** Assessment values of all callback steps. */
protected Vector allAssessments = new Vector();
// -----------------------------------------------------------------------
// Constructor
// -----------------------------------------------------------------------
/**
* Empty constructor.
*/
public RetrospectiveCallback()
{
}
// -----------------------------------------------------------------------
// Getter and setter methods
// -----------------------------------------------------------------------
/**
* Returns initial mining settings.
*
* @return initial mining settings
*/
public MiningSettings getInitialMiningSettings()
{
return initialMiningSettings;
}
/**
* Sets initial mining settings.
*
* @param initialMiningSettings initial mining settings
*/
public void setInitialMiningSettings(MiningSettings initialMiningSettings)
{
this.initialMiningSettings = initialMiningSettings;
this.currentMiningSettings = initialMiningSettings;
}
/**
* Returns initial mining algorithm specification.
*
* @return initial mining algorithm specification
*/
public MiningAlgorithmSpecification getInitialMiningAlgorithmSpecification()
{
return initialMiningAlgorithmSpecification;
}
/**
* Sets initial mining algorithm specification.
*
* @param initialMiningAlgorithmSpecification initial mining algorithm specification
*/
public void setInitialMiningAlgorithmSpecification(MiningAlgorithmSpecification initialMiningAlgorithmSpecification)
{
this.initialMiningAlgorithmSpecification = initialMiningAlgorithmSpecification;
this.currentMiningAlgorithmSpecification = initialMiningAlgorithmSpecification;
}
/**
* Returns the number of the current step.
*
* @return number of the current step
*/
public int getNumberOfCallbackSteps()
{
return allAssessments.size();
}
// -----------------------------------------------------------------------
// Methods of new parameter calculation
// -----------------------------------------------------------------------
/**
* Calculates new mining parameters. The parameters can be read
* using the methods getNewMiningSettings and getNewMiningAlgorithmSpecification.
* Internally uses method runParameterCalculation.
* This step is added to the vector of callback steps.
*
* @exception MiningException error during calculation
* @return status of calculation
*/
@SuppressWarnings("unchecked")
public int calculateNewMiningParameters( ) throws MiningException {
// Make new mining setting current one by deep copying:
try {
if (getNumberOfCallbackSteps() == 0) {
newMiningAlgorithmSpecification = currentMiningAlgorithmSpecification;
newMiningSettings = currentMiningSettings ;
};
// currentMiningAlgorithmSpecification = (MiningAlgorithmSpecification)
// (new SerializedObject( newMiningAlgorithmSpecification )).getObject();
// currentMiningSettings = (MiningSettings)
// (new SerializedObject( newMiningSettings )).getObject();
currentMiningAlgorithmSpecification = newMiningAlgorithmSpecification;
currentMiningSettings = newMiningSettings;
}
catch (Exception ex) {
throw new MiningException("Serialization error in copying settings"+ ex);
};
// Run calculation:
int status = runParameterCalculation();
// Adds this object as new callback step making a deep copy of itself:
try {
// allMiningSettings.add( (new SerializedObject( currentMiningSettings )).getObject() );
// allMiningAlgorithmSpecifications.add( (new SerializedObject( currentMiningAlgorithmSpecification )).getObject() );
allAssessments.add( new Double(currentAssessment) );
}
catch (Exception ex) {
throw new MiningException("Serialization error in coying settings"+ex);
};
return status;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -