eu.amidst.core.datastream.Attributes类的使用及代码示例

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

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

Attributes介绍

暂无

代码示例

代码示例来源: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 PlateauLDA(Attributes attributes, String wordDocumentName, String wordCountName) {
  this.attributes = attributes;
  this.wordDocumentName = wordDocumentName;
  this.wordCountAtt = this.attributes.getAttributeByName(wordCountName);
}

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

/**
 * Creates a new DynamicVariables object given a set of {@link Attributes}.
 * @param atts a set of {@link Attributes}.
 */
public DynamicVariables(Attributes atts) {
  this.nonInterfaceVariables = new ArrayList<>();
  this.interfaceVariables = new ArrayList<>();
  this.mapping = new ConcurrentHashMap<>();
  for (Attribute att : atts.getListOfNonSpecialAttributes()) {
    VariableBuilder builder = new VariableBuilder(att);
    VariableImplementation var = new VariableImplementation(builder, nonInterfaceVariables.size());
    if (mapping.containsKey(var.getName())) {
      throw new IllegalArgumentException("Attribute list contains duplicated names");
    }
    this.mapping.put(var.getName(), var.getVarID());
    nonInterfaceVariables.add(var.getVarID(), var);
    VariableImplementation interfaceVariable = VariableImplementation.newInterfaceVariable(var);
    var.setInterfaceVariable(interfaceVariable);
    interfaceVariables.add(var.getVarID(), interfaceVariable);
  }
}

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

public DynamicDataInstanceWrapper(DataInstance dataInstance) {
  this.dataInstance = dataInstance;
  seqID = this.dataInstance.getAttributes().getSeq_id();
  timeID = this.dataInstance.getAttributes().getTime_id();
}

代码示例来源: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

/**
 * Creates a set of {@link Attributes} from a given {@code Enumeration} of {@link weka.core.Attribute}s.
 * @param attributesEnumeration an {@code Enumeration} of {@link weka.core.Attribute}s
 * @return a set of {@link Attributes}.
 */
public static Attributes convertAttributes(Enumeration<weka.core.Attribute> attributesEnumeration){
  weka.core.Attribute attrWeka;
  List<Attribute> attrList = new ArrayList<>();
  /* Predictive attributes */
  while (attributesEnumeration.hasMoreElements()) {
    attrWeka = (weka.core.Attribute) attributesEnumeration.nextElement();
    convertAttribute(attrWeka,attrList);
  }
  return new Attributes(attrList);
}

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

/**
 * Constructor of classifier from a list of attributes (e.g. from a datastream).
 * The following parameters are set to their default values: numStatesHiddenVar = 2
 * and diagonal = true.
 * @param attributes object of the class Attributes
 */
public ConceptDriftDetector(Attributes attributes) throws WrongConfigurationException {
  super(attributes);
  transitionVariance=0.1;
  classIndex = atts.getNumberOfAttributes()-1;
  conceptDriftDetector = DriftDetector.GLOBAL;
  seed = 0;
  fading = 1.0;
  numberOfGlobalVars = 1;
  globalHidden = true;
  super.windowSize = 1000;
}

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

/**
   * {@inheritDoc}
   */
  @Override
  default String outputString(){
    StringBuilder builder = new StringBuilder(this.getAttributes().getFullListOfAttributes().size()*2);
    builder.append("{");
    this.getAttributes().getFullListOfAttributes().stream().forEach(att -> builder.append(att.getName()+ " = "+ att.stringValue(this.getValue(att))+", "));
    builder.append("}");
    return builder.toString();
  }
}

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

/**
 * Builds the DAG over the set of variables given with the structure of the model
 */
@Override
protected void buildDAG() {
  String className = atts.getFullListOfAttributes().get(classIndex).getName();
  hiddenVars = new ArrayList<Variable>();
  for (int i = 0; i < this.numberOfGlobalVars ; i++) {
    hiddenVars.add(vars.newGaussianVariable("GlobalHidden_"+i));
  }
  Variable classVariable = vars.getVariableByName(className);
  dag = new DAG(vars);
  for (Attribute att : atts.getListOfNonSpecialAttributes()) {
    if (att.getName().equals(className))
      continue;
    Variable variable = vars.getVariableByName(att.getName());
    dag.getParentSet(variable).addParent(classVariable);
    if (this.globalHidden) {
      for (int i = 0; i < this.numberOfGlobalVars ; i++) {
        dag.getParentSet(variable).addParent(hiddenVars.get(i));
      }
    }
  }
}

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

private static long getSequenceID(DataInstance tailInstance){
  return (long)tailInstance.getValue(tailInstance.getAttributes().getSeq_id());
}

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

/**
 * Creates a set of {@link Attributes} from a given {@code Enumeration} of {@link weka.core.Attribute}s.
 * @param attributesEnumeration an {@code Enumeration} of {@link weka.core.Attribute}s
 * @return a set of {@link Attributes}.
 */
public static Attributes convertAttributes(Enumeration<weka.core.Attribute> attributesEnumeration){
  weka.core.Attribute attrWeka;
  List<Attribute> attrList = new ArrayList<>();
  /* Predictive attributes */
  while (attributesEnumeration.hasMoreElements()) {
    attrWeka = (weka.core.Attribute) attributesEnumeration.nextElement();
    convertAttribute(attrWeka,attrList);
  }
  return new Attributes(attrList);
}

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

} else {
  data = DataStreamLoader.open(dataFile);
  numDiscVars = data.getAttributes().getNumberOfAttributes();
  nOfVars = numContVars + numDiscVars;
  System.out.println("Learning TAN: " + nOfVars + " variables, " + " samples on file " + dataFileInput + "," + samplesOnMemory + " samples on memory, " + numCores + " core(s) ...");
nameRoot = data.getAttributes().getFullListOfAttributes().get(numDiscVars - 1).getName();
nameTarget = data.getAttributes().getFullListOfAttributes().get(0).getName();

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

public static double[][] learnKMeans(int k, DataStream<DataInstance> data){
  setK(k);
  Attributes atts = data.getAttributes();
  double[][] centroids = new double[getK()][atts.getNumberOfAttributes()];
  AtomicInteger index = new AtomicInteger();
  data.stream().limit(getK()).forEach(dataInstance -> centroids[index.getAndIncrement()]=dataInstance.toArray());
  data.restart();
  boolean change = true;
  while(change){
    Map<Integer, Averager> newCentroidsAv =
        data.parallelStream(batchSize)
            .map(instance -> Pair.newPair(centroids, instance))
            .collect(Collectors.groupingByConcurrent(Pair::getClusterID,
                Collectors.reducing(new Averager(atts.getNumberOfAttributes()), p -> new Averager(p.getDataInstance()), Averager::combine)));
    double error = IntStream.rangeClosed(0, centroids.length - 1).mapToDouble( i -> {
      double distance = Pair.getED(centroids[i], newCentroidsAv.get(i).average());
      centroids[i]=newCentroidsAv.get(i).average();
      return distance;
    }).average().getAsDouble();
    if (error<epsilon)
      change = false;
    data.restart();
  }
  return centroids;
}

代码示例来源: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

/**
 * Builds the DAG structure of a Naive Bayes classifier with a global hidden Gaussian variable.
 */
private void buildGlobalDAG(){
  Variables variables = new Variables(attributes);
  String className = attributes.getFullListOfAttributes().get(classIndex).getName();
  hiddenVars = new ArrayList<Variable>();
  for (int i = 0; i < this.numberOfGlobalVars ; i++) {
    hiddenVars.add(variables.newGaussianVariable("GlobalHidden_"+i));
  }
  Variable classVariable = variables.getVariableByName(className);
  this.globalDAG = new DAG(variables);
  for (Attribute att : attributes.getListOfNonSpecialAttributes()) {
    if (att.getName().equals(className))
      continue;
    Variable variable = variables.getVariableByName(att.getName());
    globalDAG.getParentSet(variable).addParent(classVariable);
    for (int i = 0; i < this.numberOfGlobalVars ; i++) {
      globalDAG.getParentSet(variable).addParent(hiddenVars.get(i));
    }
  }
  System.out.println(globalDAG.toString());
}

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

int id = (int)d.getValue(dataInstances.getAttributes().getSeq_id());
  return map.get(id).compareTo(year)==0;
}).collect(Collectors.toList());

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

public static DataFlink<DynamicDataInstance> convertToDynamic(DataFlink<DataInstance> data){
  if (data.getAttributes().getSeq_id()==null && data.getAttributes().getTime_id()==null){
    throw new IllegalArgumentException("Data with no seq_id and time_id attribute can not be converged");
  }
  return new DataWrapper(data);
}

代码示例来源: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

/**
 * Creates a set of {@link Attributes}, including the class, from a given {@code Enumeration}
 * of {@link weka.core.Attribute}s and a {@link weka.core.Attribute}.
 * @param attributesEnumeration an {@code Enumeration} of {@link weka.core.Attribute}s
 * @param classAtt a {@link weka.core.Attribute} object that represents the class variable.
 * @return a set of {@link Attributes}.
 */
public static Attributes convertAttributes(Enumeration<weka.core.Attribute> attributesEnumeration,
                      weka.core.Attribute classAtt){
  weka.core.Attribute attrWeka;
  List<Attribute> attrList = new ArrayList<>();
  /* Predictive attributes */
  while (attributesEnumeration.hasMoreElements()) {
    attrWeka = (weka.core.Attribute) attributesEnumeration.nextElement();
    convertAttribute(attrWeka,attrList);
  }
  convertAttribute(classAtt, attrList);
  return new Attributes(attrList);
}

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

public PlateauLDAFlink(Attributes attributes, String wordDocumentName, String wordCountName) {
  this.attributes = attributes;
  this.wordDocumentName = wordDocumentName;
  this.wordCountAtt = this.attributes.getAttributeByName(wordCountName);
}

相关文章