当前位置: 首页>>代码示例>>Python>>正文


Python api.FunctionFactory类代码示例

本文整理汇总了Python中mantid.api.FunctionFactory的典型用法代码示例。如果您正苦于以下问题:Python FunctionFactory类的具体用法?Python FunctionFactory怎么用?Python FunctionFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了FunctionFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: initByName

    def initByName(self, name, *args, **kwargs):
        """
        intialise composite function of named type.
        E.g. "ProductFunction"
        This function would be protected in c++
        and should not be called directly except
        by :meth:`__init__` functions of this class
        and subclasses.

        :param name:   name of class calling this.
        :param args:   names of functions in composite function
        :param kwargs: any parameters or attributes that must be passed to the
                       composite function itself.
        """
        if len(args) == 1 and  not isinstance(args[0], FunctionWrapper):
            # We have a composite function to wrap
            self.fun = args[0]
        else:
            self.fun = FunctionFactory.createCompositeFunction(name)

            # Add the functions, checking for Composite & Product functions
            for a in args:
                if not isinstance(a, int):
                    if isinstance(a, CompositeFunctionWrapper):
                        if self.pureAddition:
                            self.pureAddition = a.pureAddition
                        if self.pureMultiplication:
                            self.pureMultiplication = a.pureMultiplication
                    functionToAdd = FunctionFactory.createInitialized(a.fun.__str__())
                    self.fun.add(functionToAdd)
        self.init_paramgeters_and_attributes(**kwargs)
开发者ID:mantidproject,项目名称:mantid,代码行数:31,代码来源:fitfunctions.py

示例2: isregistered

def isregistered(function):
    status, msg = True, ""
    try:
        FunctionFactory.createFunction(function)
    except RuntimeError as exc:
        status, msg = False, 'Could not create {} function: {}'.format(function, str(exc))
    return status, msg
开发者ID:mantidproject,项目名称:mantid,代码行数:7,代码来源:StretchedExpFTTestHelper.py

示例3: test_members_can_be_added

 def test_members_can_be_added(self):
     func = CompositeFunction()
     f1 = FunctionFactory.createInitialized('name=FlatBackground,A0=1')
     f2 = FunctionFactory.createInitialized('name=FlatBackground,A0=2')
     f3 = FunctionFactory.createInitialized('name=FlatBackground,A0=3')
     func.add(f1)
     func.add(f2)
     func.add(f3)
     self.assertEqual(len(func), 3)
     self.assertEqual(str(func[0]), 'name=FlatBackground,A0=1')
     self.assertEqual(str(func[1]), 'name=FlatBackground,A0=2')
     self.assertEqual(str(func[2]), 'name=FlatBackground,A0=3')
开发者ID:DanNixon,项目名称:mantid,代码行数:12,代码来源:CompositeFunctionTest.py

示例4: is_registered

def is_registered(function_name):
    """
    Check whether the function with the specified name has been registered.

    :param function_name: The name of the function to check for registration.
    :return:              A tuple of the status (True if function is registered,
                          false otherwise) and the error message (empty if the
                          function is registered).
    """
    try:
        FunctionFactory.createFunction(function_name)
    except RuntimeError as exc:
        return False, 'Could not create {} function: {}'.format(function_name,
                                                                str(exc))
    return True, ""
开发者ID:DanNixon,项目名称:mantid,代码行数:15,代码来源:MsdTestHelper.py

示例5: skip

    def skip(self):
        """
        Override and return a string depending on whether the directive
        should be skipped. If empty then the directive should be processed
        otherwise the string should contain the error message
        The default is to skip (and warn) if the algorithm is not known.

        Returns:
          str: Return error mesage string if the directive should be skipped
        """
        from mantid.api import AlgorithmFactory, FunctionFactory

        name, version = self.algorithm_name(), self.algorithm_version()
        msg = ""
        if version is None: # it is a fit function
            if name in FunctionFactory.getFunctionNames():
                return ""
            else:
                msg = "No fit function '%s', skipping directive" % name
        else:
            if AlgorithmFactory.exists(name, version):
                return ""
            else:
                msg = "No algorithm '%s' version '%d', skipping directive" % (name, version)

        # warn the user
        if len(msg) > 0:
            env = self.state.document.settings.env
            env.app.verbose(msg)
        return msg
开发者ID:liyulun,项目名称:mantid,代码行数:30,代码来源:base.py

示例6: test_parameters_can_be_get_and_set

 def test_parameters_can_be_get_and_set(self):
     func = FunctionFactory.createInitialized('name=FlatBackground,A0=1;name=FlatBackground,A0=2')
     self.assertEqual(func.getParameterValue('f0.A0'), 1.0)
     self.assertEqual(func.getParameterValue('f1.A0'), 2.0)
     func.setParameter('f0.A0', 10.0)
     self.assertEqual(func.getParameterValue('f0.A0'), 10.0)
     func.setParameter('f1.A0', 20.0)
     self.assertEqual(func.getParameterValue('f1.A0'), 20.0)
开发者ID:DanNixon,项目名称:mantid,代码行数:8,代码来源:CompositeFunctionTest.py

示例7: test_nested_functions

 def test_nested_functions(self):
     s = 'name=FlatBackground,A0=1;(name=FlatBackground,A0=2;name=FlatBackground,A0=3)'
     func = FunctionFactory.createInitialized(s)
     self.assertEqual(len(func), 2)
     self.assertFalse(isinstance(func[0], CompositeFunction))
     self.assertTrue(isinstance(func[1], CompositeFunction))
     self.assertEqual(len(func[1]), 2)
     self.assertEqual(func.getParameterValue('f0.A0'), 1.0)
     self.assertEqual(func.getParameterValue('f1.f0.A0'), 2.0)
     self.assertEqual(func.getParameterValue('f1.f1.A0'), 3.0)
     self.assertEqual(func.nParams(), 3)
开发者ID:DanNixon,项目名称:mantid,代码行数:11,代码来源:CompositeFunctionTest.py

示例8: create_mantid_ifunction

    def create_mantid_ifunction(self, function_name):
        """
        Create and initiializes a Mantid IFunction.

        Args:
          function_name (str): The name of the function to use.

        Returns:
          ifunction: An instance of a Mantid IFunction
        """
        from mantid.api import FunctionFactory
        return FunctionFactory.createFunction(function_name)
开发者ID:liyulun,项目名称:mantid,代码行数:12,代码来源:base.py

示例9: test_function_existing_function_can_be_unsubscribed

 def test_function_existing_function_can_be_unsubscribed(self):
     FunctionFactory.subscribe(TestFunctionCorrectForm)
     nfuncs_before = len(FunctionFactory.getFunctionNames())
     FunctionFactory.unsubscribe("TestFunctionCorrectForm")
     available_functions = FunctionFactory.getFunctionNames()
     self.assertEquals(nfuncs_before - 1, len(available_functions))
     self.assertTrue("TestFunctionCorrectForm" not in available_functions)
开发者ID:mantidproject,项目名称:mantid,代码行数:7,代码来源:FunctionFactoryTest.py

示例10: test_function_subscription

 def test_function_subscription(self):
     nfuncs_orig = len(FunctionFactory.getFunctionNames())
     FunctionFactory.subscribe(TestFunction)
     new_funcs = FunctionFactory.getFunctionNames()
     self.assertEquals(nfuncs_orig+1, len(new_funcs))
     self.assertTrue("TestFunction" in new_funcs)
     
     FunctionFactory.unsubscribe("TestFunction")
     new_funcs = FunctionFactory.getFunctionNames()
     self.assertEquals(nfuncs_orig, len(new_funcs))
     self.assertTrue("TestFunction" not in new_funcs)
开发者ID:AlistairMills,项目名称:mantid,代码行数:11,代码来源:FunctionFactoryTest.py

示例11: __init__

    def __init__(self, name, **kwargs):
        """
        Called when creating an instance

        :param name:   name of fitting function to create or
                       an Ifunction object to wrap.
        :param kwargs: standard argument for initializing fit
                       function
        """
        if not isinstance(name, str):
            self.fun = name
        else:
            self.fun = FunctionFactory.createFunction(name)
        self.init_paramgeters_and_attributes(**kwargs)
开发者ID:mantidproject,项目名称:mantid,代码行数:14,代码来源:fitfunctions.py

示例12: Dsf

                dsf = Dsf()
                dsf.SetIntensities( mtd[ self._InputWorkspaces[idsf] ].dataY(self._WorkspaceIndex) )
                dsf.errors = None # do not incorporate error data
                if self._LoadErrors:
                    dsf.SetErrors(mtd[ self._InputWorkspaces[idsf] ].dataE(self._WorkspaceIndex))
                dsf.SetFvalue( self._ParameterValues[idsf] )
                dsfgroup.InsertDsf(dsf)
            # Create the interpolator
            from dsfinterp.channelgroup import ChannelGroup
            self._channelgroup = ChannelGroup()
            self._channelgroup.InitFromDsfGroup(dsfgroup)
            if self._LocalRegression:
                self._channelgroup.InitializeInterpolator(running_regr_type=self._RegressionType, windowlength=self._RegressionWindow)
            else:
                self._channelgroup.InitializeInterpolator(windowlength=0)
        # channel group has been initialized, so evaluate the interpolator
        dsf = self._channelgroup(p['TargetParameter'])
        # Linear interpolation between the energies of the channels and the xvalues we require
        # NOTE: interpolator evaluates to zero for any of the xvals outside of the domain defined by self._xvalues
        intensities_interpolator = scipy.interpolate.interp1d(self._xvalues, p['Intensity']*dsf.intensities, kind='linear')
        return intensities_interpolator(xvals)  # can we pass by reference?

# Required to have Mantid recognize the new function
#pylint: disable=unused-import
try:
    import dsfinterp
    FunctionFactory.subscribe(DSFinterp1DFit)
except ImportError:
    logger.debug('Failed to subscribe fit function DSFinterp1DFit. '+\
                 'Python package dsfinterp may be missing (https://pypi.python.org/pypi/dsfinterp)')
开发者ID:mducle,项目名称:mantid,代码行数:30,代码来源:DSFinterp1DFit.py

示例13: fwhm

    def fwhm(self):
        """
        Return what should be considered the 'fwhm' of this function.
        """
        return 2.0*math.sqrt(2.0*math.log(2.0))*self.getParameterValue("Sigma")

    def setCentre(self, new_centre):
        """
        Called by an external entity, probably a GUI, in response to a mouse click
        that gives a guess at the centre.
        """
        self.setParameter("PeakCentre",new_centre)

    def setHeight(self, new_height):
        """
        Called by an external entity, probably a GUI, in response to a user guessing
        the height.
        """
        self.setParameter("Height", new_height)

    def setFwhm(self, new_fwhm):
        """
        Called by an external entity, probably a GUI, in response to a user guessing
        the height.
        """
        sigma = new_fwhm/(2.0*math.sqrt(2.0*math.log(2.0)))
        self.setParameter("Sigma",sigma)

# Required to have Mantid recognise the new function
FunctionFactory.subscribe(ExamplePeakFunction)
开发者ID:dezed,项目名称:mantid,代码行数:30,代码来源:ExamplePeakFunction.py

示例14: functionDeriv1D

        -------
        numpy.ndarray
            Function values
        """
        zs = self.getParameterValue('R') * np.asarray(xvals)
        return self.getParameterValue('A') * np.square(3 * self.vecbessel(zs))

    def functionDeriv1D(self, xvals, jacobian):
        r"""Calculate the partial derivatives

        Parameters
        ----------
        xvals : sequence of floats
          The domain where to evaluate the function
        jacobian: 2D array
          partial derivatives of the function with respect to the fitting
          parameters, evaluated at the domain.
        """
        amplitude = self.getParameterValue('A')
        radius = self.getParameterValue('R')
        i = 0
        for x in xvals:
            z = radius * x
            j = j1(z)/z
            jacobian.set(i, 0, np.square(3 * j))
            jacobian.set(i,1, amplitude * 2 * 9 * j * (j1d(z) - j) / radius)
            i += 1

# Required to have Mantid recognise the new function
FunctionFactory.subscribe(EISFDiffSphere)
开发者ID:mantidproject,项目名称:mantid,代码行数:30,代码来源:EISFDiffSphere.py

示例15: import

along with this program.  If not, see <http://www.gnu.org/licenses/>.

File change history is stored at: <https://github.com/mantidproject/mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
'''

from __future__ import (absolute_import, division, print_function)
from mantid.api import IFunction1D, FunctionFactory


class FickDiffusion(IFunction1D):

    def category(self):
        return "QuasiElastic"

    def init(self):
        # Active fitting parameters
        self.declareParameter("D", 1.0, 'Diffusion constant')

    def function1D(self, xvals):
        return self.getParameterValue("D")*xvals*xvals

    def functionDeriv1D(self, xvals, jacobian):
        i = 0
        for x in xvals:
            jacobian.set(i,0,2.0*x)
            i += 1

# Required to have Mantid recognise the new function
FunctionFactory.subscribe(FickDiffusion)
开发者ID:rosswhitfield,项目名称:mantid,代码行数:30,代码来源:FickDiffusion.py


注:本文中的mantid.api.FunctionFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。