Exemple #1
0
    def silly_random_search(self, initial_trials):
        ## Estimate solution using RANSAC
        bestv = np.Inf ## Smallest value found
        args_f = (self.edgels, self.i_param, self.loss)
        for k in range(initial_trials):
            qtest = random_quaternion().canonical()
            newv = corisco_aux.angle_error(qtest.q, *args_f)

            ## If the value is the best yet, store solution.
            if newv <= bestv:
                bestv = newv
                qopt = qtest
        return qopt
Exemple #2
0
 def target_function_gradient_numeric(self, x, loss=None, dx=1e-6):
     if loss is None:
         loss = self.loss
     args_f = (self.edgels, self.i_param, loss)
             
     return array([
             (corisco_aux.angle_error(x + array([ dx,0,0,0]), *args_f) - 
              corisco_aux.angle_error(x + array([-dx,0,0,0]), *args_f)) / (2 * dx),
             (corisco_aux.angle_error(x + array([0, dx,0,0]), *args_f) - 
              corisco_aux.angle_error(x + array([0,-dx,0,0]), *args_f)) / (2 * dx),
             (corisco_aux.angle_error(x + array([0,0, dx,0]), *args_f) - 
              corisco_aux.angle_error(x + array([0,0,-dx,0]), *args_f)) / (2 * dx),
             (corisco_aux.angle_error(x + array([0,0,0, dx]), *args_f) - 
              corisco_aux.angle_error(x + array([0,0,0,-dx]), *args_f)) / (2 * dx),
             ])
Exemple #3
0
    def ransac_search(self, initial_trials):
        ## Estimate solution using RANSAC
        bestv = np.Inf ## Smallest value found
        args_f = (self.edgels[~isnan(self.edgels[:,2])], self.i_param, self.loss)
        for k in range(initial_trials):
            ## Pick indices of the reference normals. Re-sample until we
            ## get a list of three different values.
            pk_a = np.random.random_integers(0,self.Ned-1)
            pk_b = np.random.random_integers(0,self.Ned-1)
            while pk_b == pk_a:
                pk_b = np.random.random_integers(0,self.Ned-1)
            pk_c = np.random.random_integers(0,self.Ned-1)
            while pk_c == pk_a or pk_c == pk_b:
                pk_c = np.random.random_integers(0,self.Ned-1)

            ## Get the normals with the first two chosen indices, and
            ## calculate a rotation matrix that has the x axis aligned to
            ## them.
            n_a = self.normals[pk_a]
            n_b = self.normals[pk_b]
            vp1 = np.cross(n_a, n_b)
            vp1 = vp1 * (vp1**2).sum()**-0.5
            q1 = aligned_quaternion(vp1)

            ## Pick a new random third norm, and find the rotation to align
            ## the y direction to this edgel.
            n_c = self.normals[pk_c]
            vaux = np.dot(n_c, q1.rot())
            ang = np.arctan2(vaux[1], -vaux[2])
            q2 = Quat(np.sin(ang/2),0,0) * q1 ## The resulting orientation

            ## Find the value of the target function for this sampled
            ## orientation.
            newv = corisco_aux.angle_error(q2.q, *args_f) 

            ## If the value is the best yet, store solution.
            if newv <= bestv :
                bestv = newv
                bpk_a = pk_a
                bpk_b = pk_b
                bpk_c = pk_c
                qopt = q2
        return qopt, bpk_a, bpk_b, bpk_c
Exemple #4
0
def val_f(x,*fargs):
    return corisco_aux.angle_error(x, fargs[0],fargs[1],fargs[2])
Exemple #5
0
 def target_function_value(self, x, loss=None):
     if loss is None:
         loss = self.loss
     args_f = (self.edgels[~isnan(self.edgels[:,2])], self.i_param, loss)
     # args_f = (self.edgels, self.i_param, loss)
     return corisco_aux.angle_error(x, *args_f)