public String predict(Example e)
        {
            String prediction = "~" + e.targetValue();
            if (null != currentBestHypothesis)
            {
                FOLExample etp = new FOLExample(folDSDomain, e, 0);
                kb.clear();
                kb.tell(etp.getDescription());
                kb.tell(currentBestHypothesis.getHypothesis());
                InferenceResult ir = kb.ask(etp.getClassification());
                if (ir.isTrue())
                {
                    if (trueGoalValue.Equals(e.targetValue()))
                    {
                        prediction = e.targetValue();
                    }
                }
                else if (ir.isPossiblyFalse() || ir.isUnknownDueToTimeout())
                {
                    if (!trueGoalValue.Equals(e.targetValue()))
                    {
                        prediction = e.targetValue();
                    }
                }
            }

            return prediction;
        }
        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;
        }
        //
        // PRIVATE METHODS
        //

        private String weightedMajority(Example e)
        {
            List<String> targetValues = dataSet.getPossibleAttributeValues(dataSet
                    .getTargetAttributeName());

            Table<String, Learner, Double> table = createTargetValueLearnerTable(
                    targetValues, e);
            return getTargetValueWithTheMaximumVotes(targetValues, table);
        }
 public String predict(Example e)
 {
     if (decisionList == null)
     {
         throw new ApplicationException(
                 "learner has not been trained with dataset yet!");
     }
     return decisionList.predict(e);
 }
Exemple #5
0
 public DataSet removeExample(Example e)
 {
     DataSet ds = new DataSet(specification);
     foreach (Example eg in examples)
     {
         if (!(e.Equals(eg)))
         {
             ds.add(eg);
         }
     }
     return ds;
 }
Exemple #6
0
 public bool matches(Example e)
 {
     foreach (String key in attrValues.Keys)
     {
         if (!(attrValues[key].Equals(e.getAttributeValueAsString(key))))
         {
             return false;
         }
     }
     return true;
     // return e.targetValue().Equals(targetValue);
 }
Exemple #7
0
 public virtual Object predict(Example e)
 {
     String attrValue = e.getAttributeValueAsString(attributeName);
     if (nodes.ContainsKey(attrValue))
     {
         return nodes[attrValue].predict(e);
     }
     else
     {
         throw new ApplicationException("no node exists for attribute value "
                 + attrValue);
     }
 }
Exemple #8
0
 public String predict(Example example)
 {
     if (tests.Count == 0)
     {
         return negative;
     }
     foreach (DLTest test in tests)
     {
         if (test.matches(example))
         {
             return testOutcomes[test];
         }
     }
     return negative;
 }
 public String predict(Example e)
 {
     return result;
 }
Exemple #10
0
 public void add(Example e)
 {
     examples.Add(e);
 }
Exemple #11
0
	//
	// PUBLIC METHODS
	//
	public FOLExample(FOLDataSetDomain folDSDomain, Example example, int egNo) {
		this.folDSDomain = folDSDomain;
		this.example = example;
		this.egNo = egNo;
		constructFOLEg();
	}
 public String predict(Example e)
 {
     return (String)tree.predict(e);
 }
        private Table<String, Learner, Double> createTargetValueLearnerTable(
                List<String> targetValues, Example e) {
		// create a table with target-attribute values as rows and learners as
		// columns and cells containing the weighted votes of each Learner for a
		// target value
		// Learner1 Learner2 Laerner3 .......
		// Yes 0.83 0.5 0
		// No 0 0 0.6

		Table<String, Learner, Double> table = new Table<String, Learner, Double>(
				targetValues, learners);
		// initialize table
		foreach (Learner l in learners) {
			foreach (String s in targetValues) {
				table.set(s, l, 0.0);
			}
		}
		foreach (Learner learner in learners) {
			String predictedValue = learner.predict(e);
			foreach (String v in targetValues) {
				if (predictedValue.Equals(v)) {
					table.set(v, learner, table.get(v, learner)
							+ learnerWeights[learner] * 1);
				}
			}
		}
		return table;
	}
 public String predict(Example e)
 {
     return weightedMajority(e);
 }
 public override Object predict(Example e)
 {
     return value;
 }