Java Code Examples for weka.classifiers.AbstractClassifier#makeCopy()

The following examples show how to use weka.classifiers.AbstractClassifier#makeCopy() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractMultiSearch.java    From meka with GNU General Public License v3.0 6 votes vote down vote up
/**
 * the default constructor.
 */
public AbstractMultiSearch() {
	super();

	m_Factory           = newFactory();
	m_Metrics           = m_Factory.newMetrics();
	m_Evaluation        = m_Metrics.getDefaultMetric();
	m_Classifier        = defaultClassifier();
	m_DefaultParameters = defaultSearchParameters();
	m_Parameters        = defaultSearchParameters();
	m_Algorithm         = defaultAlgorithm();
	m_Trace             = new ArrayList<Entry<Integer, Performance>>();

	try {
		m_BestClassifier = new SearchResult();
		m_BestClassifier.classifier = AbstractClassifier.makeCopy(m_Classifier);
	}
	catch (Exception e) {
		System.err.println("Failed to create copy of default classifier!");
		e.printStackTrace();
	}
}
 
Example 2
Source File: Tuner.java    From tsml with GNU General Public License v3.0 5 votes vote down vote up
public AbstractClassifier cloneClassifierIfNeeded(AbstractClassifier classifier) throws Exception {
    if (cloneClassifierForEachParameterEval) {
        //for some reason, the (abstract classifiers)' copy method returns a (classifier interface) reference...
        return (AbstractClassifier)AbstractClassifier.makeCopy(classifier); 
    }
    else {
        //just reuse the same instance of the classifier, assume that no info 
        //that from the previous build/eval affects this one.
        //potentially saves a lot of memory/time etc.
        return classifier;
    }
}
 
Example 3
Source File: TransformEnsembles.java    From tsml with GNU General Public License v3.0 5 votes vote down vote up
public void buildClassifier(Instances data) throws Exception {
//Sometimes I just want to re-weight it, which must be done with findWeights(). 
//		rebuild stays true by default unless explicitly set by rebuildClassifier(boolean f)
// this is just a bit of a hack to speed up experiments,
		if(rebuild){	
			System.out.println("Build whole ...");
			init(data); //Assume its already standardised
			train.add(data);
			Instances t1=ps.process(data);
			Instances t2=acf.process(data);
			if(normaliseAtts){
				nPs=new NormalizeAttribute(t1);
				t1=nPs.process(t1);
				nAcf=new NormalizeAttribute(t2);
				t2=nAcf.process(t2);
			}
			pca.buildEvaluator(data);
			Instances t3=pca.transformedData(data);
			train.add(t1); //
			train.add(t2);
			train.add(t3);
			nosTransforms=train.size();
			findWeights();
			all= AbstractClassifier.makeCopies(base,train.size());
                        all[0]=AbstractClassifier.makeCopy(baseTime);
			for(int i=0;i<all.length;i++){
				all[i].buildClassifier(train.get(i));
			}
		}
	}
 
Example 4
Source File: WekaUtil.java    From AILibs with GNU Affero General Public License v3.0 5 votes vote down vote up
public static Classifier cloneClassifier(final Classifier c) throws Exception {
	Method cloneMethod = MethodUtils.getAccessibleMethod(c.getClass(), "clone");
	if (cloneMethod != null) {
		return (Classifier) cloneMethod.invoke(c);
	}
	return AbstractClassifier.makeCopy(c);
}
 
Example 5
Source File: AbstractMultiSearch.java    From meka with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Set the base learner.
 *
 * @param newClassifier 	the classifier to use.
 */
@Override
public void setClassifier(Classifier newClassifier) {
	super.setClassifier(newClassifier);
	try {
		m_BestClassifier.classifier = AbstractClassifier.makeCopy(m_Classifier);
	}
	catch (Exception e) {
		e.printStackTrace();
	}
}
 
Example 6
Source File: PMCC.java    From meka with GNU General Public License v3.0 5 votes vote down vote up
/**
 * RebuildCC - rebuild a classifier chain 'h_old' to have a new sequence 's_new'.
 */
protected CC rebuildCC(CC h_old, int s_new[], Instances D) throws Exception {

	// make a deep copy
	CC h = (CC)AbstractClassifier.makeCopy(h_old);

	// rebuild this chain
	h.rebuildClassifier(s_new,new Instances(D));
	return h;
}
 
Example 7
Source File: CNode.java    From meka with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Build - Create transformation for this node, and train classifier of type H upon it.
 * The dataset should have class as index 'j', and remove all indices less than L *not* in paY.
 */
public void build(Instances D, Classifier H) throws Exception {
	// transform data
	T = transform(D);
	// build SLC 'h'
	h = AbstractClassifier.makeCopy(H);
	h.buildClassifier(T);
	// save templates
	//t_ = new SparseInstance(T.numAttributes());
	//t_.setDataset(T);
	//t_.setClassMissing();								// [?,x,x,x]
	T.clear();
}
 
Example 8
Source File: FRFAttributeEval.java    From android-speaker-audioanalysis with MIT License 4 votes vote down vote up
/** {@inheritDoc} */
public void buildEvaluator(Instances data) throws Exception {
  FastRandomForest forest = (FastRandomForest) AbstractClassifier.makeCopy(m_frfProto);
  forest.buildClassifier(data);
  m_Importances = forest.getFeatureImportances();
}