These perks can only be acquired by maxing out the affinity of various companions. These perks will stay with you permanently once unlocked so you can "retire" a companion after getting his/her perk if you want to. The only difference here is Dogmeat since his companion perk is part of the player's default perk list. (See Charisma > Attack Dog)