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

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

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

Attributes.getNumberOfAttributes介绍

暂无

代码示例

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

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

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

IntStream.range(0, data.getAttributes().getNumberOfAttributes())
    .forEach(i -> {
      Attribute a = data.getAttributes().getFullListOfAttributes().get(i);

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

DataFlink<DataInstance> data= sampler.sampleToDataFlink(env, this.nSamples);
Attribute attseq = new Attribute(data.getAttributes().getNumberOfAttributes(),Attributes.SEQUENCE_ID_ATT_NAME, new RealStateSpace());
Attribute atttime = new Attribute(data.getAttributes().getNumberOfAttributes()+1,Attributes.TIME_ID_ATT_NAME, new RealStateSpace());

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

DataFlink<DataInstance> data= sampler.sampleToDataFlink(env,this.nSamples);
Attribute attseq = new Attribute(data.getAttributes().getNumberOfAttributes(),Attributes.SEQUENCE_ID_ATT_NAME, new RealStateSpace());
Attribute atttime = new Attribute(data.getAttributes().getNumberOfAttributes()+1,Attributes.TIME_ID_ATT_NAME, new RealStateSpace());

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

public static void main(String[] args) throws IOException {

    BayesianNetworkGenerator.setNumberOfGaussianVars(0);
    BayesianNetworkGenerator.setNumberOfMultinomialVars(5, 3);
    BayesianNetworkGenerator.setSeed(0);
    BayesianNetwork bn = BayesianNetworkGenerator.generateNaiveBayes(2);

    int sampleSize = 1000000;
    BayesianNetworkSampler sampler = new BayesianNetworkSampler(bn);
    String file = "./datasets/simulated/randomdata.arff";
    DataStream<DataInstance> dataStream = sampler.sampleToDataStream(sampleSize);
    DataStreamWriter.writeDataToFile(dataStream, file);

    DataStream<DynamicDataInstance> data = DynamicDataStreamLoader.loadFromFile(file);

    DynamicNaiveBayesClassifier model = new DynamicNaiveBayesClassifier();
    model.setClassVarID(data.getAttributes().getNumberOfAttributes() - 1);
    model.setParallelMode(true);
    model.learn(data);
    DynamicBayesianNetwork nbClassifier = model.getDynamicBNModel();
    System.out.println(nbClassifier.toString());

  }
}

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

Instances dataset = getDataset(attributes_.getNumberOfAttributes(), getNumClusters());
Instances newInstances = new Instances(dataset);
  newInst.insertAttributeAt(attributes_.getNumberOfAttributes());
  newInst.setDataset(dataset);
  newInst.setClassValue(cnum);

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

public static void main(String[] args) throws IOException {

    BayesianNetworkGenerator.setNumberOfGaussianVars(0);
    BayesianNetworkGenerator.setNumberOfMultinomialVars(5, 2);
    BayesianNetworkGenerator.setSeed(0);
    BayesianNetwork bn = BayesianNetworkGenerator.generateNaiveBayes(2);

    int sampleSize = 1000;
    BayesianNetworkSampler sampler = new BayesianNetworkSampler(bn);
    String file = "./datasets/simulated/randomdata.arff";
    DataStream<DataInstance> dataStream = sampler.sampleToDataStream(sampleSize);
    DataStreamWriter.writeDataToFile(dataStream, file);

    DataStream<DynamicDataInstance> data = DynamicDataStreamLoader.loadFromFile(file);

    for (int i = 1; i <= 1; i++) {
      DynamicNaiveBayesClassifier model = new DynamicNaiveBayesClassifier();
      model.setClassVarID(data.getAttributes().getNumberOfAttributes() - 1);
      model.setParallelMode(true);
      model.learn(data);
      DynamicBayesianNetwork nbClassifier = model.getDynamicBNModel();
      System.out.println(nbClassifier.toString());
    }

  }
}

代码示例来源: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) ...");

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

/**
 * Initialises the class for concept drift detection.
 */
public void initLearning() {
  if (classIndex == -1)
    classIndex = attributes.getNumberOfAttributes()-1;
  switch (this.conceptDriftDetector){
    case GLOBAL:
      this.buildGlobalDAG();
      break;
  }
  svb = new ParallelVB();
  svb.setSeed(this.seed);
  svb.setPlateuStructure(new PlateuIIDReplication(hiddenVars));
  GaussianHiddenTransitionMethod gaussianHiddenTransitionMethod = new GaussianHiddenTransitionMethod(hiddenVars, 0, this.transitionVariance);
  gaussianHiddenTransitionMethod.setFading(1.0);
  svb.setTransitionMethod(gaussianHiddenTransitionMethod);
  svb.setBatchSize(this.batchSize);
  svb.setDAG(globalDAG);
  svb.setIdenitifableModelling(new IdentifiableIDAModel());
  svb.setOutput(false);
  svb.setMaximumGlobalIterations(100);
  svb.setMaximumLocalIterations(100);
  svb.setGlobalThreshold(0.001);
  svb.setLocalThreshold(0.001);
  svb.initLearning();
}

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

/**
 * Initialises the class for concept drift detection.
 */
public void initLearning() {
  if (classIndex == -1)
    classIndex = attributes.getNumberOfAttributes()-1;
  switch (this.conceptDriftDetector){
    case GLOBAL:
      this.buildGlobalDAG();
      break;
  }
  svb = new DynamicParallelVB();
  svb.setSeed(this.seed);
  svb.setPlateuStructure(new PlateuIIDReplication(hiddenVars));
  GaussianHiddenTransitionMethod gaussianHiddenTransitionMethod = new GaussianHiddenTransitionMethod(hiddenVars, 0, this.transitionVariance);
  gaussianHiddenTransitionMethod.setFading(1.0);
  svb.setTransitionMethod(gaussianHiddenTransitionMethod);
  svb.setBatchSize(this.batchSize);
  svb.setDAG(globalDynamicDAG);
  svb.setIdenitifableModelling(new IdentifiableIDAModel());
  svb.setOutput(false);
  svb.setGlobalThreshold(0.001);
  svb.setLocalThreshold(0.001);
  svb.setMaximumLocalIterations(100);
  svb.setMaximumGlobalIterations(100);
  svb.initLearning();
}

相关文章