Ejemplo n.º 1
0
 /// <summary>
 /// Prints Weka data set
 /// </summary>
 /// <param name="wekaDataset"> Instances Weka data set </param>
 private static void printDataSet(Instances wekaDataset)
 {
     Console.WriteLine("Weka dataset");
     System.Collections.IEnumerator en = wekaDataset.enumerateInstances();
     while (en.hasMoreElements())
     {
         Instance instance = (Instance)en.nextElement();
         double[] values   = instance.toDoubleArray();
         Console.WriteLine(Arrays.ToString(values));
         Console.WriteLine(instance.stringValue(instance.classIndex()));
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// {@inheritDoc}
        /// @since 1.2
        /// </summary>
        public virtual bool Contains(double x, double y)
        {
            if (!CachedBounds.Contains(x, y))
            {
                return(false);
            }
            System.Collections.IEnumerator enum_ = Curves.elements();
            int crossings = 0;

            while (enum_.hasMoreElements())
            {
                Curve c = (Curve)enum_.nextElement();
                crossings += c.crossingsFor(x, y);
            }
            return((crossings & 1) == 1);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Converts Weka data set to Neuroph data set </summary>
        /// <param name="wekaDataset"> Instances Weka data set </param>
        /// <param name="numInputs"> int Number of inputs </param>
        /// <param name="numOutputs"> int Number of outputs </param>
        /// <returns> Neuroph data set </returns>
        public static DataSet convertWekaToNeurophDataset(Instances wekaDataset, int numInputs, int numOutputs)
        {
            if (numInputs <= 0)
            {
                throw new System.ArgumentException("Number of inputs  in DataSet cannot be zero or negative!");
            }

            if (numOutputs < 0)
            {
                throw new System.ArgumentException("Number of outputs  in DataSet cannot be negative!");
            }

            if (numOutputs + numInputs < wekaDataset.numAttributes())
            {
                throw new System.ArgumentException("Number of outputs and inputs should be equal to number of attributes from data set!");
            }

            // create supervised or unsupervised data set that will be returned
            DataSet neurophDataset = null;

            if (numOutputs > 0)
            {
                neurophDataset = new DataSet(numInputs, numOutputs);
            }
            else
            {
                neurophDataset = new DataSet(numInputs);
            }

            List <double?> classValues = new List <double?>();

            // get all different class values (as ints) from weka dataset
            foreach (Instance inst in wekaDataset)
            {
                double?classDouble = inst.classValue();
                if (!classValues.Contains(classDouble))
                {
                    classValues.Add(classDouble);
                }
            }

            System.Collections.IEnumerator en = wekaDataset.enumerateInstances();
            while (en.hasMoreElements())             // iterate all instances from dataset
            {
                Instance instance = (Instance)en.nextElement();
                double[] values   = instance.toDoubleArray(); // get all the values from current instance
                if (numOutputs == 0)                          // add unsupervised row
                {
                    neurophDataset.addRow(values);
                }                 // add supervised row
                else
                {
                    double[] inputs  = new double[numInputs];
                    double[] outputs = new double[numOutputs];

                    // set inputs
                    for (int k = 0; k < values.Length; k++)
                    {
                        if (k < numInputs)
                        {
                            inputs[k] = values[k];
                        }
                    }

                    // set binary values for class outputs
                    int k = 0;
                    foreach (double?entry in classValues)
                    {
                        if ((double)entry == instance.classValue())                         // if the
                        {
                            outputs[k] = 1;
                        }
                        else
                        {
                            outputs[k] = 0;
                        }
                        k++;
                    }

                    DataSetRow row = new DataSetRow(inputs, outputs);
                    row.Label = instance.stringValue(instance.classIndex());
                    neurophDataset.addRow(row);
                }
            }

            return(neurophDataset);
        }