⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mpckmeans.java

📁 wekaUT是 university texas austin 开发的基于weka的半指导学习(semi supervised learning)的分类器
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
    /** Set the cannot link constraint weight */  public void setCannotLinkWeight(double w) {    m_CLweight = w;  }  /** Return the cannot link constraint weight */  public double getCannotLinkWeight() {    return m_CLweight;  }  /** Set the must link constraint weight */  public void setMustLinkWeight(double w) {    m_MLweight = w;  }  /** Return the must link constraint weight */  public double getMustLinkWeight() {    return m_MLweight;  }  /** Return the number of clusters */  public int getNumClusters() {    return m_NumClusters;  }  /** A duplicate function to conform to Clusterer abstract class.   * @returns the number of clusters   */  public int numberOfClusters() {    return getNumClusters();  }     /** Set the m_SeedHash */  public void setSeedHash(HashMap seedhash) {    System.err.println("Not implemented here");  }      /**   * Set the random number seed   * @param s the seed   */  public void setRandomSeed (int s) {    m_RandomSeed = s;  }      /** Return the random number seed */  public int getRandomSeed () {    return  m_RandomSeed;  }  /** Set the maximum number of iterations */  public void setMaxIterations(int maxIterations) {    m_maxIterations = maxIterations;  }  /** Get the maximum number of iterations */  public int getMaxIterations() {    return m_maxIterations;  }  /** Set the maximum number of blank iterations (those where no points are moved) */  public void setMaxBlankIterations(int maxBlankIterations) {    m_maxBlankIterations = maxBlankIterations;  }  /** Get the maximum number of blank iterations */  public int getMaxBlankIterations() {    return m_maxBlankIterations;  }    /**   * Set the minimum value of the objective function difference required for convergence   * @param objFunConvergenceDifference the minimum value of the objective function difference required for convergence   */  public void setObjFunConvergenceDifference(double objFunConvergenceDifference) {    m_ObjFunConvergenceDifference = objFunConvergenceDifference;  }  /**   * Get the minimum value of the objective function difference required for convergence   * @returns the minimum value of the objective function difference required for convergence   */  public double getObjFunConvergenceDifference() {    return m_ObjFunConvergenceDifference;  }      /** Sets training instances */  public void setInstances(Instances instances) {    m_Instances = instances;    // create the checksum coefficients    m_checksumCoeffs = new double[instances.numAttributes()];    for (int i = 0; i < m_checksumCoeffs.length; i++) {      m_checksumCoeffs[i] = m_RandomNumberGenerator.nextDouble();    }    // hash the instance checksums    m_checksumHash = new HashMap(instances.numInstances());    int classIdx = instances.classIndex();    for (int i = 0; i < instances.numInstances(); i++) {      Instance instance = instances.instance(i);      double[] values = instance.toDoubleArray();      double checksum = 0;      for (int j = 0; j < values.length; j++) {	if (j != classIdx) {	  checksum += m_checksumCoeffs[j] * values[j]; 	}       }      // take care of chaining      Object list = m_checksumHash.get(new Double((float)checksum));      ArrayList idxList = null;       if (list == null) {	idxList = new ArrayList();	m_checksumHash.put(new Double((float)checksum), idxList);      } else { // chaining	idxList = (ArrayList) list;      }      idxList.add(new Integer(i));    }   }  /** Return training instances */  public Instances getInstances() {    return m_Instances;  }  /**   * Set the number of clusters to generate   *   * @param n the number of clusters to generate   */  public void setNumClusters(int n) {    m_NumClusters = n;    if (m_verbose) {      System.out.println("Number of clusters: " + n);    }  }  /** Is the objective function decreasing or increasing? */  public boolean isObjFunDecreasing() {    return m_objFunDecreasing;  }   /**   * Set the distance metric   *   * @param s the metric   */  public void setMetric (LearnableMetric m) {    String metricName = m.getClass().getName();    m_metric = m;    m_metricLearner.setMetric(m_metric);    m_metricLearner.setClusterer(this);  }  /**   * get the distance metric   * @returns the distance metric used   */  public LearnableMetric getMetric () {    return m_metric;  }  /**   * get the array of metrics   */  public LearnableMetric[] getMetrics () {    return m_metrics;  }  /** Set/get the metric learner */  public void setMetricLearner (MPCKMeansMetricLearner ml) {    m_metricLearner = ml;    m_metricLearner.setMetric(m_metric);    m_metricLearner.setClusterer(this);  }  public MPCKMeansMetricLearner getMetricLearner () {    return m_metricLearner;  }  /** Set/get the assigner */  public MPCKMeansAssigner getAssigner() {    return m_Assigner;  }  public void setAssigner(MPCKMeansAssigner assigner) {    assigner.setClusterer(this);    this.m_Assigner = assigner;  }  /** Set/get the initializer */  public MPCKMeansInitializer getInitializer() {    return m_Initializer;  }  public void setInitializer(MPCKMeansInitializer initializer) {    initializer.setClusterer(this);    this.m_Initializer = initializer;  }  /** Read the seeds from a hastable, where every key is an instance and every value is:   * the cluster assignment of that instance    * seedVector vector containing seeds   */    public void seedClusterer(HashMap seedHash) {    System.err.println("Not implemented here");  }   public void printClusterAssignments() throws Exception {    if (m_ClusterAssignmentsOutputFile != null) {      PrintStream p = 	new PrintStream(new FileOutputStream(m_ClusterAssignmentsOutputFile));            for (int i=0; i<m_Instances.numInstances(); i++) {	p.println(i + "\t" + m_ClusterAssignments[i]);      }      p.close();    } else {      System.out.println("\nCluster Assignments:\n");      for (int i=0; i<m_Instances.numInstances(); i++) {	System.out.println(i + "\t" + m_ClusterAssignments[i]);      }    }  }  /** Prints clusters */  public void printClusters () throws Exception {    ArrayList clusters = getClusters();    for (int i=0; i<clusters.size(); i++) {      Cluster currentCluster = (Cluster) clusters.get(i);      System.out.println("\nCluster " + i + ": " + currentCluster.size() + " instances");      if (currentCluster == null) {	System.out.println("(empty)");      }      else {	for (int j=0; j<currentCluster.size(); j++) {	  Instance instance = (Instance) currentCluster.get(j);		  System.out.println("Instance: " + instance);	}      }    }  }  /**   * Computes the clusters from the cluster assignments, for external access   *    * @exception Exception if clusters could not be computed successfully   */      public ArrayList getClusters() throws Exception {    m_Clusters = new ArrayList();    Cluster [] clusterArray = new Cluster[m_NumClusters];    for (int i=0; i < m_Instances.numInstances(); i++) {      Instance inst = m_Instances.instance(i);      if(clusterArray[m_ClusterAssignments[i]] == null)	clusterArray[m_ClusterAssignments[i]] = new Cluster();      clusterArray[m_ClusterAssignments[i]].add(inst, 1);    }    for (int j =0; j< m_NumClusters; j++)       m_Clusters.add(clusterArray[j]);    return m_Clusters;  }  /**   * Computes the clusters from the cluster assignments, for external access   *    * @exception Exception if clusters could not be computed successfully   */      public HashSet[] getIndexClusters() throws Exception {    m_IndexClusters = new HashSet[m_NumClusters];    for (int i=0; i < m_Instances.numInstances(); i++) {      if (m_verbose) {	//	System.out.println("In getIndexClusters, " + i + " assigned to cluster " + m_ClusterAssignments[i]);      }      if (m_ClusterAssignments[i]!=-1 && m_ClusterAssignments[i] < m_NumClusters) {	if (m_IndexClusters[m_ClusterAssignments[i]] == null) {	  m_IndexClusters[m_ClusterAssignments[i]] = new HashSet();	}	m_IndexClusters[m_ClusterAssignments[i]].add(new Integer(i));      }    }    return m_IndexClusters;  }  public Enumeration listOptions () {    return null;  }  public String [] getOptions () {    String[] options = new String[150];    int current = 0;    if (!m_Seedable) {      options[current++] = "-X";    }    if (m_Trainable != TRAINING_NONE) {      options[current++] = "-T";      if (m_Trainable == TRAINING_INTERNAL) { 	options[current++] = "Int";      } else {	options[current++] = "Ext";      }    }    options[current++] = "-M";    options[current++] = Utils.removeSubstring(m_metric.getClass().getName(), "weka.core.metrics.");    if (m_metric instanceof OptionHandler) {      String[] metricOptions = ((OptionHandler)m_metric).getOptions();      for (int i = 0; i < metricOptions.length; i++) {	options[current++] = metricOptions[i];      }    }     if (m_Trainable != TRAINING_NONE) {      options[current++] = "-L";      options[current++] = Utils.removeSubstring(m_metricLearner.getClass().getName(), "weka.clusterers.metriclearners.");      String[] metricLearnerOptions = ((OptionHandler)m_metricLearner).getOptions();      for (int i = 0; i < metricLearnerOptions.length; i++) {	options[current++] = metricLearnerOptions[i];      }    }    if (m_regularize) {      options[current++] = "-G";      options[current++] = Utils.removeSubstring(m_metric.getRegularizer().getClass().getName(), "weka.clusterers.regularizers.");      if (m_metric.getRegularizer() instanceof OptionHandler) { 	String[] regularizerOptions = ((OptionHandler)m_metric.getRegularizer()).getOptions();	for (int i = 0; i < regularizerOptions.length; i++) {	  options[current++] = regularizerOptions[i];	}      }    }     options[current++] = "-A";    options[current++] = Utils.removeSubstring(m_Assigner.getClass().getName(), "weka.clusterers.assigners.");    if (m_Assigner instanceof OptionHandler) {      String[] assignerOptions = ((OptionHandler)m_Assigner).getOptions();      for (int i = 0; i < assignerOptions.length; i++) {	options[current++] = assignerOptions[i];      }    }    options[current++] = "-I";    options[current++] = Utils.removeSubstring(m_Initializer.getClass().getName(), "weka.clusterers.initializers.");    if (m_Initializer instanceof OptionHandler) {      String[] initializerOptions = ((OptionHandler)m_Initializer).getOptions();      for (int i = 0; i < initializerOptions.length; i++) {	options[current++] = initializerOptions[i];      }    }    if (m_useMultipleMetrics) {      options[current++] = "-U";    }    options[current++] = "-N";    options[current++] = "" + getNumClusters();    options[current++] = "-R";    options[current++] = "" + getRandomSeed();    options[current++] = "-l";    options[current++] = "" + m_logTermWeight;    options[current++] = "-r";    options[current++] = "" + m_regularizerTermWeight;    options[current++] = "-m";    options[current++] = "" + m_MLweight;    options[current++] = "-c";    options[current++] = "" + m_CLweight;    options[current++] = "-i";    options[current++] = "" + m_maxIterations;    options[current++] = "-B";    options[current++] = "" + m_maxBlankIterations;    options[current++] = "-O";    options[current++] = "" + m_ClusterAssignmentsOutputFile;    options[current++] = "-H"

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -