Astroinformatics of galaxies and quasars: a new general method for photometric redshifts estimation