How can it be that the first loop works fine, while the second loop gives a segfault. In my understanding, they should be the same.
for(auto& param : actor->parameters()){
std::cout<<"Param"<<std::endl;
std::cout<<param.data()<<std::endl;
}
for(auto it = actor->parameters().begin();it!=actor->parameters().end();++it)
{
std::cout<<"Iterator Param"<<std::endl;
std::cout<<it->data()<<std::endl;
}
I want to copy parameters between the policy net and the target net, as follows:
auto it=actor->parameters().begin();
for(auto target_it = actor_target->parameters().begin();target_it!=actor_target->parameters().end();++target_it){
target_it->data().copy_(it->data()*tau_+target_it->data()*(1.0-tau_));
++it;
}
For which the python code would be:
# update target networks
for target_param, param in zip(self.actor_target.parameters(), self.actor.parameters()):
target_param.data.copy_(param.data * self.tau + target_param.data * (1.0 - self.tau))