📄 clusterer.java
字号:
ex.printStackTrace(); } } }/** * Builds the clusters */ private void buildClusterer() throws Exception { if(m_trainingSet.classIndex() < 0) m_Clusterer.buildClusterer(m_trainingSet); else{ //class based evaluation if class attribute is set Remove removeClass = new Remove(); removeClass.setAttributeIndices(""+(m_trainingSet.classIndex()+1)); removeClass.setInvertSelection(false); removeClass.setInputFormat(m_trainingSet); Instances clusterTrain = Filter.useFilter(m_trainingSet, removeClass); m_Clusterer.buildClusterer(clusterTrain); } } /** * Sets the visual appearance of this wrapper bean * * @param newVisual a <code>BeanVisual</code> value */ public void setVisual(BeanVisual newVisual) { m_visual = newVisual; } /** * Gets the visual appearance of this wrapper bean */ public BeanVisual getVisual() { return m_visual; } /** * Use the default visual appearance for this bean */ public void useDefaultVisual() { m_visual.loadIcons(BeanVisual.ICON_PATH+"DefaultClusterer.gif", BeanVisual.ICON_PATH+"DefaultClusterer_animated.gif"); } /** * Add a batch clusterer listener * * @param cl a <code>BatchClustererListener</code> value */ public synchronized void addBatchClustererListener(BatchClustererListener cl) { m_batchClustererListeners.addElement(cl); } /** * Remove a batch clusterer listener * * @param cl a <code>BatchClustererListener</code> value */ public synchronized void removeBatchClustererListener(BatchClustererListener cl) { m_batchClustererListeners.remove(cl); } /** * Notify all batch clusterer listeners of a batch clusterer event * * @param ce a <code>BatchClustererEvent</code> value */ private void notifyBatchClustererListeners(BatchClustererEvent ce) { Vector l; synchronized (this) { l = (Vector)m_batchClustererListeners.clone(); } if (l.size() > 0) { for(int i = 0; i < l.size(); i++) { ((BatchClustererListener)l.elementAt(i)).acceptClusterer(ce); } } } /** * Add a graph listener * * @param cl a <code>GraphListener</code> value */ public synchronized void addGraphListener(GraphListener cl) { m_graphListeners.addElement(cl); } /** * Remove a graph listener * * @param cl a <code>GraphListener</code> value */ public synchronized void removeGraphListener(GraphListener cl) { m_graphListeners.remove(cl); } /** * Notify all graph listeners of a graph event * * @param ge a <code>GraphEvent</code> value */ private void notifyGraphListeners(GraphEvent ge) { Vector l; synchronized (this) { l = (Vector)m_graphListeners.clone(); } if (l.size() > 0) { for(int i = 0; i < l.size(); i++) { ((GraphListener)l.elementAt(i)).acceptGraph(ge); } } } /** * Add a text listener * * @param cl a <code>TextListener</code> value */ public synchronized void addTextListener(TextListener cl) { m_textListeners.addElement(cl); } /** * Remove a text listener * * @param cl a <code>TextListener</code> value */ public synchronized void removeTextListener(TextListener cl) { m_textListeners.remove(cl); } /** * Notify all text listeners of a text event * * @param ge a <code>TextEvent</code> value */ private void notifyTextListeners(TextEvent ge) { Vector l; synchronized (this) { l = (Vector)m_textListeners.clone(); } if (l.size() > 0) { for(int i = 0; i < l.size(); i++) { ((TextListener)l.elementAt(i)).acceptText(ge); } } } /** * Returns true if, at this time, * the object will accept a connection with respect to the named event * * @param eventName the event * @return true if the object will accept a connection */ public boolean connectionAllowed(String eventName) { /* if (eventName.compareTo("instance") == 0) { if (!(m_Clusterer instanceof weka.classifiers.UpdateableClassifier)) { return false; } } */ if (m_listenees.containsKey(eventName)) { return false; } return true; } /** * Returns true if, at this time, * the object will accept a connection according to the supplied * EventSetDescriptor * * @param esd the EventSetDescriptor * @return true if the object will accept a connection */ public boolean connectionAllowed(EventSetDescriptor esd) { return connectionAllowed(esd.getName()); } /** * Notify this object that it has been registered as a listener with * a source with respect to the named event * * @param eventName the event * @param source the source with which this object has been registered as * a listener */ public synchronized void connectionNotification(String eventName, Object source) { if (connectionAllowed(eventName)) { m_listenees.put(eventName, source); /* if (eventName.compareTo("instance") == 0) { startIncrementalHandler(); } */ } } /** * Notify this object that it has been deregistered as a listener with * a source with respect to the supplied event name * * @param eventName the event * @param source the source with which this object has been registered as * a listener */ public synchronized void disconnectionNotification(String eventName, Object source) { m_listenees.remove(eventName); } /** * Function used to stop code that calls acceptTrainingSet. This is * needed as clusterer construction is performed inside a separate * thread of execution. * * @param tf a <code>boolean</code> value */ private synchronized void block(boolean tf) { if (tf) { try { // only block if thread is still doing something useful! if (m_buildThread.isAlive() && m_state != IDLE) { wait(); } } catch (InterruptedException ex) { } } else { notifyAll(); } } /** * Stop any clusterer action */ public void stop() { // tell all listenees (upstream beans) to stop Enumeration en = m_listenees.keys(); while (en.hasMoreElements()) { Object tempO = m_listenees.get(en.nextElement()); if (tempO instanceof BeanCommon) { System.err.println("Listener is BeanCommon"); ((BeanCommon)tempO).stop(); } } // stop the build thread if (m_buildThread != null) { m_buildThread.interrupt(); m_buildThread.stop(); m_buildThread = null; m_visual.setStatic(); } } /** * Set a logger * * @param logger a <code>Logger</code> value */ public void setLog(Logger logger) { m_log = logger; } /** * Return an enumeration of requests that can be made by the user * * @return an <code>Enumeration</code> value */ public Enumeration enumerateRequests() { Vector newVector = new Vector(0); if (m_buildThread != null) { newVector.addElement("Stop"); } return newVector.elements(); } /** * Perform a particular request * * @param request the request to perform * @exception IllegalArgumentException if an error occurs */ public void performRequest(String request) { if (request.compareTo("Stop") == 0) { stop(); } else { throw new IllegalArgumentException(request + " not supported (Classifier)"); } } /** * Returns true, if at the current time, the event described by the * supplied event descriptor could be generated. * * @param esd an <code>EventSetDescriptor</code> value * @return a <code>boolean</code> value */ public boolean eventGeneratable(EventSetDescriptor esd) { String eventName = esd.getName(); return eventGeneratable(eventName); } /** * Returns true, if at the current time, the named event could * be generated. Assumes that the supplied event name is * an event that could be generated by this bean * * @param eventName the name of the event in question * @return true if the named event could be generated at this point in * time */ public boolean eventGeneratable(String eventName) { if (eventName.compareTo("graph") == 0) { // can't generate a GraphEvent if clusterer is not drawable if (!(m_Clusterer instanceof weka.core.Drawable)) { return false; } // need to have a training set before the clusterer // can generate a graph! if (!m_listenees.containsKey("trainingSet")) { return false; } // Source needs to be able to generate a trainingSet // before we can generate a graph Object source = m_listenees.get("trainingSet"); if (source instanceof EventConstraints) { if (!((EventConstraints)source).eventGeneratable("trainingSet")) { return false; } } } if (eventName.compareTo("batchClusterer") == 0) { if (!m_listenees.containsKey("trainingSet")) { return false; } Object source = m_listenees.get("trainingSet"); if (source != null && source instanceof EventConstraints) { if (!((EventConstraints)source).eventGeneratable("trainingSet")) { return false; } } } if (eventName.compareTo("text") == 0) { if (!m_listenees.containsKey("trainingSet")){ return false; } Object source = m_listenees.get("trainingSet"); if (source != null && source instanceof EventConstraints) { if (!((EventConstraints)source).eventGeneratable("trainingSet")) { return false; } } } if (eventName.compareTo("batchClassifier") == 0) return false; if (eventName.compareTo("incrementalClassifier") == 0) return false; return true; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -