AIMA.Core.Learning.Framework.Example.getAttributeValueAsDouble C# (CSharp) Method

getAttributeValueAsDouble() public method

public getAttributeValueAsDouble ( String attributeName ) : double
attributeName String
return double
	public double getAttributeValueAsDouble(String attributeName) {
        LearningAttribute attribute = attributes[attributeName];
		if (attribute == null || !(attribute is NumericAttribute)) {
			throw new ApplicationException    (
					"cannot return numerical value for non numeric attribute");
		}
		return ((NumericAttribute) attribute).valueAsDouble();
	}

Usage Example

        public Pair<List<Double>, List<Double>> numerize(Example e)
        {
            List<Double> input = new List<Double>();
            List<Double> desiredOutput = new List<Double>();

            double sepal_length = e.getAttributeValueAsDouble("sepal_length");
            double sepal_width = e.getAttributeValueAsDouble("sepal_width");
            double petal_length = e.getAttributeValueAsDouble("petal_length");
            double petal_width = e.getAttributeValueAsDouble("petal_width");

            input.Add(sepal_length);
            input.Add(sepal_width);
            input.Add(petal_length);
            input.Add(petal_width);

            String plant_category_string = e
                    .getAttributeValueAsString("plant_category");

            desiredOutput = convertCategoryToListOfDoubles(plant_category_string);

            Pair<List<Double>, List<Double>> io = new Pair<List<Double>, List<Double>>(
                    input, desiredOutput);

            return io;
        }