eu.amidst.core.datastream.Attribute.getStateSpaceType()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(6.2k)|赞(0)|评价(0)|浏览(88)

本文整理了Java中eu.amidst.core.datastream.Attribute.getStateSpaceType()方法的一些代码示例,展示了Attribute.getStateSpaceType()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Attribute.getStateSpaceType()方法的具体详情如下:
包路径:eu.amidst.core.datastream.Attribute
类名称:Attribute
方法名:getStateSpaceType

Attribute.getStateSpaceType介绍

暂无

代码示例

代码示例来源:origin: amidst/toolbox

@Override
public void open(Configuration parameters) throws Exception{
  super.open(parameters);
  String relationName = parameters.getString(DataFlinkLoader.RELATION_NAME,"");
  Collection<Attributes> collection = getRuntimeContext().getBroadcastVariable(DataFlinkLoader.ATTRIBUTES_NAME+"_"+relationName);
  attributes  = collection.iterator().next();
  if(normalize) {
    attributesToNormalize = attributes.getFullListOfAttributes().stream()
        .filter(att -> att.getStateSpaceType().getStateSpaceTypeEnum() == StateSpaceTypeEnum.REAL)
        .filter(att -> ((RealStateSpace) att.getStateSpaceType()).getMinInterval() != Double.NEGATIVE_INFINITY)
        .filter(att -> ((RealStateSpace) att.getStateSpaceType()).getMaxInterval() != Double.POSITIVE_INFINITY)
        .collect(Collectors.toList());
  }
}

代码示例来源:origin: amidst/toolbox

@Override
public DataInstance map(String value) throws Exception {
  DataInstance dataInstance = new DataInstanceFromDataRow(new DataRowWeka(attributes,value));
  if(normalize) {
    attributesToNormalize.stream()
        .forEach(att -> {
              double factor = 1000;
              double interval = factor*(((RealStateSpace) att.getStateSpaceType()).getMaxInterval() -
                  ((RealStateSpace) att.getStateSpaceType()).getMinInterval());
              double Nvalue = (dataInstance.getValue(att) -
                  ((RealStateSpace) att.getStateSpaceType()).getMinInterval())/interval;
              if (Double.isNaN(Nvalue)|| Nvalue<0 || Nvalue>factor)
                throw new IllegalStateException("Non proper normalization"+Nvalue);
              dataInstance.setValue(att, Nvalue);
            }
        );
  }
  return dataInstance;
}

代码示例来源:origin: amidst/toolbox

static StructType getSchema(Attributes atts) {
  // Generate the schema based on the list of attributes and depending on their type:
  List<StructField> fields = new ArrayList<StructField>();
  for (Attribute att: atts.getFullListOfAttributes()) {
    if (att.getStateSpaceType().getStateSpaceTypeEnum() == REAL)
      fields.add(DataTypes.createStructField(att.getName(), DataTypes.DoubleType, true));
    else
      fields.add(DataTypes.createStructField(att.getName(), DataTypes.StringType, true));
  }
  return DataTypes.createStructType(fields);
}

代码示例来源:origin: amidst/toolbox

private static Row transformArray2RowAttributes(DataInstance inst, Attributes atts) {

    double[] values = inst.toArray();

    Object[] rowValues = new Object[values.length];

    for (int a = 0; a < atts.getNumberOfAttributes(); a++) {

      Attribute attribute = atts.getFullListOfAttributes().get(a);
      StateSpaceType domain = attribute.getStateSpaceType();
      if (domain.getStateSpaceTypeEnum() == REAL)
        rowValues[a] = new Double(values[a]);
      else
        rowValues[a] = domain.stringValue(values[a]);
    }

    return RowFactory.create(rowValues);
  }
}

代码示例来源:origin: amidst/toolbox

public static void main(String[] args) throws Exception{
  int nContinuousAttributes=0;
  int nDiscreteAttributes=5;
  String names[] = {"SEQUENCE_ID", "TIME_ID","DEFAULT","Income","Expenses","Balance","TotalCredit"};
  String path = "datasets/simulated/";
  int nSamples=1000;
  String filename="bank_data_test";
  int seed = filename.hashCode();
  //Generate random dynamic data
  DataStream<DynamicDataInstance> data  = DataSetGenerator.generate(seed,nSamples,nDiscreteAttributes,nContinuousAttributes);
  List<Attribute> list = new ArrayList<Attribute>();
  //Replace the names
  IntStream.range(0, data.getAttributes().getNumberOfAttributes())
      .forEach(i -> {
        Attribute a = data.getAttributes().getFullListOfAttributes().get(i);
        StateSpaceType s = a.getStateSpaceType();
        Attribute a2 = new Attribute(a.getIndex(), names[i],s);
        list.add(a2);
      });
  //New list of attributes
  Attributes att2 = new Attributes(list);
  List<DynamicDataInstance> listData = data.stream().collect(Collectors.toList());
  //Datastream with the new attribute names
  DataStream<DynamicDataInstance> data2 =
      new DataOnMemoryListContainer<DynamicDataInstance>(att2,listData);
  //Write to a single file
  DataStreamWriter.writeDataToFile(data2, path+filename+".arff");
}

代码示例来源:origin: amidst/toolbox

public static void main(String[] args) throws Exception{
  int nContinuousAttributes=4;
  int nDiscreteAttributes=1;
  String names[] = {"SEQUENCE_ID", "TIME_ID","Default","Income","Expenses","Balance","TotalCredit"};
  String path = "datasets/simulated/";
  int nSamples=1000;
  int seed = 11234;
  String filename="bank_data_test";
  //Generate random dynamic data
  DataStream<DynamicDataInstance> data  = DataSetGenerator.generate(seed,nSamples,nDiscreteAttributes,nContinuousAttributes);
  List<Attribute> list = new ArrayList<Attribute>();
  //Replace the names
  IntStream.range(0, data.getAttributes().getNumberOfAttributes())
      .forEach(i -> {
        Attribute a = data.getAttributes().getFullListOfAttributes().get(i);
        StateSpaceType s = a.getStateSpaceType();
        Attribute a2 = new Attribute(a.getIndex(), names[i],s);
        list.add(a2);
      });
  //New list of attributes
  Attributes att2 = new Attributes(list);
  List<DynamicDataInstance> listData = data.stream().collect(Collectors.toList());
  //Datastream with the new attribute names
  DataStream<DynamicDataInstance> data2 =
      new DataOnMemoryListContainer<DynamicDataInstance>(att2,listData);
  //Write to a single file
  DataStreamWriter.writeDataToFile(data2, path+filename+".arff");
}

代码示例来源:origin: amidst/toolbox

private static double[] transformRow2DataInstance(Row row, Attributes attributes) throws Exception {
  double[] instance = new double[row.length()];
  for (int i = 0; i < row.length(); i++) {
    Attribute att = attributes.getFullListOfAttributes().get(i);
    StateSpaceType space = att.getStateSpaceType();
    switch (space.getStateSpaceTypeEnum()) {
      case REAL:
        instance[i] = row.getDouble(i);
        break;
      case FINITE_SET:
        String state = row.getString(i);
        double index = ((FiniteStateSpace) space).getIndexOfState(state);
        instance[i] = index;
        break;
      default:
        // This should never execute
        throw new Exception("Unrecognized Error");
    }
  }
  return instance;
}

代码示例来源:origin: amidst/toolbox

.forEach(i -> {
  Attribute a = data.getAttributes().getFullListOfAttributes().get(i);
  StateSpaceType s = a.getStateSpaceType();
  Attribute a2 = new Attribute(a.getIndex(), names[i],s);
  list.add(a2);

相关文章

微信公众号

最新文章

更多