| … | … | @@ -45,7 +45,7 @@ TruthValuePtr MixtureModel::operator()() const |
| 45 | 45 | { |
| 46 | 46 | // Don't bother mixing if there's only one TV |
| 47 | 47 | if (models.size() == 1) |
| 48 | return (*models.begin())->getTruthValue(); | |
| 48 | return TruthValueCast((*models.begin())->getValue(truth_key())); | |
| 49 | 49 | |
| 50 | 50 | std::vector<TruthValuePtr> tvs; |
| 51 | 51 | std::vector<double> weights; |
| … | … | @@ -53,7 +53,7 @@ TruthValuePtr MixtureModel::operator()() const |
| 53 | 53 | double weight = prior_estimate(model) * beta_factor(model); |
| 54 | 54 | LAZY_URE_LOG_FINE << "MixtureModel::operator model = " << model->id_to_string() |
| 55 | 55 | << ", weight = " << weight; |
| 56 | tvs.push_back(model->getTruthValue()); | |
| 56 | tvs.push_back(TruthValueCast(model->getValue(truth_key()))); | |
| 57 | 57 | weights.push_back(weight); |
| 58 | 58 | } |
| 59 | 59 | return weighted_average(tvs, weights); |
| … | … | @@ -95,7 +95,7 @@ TruthValuePtr MixtureModel::weighted_average(const std::vector<TruthValuePtr>& t |
| 95 | 95 | |
| 96 | 96 | double MixtureModel::beta_factor(const Handle& model) const |
| 97 | 97 | { |
| 98 | BetaDistribution beta_dist(model->getTruthValue()); | |
| 98 | BetaDistribution beta_dist(TruthValueCast(model->getValue(truth_key()))); | |
| 99 | 99 | double factor = boost::math::beta(beta_dist.alpha(), beta_dist.beta()); |
| 100 | 100 | LAZY_URE_LOG_FINE << "MixtureModel::beta_factor factor = " << factor; |
| 101 | 101 | return factor; |
| … | … | @@ -107,7 +107,7 @@ double MixtureModel::prior_estimate(const Handle& model) const |
| 107 | 107 | |
| 108 | 108 | HandleSet all_atoms(get_all_uniq_atoms(model)); |
| 109 | 109 | double partial_length = all_atoms.size(), |
| 110 | remain_data_size = data_set_size - model->getTruthValue()->get_count(), | |
| 110 | remain_data_size = data_set_size - TruthValueCast(model->getValue(truth_key()))->get_count(), | |
| 111 | 111 | kestimate = kolmogorov_estimate(remain_data_size); |
| 112 | 112 | |
| 113 | 113 | LAZY_URE_LOG_FINE << "MixtureModel::prior_estimate " |
| … | … | @@ -135,6 +135,6 @@ double MixtureModel::infer_data_set_size() const |
| 135 | 135 | { |
| 136 | 136 | double max_count = 0.0; |
| 137 | 137 | for (const Handle& model : models) |
| 138 | max_count = std::max(max_count, model->getTruthValue()->get_count()); | |
| 138 | max_count = std::max(max_count, TruthValueCast(model->getValue(truth_key()))->get_count()); | |
| 139 | 139 | return max_count; |
| 140 | 140 | } |
| … | … | @@ -219,7 +219,7 @@ void Rule::init(const Handle& rule_alias, const Handle& rule, const Handle& rbs) |
| 219 | 219 | _rbs = rbs; |
| 220 | 220 | AtomSpace& as = *rule_alias->getAtomSpace(); |
| 221 | 221 | Handle ml = as.add_link(MEMBER_LINK, rule_alias, rbs); |
| 222 | _tv = ml->getTruthValue(); | |
| 222 | _tv = TruthValueCast(ml->getValue(truth_key())); | |
| 223 | 223 | |
| 224 | 224 | verify_rule(); |
| 225 | 225 | } |
| … | … | @@ -310,7 +310,7 @@ bool UREConfig::fetch_bool_param(const string& pred_name, |
| 310 | 310 | Handle eval = _as.get_link(EVALUATION_LINK, |
| 311 | 311 | std::move(HandleSeq({pred, input}))); |
| 312 | 312 | if (eval) { |
| 313 | bool value = eval->getTruthValue()->get_mean() > 0.5; | |
| 313 | bool value = TruthValueCast(eval->getValue(truth_key()))->get_mean() > 0.5; | |
| 314 | 314 | log_param_value(input, pred_name, value); |
| 315 | 315 | return value; |
| 316 | 316 | } |
| … | … | @@ -33,7 +33,7 @@ BITNodeFitness::BITNodeFitness(FitnessType ft) : type(ft) |
| 33 | 33 | switch(type) { |
| 34 | 34 | case (MaximizeConfidence): |
| 35 | 35 | function = [](const BITNode& bitnode) { |
| 36 | return bitnode.body->getTruthValue()->get_confidence(); | |
| 36 | return TruthValueCast(bitnode.body->getValue(truth_key()))->get_confidence(); | |
| 37 | 37 | }; |
| 38 | 38 | lower = 0; |
| 39 | 39 | upper = 1; |
| … | … | @@ -99,7 +99,7 @@ void TraceRecorder::proof(const Handle& andbit_fcs, const Handle& target_result) |
| 99 | 99 | { |
| 100 | 100 | add_evaluation(_proof_predicate, |
| 101 | 101 | dont_exec(andbit_fcs), target_result, |
| 102 | target_result->getTruthValue()); | |
| 102 | TruthValueCast(target_result->getValue(truth_key()))); | |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | Handle TraceRecorder::dont_exec(const Handle& h) |
| … | … | @@ -118,7 +118,7 @@ Handle TraceRecorder::add_execution(const Handle& schema, |
| 118 | 118 | return Handle::UNDEFINED; |
| 119 | 119 | |
| 120 | 120 | Handle execution = _trace_as->add_link(EXECUTION_LINK, schema, input, output); |
| 121 | execution->setTruthValue(tv); | |
| 121 | execution->setValue(truth_key(), tv); | |
| 122 | 122 | return execution; |
| 123 | 123 | } |
| 124 | 124 | |
| … | … | @@ -144,7 +144,7 @@ Handle TraceRecorder::add_evaluation(const Handle& predicate, |
| 144 | 144 | return Handle::UNDEFINED; |
| 145 | 145 | |
| 146 | 146 | Handle evaluation = _trace_as->add_link(EVALUATION_LINK, predicate, argument); |
| 147 | evaluation->setTruthValue(tv); | |
| 147 | evaluation->setValue(truth_key(), tv); | |
| 148 | 148 | return evaluation; |
| 149 | 149 | } |
| 150 | 150 |
| … | … | @@ -48,7 +48,7 @@ double calculate_weight(const Handle& bdy, double cpx_fctr) |
| 48 | 48 | // TODO: |
| 49 | 49 | // 1. Support more fitness functions |
| 50 | 50 | // 2. Explicitely turn the fitness into a probability of success |
| 51 | TruthValuePtr tv = bdy->getTruthValue(); | |
| 51 | TruthValuePtr tv = TruthValueCast(bdy->getValue(truth_key())); | |
| 52 | 52 | double fitness = tv->get_mean() * tv->get_confidence(); |
| 53 | 53 | return std::max(1e-16, cpx_fctr * fitness); |
| 54 | 54 | } |
| … | … | @@ -237,8 +237,8 @@ void BackwardChainerUTest::test_deduction_tv_query() |
| 237 | 237 | bc.get_config().set_maximum_iterations(10); |
| 238 | 238 | bc.do_chain(); |
| 239 | 239 | |
| 240 | TS_ASSERT_DELTA(target->getTruthValue()->get_mean(), 1, 1e-10); | |
| 241 | TS_ASSERT_DELTA(target->getTruthValue()->get_confidence(), 1, 1e-10); | |
| 240 | TS_ASSERT_DELTA(TruthValueCast(target->getValue(truth_key()))->get_mean(), 1, 1e-10); | |
| 241 | TS_ASSERT_DELTA(TruthValueCast(target->getValue(truth_key()))->get_confidence(), 1, 1e-10); | |
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | void BackwardChainerUTest::test_modus_ponens_tv_query() |
| … | … | @@ -257,8 +257,8 @@ void BackwardChainerUTest::test_modus_ponens_tv_query() |
| 257 | 257 | bc.get_config().set_maximum_iterations(40); |
| 258 | 258 | bc.do_chain(); |
| 259 | 259 | |
| 260 | TS_ASSERT_DELTA(target->getTruthValue()->get_mean(), 1, 1e-10); | |
| 261 | TS_ASSERT_DELTA(target->getTruthValue()->get_confidence(), 1, 1e-10); | |
| 260 | TS_ASSERT_DELTA(TruthValueCast(target->getValue(truth_key()))->get_mean(), 1, 1e-10); | |
| 261 | TS_ASSERT_DELTA(TruthValueCast(target->getValue(truth_key()))->get_confidence(), 1, 1e-10); | |
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | void BackwardChainerUTest::test_conjunction_fuzzy_evaluation_tv_query() |
| … | … | @@ -285,8 +285,8 @@ void BackwardChainerUTest::test_conjunction_fuzzy_evaluation_tv_query() |
| 285 | 285 | bc.get_config().set_maximum_iterations(2); |
| 286 | 286 | bc.do_chain(); |
| 287 | 287 | |
| 288 | TS_ASSERT_DELTA(target->getTruthValue()->get_mean(), 0.4, 1e-6); | |
| 289 | TS_ASSERT_DELTA(target->getTruthValue()->get_confidence(), 0.2, 1e-6); | |
| 288 | TS_ASSERT_DELTA(TruthValueCast(target->getValue(truth_key()))->get_mean(), 0.4, 1e-6); | |
| 289 | TS_ASSERT_DELTA(TruthValueCast(target->getValue(truth_key()))->get_confidence(), 0.2, 1e-6); | |
| 290 | 290 | } |
| 291 | 291 | |
| 292 | 292 | void BackwardChainerUTest::test_conditional_instantiation_1() |
| … | … | @@ -385,8 +385,8 @@ void BackwardChainerUTest::test_conditional_instantiation_tv_query() |
| 385 | 385 | bc.get_config().set_maximum_iterations(20); |
| 386 | 386 | bc.do_chain(); |
| 387 | 387 | |
| 388 | TS_ASSERT_DELTA(target->getTruthValue()->get_mean(), 1, .1); | |
| 389 | TS_ASSERT_DELTA(target->getTruthValue()->get_confidence(), 1, .1); | |
| 388 | TS_ASSERT_DELTA(TruthValueCast(target->getValue(truth_key()))->get_mean(), 1, .1); | |
| 389 | TS_ASSERT_DELTA(TruthValueCast(target->getValue(truth_key()))->get_confidence(), 1, .1); | |
| 390 | 390 | } |
| 391 | 391 | |
| 392 | 392 | // This test is for rules that requires the pattern matcher to look |
| … | … | @@ -474,8 +474,8 @@ void BackwardChainerUTest::test_conditional_partial_instantiation() |
| 474 | 474 | bc.get_config().set_maximum_iterations(5); |
| 475 | 475 | bc.do_chain(); |
| 476 | 476 | |
| 477 | TS_ASSERT_DELTA(target->getTruthValue()->get_mean(), 1, 1e-10); | |
| 478 | TS_ASSERT_DELTA(target->getTruthValue()->get_confidence(), 1, 1e-10); | |
| 477 | TS_ASSERT_DELTA(TruthValueCast(target->getValue(truth_key()))->get_mean(), 1, 1e-10); | |
| 478 | TS_ASSERT_DELTA(TruthValueCast(target->getValue(truth_key()))->get_confidence(), 1, 1e-10); | |
| 479 | 479 | } |
| 480 | 480 | |
| 481 | 481 | void BackwardChainerUTest::test_impossible_criminal() |
| … | … | @@ -553,8 +553,8 @@ void BackwardChainerUTest::test_criminal() |
| 553 | 553 | logger().debug() << "expected = " << oc_to_string(expected); |
| 554 | 554 | |
| 555 | 555 | TS_ASSERT_EQUALS(results, expected); |
| 556 | TS_ASSERT_LESS_THAN(0.9, expected_target->getTruthValue()->get_mean()); | |
| 557 | TS_ASSERT_LESS_THAN(0.9, expected_target->getTruthValue()->get_confidence()); | |
| 556 | TS_ASSERT_LESS_THAN(0.9, expected_TruthValueCast(target->getValue(truth_key()))->get_mean()); | |
| 557 | TS_ASSERT_LESS_THAN(0.9, expected_TruthValueCast(target->getValue(truth_key()))->get_confidence()); | |
| 558 | 558 | |
| 559 | 559 | // Extract traces and return the backward chainer with these |
| 560 | 560 | // traces, which should greatly speed it up. |
| … | … | @@ -610,8 +610,8 @@ void BackwardChainerUTest::test_criminal() |
| 610 | 610 | logger().debug() << "expected = " << oc_to_string(expected); |
| 611 | 611 | |
| 612 | 612 | TS_ASSERT_EQUALS(results, expected); |
| 613 | TS_ASSERT_LESS_THAN(0.9, expected_target->getTruthValue()->get_mean()); | |
| 614 | TS_ASSERT_LESS_THAN(0.9, expected_target->getTruthValue()->get_confidence()); | |
| 613 | TS_ASSERT_LESS_THAN(0.9, expected_TruthValueCast(target->getValue(truth_key()))->get_mean()); | |
| 614 | TS_ASSERT_LESS_THAN(0.9, expected_TruthValueCast(target->getValue(truth_key()))->get_confidence()); | |
| 615 | 615 | } |
| 616 | 616 | |
| 617 | 617 | // Test showing we no longer need the ExecutionOutputLink |
| … | … | @@ -668,8 +668,8 @@ void BackwardChainerUTest::xtest_green_balls() |
| 668 | 668 | |
| 669 | 669 | logger().debug() << "results = " << oc_to_string(results); |
| 670 | 670 | |
| 671 | TS_ASSERT_LESS_THAN(0.9, top_result->getTruthValue()->get_mean()); | |
| 672 | TS_ASSERT_LESS_THAN(0.9, top_result->getTruthValue()->get_confidence()); | |
| 671 | TS_ASSERT_LESS_THAN(0.9, TruthValueCast(top_result->getValue(truth_key()))->get_mean()); | |
| 672 | TS_ASSERT_LESS_THAN(0.9, TruthValueCast(top_result->getValue(truth_key()))->get_confidence()); | |
| 673 | 673 | } |
| 674 | 674 | |
| 675 | 675 | void BackwardChainerUTest::xtest_induction() |
| … | … | @@ -694,10 +694,10 @@ void BackwardChainerUTest::xtest_induction() |
| 694 | 694 | bc.do_chain(); |
| 695 | 695 | |
| 696 | 696 | // TODO: fixme, for that we need to support BIT expansion over meta rule |
| 697 | TS_ASSERT_DELTA(target->getTruthValue()->get_mean(), 1, 1e-10); | |
| 697 | TS_ASSERT_DELTA(TruthValueCast(target->getValue(truth_key()))->get_mean(), 1, 1e-10); | |
| 698 | 698 | // TODO: determine the expected confidence, which depends on the |
| 699 | 699 | // number of instances the induction is based on |
| 700 | TS_ASSERT_DELTA(target->getTruthValue()->get_confidence(), 1, 1e-10); | |
| 700 | TS_ASSERT_DELTA(TruthValueCast(target->getValue(truth_key()))->get_confidence(), 1, 1e-10); | |
| 701 | 701 | } |
| 702 | 702 | |
| 703 | 703 | void BackwardChainerUTest::xtest_focus_set() |
| … | … | @@ -186,11 +186,11 @@ void GradientUTest::set_rbs() |
| 186 | 186 | // Assign GradientSum and its weight to rbs |
| 187 | 187 | TruthValuePtr stv = SimpleTruthValue::createTV(0.4, 1.0); |
| 188 | 188 | Handle GSM = L(MEMBER_LINK, GradientSum, rbs); |
| 189 | GSM->setTruthValue(stv); | |
| 189 | GSM->setValue(truth_key(), stv); | |
| 190 | 190 | |
| 191 | 191 | // Assign GradientAny and its weight to rbs |
| 192 | 192 | Handle GAM = L(MEMBER_LINK, GradientAny, rbs); |
| 193 | GAM->setTruthValue(stv); | |
| 193 | GAM->setValue(truth_key(), stv); | |
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | void GradientUTest::setUp() |