コード例 #1
0
def mmiBeamformingWeights2_f(fbinX,
                             SigmaX,
                             arrgeom,
                             delayL,
                             startpoint,
                             sampleRate,
                             fftLen,
                             halfBandShift,
                             KindOfSigma=-1):
    """@brief find the point which gives the minimum mutual information between two sources"""
    """       This function add a constraint which suppress a jammer signal to the upper branch"""
    """@param """
    """@param """
    """@param """
    """@param """

    fftLen2 = fftLen / 2

    NC = 2
    chanN = len(arrgeom)
    ndim = 4 * (chanN - NC)

    wds1 = calcArrayManifoldWoNorm_f(fbinX, fftLen, chanN, sampleRate,
                                     delayL[0], halfBandShift)
    wds2 = calcArrayManifoldWoNorm_f(fbinX, fftLen, chanN, sampleRate,
                                     delayL[1], halfBandShift)

    wq1 = calcNullBeamformer(wds1, wds2, NC)
    wq2 = calcNullBeamformer(wds2, wds1, NC)
    B1 = calcBlockingMatrix(wq1, NC)
    B2 = calcBlockingMatrix(wq2, NC)

    # initialize gsl functions
    if KindOfSigma == 1 or KindOfSigma == 2:
        sys = multiminimize.gsl_multimin_function_fdf(
            funInstantG, dfunInstantG, fdfunInstantG,
            [wq1, B1, wq2, B2, SigmaX, ALPHA, fbinX, NC], ndim)
    else:
        sys = multiminimize.gsl_multimin_function_fdf(
            funG, dfunG, fdfunG, [wq1, B1, wq2, B2, SigmaX, ALPHA, fbinX, NC],
            ndim)
    solver = multiminimize.conjugate_pr_eff(sys, ndim)
    solver.set(startpoint, STEPSIZE, TOLERANCE)
    waAs = startpoint
    #print "Using solver ", solver.name()
    #curval = 1.0E+30
    for itera in range(MAXItns):
        try:
            status1 = solver.iterate()
        except errors.gsl_NoProgressError, msg:
            print 'gsl_NoProgressError'
            print msg
            break
        except:
コード例 #2
0
def fdf_solver():
    params = numx.array((1., 2.), )
    sys = multiminimize.gsl_multimin_function_fdf(my_f, my_df, my_fdf, params, 2)
    #solver = multiminimize.conjugate_pr(sys, 2)
    #solver = multiminimize.conjugate_fr(sys, 2)
    #solver = multiminimize.vector_bfgs(sys, 2)
    solver = multiminimize.vector_bfgs2(sys, 2)
    #solver = multiminimize.steepest_descent(sys, 2)
    start = numx.array((5., 7.), )
    solver.set(start, 0.01, 1e-4)
    print( "Using solver ", solver.name() )
    print( "%5s %9s %9s  %9s %9s %9s" % ("iter", "x", "y", "f", "dx", "dy"))
    for iter in range(200):
        status = solver.iterate()
        gradient = solver.gradient()
        x = solver.getx()
        f = solver.getf()
        status = multiminimize.test_gradient(gradient, 1e-3)
        if status == errno.GSL_SUCCESS:
            print( "Converged ")
        print( "%5d % .7f % .7f  % .7f % .7f % .7f" %(iter, x[0], x[1], f, gradient[0], gradient[1]))
        if status == errno.GSL_SUCCESS:
            break

    else:
        raise ValueError("Number of Iterations exceeded!")
コード例 #3
0
    def estimateActiveWeights( self, fbinX, startpoint, MAXITNS=40, TOLERANCE=1.0E-03, STOPTOLERANCE = 1.0E-02, DIFFSTOPTOLERANCE= 1.0E-05, STEPSIZE=0.2 ):
        # @brief estimate active weight vectors at a frequency bin
        # @param fbinX: the frequency bin index you process
        # @param startpoint: the initial active weight vector
        # @param NC: the number of constrants (not yet implemented)
        # @param MAXITNS: the maximum interation for the gradient algorithm
        # @param TOLERANCE : tolerance for the linear search
        # @param STOPTOLERANCE : tolerance for the gradient algorithm
        
        if fbinX > self._fftLen/2 :
            print "fbinX %d > fftLen/2 %d?" %(fbinX,self._fftLen/2)

        ndim   = 2 * self._nSource * ( self._nChan - self._NC )
        # initialize gsl functions
        sys    = multiminimize.gsl_multimin_function_fdf( fun_MN, dfun_MN, fdfun_MN, [fbinX, self, self._NC], ndim )
        solver = multiminimize.conjugate_pr( sys, ndim )
        #solver = multiminimize.conjugate_pr_eff( sys, ndim )
        #solver = multiminimize.vector_bfgs( sys, ndim )
        #solver = multiminimize.steepest_descent( sys, ndim )
        solver.set(startpoint, STEPSIZE, TOLERANCE )
        waAs = startpoint
        #print "Using solver ", solver.name()
        mi = 10000.0
        preMi = 10000.0
        for itera in range(MAXITNS):
            try: 
                status1 = solver.iterate()
            except errors.gsl_NoProgressError, msg:
                print "No progress error (%d: %d %e)"  %(fbinX, itera, mi)
                print msg
                break
            except:
コード例 #4
0
ファイル: multiminimize.py プロジェクト: juhnowski/FishingRod
def fdf_solver():
    params = numx.array((1., 2.), )
    sys = multiminimize.gsl_multimin_function_fdf(my_f, my_df, my_fdf, params, 2)
    #solver = multiminimize.conjugate_pr(sys, 2)
    #solver = multiminimize.conjugate_fr(sys, 2)
    solver = multiminimize.vector_bfgs(sys, 2)
    #solver = multiminimize.steepest_descent(sys, 2)
    start = numx.array((5., 7.), )
    solver.set(start, 0.01, 1e-4)
    print "Using solver ", solver.name() 
    print "%5s %9s %9s  %9s %9s %9s" % ("iter", "x", "y", "f", "dx", "dy")
    for iter in range(200):
        status = solver.iterate()
        gradient = solver.gradient()
        x = solver.getx()
        f = solver.getf()
        status = multiminimize.test_gradient(gradient, 1e-3)
        if status == errno.GSL_SUCCESS:
            print "Converged "
        print "%5d % .7f % .7f  % .7f % .7f % .7f" %(iter, x[0], x[1], f, gradient[0], gradient[1])
        if status == errno.GSL_SUCCESS:
            break

    else:
        raise ValueError, "Number of Iterations exceeded!"
コード例 #5
0
ファイル: multiminimize_test.py プロジェクト: pygsl/pygsl
    def setUp(self):
        self._assertIsNotNone(self._t_type)

        self._dim = 2        
        params = numx.array((1., 2.), )        
        self._sys = multiminimize.gsl_multimin_function_fdf(my_f, my_df, my_fdf, params, self._dim)
        self._solver = self._t_type(self._sys, self._dim)
コード例 #6
0
    def setup(self):
        """
        Setup for GSL
        """
        data = numx.array([self.data_x, self.data_y, self.data_e])
        n = len(self.data_x)
        p = len(self.initial_params)
        pinit = numx.array(self.initial_params)

        self._residual_methods = ['lmsder', 'lmder']
        self._function_methods_no_jac = ['nmsimplex', 'nmsimplex2']
        self._function_methods_with_jac = [
            'conjugate_pr', 'conjugate_fr', 'vector_bfgs', 'vector_bfgs2',
            'steepest_descent'
        ]

        # set up the system
        if self.minimizer in self._residual_methods:
            mysys = multifit_nlin.gsl_multifit_function_fdf(
                self._prediction_error, self._jac, self._fdf, data, n, p)
            self._solver = getattr(multifit_nlin, self.minimizer)(mysys, n, p)
        elif self.minimizer in self._function_methods_no_jac:
            mysys = multiminimize.gsl_multimin_function(
                self._chi_squared, data, p)
            self._solver = getattr(multiminimize, self.minimizer)(mysys, p)
        elif self.minimizer in self._function_methods_with_jac:
            mysys = multiminimize.gsl_multimin_function_fdf(
                self._chi_squared, self._jac_chi_squared,
                self._chi_squared_fdf, data, p)
            self._solver = getattr(multiminimize, self.minimizer)(mysys, p)
        else:
            raise UnknownMinimizerError("No {} minimizer for GSL".format(
                self.minimizer))

        # Set up initialization parameters
        #
        # These have been chosen to be consistent with the parameters
        # used in Mantid.
        initial_steps = 1.0 * numx.array(np.ones(p))
        step_size = 0.1
        tol = 1e-4
        self._gradient_tol = 1e-3
        self._abserror = 1e-4
        self._relerror = 1e-4
        self._maxits = 500

        if self.minimizer in self._residual_methods:
            self._solver.set(pinit)
        elif self.minimizer in self._function_methods_no_jac:
            self._solver.set(pinit, initial_steps)
        else:
            self._solver.set(pinit, step_size, tol)
コード例 #7
0
def gssBeamformingWeights_f(fbinX, SigmaX, arrgeom, delayL, startpoint,
                            sampleRate, fftLen, halfBandShift):
    """@brief find the point which gives the minimum mutual information between two sources"""
    """@param """
    """@param """
    """@param """
    """@param """

    NC = 1
    chanN = len(arrgeom)
    ndim = 4 * (chanN - NC)

    wq1 = calcArrayManifold_f(fbinX, fftLen, chanN, sampleRate, delayL[0],
                              halfBandShift)
    B1 = calcBlockingMatrix(wq1)

    wq2 = calcArrayManifold_f(fbinX, fftLen, chanN, sampleRate, delayL[1],
                              halfBandShift)
    B2 = calcBlockingMatrix(wq2)

    # initialize gsl functions
    sys = multiminimize.gsl_multimin_function_fdf(
        funGSS, dfunGSS, fdfunGSS, [wq1, B1, wq2, B2, SigmaX, ALPHA, fbinX],
        ndim, NC)
    solver = multiminimize.conjugate_pr_eff(sys, ndim)
    solver.set(startpoint, STEPSIZE, STOPTOLERANCE)
    waAs = startpoint
    #print "Using solver ", solver.name()

    #curval = 1.0E+30
    for itera in range(MAXItns):
        try:
            status1 = solver.iterate()
        except errors.gsl_NoProgressError, msg:
            print 'gsl_NoProgressError'
            print msg
            break
        except:
def mmiBeamformingWeights2_f(fbinX,
                             samples,
                             SigmaX,
                             arrgeom,
                             delayL,
                             startpoint,
                             sampleRate,
                             fftLen,
                             halfBandShift,
                             pdfKind='K0'):
    """@brief find the point which gives the minimum mutual information between two sources"""
    """@param """
    """@param """
    """@param """
    """@param """

    fftLen2 = fftLen / 2
    NC = 2
    chanN = len(arrgeom)
    ndim = 4 * (chanN - NC)

    wds1 = calcArrayManifoldWoNorm_f(fbinX, fftLen, chanN, sampleRate,
                                     delayL[0], halfBandShift)
    wds2 = calcArrayManifoldWoNorm_f(fbinX, fftLen, chanN, sampleRate,
                                     delayL[1], halfBandShift)

    wq1 = calcNullBeamformer(wds1, wds2, NC)
    wq2 = calcNullBeamformer(wds2, wds1, NC)
    B1 = calcBlockingMatrix(wq1, NC)
    B2 = calcBlockingMatrix(wq2, NC)

    wqL = []
    BL = []
    wqL.append(wq1)
    BL.append(B1)
    wqL.append(wq2)
    BL.append(B2)

    # initialize gsl functions
    if pdfKind == 'K0':
        sys = multiminimize.gsl_multimin_function_fdf(
            fun_K0, dfun_K0, fdfun_K0,
            [wqL, BL, SigmaX, samples, ALPHA, fbinX, halfBandShift, NC], ndim)
    elif pdfKind == 'Gamma':
        sys = multiminimize.gsl_multimin_function_fdf(
            fun_Gamma, dfun_Gamma, fdfun_Gamma,
            [wqL, BL, SigmaX, samples, ALPHA, fbinX, halfBandShift, NC], ndim)
    else:
        pdfKind = 'Laplace'
        sys = multiminimize.gsl_multimin_function_fdf(
            fun_Laplace, dfun_Laplace, fdfun_Laplace,
            [wqL, BL, SigmaX, samples, ALPHA, fbinX, halfBandShift, NC], ndim)

    solver = multiminimize.conjugate_pr_eff(sys, ndim)
    #solver = multiminimize.vector_bfgs( sys, ndim )
    #solver = multiminimize.steepest_descent( sys, ndim )
    solver.set(startpoint, STEPSIZE, TOLERANCE)
    waAs = startpoint
    #print "Using solver ", solver.name()
    mi = 10000.0
    preMi = 10000.0
    for itera in range(MAXITNS):
        try:
            status1 = solver.iterate()
        except errors.gsl_NoProgressError, msg:
            print "No progress error"
            print msg
            break
        except:
コード例 #9
0
 def setUp(self):
     tmp = Numeric.array((1., 2.), Float)
     self.sys = multiminimize.gsl_multimin_function_fdf(my_f, my_df, my_fdf, tmp, self._getsize())
コード例 #10
0
def dfun(x, design):
    # print x
    grad = zeros(ndim, Float)
    design_df(x, design, grad)
    return grad


def fdfun(x, design):
    f = design_f(x, design)
    grad = zeros(ndim, Float)
    design_df(x, design, grad)
    return (f, grad)


sys = multiminimize.gsl_multimin_function_fdf(fun, dfun, fdfun, design, ndim)
solver = multiminimize.conjugate_pr_eff(sys, ndim)
STEPSIZE = 0.01
TOLERANCE = 1.0E-04
STOPTOLERANCE = 1.0E-03
solver.set(startpoint, STEPSIZE, TOLERANCE)

MinItns = 10
MaxItns = 100

for icnt in range(MaxItns):
    try:
        status1 = solver.iterate()
    except:
        print 'Minimization failed or stopped prematurely.'
        print msg