Example usage for weka.core Instance setMissing

List of usage examples for weka.core Instance setMissing

Introduction

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

Prototype

public void setMissing(Attribute att);

Source Link

Document

Sets a specific value to be "missing".

Usage

From source file:meka.core.MLUtils.java

License:Open Source License

/**
 * SetLabelsMissing - Set all (L) labels in x to missing.
 *//*from  w  w w  .jav  a  2s  .  c om*/
public static Instance setLabelsMissing(Instance x, int L) {
    for (int j = 0; j < L; j++) {
        x.setMissing(j);
    }
    return x;
}

From source file:mlflex.WekaInMemoryLearner.java

License:Open Source License

private static void SetAttributeValue(Instance wekaInstance, Attribute attribute, String value) {
    try {/*w  w  w  . ja  v a  2 s. com*/
        if (value.equals(Settings.MISSING_VALUE_STRING)) {
            wekaInstance.setMissing(attribute);
        } else {
            if (attribute.isNominal()) {
                wekaInstance.setValue(attribute, value);
            } else {
                wekaInstance.setValue(attribute, Double.parseDouble(value));
            }
        }
    } catch (Exception ex) {
        Utilities.Log.Debug("Data point name: " + attribute.name());
        Utilities.Log.Debug("Data point value:");
        Utilities.Log.Debug(value);
        Utilities.Log.Debug("Is double: " + DataTypes.IsDouble(value));
        Utilities.Log.Debug("Is binary: " + DataTypes.IsBinary(value));
        Utilities.Log.Debug("Is integer: " + DataTypes.IsInteger(value));
        Utilities.Log.ExceptionFatal(ex);
    }
}

From source file:mx.itesm.arch.mvc.MvcAnalyzer.java

License:Open Source License

/**
 * Classify each class in the specified List into one of the layers of the
 * MVC pattern./* w  w w  .  ja v a 2  s  .  c o m*/
 * 
 * @param dependencies
 *            List containing the dependencies for each class to classify.
 * @param internalPackages
 *            Project's internal packages.
 * @return Map containing the classification layer for each class.
 * @throws Exception
 *             If an Exception occurs during classification.
 */
private static Map<String, Layer> classifyClasses(final List<ClassDependencies> dependencies,
        final Map<String, Set<String>> internalPackages) throws Exception {
    int viewCount;
    int modelCount;
    int instanceLayer;
    Instance instance;
    boolean valueFound;
    int controllerCount;
    Instances instances;
    String instanceType;
    String[] typeValues;
    Layer componentLayer;
    String[] suffixValues;
    Layer dependencyLayer;
    FastVector attributes;
    String[] externalApiValues;
    Map<String, Layer> returnValue;
    Set<String> currentPackageContent;
    Map<String, Layer> packagesClassification;
    Map<String, String[]> externalApiPackages;

    // Model variables
    attributes = new FastVector();
    for (Variable variable : Variable.values()) {
        attributes.addElement(variable.getAttribute());
    }

    // Layer variable
    attributes.addElement(Layer.attribute);

    // Set the test instances, the Layer variable is unknown
    instances = new Instances("mvc", attributes, 0);
    instances.setClassIndex(Variable.values().length);

    // Valid suffixes to look for in the class names
    suffixValues = MvcAnalyzer.getPropertyValues(MvcAnalyzer.Variable.Suffix.getVariableName());

    // Valid file types to look for in the component names
    typeValues = MvcAnalyzer.getPropertyValues(MvcAnalyzer.Variable.Type.getVariableName());

    // Valid external api packages to look for in the classes dependencies
    externalApiValues = MvcAnalyzer.getPropertyValues(MvcAnalyzer.Variable.ExternalAPI.getVariableName());
    externalApiPackages = new HashMap<String, String[]>(externalApiValues.length);
    for (int i = 0; i < externalApiValues.length; i++) {
        if (!externalApiValues[i].equals("none")) {
            externalApiPackages.put(externalApiValues[i],
                    MvcAnalyzer.getPropertyValues("externalApi." + externalApiValues[i] + ".packages"));
        }
    }

    returnValue = new HashMap<String, Layer>(dependencies.size());
    for (ClassDependencies classDependencies : dependencies) {
        // Variables + Layer
        instance = new Instance(Variable.values().length + 1);

        // Type
        instanceType = "java";
        for (String validType : typeValues) {
            if (classDependencies.getClassName().endsWith("." + validType)) {
                instanceType = validType;
                break;
            }
        }
        instance.setValue(Variable.Type.getAttribute(), instanceType);

        // ExternalAPI
        valueFound = false;
        externalApi: for (String externalApi : externalApiValues) {
            if (externalApi.equals("none")) {
                continue;
            }

            // Check if any of the class' external dependencies match with
            // one of the key external dependencies
            if (classDependencies.getExternalDependencies() != null) {
                for (String externalDependency : classDependencies.getExternalDependencies()) {
                    for (String externalPackage : externalApiPackages.get(externalApi)) {
                        if (externalDependency.toLowerCase().startsWith(externalPackage)) {
                            valueFound = true;
                            instance.setValue(Variable.ExternalAPI.getAttribute(), externalApi);
                            break externalApi;
                        }
                    }
                }
            }
        }

        // No key external dependency found
        if (!valueFound) {
            instance.setValue(Variable.ExternalAPI.getAttribute(), "none");
        }

        // Suffix
        valueFound = false;
        for (String suffix : suffixValues) {
            if (classDependencies.getClassName().toLowerCase().endsWith(suffix)) {
                valueFound = true;
                instance.setValue(Variable.Suffix.getAttribute(), suffix);
                break;
            }
        }

        // No key suffix found
        if (!valueFound) {
            instance.setValue(Variable.Suffix.getAttribute(), "none");
        }

        // Layer, the unknown variable
        instance.setMissing(Layer.attribute);
        instances.add(instance);
        instance.setDataset(instances);

        try {
            instanceLayer = (int) MvcAnalyzer.classifier.classifyInstance(instance);
        } catch (Exception e) {
            // Default value
            instanceLayer = 0;
            logger.severe("Unable to classify: " + instance);
        }

        returnValue.put(classDependencies.getClassName(), Layer.values()[instanceLayer]);
        logger.info(
                classDependencies.getClassName() + " : " + returnValue.get(classDependencies.getClassName()));
    }

    // Check for any invalid relation
    packagesClassification = new HashMap<String, Layer>(internalPackages.size());
    for (String currentPackage : internalPackages.keySet()) {
        modelCount = viewCount = controllerCount = 0;
        currentPackageContent = internalPackages.get(currentPackage);

        for (String component : currentPackageContent) {
            componentLayer = returnValue.get(component);
            if (componentLayer == Layer.Model) {
                modelCount++;
            } else if (componentLayer == Layer.View) {
                viewCount++;
            } else if (componentLayer == Layer.Controller) {
                controllerCount++;
            }
        }

        if ((modelCount > viewCount) && (modelCount > controllerCount)) {
            packagesClassification.put(currentPackage, Layer.Model);
        } else if ((viewCount > modelCount) && (viewCount > controllerCount)) {
            packagesClassification.put(currentPackage, Layer.View);
        } else if ((controllerCount > viewCount) && (controllerCount > modelCount)) {
            packagesClassification.put(currentPackage, Layer.Controller);
        } else {
            packagesClassification.put(currentPackage, null);
        }
    }

    for (ClassDependencies classDependencies : dependencies) {
        // Code relations
        valueFound = false;
        componentLayer = returnValue.get(classDependencies.getClassName());
        if (classDependencies.getInternalDependencies() != null) {
            for (String internalDependency : classDependencies.getInternalDependencies()) {
                dependencyLayer = returnValue.get(internalDependency);

                if (!componentLayer.isValidRelation(dependencyLayer)) {
                    valueFound = true;
                    returnValue.put(classDependencies.getClassName(),
                            Layer.valueOf("Invalid" + componentLayer));
                    logger.info("Invalid relation detected between: " + classDependencies.getClassName()
                            + " and " + internalDependency);
                }
            }
        }

        // Package relations
        if (!valueFound) {
            dependencyLayer = packagesClassification.get(classDependencies.getPackageName());

            if ((dependencyLayer != null) && (componentLayer != dependencyLayer)) {
                returnValue.put(classDependencies.getClassName(), Layer.valueOf("Invalid" + componentLayer));
            }
        }
    }

    return returnValue;
}

From source file:mx.itesm.web2mexadl.mvc.MvcAnalyzer.java

License:Open Source License

/**
 * Generate the architecture document associated to the specified web
 * application data.// w  ww .  j a  v a2  s.co m
 * 
 * @param dependencies
 *            List containing the dependencies for each class to classify.
 * @param internalPackages
 *            Project's internal packages.
 * @return Map containing the classification layer for each class.
 * @throws Exception
 *             If an Exception occurs during classification.
 */
private static Map<String, Layer> generateArchitecture(final List<ClassDependencies> dependencies,
        final Map<String, Set<String>> internalPackages, final File outputDir) throws Exception {
    int viewCount;
    int modelCount;
    int instanceLayer;
    Instance instance;
    boolean valueFound;
    int controllerCount;
    Instances instances;
    String instanceType;
    String[] typeValues;
    Layer componentLayer;
    String[] suffixValues;
    Layer dependencyLayer;
    FastVector attributes;
    String[] externalApiValues;
    Map<String, Layer> returnValue;
    Set<String> currentPackageContent;
    Map<String, Layer> packagesClassification;
    Map<String, String[]> externalApiPackages;
    StringBuilder modelPackages;
    StringBuilder viewPackages;
    StringBuilder controllerPackages;

    // Model variables
    attributes = new FastVector();
    for (Variable variable : Variable.values()) {
        attributes.addElement(variable.getAttribute());
    }

    // Layer variable
    attributes.addElement(Layer.attribute);

    // Set the test instances, the Layer variable is unknown
    instances = new Instances("mvc", attributes, 0);
    instances.setClassIndex(Variable.values().length);

    // Valid suffixes to look for in the class names
    suffixValues = Util.getPropertyValues(Util.Variable.Suffix.getVariableName());

    // Valid file types to look for in the component names
    typeValues = Util.getPropertyValues(Util.Variable.Type.getVariableName());

    // Valid external api packages to look for in the classes dependencies
    externalApiValues = Util.getPropertyValues(Util.Variable.ExternalAPI.getVariableName());
    externalApiPackages = new HashMap<String, String[]>(externalApiValues.length);
    for (int i = 0; i < externalApiValues.length; i++) {
        if (!externalApiValues[i].equals("none")) {
            externalApiPackages.put(externalApiValues[i],
                    Util.getPropertyValues("externalApi." + externalApiValues[i] + ".packages"));
        }
    }

    returnValue = new HashMap<String, Layer>(dependencies.size());
    for (ClassDependencies classDependencies : dependencies) {
        // Variables + Layer
        instance = new Instance(Variable.values().length + 1);

        // Type
        instanceType = "java";
        for (String validType : typeValues) {
            if (classDependencies.getClassName().endsWith("." + validType)) {
                instanceType = validType;
                break;
            }
        }
        instance.setValue(Variable.Type.getAttribute(), instanceType);

        // ExternalAPI
        valueFound = false;
        externalApi: for (String externalApi : externalApiValues) {
            if (externalApi.equals("none")) {
                continue;
            }

            // Check if any of the class' external dependencies match with
            // one of the key external dependencies
            if (classDependencies.getExternalDependencies() != null) {
                for (String externalDependency : classDependencies.getExternalDependencies()) {
                    for (String externalPackage : externalApiPackages.get(externalApi)) {
                        if (externalDependency.toLowerCase().startsWith(externalPackage)) {
                            valueFound = true;
                            instance.setValue(Variable.ExternalAPI.getAttribute(), externalApi);
                            break externalApi;
                        }
                    }
                }
            }
        }

        // No key external dependency found
        if (!valueFound) {
            instance.setValue(Variable.ExternalAPI.getAttribute(), "none");
        }

        // Suffix
        valueFound = false;
        for (String suffix : suffixValues) {
            if (classDependencies.getClassName().toLowerCase().endsWith(suffix)) {
                valueFound = true;
                instance.setValue(Variable.Suffix.getAttribute(), suffix);
                break;
            }
        }

        // No key suffix found
        if (!valueFound) {
            instance.setValue(Variable.Suffix.getAttribute(), "none");
        }

        // Layer, the unknown variable
        instance.setMissing(Layer.attribute);
        instances.add(instance);
        instance.setDataset(instances);

        try {
            instanceLayer = (int) Util.classifier.classifyInstance(instance);
        } catch (Exception e) {
            // Default value
            instanceLayer = 0;
            logger.severe("Unable to classify: " + instance);
        }

        returnValue.put(classDependencies.getClassName(), Layer.values()[instanceLayer]);
        logger.info(
                classDependencies.getClassName() + " : " + returnValue.get(classDependencies.getClassName()));
    }

    // Check for any invalid relation
    viewPackages = new StringBuilder();
    modelPackages = new StringBuilder();
    controllerPackages = new StringBuilder();
    packagesClassification = new HashMap<String, Layer>(internalPackages.size());
    for (String currentPackage : internalPackages.keySet()) {
        modelCount = viewCount = controllerCount = 0;
        currentPackageContent = internalPackages.get(currentPackage);

        for (String component : currentPackageContent) {
            componentLayer = returnValue.get(component);
            if (componentLayer == Layer.Model) {
                modelCount++;
            } else if (componentLayer == Layer.View) {
                viewCount++;
            } else if (componentLayer == Layer.Controller) {
                controllerCount++;
            }
        }

        if ((modelCount > viewCount) && (modelCount > controllerCount)) {
            packagesClassification.put(currentPackage, Layer.Model);
            Util.addImplementationPackage(modelPackages, currentPackage);
        } else if ((viewCount > modelCount) && (viewCount > controllerCount)) {
            packagesClassification.put(currentPackage, Layer.View);
            Util.addImplementationPackage(viewPackages, currentPackage);
        } else if ((controllerCount > viewCount) && (controllerCount > modelCount)) {
            packagesClassification.put(currentPackage, Layer.Controller);
            Util.addImplementationPackage(controllerPackages, currentPackage);
        } else {
            packagesClassification.put(currentPackage, null);
        }
    }

    for (ClassDependencies classDependencies : dependencies) {
        // Code relations
        valueFound = false;
        componentLayer = returnValue.get(classDependencies.getClassName());
        if (classDependencies.getInternalDependencies() != null) {
            for (String internalDependency : classDependencies.getInternalDependencies()) {
                dependencyLayer = returnValue.get(internalDependency);

                if (!componentLayer.isValidRelation(dependencyLayer)) {
                    valueFound = true;
                    returnValue.put(classDependencies.getClassName(),
                            Layer.valueOf("Invalid" + componentLayer));
                    logger.info("Invalid relation detected between: " + classDependencies.getClassName()
                            + " and " + internalDependency);
                }
            }
        }

        // Package relations
        if (!valueFound) {
            dependencyLayer = packagesClassification.get(classDependencies.getPackageName());

            if ((dependencyLayer != null) && (componentLayer != dependencyLayer)) {
                returnValue.put(classDependencies.getClassName(), Layer.valueOf("Invalid" + componentLayer));
            }
        }
    }

    // Export MexADL architecture
    MvcAnalyzer.exportToMexADL(outputDir, modelPackages.toString(), controllerPackages.toString(),
            viewPackages.toString());

    return returnValue;
}

From source file:nl.bioinf.roelen.thema11.classifier_tools.ClassifierUser.java

License:Open Source License

/**
 * use the classifier to test the sequences in a genbank or fasta file for boundaries
 * @param fileLocation the location of the genbank of fasta file
 * @param classifier the classifier to use
 * @return /*from  w w w. ja  v  a 2 s  .  co m*/
 */
public static ArrayList<ClassifiedNucleotide> getPossibleBoundaries(String fileLocation,
        Classifier classifier) {
    ArrayList<Gene> genesFromFile = new ArrayList<>();
    ArrayList<ClassifiedNucleotide> classifiedNucleotides = new ArrayList<>();
    //read from fasta
    if (fileLocation.toUpperCase().endsWith(".FASTA") || fileLocation.toUpperCase().endsWith(".FA")
            || fileLocation.toUpperCase().endsWith(".FAN")) {
        genesFromFile.addAll(readFasta(fileLocation));
    }
    //read from genbank
    else if (fileLocation.toUpperCase().endsWith(".GENBANK") || fileLocation.toUpperCase().endsWith(".GB")) {
        GenBankReader gbr = new GenBankReader();
        gbr.readFile(fileLocation);
        GenbankResult gbresult = gbr.getResult();
        genesFromFile = gbresult.getGenes();
    }
    //get the test data
    HashMap<String, ArrayList<IntronExonBoundaryTesterResult>> geneTestResults;
    geneTestResults = TestGenes.testForIntronExonBoundaries(genesFromFile, 1);
    ArrayList<InstanceToClassify> instanceNucs = new ArrayList<>();
    try {
        //write our results to a temporary file
        File tempArrf = File.createTempFile("realSet", ".arff");
        ArffWriter.write(tempArrf.getAbsolutePath(), geneTestResults, null);
        //get data
        ConverterUtils.DataSource source = new ConverterUtils.DataSource(tempArrf.getAbsolutePath());
        //SET DATA AND OPTIONS
        Instances data = source.getDataSet();
        for (int i = 0; i < data.numInstances(); i++) {
            Instance in = data.instance(i);
            //get the name of the gene or sequence tested
            String nameOfInstance = in.stringValue(in.numAttributes() - 3);
            //get the tested position
            int testedPosition = (int) in.value(in.numAttributes() - 2);
            //set the class as missing, because we want to find it
            in.setMissing((in.numAttributes() - 1));

            Instance instanceNoExtras = new Instance(in);

            //delete the name and position, they are irrelevant for classifying
            instanceNoExtras.deleteAttributeAt(instanceNoExtras.numAttributes() - 2);
            instanceNoExtras.deleteAttributeAt(instanceNoExtras.numAttributes() - 2);
            InstanceToClassify ic = new InstanceToClassify(instanceNoExtras, testedPosition, nameOfInstance);
            instanceNucs.add(ic);
        }
        for (InstanceToClassify ic : instanceNucs) {
            Instance in = ic.getInstance();
            in.setDataset(data);
            data.setClassIndex(data.numAttributes() - 1);
            //classify our instance
            classifier.classifyInstance(in);
            //save the likelyhood something is part of something
            double likelyhoodBoundary = classifier.distributionForInstance(in)[0];
            double likelyhoodNotBoundary = classifier.distributionForInstance(in)[1];

            //create a classified nucleotide and give it the added data
            ClassifiedNucleotide cn = new ClassifiedNucleotide(likelyhoodBoundary, likelyhoodNotBoundary,
                    ic.getName(), ic.getPosition());
            classifiedNucleotides.add(cn);
        }

    } catch (IOException ex) {
        Logger.getLogger(ClassifierUser.class.getName()).log(Level.SEVERE, null, ex);
    } catch (Exception ex) {
        Logger.getLogger(ClassifierUser.class.getName()).log(Level.SEVERE, null, ex);
    }
    return classifiedNucleotides;
}

From source file:sg.edu.nus.comp.nlp.ims.classifiers.CMultiClassesSVM.java

License:Open Source License

@Override
public double[] distributionForInstance(Instance p_Instance) throws Exception {
    double[] probs = new double[p_Instance.numClasses()];
    Instance newInst = this.filterInstance(p_Instance);
    newInst.setDataset(this.m_OutputFormat);
    newInst.setMissing(newInst.classAttribute());
    if (this.m_Classifiers == null) {
        return new double[] { 1 };
    }//from  w  ww.java  2  s  . c  o  m
    if (this.m_Classifiers.length == 1) {
        return this.m_Classifiers[0].distributionForInstance(newInst);
    }
    for (int i = 0; i < this.m_Classifiers.length; i++) {
        if (this.m_Classifiers[i] != null) {
            double[] current = this.m_Classifiers[i].distributionForInstance(newInst);
            for (int j = 0; j < this.m_ClassAttribute.numValues(); j++) {
                if (j == i) {
                    probs[j] += current[1];
                } else {
                    probs[j] += current[0];
                }
            }
        }
    }
    if (Utils.gr(Utils.sum(probs), 0)) {
        Utils.normalize(probs);
        return probs;
    } else {
        return m_ZeroR.distributionForInstance(newInst);
    }
}

From source file:wekimini.DataGenerator.java

private void addToTempInstances(double[] inputs, double[] outputs, boolean[] recordingMask,
        int recordingRound) {
    int thisId = nextID;
    nextID++;//from   w w  w .j a  va2 s .c  o m

    double myVals[] = new double[numMetaData + numInputs + numOutputs];
    myVals[idIndex] = thisId;
    myVals[recordingRoundIndex] = recordingRound;

    Date now = new Date();
    //myVals[timestampIndex] = Double.parseDouble(dateFormat.format(now)); //Error: This gives us scientific notation!

    String pretty = prettyDateFormat.format(now);
    try {
        myVals[timestampIndex] = trainingInputs.attribute(timestampIndex).parseDate(pretty);
        //myVals[timestampIndex] =
    } catch (ParseException ex) {
        myVals[timestampIndex] = 0;
        Logger.getLogger(DataManager.class.getName()).log(Level.SEVERE, null, ex);
    }

    /*for (int i = 0; i < numInputs; i++) {
     myVals[numMetaData + i] = featureVals[i];
     } */
    System.arraycopy(inputs, 0, myVals, numMetaData, inputs.length); //TODO DOUBLECHECK

    /*for (int i = 0; i < numParams; i++) {
     if (isParamDiscrete[i] && (paramVals[i] < 0 || paramVals[i] >= numParamValues[i])) {
     throw new IllegalArgumentException("Invalid value for this discrete parameter");
     }
            
     myVals[numMetaData + numFeatures + i] = paramVals[i];
     } */
    System.arraycopy(outputs, 0, myVals, numMetaData + numInputs, outputs.length);

    Instance in = new Instance(1.0, myVals);
    for (int i = 0; i < recordingMask.length; i++) {
        if (!recordingMask[i]) {
            in.setMissing(numMetaData + numInputs + i);
        } else {
            w.getDataManager().setNumExamplesPerOutput(i, w.getDataManager().getNumExamplesPerOutput(i) + 1);
            // outputInstanceCounts[i]++;
        }
    }
    in.setDataset(tempInstances);
    tempInstances.add(in);
    //setHasInstances(true);
    //fireStateChanged();
    //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

From source file:wekimini.DataGenerator.java

private void addToDummyInstances(double[] inputs, double[] outputs, boolean[] recordingMask,
        int recordingRound) {
    int thisId = nextID;
    nextID++;/*from w ww .  j  a va  2  s.  c o m*/

    double myVals[] = new double[numMetaData + numInputs + numOutputs];
    myVals[idIndex] = thisId;
    myVals[recordingRoundIndex] = recordingRound;

    Date now = new Date();
    //myVals[timestampIndex] = Double.parseDouble(dateFormat.format(now)); //Error: This gives us scientific notation!

    String pretty = prettyDateFormat.format(now);
    try {
        myVals[timestampIndex] = trainingInputs.attribute(timestampIndex).parseDate(pretty);
        //myVals[timestampIndex] =
    } catch (ParseException ex) {
        myVals[timestampIndex] = 0;
        Logger.getLogger(DataManager.class.getName()).log(Level.SEVERE, null, ex);
    }

    /*for (int i = 0; i < numInputs; i++) {
     myVals[numMetaData + i] = featureVals[i];
     } */
    System.arraycopy(inputs, 0, myVals, numMetaData, inputs.length); //TODO DOUBLECHECK

    /*for (int i = 0; i < numParams; i++) {
     if (isParamDiscrete[i] && (paramVals[i] < 0 || paramVals[i] >= numParamValues[i])) {
     throw new IllegalArgumentException("Invalid value for this discrete parameter");
     }
            
     myVals[numMetaData + numFeatures + i] = paramVals[i];
     } */
    System.arraycopy(outputs, 0, myVals, numMetaData + numInputs, outputs.length);

    Instance in = new Instance(1.0, myVals);
    for (int i = 0; i < recordingMask.length; i++) {
        if (!recordingMask[i]) {
            in.setMissing(numMetaData + numInputs + i);
        } else {
            w.getDataManager().setNumExamplesPerOutput(i, w.getDataManager().getNumExamplesPerOutput(i) + 1);
            // outputInstanceCounts[i]++;
        }
    }
    in.setDataset(dummyInstances);
    dummyInstances.add(in);
    //setHasInstances(true);
    //fireStateChanged();
    //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

From source file:wekimini.DataManager.java

public void addToTraining(double[] inputs, double[] outputs, boolean[] recordingMask, int recordingRound) {

    int thisId = nextID;
    nextID++;//from ww  w . j a va2s. c o m

    double myVals[] = new double[numMetaData + numInputs + numOutputs];
    myVals[idIndex] = thisId;
    myVals[recordingRoundIndex] = recordingRound;

    Date now = new Date();
    //myVals[timestampIndex] = Double.parseDouble(dateFormat.format(now)); //Error: This gives us scientific notation!

    String pretty = prettyDateFormat.format(now);
    try {
        myVals[timestampIndex] = allInstances.attribute(timestampIndex).parseDate(pretty);
        //myVals[timestampIndex] =
    } catch (ParseException ex) {
        myVals[timestampIndex] = 0;
        Logger.getLogger(DataManager.class.getName()).log(Level.SEVERE, null, ex);
    }

    /*for (int i = 0; i < numInputs; i++) {
     myVals[numMetaData + i] = featureVals[i];
     } */
    System.arraycopy(inputs, 0, myVals, numMetaData, inputs.length); //TODO DOUBLECHECK

    /*for (int i = 0; i < numParams; i++) {
     if (isParamDiscrete[i] && (paramVals[i] < 0 || paramVals[i] >= numParamValues[i])) {
     throw new IllegalArgumentException("Invalid value for this discrete parameter");
     }
            
     myVals[numMetaData + numFeatures + i] = paramVals[i];
     } */
    System.arraycopy(outputs, 0, myVals, numMetaData + numInputs, outputs.length);

    Instance in = new Instance(1.0, myVals);
    for (int i = 0; i < recordingMask.length; i++) {
        if (!recordingMask[i]) {
            in.setMissing(numMetaData + numInputs + i);
        } else {
            setNumExamplesPerOutput(i, getNumExamplesPerOutput(i) + 1);
            // outputInstanceCounts[i]++;
        }
    }
    in.setDataset(allInstances);
    allInstances.add(in);
    setHasInstances(true);
    fireStateChanged();
    //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

From source file:wekimini.DataManager.java

public void setOutputMissing(int index, int outputNum) {
    //if (paramNum >= 0 && paramNum < numParams) {
    Instance i = allInstances.instance(index);
    if (!i.isMissing(numMetaData + numInputs + outputNum)) {
        i.setMissing(numMetaData + numInputs + outputNum);
        setNumExamplesPerOutput(outputNum, getNumExamplesPerOutput(outputNum) - 1);
    }/*from   ww  w  . j  a  va 2s .c  om*/

    //Need to recompute numOutputs!
    //}
}