fix peaks in linef
[imago.git] / src / ransac.py
index cc16d2f..6557ea4 100644 (file)
@@ -48,6 +48,9 @@ class Linear_model:
             score += min(d, dist)
         return score, cons
 
+    def remove(self, data):
+        self.data = list(set(self.data) - set(data))
+
 def iterate(model, distance):
     score = float("inf")
     consensual = model.initial()
@@ -78,20 +81,13 @@ def estimate(data, dist, k, modelClass=Linear_model, model=None):
 
     return estimate, consensual
 
-def ransac_duo(data, dist, k, mk, modelClass=Linear_model):
-    cons = []
-    for i in xrange(mk):
-        model, cons = estimate(set(data) - set(cons), dist, k, modelClass)
-    return (model, cons), estimate(set(data) - set(cons), dist, k, modelClass)
-
 def ransac_multi(m, data, dist, k, modelClass=Linear_model, model=None):
+    if not model:
+        model = modelClass(data)
     ests = []
     cons = []
     for i in xrange(m):
         est, cons_new = estimate(None, dist, k, model=model)
         model.remove(cons_new)
-        ests.append(est)
+        ests.append((est, cons_new))
     return ests
-
-        
-