weka.core.SerializedObject Java Examples

The following examples show how to use weka.core.SerializedObject. 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: Kernel.java    From tsml with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a given number of deep or shallow (if the kernel implements Copyable) 
 * copies of the given kernel using serialization.
 * 
 * @param model 	the kernel to copy
 * @param num 	the number of kernel copies to create.
 * @return 		an array of kernels.
 * @throws Exception 	if an error occurs
 */
public static Kernel[] makeCopies(Kernel model, int num) throws Exception {
  if (model == null)
    throw new Exception("No model kernel set");

  Kernel[] kernels = new Kernel[num];
  if (model instanceof Copyable) {
    for (int i = 0; i < kernels.length; i++) {
      kernels[i] = (Kernel) ((Copyable) model).copy();
    }
  } else {
    SerializedObject so = new SerializedObject(model);
    for (int i = 0; i < kernels.length; i++)
      kernels[i] = (Kernel) so.getObject();
  }

  return kernels;
}
 
Example #2
Source File: EditableBayesNet.java    From tsml with GNU General Public License v3.0 6 votes vote down vote up
DelValueAction(int nTargetNode, String sValue) {
	try {
		m_nTargetNode = nTargetNode;
		m_sValue = sValue;
		m_att = m_Instances.attribute(nTargetNode);
		SerializedObject so = new SerializedObject(m_Distributions[nTargetNode]);
		m_CPT = (Estimator[]) so.getObject();
		;
		m_children = new FastVector();
		for (int iNode = 0; iNode < getNrOfNodes(); iNode++) {
			if (m_ParentSets[iNode].contains(nTargetNode)) {
				m_children.addElement(iNode);
			}
		}
		m_childAtts = new Estimator[m_children.size()][];
		for (int iChild = 0; iChild < m_children.size(); iChild++) {
			int nChild = (Integer) m_children.elementAt(iChild);
			m_childAtts[iChild] = m_Distributions[nChild];
		}
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
Example #3
Source File: EditableBayesNet.java    From tsml with GNU General Public License v3.0 5 votes vote down vote up
public void undo() {
	try {
		SerializedObject so = new SerializedObject(m_CPT);
		m_Distributions[m_nTargetNode] = (Estimator[]) so.getObject();
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
Example #4
Source File: AbstractMultiLabelClassifier.java    From meka with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a given number of deep copies of the given multi-label classifier using serialization.
 *
 * @param model the classifier to copy
 * @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;
}
 
Example #5
Source File: MultiSearch.java    From meka with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the default search parameters.
 *
 * @return		the parameters
 */
protected AbstractParameter[] defaultSearchParameters() {
	AbstractParameter[] 	result;
	MathParameter param;

	result = new AbstractParameter[2];

	param = new MathParameter();
	param.setProperty("M");
	param.setMin(5);
	param.setMax(15);
	param.setStep(5);
	param.setBase(10);
	param.setExpression("I");
	result[0] = param;

	param = new MathParameter();
	param.setProperty("K");
	param.setMin(1);
	param.setMax(3);
	param.setStep(1);
	param.setBase(10);
	param.setExpression("I");
	result[1] = param;

	try {
		result = (AbstractParameter[]) new SerializedObject(result).getObject();
	}
	catch (Exception e) {
		result = new AbstractParameter[0];
		System.err.println("Failed to create copy of default parameters!");
		e.printStackTrace();
	}

	return result;
}
 
Example #6
Source File: MultiSearch.java    From meka with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the default search parameters.
 *
 * @return		the parameters
 */
protected AbstractParameter[] defaultSearchParameters() {
	AbstractParameter[] 	result;
	MathParameter param;

	result = new AbstractParameter[1];

	param = new MathParameter();
	param.setProperty("K");
	param.setMin(1);
	param.setMax(3);
	param.setStep(1);
	param.setBase(10);
	param.setExpression("I");
	result[0] = param;

	try {
		result = (AbstractParameter[]) new SerializedObject(result).getObject();
	}
	catch (Exception e) {
		result = new AbstractParameter[0];
		System.err.println("Failed to create copy of default parameters!");
		e.printStackTrace();
	}

	return result;
}
 
Example #7
Source File: Classifier.java    From KEEL with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a given number of deep copies of the given classifier using serialization.
 *
 * @param model the classifier to copy
 * @param num the number of classifier copies to create.
 * @return an array of classifiers.
 * @exception Exception if an error occurs
 */
public static Classifier [] makeCopies(Classifier model,
			 int num) throws Exception {

  if (model == null) {
    throw new Exception("No model classifier set");
  }
  Classifier [] classifiers = new Classifier [num];
  SerializedObject so = new SerializedObject(model);
  for(int i = 0; i < classifiers.length; i++) {
    classifiers[i] = (Classifier) so.getObject();
  }
  return classifiers;
}
 
Example #8
Source File: Utilities.java    From tsml with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public static <A> A deepCopy(A value) throws Exception {
    if(value instanceof Serializable) {
        return (A) new SerializedObject(value).getObject();
    } else {
        String str = StrUtils.toOptionValue(value);
        Object object = StrUtils.fromOptionValue(str);
        return (A) object;
    }
}
 
Example #9
Source File: Estimator.java    From tsml with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a given number of deep copies of the given estimator using serialization.
 * 
 * @param model the estimator to copy
 * @param num the number of estimator copies to create.
 * @return an array of estimators.
 * @exception Exception if an error occurs
 */
public static Estimator [] makeCopies(Estimator model,
			 int num) throws Exception {

  if (model == null) {
    throw new Exception("No model estimator set");
  }
  Estimator [] estimators = new Estimator [num];
  SerializedObject so = new SerializedObject(model);
  for(int i = 0; i < estimators.length; i++) {
    estimators[i] = (Estimator) so.getObject();
  }
  return estimators;
}
 
Example #10
Source File: Filter.java    From tsml with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a given number of deep copies of the given filter using 
 * serialization.
 * 
 * @param model 	the filter to copy
 * @param num 	the number of filter copies to create.
 * @return 		an array of filters.
 * @throws Exception 	if an error occurs
 */
public static Filter[] makeCopies(Filter model, int num) throws Exception {

  if (model == null) {
    throw new Exception("No model filter set");
  }
  Filter[] filters = new Filter[num];
  SerializedObject so = new SerializedObject(model);
  for (int i = 0; i < filters.length; i++) {
    filters[i] = (Filter) so.getObject();
  }
  return filters;
}
 
Example #11
Source File: AbstractClassifier.java    From tsml with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a given number of deep copies of the given classifier using serialization.
 *
 * @param model the classifier to copy
 * @param num the number of classifier copies to create.
 * @return an array of classifiers.
 * @exception Exception if an error occurs
 */
public static Classifier [] makeCopies(Classifier model, int num) throws Exception {

  if (model == null) {
    throw new Exception("No model classifier set");
  }
  Classifier [] classifiers = new Classifier [num];
  SerializedObject so = new SerializedObject(model);
  for(int i = 0; i < classifiers.length; i++) {
    classifiers[i] = (Classifier) so.getObject();
  }
  return classifiers;
}
 
Example #12
Source File: EditableBayesNet.java    From tsml with GNU General Public License v3.0 5 votes vote down vote up
SetDistributionAction(int nTargetNode, double[][] P) {
	try {
		m_nTargetNode = nTargetNode;
		SerializedObject so = new SerializedObject(m_Distributions[nTargetNode]);
		m_CPT = (Estimator[]) so.getObject();
		;
		m_P = P;
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
Example #13
Source File: EditableBayesNet.java    From tsml with GNU General Public License v3.0 5 votes vote down vote up
public void undo() {
	try {
		SerializedObject so = new SerializedObject(m_CPT);
		m_Distributions[m_nChild] = (Estimator[]) so.getObject();
		ParentSet parentSet = new ParentSet();
		for (int iParent = 0; iParent < m_nParents.length; iParent++) {
			parentSet.addParent(m_nParents[iParent], m_Instances);
		}
		m_ParentSets[m_nChild] = parentSet;
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
Example #14
Source File: EditableBayesNet.java    From tsml with GNU General Public License v3.0 5 votes vote down vote up
public void undo() {
	try {
		for (int iChild = 0; iChild < m_children.size(); iChild++) {
			int nChild = (Integer) m_children.elementAt(iChild);
			deleteArc(m_nParent, nChild);
			SerializedObject so = new SerializedObject(m_CPT[iChild]);
			m_Distributions[nChild] = (Estimator[]) so.getObject();
		}
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
Example #15
Source File: AbstractClusterer.java    From tsml with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates copies of the current clusterer. Note that this method
 * now uses Serialization to perform a deep copy, so the Clusterer
 * object must be fully Serializable. Any currently built model will
 * now be copied as well.
 *
 * @param model an example clusterer to copy
 * @param num the number of clusterer copies to create.
 * @return an array of clusterers.
 * @exception Exception if an error occurs 
 */
public static Clusterer [] makeCopies(Clusterer model,
			int num) throws Exception {
   if (model == null) {
    throw new Exception("No model clusterer set");
  }
  Clusterer [] clusterers = new Clusterer [num];
  SerializedObject so = new SerializedObject(model);
  for(int i = 0; i < clusterers.length; i++) {
    clusterers[i] = (Clusterer) so.getObject();
  }
  return clusterers;
}
 
Example #16
Source File: AbstractDensityBasedClusterer.java    From tsml with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates copies of the current clusterer. Note that this method
 * now uses Serialization to perform a deep copy, so the Clusterer
 * object must be fully Serializable. Any currently built model will
 * now be copied as well.
 *
 * @param model an example clusterer to copy
 * @param num the number of clusterer copies to create.
 * @return an array of clusterers.
 * @exception Exception if an error occurs 
 */
public static DensityBasedClusterer [] makeCopies(DensityBasedClusterer model,
				    int num) throws Exception {
   if (model == null) {
    throw new Exception("No model clusterer set");
  }
  DensityBasedClusterer [] clusterers = new DensityBasedClusterer [num];
  SerializedObject so = new SerializedObject(model);
  for(int i = 0; i < clusterers.length; i++) {
    clusterers[i] = (DensityBasedClusterer) so.getObject();
  }
  return clusterers;
}
 
Example #17
Source File: AbstractAssociator.java    From tsml with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates copies of the current associator. Note that this method
 * now uses Serialization to perform a deep copy, so the Associator
 * object must be fully Serializable. Any currently built model will
 * now be copied as well.
 *
 * @param model an example associator to copy
 * @param num the number of associators copies to create.
 * @return an array of associators.
 * @exception Exception if an error occurs 
 */
public static Associator[] makeCopies(Associator model,
			 int num) throws Exception {

  if (model == null) {
    throw new Exception("No model associator set");
  }
  Associator [] associators = new Associator [num];
  SerializedObject so = new SerializedObject(model);
  for(int i = 0; i < associators.length; i++) {
    associators[i] = (Associator) so.getObject();
  }
  return associators;
}
 
Example #18
Source File: ASEvaluation.java    From tsml with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates copies of the current evaluator. Note that this method
 * now uses Serialization to perform a deep copy, so the evaluator
 * object must be fully Serializable. Any currently built model will
 * now be copied as well.
 *
 * @param model an example evaluator to copy
 * @param num the number of evaluator copies to create.
 * @return an array of evaluators.
 * @exception Exception if an error occurs 
 */
public static ASEvaluation [] makeCopies(ASEvaluation model,
			 int num) throws Exception {

  if (model == null) {
    throw new Exception("No model evaluator set");
  }
  ASEvaluation [] evaluators = new ASEvaluation [num];
  SerializedObject so = new SerializedObject(model);
  for(int i = 0; i < evaluators.length; i++) {
    evaluators[i] = (ASEvaluation) so.getObject();
  }
  return evaluators;
}
 
Example #19
Source File: ASSearch.java    From tsml with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates copies of the current search scheme. Note that this method
 * now uses Serialization to perform a deep copy, so the search
 * object must be fully Serializable. Any currently built model will
 * now be copied as well.
 *
 * @param model an example search scheme to copy
 * @param num the number of search scheme copies to create.
 * @return an array of search schemes.
 * @throws Exception if an error occurs 
 */
public static ASSearch[] makeCopies(ASSearch model, int num) throws Exception {

  if (model == null)
    throw new Exception("No model search scheme set");
    
  ASSearch[] result = new ASSearch[num];
  SerializedObject so = new SerializedObject(model);
  for (int i = 0; i < result.length; i++)
    result[i] = (ASSearch) so.getObject();

  return result;
}
 
Example #20
Source File: CheckAttributeSelection.java    From tsml with GNU General Public License v3.0 5 votes vote down vote up
/**
 * returns deep copies of the given object
 * 
 * @param obj		the object to copy
 * @param num		the number of copies
 * @return		the deep copies
 * @throws Exception	if copying fails
 */
protected Object[] makeCopies(Object obj, int num) throws Exception {
  if (obj == null)
    throw new Exception("No object set");

  Object[] objs = new Object[num];
  SerializedObject so = new SerializedObject(obj);
  for(int i = 0; i < objs.length; i++) {
    objs[i] = so.getObject();
  }
  
  return objs;
}
 
Example #21
Source File: EditableBayesNet.java    From tsml with GNU General Public License v3.0 5 votes vote down vote up
AddArcAction(int nParent, int nChild) {
	try {
		m_nParent = nParent;
		m_children = new FastVector();
		m_children.addElement(nChild);
		//m_nChild = nChild;
		SerializedObject so = new SerializedObject(m_Distributions[nChild]);
		m_CPT = new Estimator[1][];
		m_CPT[0] = (Estimator[]) so.getObject();
		;
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
Example #22
Source File: EditableBayesNet.java    From tsml with GNU General Public License v3.0 5 votes vote down vote up
AddArcAction(int nParent, FastVector children) {
	try {
		m_nParent = nParent;
		m_children = new FastVector();
		m_CPT = new Estimator[children.size()][];
		for (int iChild = 0; iChild < children.size(); iChild++) {
			int nChild = (Integer) children.elementAt(iChild);
			m_children.addElement(nChild);
			SerializedObject so = new SerializedObject(m_Distributions[nChild]);
			m_CPT[iChild] = (Estimator[]) so.getObject();
		}
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
Example #23
Source File: EditableBayesNet.java    From tsml with GNU General Public License v3.0 5 votes vote down vote up
DeleteArcAction(int nParent, int nChild) {
	try {
	m_nChild = nChild;
	m_nParent = nParent;
	m_nParents = new int[getNrOfParents(nChild)];
	for (int iParent = 0; iParent < m_nParents.length; iParent++) {
		m_nParents[iParent] = getParent(nChild, iParent);
	}
	SerializedObject so = new SerializedObject(m_Distributions[nChild]);
	m_CPT = (Estimator[]) so.getObject();
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
Example #24
Source File: Copy.java    From tsml with GNU General Public License v3.0 4 votes vote down vote up
static <A> A deepCopy(A object) throws
                                      Exception {
    return (A) new SerializedObject(object).getObject();
}
 
Example #25
Source File: Kernel.java    From tsml with GNU General Public License v3.0 3 votes vote down vote up
/**
 * Creates a shallow copy of the kernel (if it implements Copyable) 
 * otherwise a deep copy using serialization.
 *
 * @param kernel 	the kernel to copy
 * @return 		a shallow or deep copy of the kernel
 * @throws Exception 	if an error occurs
 */
public static Kernel makeCopy(Kernel kernel) throws Exception {
  if (kernel instanceof Copyable) {
    return (Kernel) ((Copyable) kernel).copy();
  }
  return (Kernel) new SerializedObject(kernel).getObject();
}
 
Example #26
Source File: Filter.java    From tsml with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Creates a deep copy of the given filter using serialization.
 *
 * @param model 	the filter to copy
 * @return 		a deep copy of the filter
 * @throws Exception 	if an error occurs
 */
public static Filter makeCopy(Filter model) throws Exception {
  return (Filter)new SerializedObject(model).getObject();
}
 
Example #27
Source File: Estimator.java    From tsml with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Creates a deep copy of the given estimator using serialization.
 *
 * @param model the estimator to copy
 * @return a deep copy of the estimator
 * @exception Exception if an error occurs
 */
public static Estimator makeCopy(Estimator model) throws Exception {

  return (Estimator)new SerializedObject(model).getObject();
}
 
Example #28
Source File: AbstractClassifier.java    From tsml with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Creates a deep copy of the given classifier using serialization.
 *
 * @param model the classifier to copy
 * @return a deep copy of the classifier
 * @exception Exception if an error occurs
 */
public static Classifier makeCopy(Classifier model) throws Exception {

  return (Classifier)new SerializedObject(model).getObject();
}
 
Example #29
Source File: Classifier.java    From KEEL with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Creates a deep copy of the given classifier using serialization.
 *
 * @param model the classifier to copy
 * @return a deep copy of the classifier
 * @exception Exception if an error occurs
 */
public static Classifier makeCopy(Classifier model) throws Exception {

  return (Classifier)new SerializedObject(model).getObject();
}
 
Example #30
Source File: AbstractAssociator.java    From tsml with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Creates a deep copy of the given associator using serialization.
 *
 * @param model the associator to copy
 * @return a deep copy of the associator
 * @exception Exception if an error occurs
 */
public static Associator makeCopy(Associator model) throws Exception {
  return (Associator) new SerializedObject(model).getObject();
}