Plasticity in connections between neurons allows learning and adaptation, but it also allows noise to degrade the function of a network. Ongoing network self-repair is thus necessary. We describe a method to derive spike-timing-dependent plasticity rules for self-repair, based on the firing patterns of a functioning network. These plasticity rules for self-repair also provide the basis for unsupervised learning of new tasks. The particular plasticity rule derived for a network depends on the network and task. Here, self-repair is illustrated for a model of the mammalian olfactory system in which the computational task is that of odor recognition. In this olfactory example, the derived rule has qualitative similarity with experimental results seen in spike-timing-dependent plasticity. Unsupervised learning of new tasks by using the derived self-repair rule is demonstrated by learning to recognize new odors.