📄 sequentialminingmodel.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 Victor Borichev
* @author Valentine Stepanenko (valentine.stepanenko@zsoft.ru)
* @version 1.0
*/
package com.prudsys.pdm.Models.Sequential;
import java.io.*;
import java.util.*;
import com.prudsys.pdm.Core.*;
import com.prudsys.pdm.Input.*;
import com.prudsys.pdm.Transform.*;
import com.prudsys.pdm.Adapters.PmmlVersion20.*;
import com.prudsys.pdm.Utils.*;
/**
* Description of data produced by a sequential mining function. <p>
*
* From PDM CWM extension. <p>
*
* Superclasses:
* <ul>
* <li> MiningModel
* </ul>
* Attributes:
* <ul>
* <li> <i>itemIdName</i>: Name of the item id attribute. <br>
* - class: String <br>
* - multiplicity: exactly one
* <li> <i>transactIdName</i>: Name of the transction id attribute. <br>
* - class: String <br>
* - multiplicity: exactly one
* <li> <i>itemIndexName</i>: Name of the item index attribute. <br>
* - class: String <br>
* - multiplicity: exactly one
* <li> <i>sequentialRules</i>: List of all sequences. <br>
* - class: ItemSetSeq <br>
* - multiplicity: one or more
* <li> <i>sequenceRules</i>: List of all sequence rules. <br>
* - class: RuleSetSeq <br>
* - multiplicity: one or more
* </ul>
*
* In addition, functionality from PMML was added.
* It corresponds to the PMML element SequenceModel.
*
* @see ItemSetSeq
* @see RuleSetSeq
* @see com.prudsys.pdm.Adapters.PmmlVersion20.SequenceModel
*/
public class SequentialMiningModel extends MiningModel
{
// -----------------------------------------------------------------------
// Constants of PMML and MiningInputStream export
// -----------------------------------------------------------------------
/** Export as PMML 2.0 rule. */
public static final int EXPORT_PMML_NAME_TYPE_PMML20 = 0;
/** Export as XELOPES extension of PMML 2.0 for item, transaction, position IDs. */
public static final int EXPORT_PMML_NAME_TYPE_XELOPES = 1;
/** Export large sequences in toMiningInputStream method. */
public static final int EXPORT_MIS_LARGE_SEQUENCES = 0;
/** Export sequence rules in toMiningInputStream method. */
public static final int EXPORT_MIS_SEQUENCE_RULES = 1;
/** Include support value into export in toMiningInputStream. */
public static final int EXPORT_MISCHAR_SUPPORT = 0;
/** Include confidence value into export in toMiningInputStream. */
public static final int EXPORT_MISCHAR_CONFIDENCE = 1;
/** Include coverage value into export in toMiningInputStream. */
public static final int EXPORT_MISCHAR_COVERAGE = 2;
/** Include lift value into export in toMiningInputStream. */
public static final int EXPORT_MISCHAR_LIFT = 4;
/** Include cosine value into export in toMiningInputStream. */
public static final int EXPORT_MISCHAR_COSINE = 8;
// -----------------------------------------------------------------------
// Variables declarations
// -----------------------------------------------------------------------
/** Name of itemId attribute. */
private String itemIdName = "itemId";
/** Name of transactId attribute. */
private String transactIdName = "transactionId";
/** Name of itemIndex (i.e. position) attribute. */
private String itemIndexName = "itemIndex";
/** Vector of large sequences. */
private Vector sequentialRules = null;
/** Vector of sequence rules. */
private Vector sequenceRules = null;
/** Number of transactions of mining data. */
protected int numberOfTransactions = -1;
/** Export all transaction IDs into PMML? */
private boolean exportTransactIds = true;
/** PMML export type of assciation rules model. */
private int exportTransactItemNames = EXPORT_PMML_NAME_TYPE_XELOPES;
/** Hashtable of all large sequences. */
private Hashtable slits = null;
/** Hashtable of all recommendations. */
private Hashtable recs = null;
/** Export type of toMiningInputStream method. */
protected int misExportType = EXPORT_MIS_SEQUENCE_RULES;
/** Export subtype of toMiningInputStream for characteristics. */
protected int misExportCharType = EXPORT_MISCHAR_SUPPORT + EXPORT_MISCHAR_CONFIDENCE;
// -----------------------------------------------------------------------
// Constructor
// -----------------------------------------------------------------------
/**
* Constructor sets function and algorithm parameters.
*/
public SequentialMiningModel()
{
function = MiningModel.SEQUENTIAL_FUNCTION;
algorithm = MiningModel.SEQUENCE_ANALYSIS_ALGORITHM;
}
// -----------------------------------------------------------------------
// Getter and setter methods
// -----------------------------------------------------------------------
/**
* Get name of itemId attribute.
*
* @return name of itemId attribute
*/
public String getItemIdName()
{
return itemIdName;
}
/**
* Set name of itemId attribute.
*
* @param itemIdName name of itemId attribute
*/
public void setItemIdName(String itemIdName)
{
this.itemIdName = itemIdName;
}
/**
* Get name of transactionId attribute.
*
* @return name of transactionId attribute
*/
public String getTransactIdName()
{
return transactIdName;
}
/**
* Set name of tranactionId attribute.
*
* @param transactIdName name of transactionId attribute
*/
public void setTransactIdName(String transactIdName)
{
this.transactIdName = transactIdName;
}
/**
* Get name of item index.
*
* @return name of item index
*/
public String getItemIndexName()
{
return itemIndexName;
}
/**
* Set name of item index.
*
* @param itemIndexName name of item index
*/
public void setItemIndexName(String itemIndexName)
{
this.itemIndexName = itemIndexName;
}
/**
* Returns vector of sequences.
*
* @return vector of sequences (ItemSetSeq objects)
*/
public Vector getSequentialRules()
{
return sequentialRules;
}
/**
* Sets vector of sequences.
*
* @param sequentialRules vector of sequences (ItemSetSeq objects)
*/
public void setSequentialRules(Vector sequentialRules)
{
this.sequentialRules = sequentialRules;
}
/**
* Returns sequence rules (if calculated).
*
* @return sequence rules (RuleSetSeq objects)
*/
public Vector getSequenceRules()
{
return sequenceRules;
}
/**
* Sets new sequence rules.
*
* @param sequenceRules new sequence rules (RuleSetSeq objects)
*/
public void setSequenceRules(Vector sequenceRules)
{
this.sequenceRules = sequenceRules;
}
/**
* Returns number of transactions. If not specified explicitely,
* it is calculated using the number of categories of the transaction IDs
* attribute (where the paramter unstoredCategories must be false).
*
* @return number of transactions, -1 if unknown
*/
public int getNumberOfTransactions()
{
int nTransact = numberOfTransactions;
if (nTransact < 0) {
CategoricalAttribute transactId = (CategoricalAttribute) miningSettings.
getDataSpecification().getMiningAttribute(transactIdName);
if ( transactId != null && !transactId.isUnstoredCategories() )
nTransact = transactId.getCategoriesNumber();
};
return nTransact;
}
/**
* Set number of transactions.
*
* @param numberOfTransactions new number of transactions, -1 if unknown
*/
public void setNumberOfTransactions(int numberOfTransactions)
{
this.numberOfTransactions = numberOfTransactions;
}
/**
* Write all transaction IDs into PMML (default: yes)?
*
* @return true if write all transaction IDs into PMML, otherwise not
*/
public boolean isExportTransactIds()
{
return exportTransactIds;
}
/**
* Set export all transaction IDs into PMML (default: true).
*
* @param exportTransactIds true if export, otherwise false
*/
public void setExportTransactIds(boolean exportTransactIds)
{
this.exportTransactIds = exportTransactIds;
}
/**
* Returns type how item, transaction, and position IDs are handled in PMML.
*
* @return PMML export type of transaction, item, position IDs
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -