List of usage examples for weka.core SerializedObject SerializedObject
public SerializedObject(Object toStore) throws Exception
From source file:activeSegmentation.learning.WekaClassifier.java
License:Open Source License
@Override public IClassifier makeCopy() throws Exception { // TODO Auto-generated method stub return (IClassifier) new SerializedObject(this).getObject(); }
From source file:meka.classifiers.multilabel.AbstractMultiLabelClassifier.java
License:Open Source License
/** * Creates a given number of deep copies of the given multi-label classifier using serialization. * * @param model the classifier to copy/*from w w w . ja v a 2s.c o m*/ * @param num the number of classifier copies to create. * @return an array of classifiers. * @exception Exception if an error occurs */ public static MultiLabelClassifier[] makeCopies(MultiLabelClassifier model, int num) throws Exception { if (model == null) { throw new Exception("No model classifier set"); } MultiLabelClassifier classifiers[] = new MultiLabelClassifier[num]; SerializedObject so = new SerializedObject(model); for (int i = 0; i < classifiers.length; i++) { classifiers[i] = (MultiLabelClassifier) so.getObject(); } return classifiers; }
From source file:meka.classifiers.multilabel.ProblemTransformationMethod.java
License:Open Source License
/** * Creates a given number of deep copies of the given multi-label classifier using serialization. * * @param model the classifier to copy//from w w w . ja v a2s .c om * @param num the number of classifier copies to create. * @return an array of classifiers. * @exception Exception if an error occurs */ public static ProblemTransformationMethod[] makeCopies(ProblemTransformationMethod model, int num) throws Exception { if (model == null) { throw new Exception("No model classifier set"); } ProblemTransformationMethod classifiers[] = new ProblemTransformationMethod[num]; SerializedObject so = new SerializedObject(model); for (int i = 0; i < classifiers.length; i++) { classifiers[i] = (ProblemTransformationMethod) so.getObject(); } return classifiers; }
From source file:meka.core.ObjectUtils.java
License:Open Source License
/** * Creates a deep copy of the given object (must be serializable!). Returns * null in case of an error.// ww w . j a v a 2s . co m * * @param o the object to copy * @return the deep copy */ public static Object deepCopy(Object o) { Object result; SerializedObject so; try { so = new SerializedObject((Serializable) o); result = so.getObject(); } catch (Exception e) { System.err.println("Failed to serialize " + o.getClass().getName() + ":"); e.printStackTrace(); result = null; } return result; }
From source file:milk.classifiers.MIClassifier.java
License:Open Source License
/** * Creates copies of the current classifier, which can then * be used for boosting etc. Note that this method now uses * Serialization to perform a deep copy, so the Classifier * object must be fully Serializable. Any currently built model * will now be copied as well.// ww w . j a va 2s.c o m * * @param model an example classifier to copy * @param num the number of classifiers copies to create. * @return an array of MI-classifiers. * @exception Exception if an error occurs */ public static MIClassifier[] makeCopies(MIClassifier model, int num) throws Exception { if (model == null) { throw new Exception("No model classifier set"); } MIClassifier[] classifiers = new MIClassifier[num]; SerializedObject so = new SerializedObject(model); for (int i = 0; i < classifiers.length; i++) { classifiers[i] = (MIClassifier) so.getObject(); } return classifiers; }
From source file:milk.experiment.MIRemoteExperiment.java
License:Open Source License
/** * Prepares a remote experiment for running, creates sub experiments */*from ww w .j av a 2 s .c o m*/ * @exception Exception if an error occurs */ public void initialize() throws Exception { if (m_baseExperiment == null) { throw new Exception("No base experiment specified!"); } m_experimentAborted = false; m_finishedCount = 0; m_failedCount = 0; m_RunNumber = getRunLower(); m_DatasetNumber = 0; m_PropertyNumber = 0; m_CurrentProperty = -1; m_CurrentInstances = null; m_Finished = false; if (m_remoteHosts.size() == 0) { throw new Exception("No hosts specified!"); } // initialize all remote hosts to available m_remoteHostsStatus = new int[m_remoteHosts.size()]; m_remoteHostFailureCounts = new int[m_remoteHosts.size()]; m_remoteHostsQueue = new Queue(); // prime the hosts queue for (int i = 0; i < m_remoteHosts.size(); i++) { m_remoteHostsQueue.push(new Integer(i)); } // set up sub experiments m_subExpQueue = new Queue(); int numExps; if (getSplitByDataSet()) { numExps = m_baseExperiment.getDatasets().size(); } else { numExps = getRunUpper() - getRunLower() + 1; } m_subExperiments = new MIExperiment[numExps]; m_subExpComplete = new int[numExps]; // create copy of base experiment SerializedObject so = new SerializedObject(m_baseExperiment); if (getSplitByDataSet()) { for (int i = 0; i < m_baseExperiment.getDatasets().size(); i++) { m_subExperiments[i] = (MIExperiment) so.getObject(); // one for each data set DefaultListModel temp = new DefaultListModel(); temp.addElement(m_baseExperiment.getDatasets().elementAt(i)); m_subExperiments[i].setDatasets(temp); m_subExpQueue.push(new Integer(i)); } } else { for (int i = getRunLower(); i <= getRunUpper(); i++) { m_subExperiments[i - getRunLower()] = (MIExperiment) so.getObject(); // one run for each sub experiment m_subExperiments[i - getRunLower()].setRunLower(i); m_subExperiments[i - getRunLower()].setRunUpper(i); m_subExpQueue.push(new Integer(i - getRunLower())); } } }
From source file:mimlclassifier.MIMLClassifier.java
License:Open Source License
@Override public MultiLabelLearner makeCopy() throws Exception { return (MultiLabelLearner) new SerializedObject(this).getObject(); }
From source file:mulan.classifier.MultiLabelLearnerBase.java
License:Open Source License
public MultiLabelLearner makeCopy() throws Exception { return (MultiLabelLearner) new SerializedObject(this).getObject(); }
From source file:mulan.data.LabelsMetaDataImpl.java
License:Open Source License
@SuppressWarnings("unchecked") @Override/* w ww. j a v a 2s .c o m*/ public LabelsMetaData clone() { Set<LabelNode> rootNodes = null; try { SerializedObject obj = new SerializedObject(rootLabelNodes); rootNodes = (Set<LabelNode>) obj.getObject(); } catch (Exception ex) { throw new WekaException("Failed to create copy of 'root label nodes'.", ex); } LabelsMetaDataImpl copyResult = new LabelsMetaDataImpl(); for (LabelNode rootNode : rootNodes) { copyResult.addRootNode(rootNode); } return copyResult; }
From source file:mulan.evaluation.measure.ClassificationMeasureBase.java
License:Open Source License
public Measure makeCopy() throws Exception { return (Measure) new SerializedObject(this).getObject(); }