performs the rl update at a state
| 915 | |
| 916 | // performs the rl update at a state |
| 917 | void rl_perform_update(agent* thisAgent, double op_value, bool op_rl, Symbol* goal, bool update_efr) |
| 918 | { |
| 919 | bool using_gaps = (thisAgent->rl_params->temporal_extension->get_value() == on); |
| 920 | |
| 921 | if (!using_gaps || op_rl) |
| 922 | { |
| 923 | rl_data* data = goal->id->rl_info; |
| 924 | |
| 925 | if (!data->prev_op_rl_rules->empty()) |
| 926 | { |
| 927 | rl_et_map::iterator iter; |
| 928 | double alpha = thisAgent->rl_params->learning_rate->get_value(); |
| 929 | double lambda = thisAgent->rl_params->et_decay_rate->get_value(); |
| 930 | double gamma = thisAgent->rl_params->discount_rate->get_value(); |
| 931 | double tolerance = thisAgent->rl_params->et_tolerance->get_value(); |
| 932 | double theta = thisAgent->rl_params->meta_learning_rate->get_value(); |
| 933 | |
| 934 | // if temporal_discount is off, don't discount for gaps |
| 935 | unsigned int effective_age = data->hrl_age + 1; |
| 936 | if (thisAgent->rl_params->temporal_discount->get_value() == on) |
| 937 | { |
| 938 | effective_age += data->gap_age; |
| 939 | } |
| 940 | |
| 941 | double discount = pow(gamma, static_cast< double >(effective_age)); |
| 942 | |
| 943 | // notify of gap closure |
| 944 | if (data->gap_age && using_gaps && thisAgent->sysparams[ TRACE_RL_SYSPARAM ]) |
| 945 | { |
| 946 | char buf[256]; |
| 947 | SNPRINTF(buf, 254, "gap ended (%c%llu)", goal->id->name_letter, static_cast<long long unsigned>(goal->id->name_number)); |
| 948 | |
| 949 | print(thisAgent, buf); |
| 950 | xml_generate_warning(thisAgent, buf); |
| 951 | } |
| 952 | |
| 953 | // Iterate through eligibility_traces, decay traces. If less than TOLERANCE, remove from map. |
| 954 | if (lambda == 0) |
| 955 | { |
| 956 | if (!data->eligibility_traces->empty()) |
| 957 | { |
| 958 | data->eligibility_traces->clear(); |
| 959 | } |
| 960 | } |
| 961 | else |
| 962 | { |
| 963 | for (iter = data->eligibility_traces->begin(); iter != data->eligibility_traces->end();) |
| 964 | { |
| 965 | iter->second *= lambda; |
| 966 | iter->second *= discount; |
| 967 | if (iter->second < tolerance) |
| 968 | { |
| 969 | data->eligibility_traces->erase(iter++); |
| 970 | } |
| 971 | else |
| 972 | { |
| 973 | ++iter; |
| 974 | } |
no test coverage detected