Package weka.core

Examples of weka.core.Instance


    return result;
  }

  protected Instance remapDateTimeStamp(Instance inst) throws Exception {
    Instance result = inst;

    if (m_addDateMap != null) {
      m_addDateMap.input(result);
      result = m_addDateMap.output();
View Full Code Here


        return;
      }

      m_primaryPeriodicSequence = new HashMap<String, String>();
      for (int i = 0; i < insts.numInstances() - 1; i++) {
        Instance current = insts.instance(i);
        Instance next = insts.instance(i + 1);
        if (!Utils.isMissingValue(current.value(primaryIndex))
            && !Utils.isMissingValue(next.value(primaryIndex))) {
          String key = current.stringValue(primaryIndex);
          String value = next.stringValue(primaryIndex);
          if (m_primaryPeriodicSequence.get(key) == null) {
            m_primaryPeriodicSequence.put(key, value);
          } else {
            // check to see if this value is consistent with
            // what we've seen previously
            String previous = m_primaryPeriodicSequence.get(key);
            if (!previous.equals(value)) {
              // we don't have a consistent sequence, so can't
              // use this as the main periodic sequence
              m_primaryPeriodicSequence = null;
              break;
            }
          }
        }
      }

      if (m_primaryPeriodicSequence != null) {
        // now look for any other nominal attributes that
        // might be secondary periodic sequences at a higher
        // granularity than the primary sequence
        m_secondaryPeriodicLookups = new HashMap<Attribute, Map<String, String>>();

        for (int i = 0; i < insts.numAttributes(); i++) {
          if (insts.attribute(i).isNominal() && i != primaryIndex) {
            Attribute candidate = insts.attribute(i);
            Map<String, String> candidateMap = new HashMap<String, String>();
            for (int j = 0; j < insts.numInstances(); j++) {
              Instance current = insts.instance(j);
              if (!Utils.isMissingValue(current.value(primaryIndex))
                  && !Utils.isMissingValue(j)) {
                String key = current.stringValue(primaryIndex);
                String value = current.stringValue(j);

                if (candidateMap.get(key) == null) {
                  candidateMap.put(key, value);
                } else {
                  // check to see if this value is consistent with what
View Full Code Here

    if (m_adjustForTrends) {
      int timeStampIndex = result.attribute(m_timeStampName).index();

      m_lastTimeValue = result.instance(result.numInstances() - 1).value(
          timeStampIndex);
      Instance last = result.instance(result.numInstances() - 1);
      Instance secondToLast = result.instance(result.numInstances() - 2);
      /*
       * m_deltaTime = last.value(timeStampIndex) -
       * secondToLast.value(timeStampIndex);
       */

 
View Full Code Here

      throw new Exception("[TSLagMaker] cannot process instance because the "
          + "structure\ndiffers from what we were configured with:\n\n"
          + message);
    }

    Instance result = source;

    if (setAnyPeriodic) {
      setPeriodicValues(result);
    }

    m_lastHistoricInstance = new DenseInstance(result);
    m_lastHistoricInstance.setDataset(result.dataset());

    if (m_extraneousAttributeRemover != null) {
      m_extraneousAttributeRemover.input(result);
      result = m_extraneousAttributeRemover.output();
    }

    if (m_artificialTimeMaker != null) {
      m_artificialTimeMaker.input(result);
      result = m_artificialTimeMaker.output();

      // set the correct value here - it can't be done after the fact because
      // of other filters that create the product of time and something else.
      if (incrementTime) {
        double newTime = m_lastTimeValue + 1;
        int timeIndex = result.dataset().attribute(m_timeStampName).index();
        result.setValue(timeIndex, newTime);
        m_lastTimeValue = newTime;
      }
    } else {
      // if we have a genuine time stamp field then make sure
      // that we keep track of the most recent time value
      if (m_adjustForTrends) {
        int timeIndex = result.dataset().attribute(m_timeStampName).index();
        if (incrementTime) {

          double newTime = weka.classifiers.timeseries.core.Utils
              .advanceSuppliedTimeValue(m_lastTimeValue, m_dateBasedPeriodicity);

          // default to add the delta
          /*
           * double newTime = m_lastTimeValue +
           * m_dateBasedPeriodicity.deltaTime();//m_deltaTime; Date d = new
           * Date((long)m_lastTimeValue); Calendar c = new GregorianCalendar();
           * c.setTime(d); if (m_dateBasedPeriodicity == Periodicity.MONTHLY) {
           * c.add(Calendar.MONTH, 1); newTime = (double)c.getTimeInMillis(); }
           * else if (m_dateBasedPeriodicity == Periodicity.WEEKLY) {
           * c.add(Calendar.WEEK_OF_YEAR, 1); newTime =
           * (double)c.getTimeInMillis(); } else if (m_dateBasedPeriodicity ==
           * Periodicity.QUARTERLY) { c.add(Calendar.MONTH, 3); newTime =
           * (double)c.getTimeInMillis(); } else if (m_dateBasedPeriodicity ==
           * Periodicity.DAILY) { c.add(Calendar.DAY_OF_YEAR, 1); newTime =
           * (double)c.getTimeInMillis(); }
           */
          result.setValue(timeIndex, newTime);
          // if (!temporary) {
          m_lastTimeValue = newTime;
          // }
        } else {
          // if (!temporary) {
          // if we have a value, just store it
          if (!result.isMissing(timeIndex)) {
            m_lastTimeValue = result.value(timeIndex);
          }/*
            * else { System.err.println("*****WARNING missing time..."); }
            */
          // }
        }
View Full Code Here

        // in accordance with what the embeded classifier was trained with
        Instances mappedClassifierDataset =
          ((weka.classifiers.misc.InputMappedClassifier)classifier).
          getModelHeader(new Instances(mappedClassifierHeader, 0));
        for (int zz = 0; zz < inst.numInstances(); zz++) {
          Instance mapped = ((weka.classifiers.misc.InputMappedClassifier)classifier).
          constructMappedInstance(inst.instance(zz));
          mappedClassifierDataset.add(mapped);
        }
       
        eval.setPriors(mappedClassifierDataset);
View Full Code Here

       
        for (int i = 0; i < m_testData.numInstances(); i++) {
          if (m_stopped) {
            break;
          }
          Instance temp = m_testData.instance(i);
          plotInstances.process(temp, m_classifier, eval);
        }
       
        if (m_stopped) {
          return;
View Full Code Here

      resetQueue();
      m_NewBatch = false;
      resetHistory();
    }

    Instance newInstance = historyInput(instance);
    if (newInstance != null) {
      push(newInstance);
      return true;
    } else {
      return false;
View Full Code Here

      resetQueue();
      m_NewBatch = false;
      resetHistory();
    }

    Instance newInstance = historyInput(instance, true);
   
    return newInstance;
  }
View Full Code Here

   * @return a new instance with translated values, or null if no
   * output instance is produced
   */
  protected Instance historyInput(Instance instance, boolean temporarily) {
   
    Instance result = null;
    m_History.add(instance);
    if (m_History.size() <= Math.abs(m_InstanceRange)) {
      if (getFillWithMissing() && (m_InstanceRange < 0)) {
        // return mergeInstances(null, instance);
        result = mergeInstances(null, instance);
View Full Code Here

        }
      } else {
        vals[i] = dest.value(i);
      }
    }
    Instance inst = null;
    if (dest instanceof SparseInstance) {
      inst = new SparseInstance(dest.weight(), vals);
    } else {
      inst = new DenseInstance(dest.weight(), vals);
    }
    inst.setDataset(dest.dataset());
    return inst;
  }
View Full Code Here

TOP

Related Classes of weka.core.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.