Tabnine Logo
DenseInstance.<init>
Code IndexAdd Tabnine to your IDE (free)

How to use
com.yahoo.labs.samoa.instances.DenseInstance
constructor

Best Java code snippets using com.yahoo.labs.samoa.instances.DenseInstance.<init> (Showing top 20 results out of 315)

origin: nz.ac.waikato.cms.moa/moa

protected Instance newDenseInstance(int numberAttributes) {
  Instance inst = new DenseInstance(numberAttributes);
  //inst.setInstanceInformation(this.instanceInformation);
  return inst;
}
origin: nz.ac.waikato.cms.moa/moa

@Override
protected Instance newDenseInstance(int numAttributes) {
  // numAttributes is this.instanceInformation.numAttributes()
  this.range.setUpper(numAttributes);
  return new DenseInstance(numAttributes);
}
origin: nz.ac.waikato.cms.moa/moa

public void learnObject(double[] features){
  DenseInstance inst = new DenseInstance(features.length);
  for(int i=0; i<features.length; i++){
    inst.setValue(i, features[i]);
  }
  trainOnInstance(inst);
}
origin: nz.ac.waikato.cms.moa/moa

@Override
public InstanceExample nextInstance() {
  Centroid centroid = this.centroids[MiscUtils.chooseRandomIndexBasedOnWeights(this.centroidWeights,
      this.instanceRandom)];
  int numAtts = this.numAttsOption.getValue();
  double[] attVals = new double[numAtts + 1];
  for (int i = 0; i < numAtts; i++) {
    attVals[i] = (this.instanceRandom.nextDouble() * 2.0) - 1.0;
  }
  double magnitude = 0.0;
  for (int i = 0; i < numAtts; i++) {
    magnitude += attVals[i] * attVals[i];
  }
  magnitude = Math.sqrt(magnitude);
  double desiredMag = this.instanceRandom.nextGaussian()
      * centroid.stdDev;
  double scale = desiredMag / magnitude;
  for (int i = 0; i < numAtts; i++) {
    attVals[i] = centroid.centre[i] + attVals[i] * scale;
  }
  Instance inst = new DenseInstance(1.0, attVals);
  inst.setDataset(getHeader());
  inst.setClassValue(centroid.classLabel);
  return new InstanceExample(inst);
}
origin: nz.ac.waikato.cms.moa/moa

public Instance extendWithOldLabels(Instance instance) {
  if (this.header == null) {
    initHeader(instance.dataset());
    this.baseLearner.setModelContext(new InstancesHeader(this.header));
  }
  int numLabels = this.oldLabels.length;
  if (numLabels == 0) {
    return instance;
  }
  double[] x = instance.toDoubleArray();
  double[] x2 = Arrays.copyOfRange(this.oldLabels, 0, numLabels + x.length);
  System.arraycopy(x, 0, x2, numLabels, x.length);
  Instance extendedInstance = new DenseInstance(instance.weight(), x2);
  extendedInstance.setDataset(this.header);
  //System.out.println( extendedInstance);
  return extendedInstance;
}
origin: YahooArchive/samoa

for(int c = 0; c < kernels.size(); c++){
  for(int m = 0; m < kernels.get(c).microClusters.size(); m++){
    Instance inst = new DenseInstance(1, sample);
    if(kernels.get(c).microClusters.get(m).getInclusionProbability(inst) > 0){
      incluster = true;
origin: YahooArchive/samoa

@Override
public Example<Instance> nextInstance() {
  int numAtts = this.numAttsOption.getValue();
  double[] attVals = new double[numAtts + 1];
  double sum = 0.0;
  double sumWeights = 0.0;
  for (int i = 0; i < numAtts; i++) {
    attVals[i] = this.instanceRandom.nextDouble();
    sum += this.weights[i] * attVals[i];
    sumWeights += this.weights[i];
  }
  int classLabel;
  if (sum >= sumWeights * 0.5) {
    classLabel = 1;
  } else {
    classLabel = 0;
  }
  // Add Noise
  if ((1 + (this.instanceRandom.nextInt(100))) <= this.noisePercentageOption.getValue()) {
    classLabel = (classLabel == 0 ? 1 : 0);
  }
  Instance inst = new DenseInstance(1.0, attVals);
  inst.setDataset(getHeader());
  inst.setClassValue(classLabel);
  addDrift();
  return new InstanceExample(inst);
}
origin: nz.ac.waikato.cms.moa/moa

@Override
public InstanceExample nextInstance() {
  InstancesHeader header = getHeader();
  Instance inst = new DenseInstance(header.numAttributes());
  inst.setDataset(header);
  int selected = this.instanceRandom.nextInt(10);
  for (int i = 0; i < 7; i++) {
    if ((1 + (this.instanceRandom.nextInt(100))) <= this.noisePercentageOption.getValue()) {
      inst.setValue(i, originalInstances[selected][i] == 0 ? 1 : 0);
    } else {
      inst.setValue(i, originalInstances[selected][i]);
    }
  }
  if (!this.suppressIrrelevantAttributesOption.isSet()) {
    for (int i = 0; i < NUM_IRRELEVANT_ATTRIBUTES; i++) {
      inst.setValue(i + 7, this.instanceRandom.nextInt(2));
    }
  }
  inst.setClassValue(selected);
  return new InstanceExample(inst);
}
origin: nz.ac.waikato.cms.moa/moa

@Override
public InstanceExample nextInstance() {
  InstancesHeader header = getHeader();
  Instance inst = new DenseInstance(header.numAttributes());
  inst.setDataset(header);
  int selected = this.instanceRandom.nextInt(10);
  for (int i = 0; i < 7; i++) {
    if ((1 + (this.instanceRandom.nextInt(100))) <= this.noisePercentageOption.getValue()) {
      inst.setValue(this.numberAttribute[i], originalInstances[selected][i] == 0 ? 1 : 0);
    } else {
      inst.setValue(this.numberAttribute[i], originalInstances[selected][i]);
    }
  }
  if (!this.suppressIrrelevantAttributesOption.isSet()) {
    for (int i = 0; i < NUM_IRRELEVANT_ATTRIBUTES; i++) {
      inst.setValue(this.numberAttribute[i + 7], this.instanceRandom.nextInt(2));
    }
  }
  inst.setClassValue(selected);
  return new InstanceExample(inst);
}
origin: YahooArchive/samoa

@Override
public InstanceExample nextInstance() {
  double[] attVals = new double[this.numNominalsOption.getValue()
      + this.numNumericsOption.getValue()];
  InstancesHeader header = getHeader();
  Instance inst = new DenseInstance(header.numAttributes());
  for (int i = 0; i < attVals.length; i++) {
    attVals[i] = i < this.numNominalsOption.getValue() ? this.instanceRandom.nextInt(this.numValsPerNominalOption.getValue())
        : this.instanceRandom.nextDouble();
    inst.setValue(i, attVals[i]);
  }
  inst.setDataset(header);
  inst.setClassValue(classifyInstance(this.treeRoot, attVals));
  return new InstanceExample(inst);
}
origin: com.yahoo.labs.samoa/samoa-api

@Override
public InstanceExample nextInstance() {
  double[] attVals = new double[this.numNominalsOption.getValue()
      + this.numNumericsOption.getValue()];
  InstancesHeader header = getHeader();
  Instance inst = new DenseInstance(header.numAttributes());
  for (int i = 0; i < attVals.length; i++) {
    attVals[i] = i < this.numNominalsOption.getValue() ? this.instanceRandom.nextInt(this.numValsPerNominalOption.getValue())
        : this.instanceRandom.nextDouble();
    inst.setValue(i, attVals[i]);
  }
  inst.setDataset(header);
  inst.setClassValue(classifyInstance(this.treeRoot, attVals));
  return new InstanceExample(inst);
}
origin: nz.ac.waikato.cms.moa/moa

@Override
public InstanceExample nextInstance() {
  double[] attVals = new double[this.numNominalsOption.getValue()
      + this.numNumericsOption.getValue()];
  InstancesHeader header = getHeader();
  Instance inst = new DenseInstance(header.numAttributes());
  for (int i = 0; i < attVals.length; i++) {
    attVals[i] = i < this.numNominalsOption.getValue() ? this.instanceRandom.nextInt(this.numValsPerNominalOption.getValue())
        : this.instanceRandom.nextDouble();
    inst.setValue(i, attVals[i]);
  }
  inst.setDataset(header);
  inst.setClassValue(classifyInstance(this.treeRoot, attVals));
  return new InstanceExample(inst);
}
origin: YahooArchive/samoa

public void evaluateClusteringSamoa(Clustering clustering,
    Clustering trueClustering, ArrayList<Instance> points)
    throws Exception {
  double BSS_GT = 1.0;
  double BSS;
  int dimension = points.get(0).numAttributes() - 1;
  SphereCluster sc = new SphereCluster(points, dimension);
  // DO INTERNAL EVALUATION
  //clustering.getClustering().get(0).getCenter();
  BSS = getBSS(clustering, sc.getCenter());
  if (trueClustering != null) {
    List<Instance> listInstances = new ArrayList<>();
    for (Cluster c : trueClustering.getClustering()) {
      DenseInstance inst = new DenseInstance(c.getWeight(), c.getCenter());
      listInstances.add(inst);
    }
    SphereCluster gt = new SphereCluster(listInstances, dimension);
    BSS_GT = getBSS(trueClustering, gt.getCenter());
  }
  addValue("BSS", BSS);
  addValue("BSS-GT", BSS_GT);
  addValue("BSS-Ratio", BSS / BSS_GT);
}
origin: nz.ac.waikato.cms.moa/moa

  public void train(DataSet trainingSet) {
    // TODO fix not working builder!
    // ClusTree private variables are not updated but are mandatory for the algorithm to function.
//        if (UseBulkLoadingOption.isSet()) { 
//            // Use BulkLoading
//            EMTopDownTreeBuilder builder = new EMTopDownTreeBuilder();
//            try {
//                this.root = builder.buildTree(trainingSet);
//            } catch (Exception e) {
//                e.printStackTrace();
//            }
//        } else {
      //Use traditional initialization
      for (DataObject o : trainingSet.getDataObjectArray()){
        DenseInstance inst = new DenseInstance(o.getFeatures().length);
        for(int i=0; i<o.getFeatures().length; i++){
          inst.setValue(i, o.getFeatures()[i]);
        }
        trainOnInstance(inst);
      }
//        }
  }
   
origin: YahooArchive/samoa

List<Instance> listInstances = new ArrayList<>();
for (Cluster c : trueClustering.getClustering()) {
  DenseInstance inst = new DenseInstance(c.getWeight(), c.getCenter());
  listInstances.add(inst);
  s += " " + c.getWeight();
origin: com.yahoo.labs.samoa/samoa-api

public void evaluateClusteringSamoa(Clustering clustering,
    Clustering trueClustering, ArrayList<Instance> points)
    throws Exception {
  double BSS_GT = 1.0;
  double BSS = 0.0;
  int dimension = points.get(0).numAttributes() - 1;
  SphereCluster sc = new SphereCluster(points, dimension);
  // DO INTERNAL EVALUATION
  //clustering.getClustering().get(0).getCenter();
  BSS = getBSS(clustering, sc.getCenter());
  if (trueClustering != null) {
    String s = "";
    List<Instance> listInstances = new ArrayList<Instance>();
    for (Cluster c : trueClustering.getClustering()) {
      DenseInstance inst = new DenseInstance(c.getWeight(), c.getCenter());
      listInstances.add(inst);
      s += " " + c.getWeight();
    }
    //	System.out.println(s);
    SphereCluster gt = new SphereCluster(listInstances, dimension);
    BSS_GT = getBSS(trueClustering, gt.getCenter());
  }
  addValue("BSS", BSS);
  addValue("BSS-GT", BSS_GT);
  addValue("BSS-Ratio", BSS / BSS_GT);
}
origin: nz.ac.waikato.cms.moa/moa

public Clustering getClusteringResult() {
  Clustering clustering = null;
  weka.core.Instances wekaInstances= this.instanceConverter.wekaInstances(instances);
  try {
    
    clusterer.buildClusterer(wekaInstances);
    int numClusters = clusterer.numberOfClusters();
    Instances dataset = getDataset(instances.numAttributes(), numClusters);
    List<Instance> newInstances = new ArrayList<Instance>() ; //Instances(dataset);
    for (int i = 0; i < wekaInstances.numInstances(); i++) {
      weka.core.Instance inst = wekaInstances.get(i);
      int cnum = clusterer.clusterInstance(inst);
      Instance newInst = new DenseInstance(instances.instance(cnum));
      newInst.insertAttributeAt(inst.numAttributes());
      newInst.setDataset(dataset);
      newInst.setClassValue(cnum);
      newInstances.add(newInst);
    }
    clustering = new Clustering(newInstances);
  } catch (Exception e) {
    e.printStackTrace();
  }
  instances = null;
  return clustering;
}
origin: nz.ac.waikato.cms.moa/moa

@Override
public Example<Instance> nextInstance() {
  Example<Instance> original = originalStream.nextInstance();
  // copies the original values
  double values[] = new double[this.newHeader.numAttributes()];
  int ix = 0;
  for(int i = 0; i < original.getData().dataset().numAttributes(); i++){
    if(original.getData().dataset().classIndex() != i) {
      values[ix] = original.getData().value(i);
      ix++;
    }
  }
  // appends the new values
  while(ix < values.length - 1){
    Attribute att = this.newHeader.attribute(ix);
    if(att.isNumeric()) values[ix] = this.random.nextDouble();
    else values[ix] = this.random.nextInt(numValuesCategoricalFeatureOption.getValue());
    ix++;
  }
  //copies the class value
  if(original.getData().classIndex() != -1) {
    values[values.length - 1] = original.getData().classValue();
  }
  // instantiates and returns the actual instance
  Instance instnc = new DenseInstance(1.0, values);
  instnc.setDataset(this.newHeader);
  return new InstanceExample(instnc);
}
origin: nz.ac.waikato.cms.moa/moa

public void weka() {
  try{
    Class.forName("weka.gui.Logger");
  }
  catch (Exception e){
    m_logPanel.addText("Please add weka.jar to the classpath to use the Weka explorer.");
    return;
  }                
  
  Clustering wekaClustering;
  wekaClustering = null;
  if(wekaClustering == null || wekaClustering.size()==0){
    m_logPanel.addText("Empty Clustering");
    return;
  }
  int dims = wekaClustering.get(0).getCenter().length;
  FastVector attributes = new FastVector();
  for(int i = 0; i < dims; i++)
      attributes.addElement( new Attribute("att" + i) );
  Instances instances = new Instances("trainset",attributes,0);
  for(int c = 0; c < wekaClustering.size(); c++){
    Cluster cluster = wekaClustering.get(c);
    Instance inst = new DenseInstance(cluster.getWeight(), cluster.getCenter());
    inst.setDataset(instances);
    instances.add(inst);
  }
  WekaExplorer explorer = new WekaExplorer(instances);
}
origin: nz.ac.waikato.cms.moa/moa

public InstanceExample nextInstance() {
  this.numInstances++;
  InstancesHeader header = getHeader();
  Instance inst = new DenseInstance(header.numAttributes());
  inst.setDataset(header);
  double nextValue = this.nextValue();
  if (this.notBinaryStreamOption.isSet()) {
    inst.setValue(0,  nextValue);
  } else {
    inst.setValue(0, this.nextbinaryValue(nextValue));
  }
  //Ground truth
  inst.setValue(1, this.getChange() ? 1 : 0);
  if (this.getChange() == true) {
    //this.clusterEvents.add(new ClusterEvent(this, this.numInstances, "Change", "Drift"));
  }
  inst.setValue(2,  nextValue);
  return new InstanceExample(inst);
}
com.yahoo.labs.samoa.instancesDenseInstance<init>

Javadoc

Instantiates a new dense instance.

Popular methods of DenseInstance

  • setValue
  • value
  • weight

Popular in Java

  • Start an intent from android
  • scheduleAtFixedRate (ScheduledExecutorService)
  • getApplicationContext (Context)
  • setContentView (Activity)
  • SecureRandom (java.security)
    This class generates cryptographically secure pseudo-random numbers. It is best to invoke SecureRand
  • BitSet (java.util)
    The BitSet class implements abit array [http://en.wikipedia.org/wiki/Bit_array]. Each element is eit
  • Comparator (java.util)
    A Comparator is used to compare two objects to determine their ordering with respect to each other.
  • FileUtils (org.apache.commons.io)
    General file manipulation utilities. Facilities are provided in the following areas: * writing to a
  • IsNull (org.hamcrest.core)
    Is the value null?
  • Option (scala)
  • CodeWhisperer alternatives
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now