Package org.encog.app.analyst.script

Examples of org.encog.app.analyst.script.DataField


  /**
   * Finalize the field, and create a DataField.
   * @return The new DataField.
   */
  public DataField finalizeField() {
    final DataField result = new DataField(getName());

    // if max and min are the same, we are dealing with a zero-sized range,
    // which will cause other issues.  This is caused by ever number in the
    // column having exactly (or nearly exactly) the same value.  Provide a
    // small range around that value so that every value in this column normalizes
    // to the midpoint of the desired normalization range, typically 0 or 0.5.
    if( Math.abs(getMax()-getMin())<Encog.DEFAULT_DOUBLE_EQUAL ) {
      result.setMin(getMin()-0.0001);
      result.setMax(getMin()+0.0001);
    } else {
      result.setMin(getMin());
      result.setMax(getMax());     
    }
   
    result.setName(getName());
    result.setMean(getMean());
    result.setStandardDeviation(getStandardDeviation());
    result.setInteger(isInteger());
    result.setReal(isReal());
    result.setClass(isClass());
    result.setComplete(isComplete());
    result.setSource(getSource());

    result.getClassMembers().clear();

    if (result.isClass()) {
      final List<AnalystClassItem> list = getAnalyzedClassMembers();
      result.getClassMembers().addAll(list);
    }

    return result;
  }
View Full Code Here


    if( stat.isClassify() ) {
      int m = stat.determineMode(analyst);
      return stat.encode(m);
    } else {
    // mean
      DataField df = analyst.getScript().findDataField(stat.getName());
      double[] result = new double[1];
      result[0] = df.getMean();
      return result;
    }
  }
View Full Code Here

    int idx = 0;
    for (AnalystField field : this.getAnalyst().getScript().getNormalize()
        .getNormalizedFields()) {
      if (field.isInput()) {
        String str;
        DataField df = this.getAnalyst().getScript()
            .findDataField(field.getName());

        switch (field.getAction()) {
        case PassThrough:
          str = EngineArray.replace(df.getSource(),"##", ""+ (-field.getTimeSlice()));
          addLine("input[" + idx + "]=" + str + ";");
          idx++;
          break;
        case Normalize:
          str = EngineArray.replace(df.getSource(),"##",""+ (-field.getTimeSlice()));
          addLine("input[" + idx + "]=Norm(" + str + ","
              + field.getNormalizedHigh() + ","
              + field.getNormalizedLow() + ","
              + field.getActualHigh() + ","
              + field.getActualLow() + ");");
View Full Code Here

      boolean success = false;

      if (this.goal == AnalystGoal.Classification) {
        // first try to the last classify field
        for (final AnalystField field : fields) {
          final DataField df = this.script.findDataField(field
              .getName());
          if (field.getAction().isClassify() && df.isClass()) {
            this.targetField = field;
            success = true;
          }
        }
      } else {

        // otherwise, just return the last regression field
        for (final AnalystField field : fields) {
          final DataField df = this.script.findDataField(field
              .getName());
          if (!df.isClass() && (df.isReal() || df.isInteger())) {
            this.targetField = field;
            success = true;
          }
        }
      }

      if (!success) {
        throw new AnalystError(
            "Can't determine target field automatically, "
                + "please specify one.\nThis can also happen if you "
                + "specified the wrong file format.\nNote: If your file has no headers, specify \"field:1\" - \"field:n\".");
      }
    } else {
      this.targetField = this.script
          .findAnalystField(this.targetFieldName);
      if (this.targetField == null) {
        throw new AnalystError("Invalid target field: "
            + this.targetField);
      }
    }

    this.script.getProperties().setProperty(
        ScriptProperties.DATA_CONFIG_GOAL, this.goal);

    if (!this.timeSeries && this.taskBalance) {
      this.script.getProperties().setProperty(
          ScriptProperties.BALANCE_CONFIG_BALANCE_FIELD,
          this.targetField.getName());
      final DataField field = this.analyst.getScript().findDataField(
          this.targetField.getName());
      if ((field != null) && field.isClass()) {
        final int countPer = field.getMinClassCount();
        this.script.getProperties().setProperty(
            ScriptProperties.BALANCE_CONFIG_COUNT_PER, countPer);
      } else {
        throw new AnalystError("Balance currently may only be used on a nominal/class field, not a numeric field.");
      }
    }

    // determine output field
    if (this.methodType != WizardMethodType.BayesianNetwork) {
      // now that the target field has been determined, set the analyst
      // fields
      AnalystField af = null;
      for (final AnalystField field : this.analyst.getScript()
          .getNormalize().getNormalizedFields()) {
        if ((field.getAction() != NormalizationAction.Ignore)
            && field == this.targetField) {
          if ((af == null)
              || (af.getTimeSlice() < field.getTimeSlice())) {
            af = field;
          }
        }
      }

      /* If we found the output field, then flip its status to output */
      if (af != null) {
        af.setOutput(true);
        /* However, if we are including the target field in the input, for time series,
         * then we must create an input field for it.
         */
        if( this.includeTargetField ) {
          AnalystField af2 = new AnalystField(af);
          af.setOutput(false);
          this.script.getNormalize().getNormalizedFields().add(af2);
        }
      }
    }

    // set the clusters count
    if (this.taskCluster) {
      if ((this.targetField == null)
          || (this.goal != AnalystGoal.Classification)) {
        this.script.getProperties().setProperty(
            ScriptProperties.CLUSTER_CONFIG_CLUSTERS, 2);
      } else {
        final DataField tf = this.script.findDataField(this.targetField
            .getName());
        this.script.getProperties().setProperty(
            ScriptProperties.CLUSTER_CONFIG_CLUSTERS,
            tf.getClassMembers().size());
      }
    }
  }
View Full Code Here

        .getNormalizedFields();
    norm.clear();
    final DataField[] dataFields = this.script.getFields();

    for (int i = 0; i < this.script.getFields().length; i++) {
      final DataField f = dataFields[i];

      NormalizationAction action;
      final boolean isLast = i == this.script.getFields().length - 1;

      if( (this.methodType == WizardMethodType.EPL ) || (this.methodType == WizardMethodType.BayesianNetwork) ) {
        AnalystField af;
        if (f.isClass()) {
          af = new AnalystField(f.getName(),
              NormalizationAction.SingleField, 0, 0);
        } else {
          af = new AnalystField(f.getName(),
              NormalizationAction.PassThrough, 0, 0);
        }
        norm.add(af);
      } else if ((f.isInteger() || f.isReal()) && !f.isClass()) {
        action = NormalizationAction.Normalize;
        AnalystField af;
        if (this.range == NormalizeRange.NegOne2One) {
          af = new AnalystField(f.getName(), action, 1, -1);
        } else {
          af = new AnalystField(f.getName(), action, 1, 0);
        }
        norm.add(af);
        af.setActualHigh(f.getMax());
        af.setActualLow(f.getMin());
      } else if (f.isClass()) {
        if (isLast && this.directClassification) {
          action = NormalizationAction.SingleField;
        } else if (f.getClassMembers().size() > 2) {
          action = NormalizationAction.Equilateral;
        } else {
          action = NormalizationAction.OneOf;
        }

        if (this.range == NormalizeRange.NegOne2One) {
          norm.add(new AnalystField(f.getName(), action, 1, -1));
        } else {
          norm.add(new AnalystField(f.getName(), action, 1, 0));
        }
      } else {
        action = NormalizationAction.Ignore;
        norm.add(new AnalystField(action, f.getName()));
      }
    }

    this.script.getNormalize().init(this.script);
  }
View Full Code Here

    // get other config data
    final int countPer = getProp().getPropertyInt(
        ScriptProperties.BALANCE_CONFIG_COUNT_PER);
    final String targetFieldStr = getProp().getPropertyString(
        ScriptProperties.BALANCE_CONFIG_BALANCE_FIELD);
    final DataField targetFieldDF = getAnalyst().getScript().findDataField(
        targetFieldStr);
    if (targetFieldDF == null) {
      throw new AnalystError("Can't find balance target field: "
          + targetFieldStr);
    }
    if (!targetFieldDF.isClass()) {
      throw new AnalystError("Can't balance on non-class field: "
          + targetFieldStr);
    }

    final int targetFieldIndex = getAnalyst().getScript()
View Full Code Here

  private void generateSourceData(List<SourceElement> sourceData) {
    DataField[] fields = new DataField[sourceData.size() + 1];
    int index = 0;

    for (SourceElement element : sourceData) {
      DataField df = new DataField(element.getName());
      df.setSource(element.getSource());
      df.setInteger(false);
      df.setClass(false);
      df.setMax(100000);
      df.setMean(0);
      df.setMin(-100000);
      df.setStandardDeviation(0);
      fields[index++] = df;
    }

    // now add the prediction
    DataField df = new DataField("prediction");
    df.setSource("prediction");
    df.setInteger(false);
    df.setClass(false);
    df.setMax(100000);
    df.setMin(-100000);
    df.setMean(0);
    df.setStandardDeviation(0);
    fields[index++] = df;

    this.script.setFields(fields);
  }
View Full Code Here

   
    // create the variables
    int classType = 0;
    pop.getContext().clearDefinedVariables();
    for(AnalystField field : getScript().getNormalize().getNormalizedFields() ) {
      DataField df = getScript().findDataField(field.getName());
      String varName = field.getName();
     
      VariableMapping mapping;
     
      switch( field.getAction() ) {
        case Ignore:
          mapping = null;
          break;
        case PassThrough:
          if( df.isInteger() ) {
            mapping = new VariableMapping(varName, ValueType.intType);
          } else if( df.isReal() ) {
            mapping = new VariableMapping(varName, ValueType.floatingType);
          } else {
            mapping = new VariableMapping(varName, ValueType.stringType);
          }
          break;
        case Equilateral:
        case OneOf:
        case Normalize:
          mapping = new VariableMapping(varName, ValueType.floatingType);
          break;
        case SingleField:
          if( df.isClass() ) {
            mapping = new VariableMapping(varName, ValueType.enumType, classType++, df.getClassMembers().size() );
          } else if( df.isInteger() ) {
            mapping = new VariableMapping(varName, ValueType.intType );
          } else {
            mapping = new VariableMapping(varName, ValueType.floatingType);
          }
          break;
View Full Code Here

    if (this.normalizedFields == null) {
      return;
    }

    for (final AnalystField norm : this.normalizedFields) {
      final DataField f = script.findDataField(norm.getName());

      if (f == null) {
        throw new AnalystError("Normalize specifies unknown field: "
            + norm.getName());
      }

      if (norm.getAction() == NormalizationAction.Normalize) {
        norm.setActualHigh(f.getMax());
        norm.setActualLow(f.getMin());
      }

      if ((norm.getAction() == NormalizationAction.Equilateral)
          || (norm.getAction() == NormalizationAction.OneOf)
          || (norm.getAction() == NormalizationAction.SingleField)) {

        int index = 0;
        for (final AnalystClassItem item : f.getClassMembers()) {
          norm.getClasses().add(
              new ClassItem(item.getName(), index++));
        }
      }
    }
View Full Code Here

      String name,
      boolean isClass,
      boolean isComplete,
      boolean isInteger,
      boolean isReal) {
    DataField df = this.encogAnalyst.getScript().getFields()[i];
    Assert.assertEquals(max, df.getMax(),0.001);
    Assert.assertEquals(mean, df.getMean(),0.001);
    Assert.assertEquals(min, df.getMin(),0.001);
    Assert.assertEquals(sd, df.getStandardDeviation(),0.001);
    Assert.assertEquals(name, df.getName() );
    Assert.assertEquals(isClass, df.isClass() );
    Assert.assertEquals(isComplete, df.isComplete() );
    Assert.assertEquals(isInteger, df.isInteger() );
    Assert.assertEquals(isReal, df.isReal() );   
  }
View Full Code Here

TOP

Related Classes of org.encog.app.analyst.script.DataField

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.