Exemple #1
0
    def DerCost(self, GD, Cont):
        u1 = np.ones(self.Ntrans)
        u2 = np.zeros(self.Ntrans)

        # Matrix with derivative wrt 1st component of covariance matrix
        Partial1_covMat = usefun.Make_der_CovMat(np.transpose(np.array(GD)),
                                                 np.transpose(np.array(GD)),
                                                 np.array([u1, u2]),
                                                 self.partialder2kernel)

        # Matrix with derivative wrt 2nd component of covariance matrix
        Partial2_covMat = usefun.Make_der_CovMat(np.transpose(np.array(GD)),
                                                 np.transpose(np.array(GD)),
                                                 np.array([u2, u1]),
                                                 self.partialder2kernel)

        der_1 = sum([
            np.dot(Partial1_covMat, Contu) * Contu
            for Contu in np.transpose(np.array(Cont))
        ])
        der_2 = sum([
            np.dot(Partial2_covMat, Contu) * Contu
            for Contu in np.transpose(np.array(Cont))
        ])

        return self.GDspace.element(np.transpose(np.array([der_1, der_2])))
Exemple #2
0
    def __init__(self, DomainField, Ntrans, kernel, partialderdim1kernel,
                 partialder2kernel):
        """Initialize a new instance.
        DomainField : space on wich vector fields will be defined
        Ntrans : number of translations
        Kernel : kernel
        partialderdim1kernel :  partial derivative with respect to one componenet of
        the 1st component, 
         to be used as partialder2kernel(x, y, d) where d is in [|0, dim-1|]
        partialder2kernel : partial derivative with respect to 2nd component, 
         to be used as partialder2kernel(x, y, u) with x and y points, and u 
         vectors for differentiation (same number of vectors as the number of 
         points for y)
        """

        self.Ntrans = Ntrans
        self.kernel = kernel
        self.partialderdim1kernel = partialderdim1kernel
        self.partialder2kernel = partialder2kernel
        self.dim = DomainField.ndim
        self.get_unstructured_op = usefun.get_from_structured_to_unstructured(
            DomainField, kernel)
        self.gradient_op = Gradient(DomainField)
        GDspace = odl.ProductSpace(odl.space.rn(self.dim), self.Ntrans)
        Contspace = odl.ProductSpace(odl.space.rn(self.dim), self.Ntrans)
        self.dimCont = self.Ntrans * self.dim

        super().__init__(GDspace, Contspace, DomainField)
Exemple #3
0
 def ComputeFieldEvaluate(self, o, h, points):
     " points is a list of points "
     points = np.array(points)
     mat = usefun.make_covariance_mixte_matrix(
         np.transpose(np.array(points)), np.transpose(np.array(o)),
         self.kernel)
     return np.dot(mat, np.array(h))
Exemple #4
0
 def ComputeFieldEvaluateDer(self, o, h, points, vectors):
     points = np.array(points)
     vectors = np.array(vectors)
     mat = usefun.Make_der_CovMat(np.transpose(np.array(o)),
                                  np.transpose(points),
                                  np.transpose(vectors),
                                  self.partialder2kernel)
     return np.dot(mat, np.array(h))
Exemple #5
0
    def Cost(self, GD, Cont):
        mat = usefun.make_covariance_matrix(np.transpose(np.array(GD)),
                                            self.kernel)
        energy = sum([
            np.dot(np.dot(np.transpose(np.array(Cont))[u], mat),
                   np.transpose(np.array(Cont))[u]) for u in range(self.dim)
        ])

        return float(energy)
    def __init__(self, DomainField, GDspace, NbGD, kernel,
                 partialderdim1kernel, partialder2kernel, pointfunctionlist,
                 pointfunctiondifflist, vectorfunctionlist,
                 vectorfunctiondifflist):
        """Initialize a new instance.
        DomainField : space on wich vector fields will be defined
        dimGD = dimension of GDspace
        Kernel : kernel
        partialderdim1kernel :  partial derivative with respect to one componenet of
        the 1st component, 
         to be used as partialder2kernel(x, y, d) where d is in [|0, dim-1|]
        partialder2kernel : partial derivative with respect to 2nd component, 
         to be used as partialder2kernel(x, y, u) with x and y points, and u 
         vectors for differentiation (same number of vectors as the number of 
         points for y)
         get_columnvector_gd : function that takes a GD and return a vector
             so that when we multiply it by a point/vectorfunctiondiff we
             obtain its differential
         get_spaceelement_gd : function, inverse of get_columnvector_gd 
             (takes a vector and return the corresponding GD)
        pointfunctionlist : list of functions, each one associating a list of
              points to a geometrical descriptor
        pointfunctiondifflist : list of functions, each one associating a list of
              matrix to a geometrical descriptor, the k-th matrix is the differential
              of the k-th point with respect to the geometrical descriptor
        vectorfunctionlist : list of functions, each one associating a list of
              vectors to a geometrical descriptor
        vectorfunctiondifflist : list of functions, each one associating a list of
              matrix to a geometrical descriptor, the k-th matrix is the differential
              of the k-th vector with respect to the geometrical descriptor
              
        """

        self.kernel = kernel
        self.partialderdim1kernel = partialderdim1kernel
        self.partialder2kernel = partialder2kernel
        self.dim = DomainField.ndim
        self.NbGD = NbGD
        self.dimGD = NbGD * self.dim
        self.get_unstructured_op = usefun.get_from_structured_to_unstructured(
            DomainField, kernel)
        self.gradient_op = Gradient(DomainField)
        self.ptfun = pointfunctionlist
        self.vecfun = vectorfunctionlist
        self.ptfundiff = pointfunctiondifflist
        self.vecfundiff = vectorfunctiondifflist
        self.dimCont = len(pointfunctionlist)

        Contspace = odl.space.rn(self.dimCont)

        super().__init__(GDspace, Contspace, DomainField)
    def ComputeFieldEvaluateDer(self, o, h, points, vectors):
        points = np.array(points)
        vectors = np.array(vectors)

        mat_list = [
            usefun.Make_der_CovMat(np.transpose(funi(o)), np.transpose(points),
                                   np.transpose(vectors),
                                   self.partialder2kernel)
            for funi in self.ptfun
        ]
        return sum([
            np.dot(mat_list[i], h[i] * np.array(self.vecfun[i](o)))
            for i in range(self.dimCont)
        ])
    def ComputeFieldEvaluate(self, o, h, points):
        " points is a list of points "
        points = np.array(points)

        mat_list = [
            usefun.make_covariance_mixte_matrix(np.transpose(points),
                                                np.transpose(funi(o)),
                                                self.kernel)
            for funi in self.ptfun
        ]

        return sum([
            np.dot(mat_list[i], h[i] * np.array(self.vecfun[i](o)))
            for i in range(self.dimCont)
        ])
Exemple #9
0
 def InvCo(self, GD):
     mat = usefun.make_covariance_matrix(np.transpose(np.array(GD)),
                                         self.kernel)
     return np.kron(np.linalg.inv(mat), np.identity(self.dim))
Exemple #10
0
 def AdjointApply(self, GD, Mom):
     return usefun.Dirac(np.array(GD), np.array(Mom), self.domain)
Exemple #11
0
 def CreateStructuredFromGDCont(self, o, h):
     return usefun.create_structured(np.transpose(np.array(o)),
                                     np.transpose(np.array(h)))
 def CreateStructuredListFromGD(self, o):
     return [
         usefun.create_structured(np.transpose(self.ptfun[i](o)),
                                  np.transpose(self.vecfun[i](o)))
         for i in range(self.dimCont)
     ]