1. A method for localization and mapping in a system comprising a processor and a camera, wherein the processor is configured to generate a graph with a plurality of pose nodes and a plurality of edges; the method comprising: updating the graph if the number of pose nodes in the graph exceeds a first threshold, comprising: i) identifying a pose node directly linked to associated Markov blanket nodes with two or more incident edges; ii) composing said incident edges to generate one or more new edges between pairs of said associated Markov blanket nodes; and iii) removing the identified pose node and said two or more incident edges; removing at least one edge of said plurality of edges present in the graph if the total number of edges in the graph exceeds a second threshold; and updating an estimate of a location of the remaining pose nodes based at least in part on the plurality of edges present in the graph.