Package org.integratedmodelling.riskwiz.learning.data

Examples of org.integratedmodelling.riskwiz.learning.data.Instance


     * @param parent  the instance node
     * @return    the configured Instance
     * @throws Exception  if generation fails, e.g., due to unknown attribute type
     */
    protected Instance createInstance(Instances header, Element parent) throws Exception {
        Instance  result;
        Element  node;
        Element  child;
        boolean  sparse;
        int    i;
        int    index;
        Vector  list;
        Vector  subList;
        double[]  values;
        String  content;
        double  weight;
        Instances  data;
   
        result = null;

        // sparse?
        sparse = (parent.getAttribute(ATT_TYPE).equals(VAL_SPARSE));
        values = new double[header.numAttributes()];
   
        // weight
        if (parent.getAttribute(ATT_WEIGHT).length() != 0) {
            weight = Double.parseDouble(parent.getAttribute(ATT_WEIGHT));
        } else {
            weight = 1.0;
        }
   
        list = getChildTags(parent, TAG_VALUE);
        for (i = 0; i < list.size(); i++) {
            node = (Element) list.get(i);
     
            // determine index
            if (sparse) {
                index = Integer.parseInt(node.getAttribute(ATT_INDEX)) - 1;
            } else {
                index = i;
            }

            // set value
            if (node.getAttribute(ATT_MISSING).equals(VAL_YES)) {
                values[index] = Instance.missingValue();
            } else {
                content = getContent(node);
                switch (header.attribute(index).type()) {
                case Attribute.NUMERIC:
                    values[index] = Double.parseDouble(content);
                    break;
     
                case Attribute.DATE:
                    values[index] = header.attribute(index).parseDate(content);
                    break;
     
                case Attribute.NOMINAL:
                    values[index] = header.attribute(index).indexOfValue(content);
                    break;
     
                case Attribute.STRING:
                    values[index] = header.attribute(index).addStringValue(
                            content);
                    break;
     
                case Attribute.RELATIONAL:
                    subList = getChildTags(node, TAG_INSTANCES);
                    child = (Element) subList.get(0);
                    data = createInstances(header.attribute(index).relation(),
                            child);
                    values[index] = header.attribute(index).addRelation(data);
                    break;
     
                default:
                    throw new Exception(
                            "Attribute type " + header.attribute(index).type()
                            + " is not supported!")
                }
            }
        }
   
        // create instance
        if (sparse) {
            result = new SparseInstance(weight, values);
        } else {
            result = new Instance(weight, values);
        }
   
        return result;
    }
View Full Code Here


         *
         * @param dataset  the dataset to set for the instance
         * @return    the next Instance
         */
        public Instance nextElement(Instances dataset) {
            Instance  result;
       
            result = null;
       
            if (isIncremental()) {
                // is there still an instance in the buffer?
                if (m_IncrementalBuffer != null) {
                    result = m_IncrementalBuffer;
                    m_IncrementalBuffer = null;
                } else {
                    try {
                        result = m_Loader.getNextInstance(dataset);
                    } catch (Exception e) {
                        e.printStackTrace();
                        result = null;
                    }
                }
            } else {
                if (m_BatchCounter < m_BatchBuffer.numInstances()) {
                    result = m_BatchBuffer.instance(m_BatchCounter);
                    m_BatchCounter++;
                }
            }
 
            result.setDataset(dataset);
       
            return result;
        }
View Full Code Here

                    vals[j] = index;
                } else {
                    vals[j] = ((Double) cval).doubleValue();
                }
            }
            dataSet.add(new Instance(1.0, vals));
        }
        m_structure = new Instances(dataSet, 0);
        setRetrieval(BATCH);
        m_cumulativeStructure = null; // conserve memory
        return dataSet;
View Full Code Here

                // incremental
                if (loader instanceof IncrementalConverter) {
                    Instances structure = loader.getStructure();

                    System.out.println(structure);
                    Instance temp;

                    do {
                        temp = loader.getNextInstance(structure);
                        if (temp != null) {
                            System.out.println(temp);
View Full Code Here

        }
   
        this.table = new Vector<Vector<String>>();
        for (int i = 0; i < insts.numInstances(); i++) {
            Vector<String> tuple = new Vector<String>(insts.numInstances());
            Instance  inst = insts.instance(i);
      
            for (int j = 0; j < rowsize; j++) {
                tuple.add(inst.toString(insts.attribute(j)));
            }
            this.table.add(tuple);
        }
    }
View Full Code Here

TOP

Related Classes of org.integratedmodelling.riskwiz.learning.data.Instance

Copyright © 2018 www.massapicom. 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.