示例#1
0
 def __init__(self, data, vol=None, shift=0, mask=None, conj=None):
     Functional.__init__(self)
     self.x = Variable(data.shape)
     self.f = np.atleast_2d(data)
     self.shift = shift
     self.vol = np.ones(data.shape[1]) if vol is None else vol
     self.mask = np.ones(data.shape[0],
                         dtype=bool) if mask is None else mask
     if conj is None:
         cj_vol = 1.0 / self.vol
         cj_data = np.zeros_like(self.f)
         cj_data[self.mask, :] = np.einsum('ik,k->ik', self.f[self.mask, :],
                                           -self.vol)
         cj_shift = -0.5 * np.einsum('ik,k->', cj_data**2, cj_vol)
         cj_shift -= self.shift
         self.conj = SSD(cj_data,
                         shift=cj_shift,
                         vol=cj_vol,
                         mask=mask,
                         conj=self)
     else:
         self.conj = conj
     prox_shift = np.zeros_like(self.f)
     prox_shift[self.mask, :] = self.f[self.mask, :]
     prox_shift = prox_shift.ravel()
     self._prox = ShiftScaleOp(self.x.size, prox_shift, 0.5, 1.0)
示例#2
0
    def __init__(self, I, If, J, v, b, conj=None):
        """
        Args:
            I : ndarray of bools, shape (nfuns, npoints)
            If : nfuns lists of nregions arrays, shape (nfaces,ndim+1) each
            J : ndarray of ints, shape (nregions, nsubpoints)
            v : ndarray of floats, shape (npoints, ndim)
            b : ndarray of floats, shape (nfuns, npoints)
        """
        Functional.__init__(self)

        nfuns, npoints = I.shape
        nregions, nsubpoints = J.shape
        ndim = v.shape[1]
        self.I, self.J, self.v, self.b = I, J, v, b

        self.x = Variable((nregions, nfuns, ndim + 1))

        if conj is None:
            self.conj = EpigraphSupp(I, If, J, v, b, conj=self)
        else:
            self.conj = conj

        self.A = self.conj.A
        self.b = self.conj.b
        self._prox = EpigraphProj(I, J, v, b, Ab=(self.A, self.b))
示例#3
0
文件: affine.py 项目: Room-10/Opymize
 def __init__(self, N, b=0, c=1, conj=None):
     Functional.__init__(self)
     self.b = b
     self.c = c
     self.x = Variable(N)
     from opymize.functionals import IndicatorFct
     self.conj = IndicatorFct(N, c1=c, c2=b,
                              conj=self) if conj is None else conj
     self._prox = ShiftScaleOp(N, self.c, 1, -1)
示例#4
0
 def __init__(self, N, c1=0, c2=0, conj=None):
     Functional.__init__(self)
     self.c1 = c1
     self.c2 = c2
     self.x = Variable(N)
     from opymize.functionals import AffineFct
     self.conj = AffineFct(N, b=-c2, c=c1,
                           conj=self) if conj is None else conj
     self._prox = ConstOp(N, self.x.new() + c1)
示例#5
0
 def __init__(self, N, M, lbd, matrixnorm="frobenius", conj=None):
     Functional.__init__(self)
     assert matrixnorm in ['frobenius', 'nuclear']
     self.x = Variable((N,) + M)
     self.lbd = lbd
     self.matrixnorm = matrixnorm
     conjnorm = 'spectral' if matrixnorm == 'nuclear' else 'frobenius'
     self.conj = L1NormsConj(N, M, lbd, conjnorm, conj=self) if conj is None else conj
     self._xnorms = np.zeros((N,), order='C')
示例#6
0
 def __init__(self, mask, c, conj=None):
     Functional.__init__(self)
     self.x = Variable(c.shape)
     self.mask = mask
     self.c = c
     if conj is None:
         from opymize.functionals import MaskedAffineFct
         self.conj = MaskedAffineFct(mask, c, conj=self)
     else:
         self.conj = conj
     self._prox = ConstrainOp(mask, c)
示例#7
0
 def __init__(self, data, vol=None, mask=None, conj=None):
     Functional.__init__(self)
     self.f = np.atleast_2d(data)
     self.x = Variable(self.f.shape)
     self.vol = np.ones(data.shape[1]) if vol is None else vol
     self.mask = np.ones(data.shape[0],
                         dtype=bool) if mask is None else mask
     if conj is None:
         self.conj = MaxFctConj(data, weights=vol, mask=mask, conj=self)
     else:
         self.conj = conj
示例#8
0
 def __init__(self, f1, f2, vol=None, mask=None, conj=None):
     Functional.__init__(self)
     self.x = Variable(f1.shape)
     self.a = 0.5 * (f1 + f2)
     self.b = 0.5 * (f2 - f1)
     self.vol = np.ones(f1.shape[1]) if vol is None else vol
     self.mask = np.ones(f1.shape[0], dtype=bool) if mask is None else mask
     if conj is None:
         cj_vol = 1.0 / self.vol
         self.conj = BndSSD(f1, f2, vol=cj_vol, mask=mask, conj=self)
     else:
         self.conj = conj
示例#9
0
 def __init__(self, N, M, lbd=1.0, alph=1.0, conj=None):
     Functional.__init__(self)
     assert lbd > 0
     assert alph > 0
     self.x = Variable((N, M + 1))
     self.lbd = lbd
     self.alph = alph
     if conj is None:
         dlbd, dalph = self.lbd, self.alph / self.lbd
         self.conj = TruncQuadEpiInd(N, M, lbd=dlbd, alph=dalph, conj=self)
     else:
         self.conj = conj
示例#10
0
 def __init__(self, N, M, a=1.0, b=None, c=None, conj=None):
     Functional.__init__(self)
     assert a > 0
     self.x = Variable((N, M + 1))
     self.a = a
     self.b = np.zeros((N, M)) if b is None else b
     self.c = np.zeros((N, )) if c is None else c
     if conj is None:
         da, db, dc = quad_dual_coefficients(self.a, self.b, self.c)
         self.conj = QuadEpiInd(N, M, a=da, b=db, c=dc, conj=self)
     else:
         self.conj = conj
示例#11
0
 def __init__(self, data, weights=None, mask=None, conj=None):
     Functional.__init__(self)
     self.f = np.atleast_2d(data)
     self.x = Variable(self.f.shape)
     self.weights = np.ones(data.shape[1]) if weights is None else weights
     self.mask = np.ones(data.shape[0],
                         dtype=bool) if mask is None else mask
     if conj is None:
         self.conj = MaxFct(data, vol=vol, mask=mask, conj=self)
     else:
         self.conj = conj
     self._prox = IntervProj(self.weights, self.f, mask=mask)
示例#12
0
 def __init__(self, N, M, lbd=1.0, alph=1.0, conj=None):
     Functional.__init__(self)
     assert lbd > 0
     assert alph > 0
     self.x = Variable((N, M + 1))
     self.lbd = lbd
     self.alph = alph
     if conj is None:
         dlbd, dalph = self.lbd, self.alph * self.lbd
         self.conj = HuberPerspective(N, M, lbd=dlbd, alph=dalph, conj=self)
     else:
         self.conj = conj
     self._prox = QuadEpiProj(N, M, lbd=self.lbd, alph=self.alph)
示例#13
0
 def __init__(self, data, vol=None, mask=None, conj=None):
     Functional.__init__(self)
     self.x = Variable(data.shape)
     self.f = np.atleast_2d(data)
     self.shift = -0.5*np.einsum('ik,k->', data**2, vol)
     self.vol = np.ones(data.shape[1]) if vol is None else vol
     self.mask = np.ones(data.shape[0], dtype=bool) if mask is None else mask
     if conj is None:
         cj_vol = 1.0/self.vol
         cj_data = np.zeros_like(self.f)
         cj_data[self.mask,:] = np.einsum('ik,k->ik', self.f[self.mask,:], self.vol)
         self.conj = PosSSD(cj_data, vol=cj_vol, mask=mask, conj=self)
     else:
         self.conj = conj
示例#14
0
文件: affine.py 项目: Room-10/Opymize
 def __init__(self, mask, c, conj=None):
     Functional.__init__(self)
     self.x = Variable(c.shape)
     self.mask = mask.astype(bool)
     self.nmask = ~self.mask
     self.c = c
     if conj is None:
         from opymize.functionals import MaskedIndicatorFct
         self.conj = MaskedIndicatorFct(mask, c, conj=self)
     else:
         self.conj = conj
     scale = self.x.vars(self.x.new())[0]
     scale[self.mask, :] = 1.0
     self._prox = ShiftScaleOp(self.x.size, self.c.ravel(), scale.ravel(),
                               -1)
示例#15
0
    def __init__(self, I, If, J, v, b, conj=None):
        """
        Args:
            I : ndarray of bools, shape (nfuns, npoints)
                Selection of support points used by each of the f[i].
            If : nfuns lists of nregions arrays, shape (nfaces,ndim+1) each
                Indices of faces forming the graph of each of the f[i]_j.
            J : ndarray of ints, shape (nregions, nsubpoints)
                Description of the simplicial regions.
            v : ndarray of floats, shape (npoints, ndim)
                All possible support points of the f[i].
            b : ndarray of floats, shape (nfuns, npoints)
                Values of the f[i] at the support points. Only values at the
                support points selected by I are used.
        """
        Functional.__init__(self)

        nfuns, npoints = I.shape
        nregions, nsubpoints = J.shape
        ndim = v.shape[1]
        self.x = Variable((nregions, nfuns, ndim + 1))
        self.A, self.b = epigraph_Ab(I, J, v, b)

        # Each f[i] is known by its values on support points v.
        # The following code computes the equations of the affine functions
        # that describe each f[i]_j.
        self.eqns = []
        for j in range(nregions):
            for i in range(nfuns):
                faces = If[i][j]
                points = v[J[j]][faces]
                vals = b[i, J[j]][faces]
                ptmats = points[:, 1:] - points[:, :1]
                valbs = vals[:, 1:] - vals[:, :1]
                Ab = np.zeros((faces.shape[0], ndim + 1))
                Ab[:, :-1] = np.linalg.solve(ptmats, valbs)
                Ab[:,
                   -1] = vals[:,
                              0] - (Ab[:, :-1] * points[:, 0, :]).sum(axis=-1)
                self.eqns.append(Ab)
        self.checks = -np.ones((nregions, ndim + 1, ndim + 1))
        self.checks[:, :, 0:-1] = v[J[:, 0:ndim + 1], :]
        self.checks[:] = np.linalg.inv(self.checks).transpose(0, 2, 1)

        if conj is None:
            self.conj = EpigraphInd(I, If, J, v, b, conj=self)
        else:
            self.conj = conj
示例#16
0
 def __init__(self, f1, f2, vol=None, mask=None, conj=None):
     Functional.__init__(self)
     self.x = Variable(f1.shape)
     self.f1 = f1
     self.f2 = f2
     self.vol = np.ones(f1.shape[1]) if vol is None else vol
     self.mask = np.ones(f1.shape[0], dtype=bool) if mask is None else mask
     if conj is None:
         cj_vol = 1.0 / self.vol
         self.conj = BndSSDConj(f1, f2, vol=cj_vol, mask=mask, conj=self)
     else:
         self.conj = conj
     f1_msk, f2_msk = [np.zeros_like(a) for a in [f1, f2]]
     f1_msk[self.mask, :] = self.vol[None, :] * f1[self.mask, :]
     f2_msk[self.mask, :] = self.vol[None, :] * f2[self.mask, :]
     self._prox = ProxBndSSD(f1_msk, f2_msk)
示例#17
0
 def __init__(self, N, conj=None):
     Functional.__init__(self)
     self.x = Variable(N)
     self.conj = PositivityFct(N, conj=self) if conj is None else conj
     self._prox = NegProj(N)
示例#18
0
 def __init__(self, fcts, conj=None):
     Functional.__init__(self)
     self.x = Variable(*[(F.x.size, ) for F in fcts])
     self.fcts = fcts
     self.conj = SplitSum([F.conj for F in fcts],
                          conj=self) if conj is None else conj