Package trust.jfcm.learning

Source Code of trust.jfcm.learning.FcmTrainingSet

package trust.jfcm.learning;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;

import trust.jfcm.Concept;


/**
* This class implements a dataset specific for the FCM training
* @author pc
*
*/
public class FcmTrainingSet implements Cloneable{
 
      /**
       * List of elements composing the training set
       */
    ArrayList<FcmTrainingSetEntry>  trainingSet;
   
    /**
     * Associated Map
     */
    FcmLearning map;
 
   
    public FcmTrainingSet(FcmLearning map){
      trainingSet = new ArrayList<FcmTrainingSetEntry>();
      this.map = map;
    }
   
    public void setMap(FcmLearning map){
      this.map = map;
    }
   
    /**
     * Add a new entry structured as inputs and outputs values
     * @param inputs
     * @param outputs
     */
    public void addEntry(Map<String, Double> inputs, Map<String, Double> outputs){
     
      //System.out.println("Entering addEntry method...");
     
      int id = trainingSet.size() + 1;
      FcmTrainingSetEntry entry = new FcmTrainingSetEntry(id);
      Iterator<Entry<String, Double>> it = inputs.entrySet().iterator();
      while(it.hasNext()){

        Entry<String, Double> e =  it.next();
        //System.out.println(e.getKey());
        Concept c = map.getConcept(e.getKey());
        if(c==null)
          System.err.println("Error: Concept "+e.getKey()+" not found.");
       
        if(c instanceof LearningConcept){
         
          entry.addInput((LearningConcept)c, e.getValue());
          //System.out.println("Entry: "+entry);
        }
      }
     
      it = outputs.entrySet().iterator();
      while(it.hasNext()){
        Entry<String, Double> e =  it.next();
        Concept c = map.getConcept(e.getKey());
        if(c==null)
          System.err.println("Error: Concept "+e.getKey()+" not found.");
       
        if(c instanceof LearningConcept)
          entry.addOutput((LearningConcept)c, e.getValue());
      }
      //System.out.println("Training set Adding entry: "+entry);
      trainingSet.add(entry);
    }
   
    /* Business methods */
    public int size(){
      return trainingSet.size();
    }
   
    public void remove(int index){
      trainingSet.remove(index);
    }
   
    public FcmTrainingSetEntry get(int index){
      return trainingSet.get(index);
    }
   
    /**
     * Remove all the instances from the dataset
     */
    public void empty(){
      trainingSet.clear();
    }
   
    /**
     * Clone
     */
    @SuppressWarnings("unchecked")
    public Object clone(){
      FcmTrainingSet obj = new FcmTrainingSet(map);
      obj.trainingSet = (ArrayList<FcmTrainingSetEntry>) this.trainingSet.clone();
      return obj;
    }
   
    public String toString(){
      return trainingSet.toString();
    }

}
TOP

Related Classes of trust.jfcm.learning.FcmTrainingSet

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.