caio-davi / PSO-PINN

Physics-Informed Neural Networks Trained with Particle Swarm Optimization
MIT License
17 stars 7 forks source link

Adding attributes to class pso #5

Open engsbk opened 2 years ago

engsbk commented 2 years ago

Hello @caio-davi,

I hope you can assist me with this simple issue (but for some reason won't resolve). I tried adding an attribute to the class pso in pso_adam.py. In other words, I added self.weight_flag to the list of variables in __init__(), but whenever I try to use it inside fitness_fn(self, x) or any other function, the compiler throws this error:

'pso' object has no attribute 'weight_flag'

I checked my indentation and I tried multiple editors. I also tried renaming the class to 'pso_adam'. None of these trials resolved the error, but I can't seem to know what is causing the error.

My question is: If I want tot add more attributes to the pso class in pso_adam.py, what is the best way to do it?

Thanks again for this great work.

caio-davi commented 2 years ago

It seems the right approach. The fitness_fn function is called during the initialization, though. Make sure to declare the new attribute before calling it.