Example usage for weka.core Attribute setWeight

List of usage examples for weka.core Attribute setWeight

Introduction

In this page you can find the example usage for weka.core Attribute setWeight.

Prototype

public void setWeight(double value) 

Source Link

Document

Sets the new attribute's weight.

Usage

From source file:de.uni_potsdam.hpi.bpt.promnicat.analysisModules.clustering.Clustering.java

License:Open Source License

/**
 * Creates a configuration for the different features that shall be considered for clustering,
 * including a weighting (in int numbers)
 * //from  ww w  .ja va 2 s  . c om
 * @return the configuration containing the selected features for clustering
 */

private static FeatureConfig createMetricsConfig() {
    FeatureConfig features = new FeatureConfig();
    numericAttributes = new FastVector();
    stringAttributes = new FastVector();

    features.addMetric(ProcessFeatureConstants.METRICS.NUM_ACTIVITIES);
    Attribute att = new Attribute(ProcessFeatureConstants.METRICS.NUM_ACTIVITIES.name());
    att.setWeight(1);
    numericAttributes.addElement(att);

    features.addMetric(ProcessFeatureConstants.METRICS.NUM_EDGES);
    Attribute att2 = new Attribute(ProcessFeatureConstants.METRICS.NUM_EDGES.name());
    att2.setWeight(1);
    numericAttributes.addElement(att2);

    features.addLabel(ProcessFeatureConstants.PROCESS_LABELS.ALL_ACTIVITY_LABELS);
    Attribute att4 = new Attribute(ProcessFeatureConstants.PROCESS_LABELS.ALL_ACTIVITY_LABELS.name(),
            (FastVector) null, 0);
    att4.setWeight(1);

    stringAttributes.addElement(att4);
    return features;
}

From source file:de.uni_potsdam.hpi.bpt.promnicat.processEvolution.clustering.ProcessEvolutionClusterer.java

License:Open Source License

/**
 * @param configuration the configuration to get the numeric values from
 * @return the numeric attributes in a {@link FastVector}
 *//*from   w w w . ja  v a2s  .  co m*/
private static FastVector getNumericAttributes(ProcessEvolutionClusteringConfiguration configuration) {
    FastVector numericAttributes = new FastVector();
    Map<String, Double> attributes = configuration.getNumericAttributes();
    // add every attribute to the fast vector
    for (String attributeName : attributes.keySet()) {
        Attribute attribute = new Attribute(attributeName);
        attribute.setWeight(attributes.get(attributeName));
        numericAttributes.addElement(attribute);
    }
    return numericAttributes;
}

From source file:moa.classifiers.novelClass.SluiceBox.SluiceBoxRush.java

License:Apache License

/**
 * @depricated/* w  w w  .j  av  a  2s  . c  om*/
 */
protected void processWarmupCache() {
    this.setModelContext(new InstancesHeader(this.warmupCache.get(0).dataset()));
    for (int i = 0; i < this.getModelContext().numAttributes(); ++i) {
        Attribute a = this.getModelContext().attribute(i);
        double w = (this.getModelContext().classIndex() == i) ? 0.0 : 1.0;
        a.setWeight(w);
        UnsafeUtils.setAttributeRange(a, 0.0, 1.0);
    }
    int size = this.warmupCache.size();
    int k = this.minimumClusterSizeOption.getValue();
    assert (size > 3) : "Warmup size is too small";
    ArrayList<Double> distancesRow = new ArrayList<>(size);
    double kthDistances[] = new double[size];
    for (int i = 0; i < size; ++i) {
        distancesRow.clear();
        for (int j = 0; j < size; ++j) {
            Double dist = VectorDistances.distance(warmupCache.get(i).toDoubleArray(),
                    warmupCache.get(j).toDoubleArray(), modelContext,
                    this.distanceStrategyOption.getChosenIndex());
            if (!dist.isInfinite() && !dist.isNaN() && (dist > 0)) {
                distancesRow.add(dist);
            }
        }
        Collections.sort(distancesRow);
        if (distancesRow.isEmpty()) {
            kthDistances[i] = 0;
        } else if (distancesRow.size() >= k) {
            kthDistances[i] = distancesRow.get(k);
        } else {
            kthDistances[i] = distancesRow.get(distancesRow.size() - 1);
        }
    }
    Arrays.parallelSort(kthDistances);
    double idealSigma = 0.1;
    double x1 = 0.0;
    double y1 = kthDistances[0];
    double xn = kthDistances.length;
    double yn = kthDistances[kthDistances.length - 1];
    double m = (yn - y1) / (xn - x1);
    double b = yn - (m * xn);
    double maxDistanceToLine = 0.0;
    double currentDistanceToLine = 0.0;
    for (int i = 0; i < kthDistances.length; ++i) {
        currentDistanceToLine = Math.abs((m * i + b) - kthDistances[i]);
        if (Double.isFinite(currentDistanceToLine) && currentDistanceToLine >= maxDistanceToLine) {
            maxDistanceToLine = currentDistanceToLine;
            idealSigma = kthDistances[i];
        }
    }
    if (Double.isNaN(idealSigma)) {
        idealSigma = 0.001;
    }
    idealSigma = Math.max(idealSigma, weka.core.Utils.SMALL);
    this.dynamicStreamClustering.initialStandardDeviationOption.setValue(idealSigma);
    System.out.println("Default Sigma = " + idealSigma);
    for (Instance x : this.warmupCache) {
        this.dynamicStreamClustering.trainOnInstance(x);
    }
}

From source file:moa.cluster.Riffle.java

License:Apache License

/**
 * Sanity check and initialization of dynamic fields
 *
 * @param x//from  ww w.  j a va 2 s  .c  o  m
 */
protected final void safeInit(Instance x) {
    if (this.embeddedLearnerOption.getValueAsCLIString().contains("Majority class")) {
        this.excludeOutlierVoting = true;
    }
    if (centroid == null) {
        centroid = x.toDoubleArray();
    }
    if (this.instances == null) {
        prepareEmbeddedClassifier();
        ArrayList<Attribute> attribs = new ArrayList<>();
        this.symbolFrequencies = new double[x.dataset().numAttributes()][];
        for (int i = 0; i < x.dataset().numAttributes(); ++i) {
            Attribute a = (Attribute) x.dataset().attribute(i).copy();
            if (i == x.classIndex()) {
                a.setWeight(0.0);
            } else {
                a.setWeight(1.0);
            }
            switch (a.type()) {
            case Attribute.STRING:
            case Attribute.NOMINAL:
                //UnsafeUtils.setAttributeRange(a, x.value(i), x.value(i));
                this.symbolFrequencies[i] = new double[a.numValues()];
                break;
            case Attribute.NUMERIC:
            case Attribute.RELATIONAL:
            case Attribute.DATE:
            default:
                // UnsafeUtils.setAttributeRange(a, x.value(i), x.value(i));
                this.symbolFrequencies[i] = null;
            }
            attribs.add(a);
        }
        this.instances = new Instances("ClusterData", attribs, 1);
        this.instances.setClassIndex(x.classIndex());

    }
    //        else {
    //            for (int i = 0; i < x.dataset().numAttributes() && i < this.header.numAttributes(); ++i) {
    //                double val = x.value(i);
    //                Attribute a = this.header.attribute(i);
    //                // expand range as necessary
    //                if (val < a.getLowerNumericBound() || val > a.getUpperNumericBound()){
    //                    UnsafeUtils.setAttributeRange(a, Math.min(val,a.getLowerNumericBound()), Math.max(val,a.getUpperNumericBound()));
    //                }
    //                // increase frequency counts if new string value is encountered
    //                if (a.type() == Attribute.STRING && (val >= Math.max(this.symbolFrequencies[i].length, a.numValues()))) {
    //                    double newArray[] = new double[Math.max(this.symbolFrequencies[i].length, a.numValues())];
    //                    Arrays.fill(newArray, 0);
    //                    for(int j = 0; j <= this.symbolFrequencies[i].length; j++) {
    //                        newArray[j] = this.symbolFrequencies[i][j];
    //                    }
    //                    this.symbolFrequencies[i] = newArray;
    //                }
    //            }
    //        }
    if (this.variances == null) {
        this.variances = new double[x.numAttributes()];
        Arrays.fill(this.variances, 1);
    }
    if (this.entropies == null) {
        this.entropies = new double[x.numAttributes()];
        Arrays.fill(this.entropies, 0);
    }
    if (this.labelFrequencies == null) {
        this.labelFrequencies = new double[x.numClasses()];
        Arrays.fill(this.labelFrequencies, 0);
    }
    if (this.gtLabelFrequencies == null) {
        this.gtLabelFrequencies = new double[x.numClasses()];
        Arrays.fill(this.gtLabelFrequencies, 0);
    }
    if (this.rho == null) {
        this.rho = new double[x.numAttributes()];
        Arrays.fill(this.rho, 0);
    }
}

From source file:moa.clusterer.outliers.Sieve.java

License:Apache License

/**
 * Initialized the perceptron that learns to detect outliers
 *///from  w w w .  ja  v  a2 s .c o m
protected void setupPerceptron() {
    ArrayList<String> labels = new ArrayList<>(2);
    labels.add("Member");
    labels.add("Outlier");

    ArrayList<Attribute> attribs = new ArrayList<>(7);
    attribs.add(new Attribute("P")); // 0
    attribs.add(new Attribute("D")); // 1
    attribs.add(new Attribute("PxD")); // 2
    attribs.add(new Attribute("Chauv")); // 3
    attribs.add(new Attribute("isOutlier", labels)); // 4
    for (Attribute a : attribs) {
        a.setWeight(1.0);
    }
    attribs.get(attribs.size() - 1).setWeight(0);
    outlierPerceptronTrainingSet = new Instances("PerceptronTrainer", attribs, 5000 * this.clusters.size());
    outlierPerceptronTrainingSet.setClassIndex(outlierPerceptronTrainingSet.numAttributes() - 1); //zero-indexed so last
    outlierPerceptronTrainingSet.setClass(attribs.get(attribs.size() - 1));
}

From source file:reactivetechnologies.sentigrade.dto.VectorRequestData.java

License:Apache License

@Override
protected void buildStructure() {
    Attribute attr0 = new Attribute(ClassificationModelEngine.CLASSIFIER_ATTRIB_ST_ADJ,
            ClassificationModelEngine.CLASSIFIER_ATTRIB_ST_ADJ_IDX);
    Attribute attr1 = new Attribute(ClassificationModelEngine.CLASSIFIER_ATTRIB_ST_ADV,
            ClassificationModelEngine.CLASSIFIER_ATTRIB_ST_ADV_IDX);
    Attribute attr2 = new Attribute(ClassificationModelEngine.CLASSIFIER_ATTRIB_ST_NOUN,
            ClassificationModelEngine.CLASSIFIER_ATTRIB_ST_NOUN_IDX);
    Attribute attr3 = new Attribute(ClassificationModelEngine.CLASSIFIER_ATTRIB_ST_VERB,
            ClassificationModelEngine.CLASSIFIER_ATTRIB_ST_VERB_IDX);
    Attribute attr4 = new Attribute(ClassificationModelEngine.CLASSIFIER_ATTRIB_ST_ALL,
            ClassificationModelEngine.CLASSIFIER_ATTRIB_ST_ALL_IDX);
    attr4.setWeight(2.0);
    Attribute attr5 = new Attribute(ClassificationModelEngine.CLASSIFIER_ATTRIB_CLASS, getClasses(),
            ClassificationModelEngine.CLASSIFIER_ATTRIB_ST_CLASS_IDX);

    structure = new Instances(getDomain(),
            new ArrayList<>(Arrays.asList(attr0, attr1, attr2, attr3, attr4, attr5)), getDataSet().size());
    structure.setClass(attr5);/*from  ww  w  .j a  va 2 s .c o  m*/
}