Example usage for weka.core Instance setValue

List of usage examples for weka.core Instance setValue

Introduction

In this page you can find the example usage for weka.core Instance setValue.

Prototype

public void setValue(Attribute att, String value);

Source Link

Document

Sets a value of an nominal or string attribute to the given value.

Usage

From source file:wekimini.DataManager.java

public void setOutputValue(int index, int whichOutput, double val) {
    Instance i = allInstances.instance(index);
    if (i == null) {
        return;//from  w w w . j ava2 s  .c om
    }

    boolean changesNumberOfInstances = i.isMissing(numMetaData + numInputs + whichOutput);

    if (isDiscrete[whichOutput]) {
        int v = (int) val;
        Attribute a = i.attribute(numMetaData + numInputs + whichOutput);
        if (a.isNominal() && v >= 0 && v <= numClasses[whichOutput]) {
            i.setValue(numMetaData + numInputs + whichOutput, v);
        } else {
            logger.log(Level.SEVERE, "Attribute value out of range");
            //TODO: CHeck this
        }
    } else {
        //TODO insert error checking / range limiting for this version!
        i.setValue(numMetaData + numInputs + whichOutput, val);
    }
    if (changesNumberOfInstances) {
        setNumExamplesPerOutput(whichOutput, getNumExamplesPerOutput(whichOutput) + 1);
    }
}

From source file:wekimini.DataManager.java

public void setInputValue(int index, int whichInput, double val) {
    /*  if (whichInput < 0 || whichInput >= numInputs) {
     throw new IllegalArgumentException("Invalid input number in setInputValue");
     } *//* w  w w  .  ja va2 s .  c om*/
    Instance i = allInstances.instance(index);
    if (i != null) {
        i.setValue(numMetaData + whichInput, val);
    } //else TODO ?
}

From source file:wekimini.InputGenerator.java

public void selectNewInputs(int numNewInstances) {
    setStoredStats();/*from w w w  .jav  a  2s .co  m*/

    for (int j = 0; j < numNewInstances; j++) {
        Instance tempInstance = storedInputs.firstInstance();

        for (int i = 0; i < numInputs; i++) {
            int index = i + numMetaData;
            double value = storedMin[i] + ((storedMax[i] - storedMin[i]) / (numNewInstances - 1)) * j;
            tempInstance.setValue(index, value);
        }
        trainingInputs.add(tempInstance);
    }
}

From source file:Windows.windowGenerating.java

/**
 * Metoda zamienia liste zbiorw na instance. Pierwsza ptla tworzy list
 * wartoci jakie mog przybiera atrybut./*  ww w .j av  a 2  s . c o m*/
 *
 * @param atr lista atryburw
 * @param s lista zawierajaca kombinajcie uzupenionych danych
 * @return
 *
 */
public static Instances setToInstances(List<Set<String>> atr, Set<List<String>> s) {

    ArrayList<Attribute> lAtrib = new ArrayList<>();

    for (int i = 0; i < atr.size(); i++) {
        FastVector labels = new FastVector(); //Utworzenie obiektu kolekcji wartosci nowego atrybutu symbolicznego
        Set<String> setValuesAtr = atr.get(i);
        Iterator ite = setValuesAtr.iterator();
        while (ite.hasNext()) {
            Object e = ite.next();
            labels.addElement(e);
        }
        Attribute attrib = new Attribute(listOfHeather.get(i), labels);
        lAtrib.add(attrib);
    }

    Instances dataNewObj = new Instances("Nowa tablica", lAtrib, 0);

    for (int i = 0; i < numOfNewInstance; i++) {
        Instance n = new DenseInstance(lAtrib.size());
        dataNewObj.add(n);
    }
    System.out.println(dataNewObj.numInstances() + " jest instancji nowo wygenerowanych");
    int iteratorek = 0;
    Iterator iter = s.iterator();
    while (iter.hasNext()) {
        Instance instance = dataNewObj.instance(iteratorek); //Pobranie obiektu o podanym numerze
        List<String> str = (List<String>) iter.next();
        for (int j = 0; j < dataNewObj.numAttributes(); j++) {
            instance.setValue(j, str.get(j));
        }
        iteratorek++;
    }
    return dataNewObj;
}