📄 sparsesvmalgorithm.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
* @author Victor Borichev
* @author Valentine Stepanenko (valentine.stepanenko@zsoft.ru)
* @version 1.0
*/
package com.prudsys.pdm.Models.Regression.SVM.Algorithms.SparseSVM;
import com.prudsys.pdm.Core.MiningException;
import com.prudsys.pdm.Models.Regression.SVM.SupportVectorAlgorithm;
import com.prudsys.pdm.Models.Supervised.Classifier;
/**
* Implementation of Sparse Grid algorithms for sparse data.
* SVMMethod is used as SupportVectorClassifier object.
*/
public class SparseSVMAlgorithm extends SupportVectorAlgorithm {
private SVMMethod svmMethod;
private double cacheSize;
private double terminationEpsilon;
private int shrinking;
private double weight;
/**
* Empty constructor.
*/
public SparseSVMAlgorithm() {
}
/**
* Run algorithm. Result is written in variable svmMethod.
*/
protected void runAlgorithm() throws MiningException {
System.out.print("Building classifier...");
svmMethod = new SVMMethod();
svmMethod.setMetaData( metaData );
// Types of SVM:
svmMethod.m_param.svm_type = svmType; // type of SVM
svmMethod.m_param.kernel_type = kernelType; // kernel type
// Parameters of the approximation functions:
svmMethod.m_param.degree = degree; // for poly
svmMethod.m_param.gamma = gamma; // for poly/rbf/sigmoid
svmMethod.m_param.coef0 = coef0; // for poly/sigmoid
// These parameters are for training only:
svmMethod.m_param.cache_size = cacheSize; // in MB
svmMethod.m_param.eps = terminationEpsilon; // stopping criteria
svmMethod.m_param.C = C; // for C_SVC, EPSILON_SVR, NU_SVR, SPARSE GRIDS
// public int nr_weight; // for C_SVC
// public int[] weight_label; // for C_SVC
if (svmMethod.m_param.nr_weight!=0)
svmMethod.m_param.weight[0] = weight; // for C_SVC
svmMethod.m_param.nu = nu; // for NU_SVC, ONE_CLASS, and NU_SVR
svmMethod.m_param.p = lossEpsilon; // for EPSILON_SVR
svmMethod.m_param.shrinking = shrinking; // use the shrinking heuristics
// Run algorithm:
svmMethod.buildClassifier(miningInputStream, target);
System.out.println("\tok");
}
/**
* Returns classifier.
*
* @return classifier
*/
public Classifier getClassifier() {
return svmMethod;
}
// Specific parameters:
public void setCacheSize(double cacheSize) {
this.cacheSize = cacheSize;
}
public double getCacheSize() {
return cacheSize;
}
public void setTerminationEpsilon(double terminationEpsilon) {
this.terminationEpsilon = terminationEpsilon;
}
public double getTerminationEpsilon() {
return terminationEpsilon;
}
public void setShrinking(int shrinking) {
this.shrinking = shrinking;
}
public int getShrinking() {
return shrinking;
}
public void setWeight(double weight) {
this.weight = weight;
}
public double getWeight() {
return weight;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -