예제 #1
0
        /**
         * <summary> Adds the attribute types according to given {@link Instance}. For instance, if the attribute type of given {@link Instance}
         * is a Discrete type, it than adds a discrete attribute type to the list of attribute types.</summary>
         *
         * <param name="instance">{@link Instance} input.</param>
         */
        private void SetDefinition(Instance.Instance instance)
        {
            var attributeTypes = new List <AttributeType>();

            for (var i = 0; i < instance.AttributeSize(); i++)
            {
                if (instance.GetAttribute(i) is BinaryAttribute)
                {
                    attributeTypes.Add(AttributeType.BINARY);
                }
                else
                {
                    if (instance.GetAttribute(i) is DiscreteIndexedAttribute)
                    {
                        attributeTypes.Add(AttributeType.DISCRETE_INDEXED);
                    }
                    else
                    {
                        if (instance.GetAttribute(i) is DiscreteAttribute)
                        {
                            attributeTypes.Add(AttributeType.DISCRETE);
                        }
                        else
                        {
                            if (instance.GetAttribute(i) is ContinuousAttribute)
                            {
                                attributeTypes.Add(AttributeType.CONTINUOUS);
                            }
                        }
                    }
                }
            }

            _definition = new DataDefinition(attributeTypes);
        }
예제 #2
0
        /**
         * <summary> Constructor for generating a new {@link DataSet} from given {@link File}.</summary>
         *
         * <param name="file">{@link File} to generate {@link DataSet} from.</param>
         */
        public DataSet(string fileName)
        {
            var i = 0;

            _instances  = new InstanceList.InstanceList();
            _definition = new DataDefinition();
            var input = new StreamReader(fileName);

            while (!input.EndOfStream)
            {
                var instanceText = input.ReadLine();
                var attributes   = instanceText.Split(",");
                if (i == 0)
                {
                    for (var j = 0; j < attributes.Length - 1; j++)
                    {
                        try
                        {
                            double.Parse(attributes[j]);
                            _definition.AddAttribute(AttributeType.CONTINUOUS);
                        }
                        catch (Exception)
                        {
                            _definition.AddAttribute(AttributeType.DISCRETE);
                        }
                    }
                }
                else
                {
                    if (attributes.Length != _definition.AttributeCount() + 1)
                    {
                        continue;
                    }
                }

                Instance.Instance instance;
                if (!attributes[attributes.Length - 1].Contains(";"))
                {
                    instance = new Instance.Instance(attributes[attributes.Length - 1]);
                }
                else
                {
                    var labels = attributes[attributes.Length - 1].Split(";");
                    instance = new CompositeInstance(labels);
                }

                for (var j = 0; j < attributes.Length - 1; j++)
                {
                    switch (_definition.GetAttributeType(j))
                    {
                    case AttributeType.CONTINUOUS:
                        instance.AddAttribute(new ContinuousAttribute(double.Parse(attributes[j])));
                        break;

                    case AttributeType.DISCRETE:
                        instance.AddAttribute(new DiscreteAttribute(attributes[j]));
                        break;
                    }
                }

                if (instance.AttributeSize() == _definition.AttributeCount())
                {
                    _instances.Add(instance);
                }

                i++;
            }

            input.Close();
        }
예제 #3
0
 /**
  * <summary> Constructor for generating a new {@link DataSet} with given {@link DataDefinition}.</summary>
  *
  * <param name="definition">Data definition of the data set.</param>
  */
 public DataSet(DataDefinition definition)
 {
     this._definition = definition;
     _instances       = new InstanceList.InstanceList();
 }
예제 #4
0
 /**
  * <summary> Constructor for generating a new {@link DataSet}.</summary>
  */
 public DataSet()
 {
     _definition = null;
     _instances  = new InstanceList.InstanceList();
 }
예제 #5
0
 /**
  * <summary> Constructor for generating a new {@link DataSet} with a {@link DataDefinition}, from a {@link File} by using a separator.</summary>
  *
  * <param name="definition">Data definition of the data set.</param>
  * <param name="separator"> Separator character which separates the attribute values in the data file.</param>
  * <param name="fileName">  Name of the data set file.</param>
  */
 public DataSet(DataDefinition definition, string separator, string fileName)
 {
     this._definition = definition;
     _instances       = new InstanceList.InstanceList(definition, separator, fileName);
 }