self-learn algorithm implemenation