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


Python genpy.PFAEngine类代码示例

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


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

示例1: testNChooseKFcn

    def testNChooseKFcn(self):
        engine, = PFAEngine.fromYaml('''
input: int
output: int
action:
  - m.special.nChooseK: [input, 2]
''')
        self.assertEqual(engine.action(20),    190)
        self.assertEqual(engine.action(10),     45)
        self.assertEqual(engine.action(3),       3)

    ### raise the right exceptions ###
        engine, = PFAEngine.fromYaml('''
input: int
output: int
action:
  - m.special.nChooseK: [input, 4]
''')
        self.assertRaises(PFARuntimeException, lambda: engine.action(1))
        self.assertRaises(PFARuntimeException, lambda: engine.action(0))

        engine, = PFAEngine.fromYaml('''
input: int
output: int
action:
  - m.special.nChooseK: [input, -4] #[input, lambda]
''')
        self.assertRaises(PFARuntimeException, lambda: engine.action(-2))
开发者ID:ajutzeler,项目名称:hadrian,代码行数:28,代码来源:testSpec.py

示例2: testreplaceLast

    def testreplaceLast(self):
        engine, = PFAEngine.fromYaml("""
input: string
output: string
action:
  - {re.replacelast: [input, ["ab(c|d)*"], ["person"]]}
""")
        self.assertEqual(engine.action("abcccdcPPPPabcccdc"),     "abcccdcPPPPperson")
        self.assertEqual(engine.action("abcccdcPPPPabcccdcPPPP"), "abcccdcPPPPpersonPPPP")

# check non-ascii input
#        engine, = PFAEngine.fromYaml("""
#input: string
#output: string
#action:
#  - {re.replacelast: [input, [对讲机+], ["walkie talkie"]]}
#""")
#        self.assertEqual(engine.action("This 对讲机 works better than that 对讲机."), "This 对讲机 works better than that walkie talkie.")

# check byte input
        engine, = PFAEngine.fromYaml("""
input: bytes
output: bytes
action:
  - {re.replacelast: [input, {bytes.encodeUtf8: {string: "对讲机+"}}, {bytes.encodeUtf8: {string: "walkie talkie"}}]}
""")
        self.assertEqual(engine.action("This 对讲机 works better than that 对讲机."), "This 对讲机 works better than that walkie talkie.")
开发者ID:bwengals,项目名称:hadrian,代码行数:27,代码来源:testRegex.py

示例3: bad

        def bad():
            PFAEngine.fromYaml('''
input: [int, string, "null"]
output: int
action:
  - {impute.defaultOnNull: [input, 12]}
''')
开发者ID:codeaudit,项目名称:hadrian,代码行数:7,代码来源:testImpute.py

示例4: testDoAbs

    def testDoAbs(self):
        engine, = PFAEngine.fromYaml('''
input: double
output: double
action:
  - {m.abs: input}
''')
        self.assertAlmostEqual(engine.action(-3.14), 3.14, places=2)

        engine, = PFAEngine.fromYaml('''
input: int
output: int
action:
  - {m.abs: input}
''')
        self.assertEqual(engine.action(2147483647), 2147483647)
        self.assertEqual(engine.action(-2147483647), 2147483647)
        self.assertRaises(PFARuntimeException, lambda: engine.action(-2147483648))

        engine, = PFAEngine.fromYaml('''
input: long
output: long
action:
  - {m.abs: input}
''')
        self.assertEqual(engine.action(9223372036854775807), 9223372036854775807)
        self.assertEqual(engine.action(-9223372036854775807), 9223372036854775807)
        self.assertRaises(PFARuntimeException, lambda: engine.action(-9223372036854775808))
开发者ID:codeaudit,项目名称:hadrian,代码行数:28,代码来源:testMath.py

示例5: testfindFirst

    def testfindFirst(self):
        engine, = PFAEngine.fromYaml("""
input: string
output: [string, "null"]
action:
  - {re.findfirst: [input, [ab]]}
""")
        self.assertEqual(engine.action("88ccc555"),  None)
        self.assertEqual(engine.action("abcabcabc"), "ab")

# check non-ascii input
#        engine, = PFAEngine.fromYaml("""
#input: string
#output: [string, "null"]
#action:
#  - {re.findfirst: [input, [机机+]]}
#""")
#        self.assertEqual(engine.action("abc机机机abca机机bc  asdkj 机机机sd"), "机机机")
#        self.assertEqual(engine.action("abdefg"), None)

# check byte input
        engine, = PFAEngine.fromYaml("""
input: bytes
output: [bytes, "null"]
action:
  - re.findfirst: [input, {bytes.encodeUtf8: {string: "对讲机(讲|机)*"}}]
""")
        self.assertEqual(engine.action("abcde对讲机讲fgg对讲机讲h"), "对讲机讲")
        self.assertEqual(engine.action("abcdefghijk"), None)
开发者ID:bwengals,项目名称:hadrian,代码行数:29,代码来源:testRegex.py

示例6: testDoCmp

    def testDoCmp(self):
        engine, = PFAEngine.fromYaml('''
input: int
output: int
action:
  - {cmp: [input, 5]}
''')
        self.assertEqual(engine.action(3), -1)
        self.assertEqual(engine.action(5), 0)
        self.assertEqual(engine.action(7), 1)

        engine, = PFAEngine.fromYaml('''
input: double
output: int
action:
  - {cmp: [input, 5.3]}
''')
        self.assertEqual(engine.action(5.2), -1)
        self.assertEqual(engine.action(5.3), 0)
        self.assertEqual(engine.action(5.4), 1)

        engine, = PFAEngine.fromYaml('''
input: string
output: int
action:
  - {cmp: [input, [HAL]]}
''')
        self.assertEqual(engine.action("GZK"), -1)
        self.assertEqual(engine.action("HAL"), 0)
        self.assertEqual(engine.action("IBM"), 1)
开发者ID:bwengals,项目名称:hadrian,代码行数:30,代码来源:testCore.py

示例7: testDoMin

    def testDoMin(self):
        engine, = PFAEngine.fromYaml('''
input: double
output: double
action:
  - {min: [input, 3.2]}
''')
        self.assertEqual(engine.action(2.2), 2.2)
        self.assertEqual(engine.action(4.2), 3.2)

        engine, = PFAEngine.fromYaml('''
input: int
output: int
action:
  - {min: [input, 3]}
''')
        self.assertEqual(engine.action(2), 2)
        self.assertEqual(engine.action(4), 3)

        engine, = PFAEngine.fromYaml('''
input: string
output: string
action:
  - {min: [input, [HAL]]}
''')
        self.assertEqual(engine.action("GZK"), "GZK")
        self.assertEqual(engine.action("IBM"), "HAL")
开发者ID:bwengals,项目名称:hadrian,代码行数:27,代码来源:testCore.py

示例8: testReLu

    def testReLu(self):
        engine, = PFAEngine.fromYaml("""
input: double
output: double
action: {m.link.relu: input}
""")
        self.assertAlmostEqual(engine.action(2.2), 2.2, places = 1)

        engine, = PFAEngine.fromYaml("""
input: {type: array, items: double}
output: {type: array, items: double}
action: {m.link.relu: input}
""")
        out = engine.action([-1, -2, 3, 4])
        self.assertAlmostEqual(out[0], 0.0, places = 5)
        self.assertAlmostEqual(out[1], 0.0, places = 5)
        self.assertAlmostEqual(out[2], 3.0, places = 5)
        self.assertAlmostEqual(out[3], 4.0, places = 5)

        engine, = PFAEngine.fromYaml("""
input: {type: map, values: double}
output: {type: map, values: double}
action: {m.link.relu: input}
""")
        out = engine.action({"one": -1, "two": -2, "three": 3, "four": 4})
        self.assertAlmostEqual(out["one"],   0.0, places = 5)
        self.assertAlmostEqual(out["two"],   0.0, places = 5)
        self.assertAlmostEqual(out["three"], 3.0, places = 5)
        self.assertAlmostEqual(out["four"],  4.0, places = 5)
开发者ID:nkhuyu,项目名称:hadrian,代码行数:29,代码来源:testLink.py

示例9: testtanh

    def testtanh(self):
        engine, = PFAEngine.fromYaml("""
input: double
output: double
action: {m.link.tanh: input}
""")
        self.assertAlmostEqual(engine.action(2.2), 0.9757431300314515, places = 5)

        engine, = PFAEngine.fromYaml("""
input: {type: array, items: double}
output: {type: array, items: double}
action: {m.link.tanh: input}
""")
        out = engine.action([-1, -2, 3, 4])
        self.assertAlmostEqual(out[0], -0.761594155956, places = 5)
        self.assertAlmostEqual(out[1], -0.964027580076, places = 5)
        self.assertAlmostEqual(out[2], 0.995054753687 , places = 5)
        self.assertAlmostEqual(out[3], 0.999329299739 , places = 5)

        engine, = PFAEngine.fromYaml("""
input: {type: map, values: double}
output: {type: map, values: double}
action: {m.link.tanh: input}
""")
        out = engine.action({"one": -1, "two": -2, "three": 3, "four": 4})
        self.assertAlmostEqual(out["one"],   -0.761594155956, places = 5)
        self.assertAlmostEqual(out["two"],   -0.964027580076, places = 5)
        self.assertAlmostEqual(out["three"], 0.995054753687 , places = 5)
        self.assertAlmostEqual(out["four"],  0.999329299739 , places = 5)
开发者ID:nkhuyu,项目名称:hadrian,代码行数:29,代码来源:testLink.py

示例10: testCauchit

    def testCauchit(self):
        engine, = PFAEngine.fromYaml("""
input: double
output: double
action: {m.link.cauchit: input}
""")
        self.assertAlmostEqual(engine.action(2.2), 0.8642002512199081, places = 5)

        engine, = PFAEngine.fromYaml("""
input: {type: array, items: double}
output: {type: array, items: double}
action: {m.link.cauchit: input}
""")
        out = engine.action([1, 2, 3, 4])
        self.assertAlmostEqual(out[0], 0.75              , places = 5)
        self.assertAlmostEqual(out[1], 0.8524163823495667, places = 5)
        self.assertAlmostEqual(out[2], 0.8975836176504333, places = 5)
        self.assertAlmostEqual(out[3], 0.9220208696226307, places = 5)

        engine, = PFAEngine.fromYaml("""
input: {type: map, values: double}
output: {type: map, values: double}
action: {m.link.cauchit: input}
""")
        out = engine.action({"one": 1, "two": 2, "three": 3, "four": 4})
        self.assertAlmostEqual(out["one"],   0.75              , places = 5)
        self.assertAlmostEqual(out["two"],   0.8524163823495667, places = 5)
        self.assertAlmostEqual(out["three"], 0.8975836176504333, places = 5)
        self.assertAlmostEqual(out["four"],  0.9220208696226307, places = 5)
开发者ID:nkhuyu,项目名称:hadrian,代码行数:29,代码来源:testLink.py

示例11: testSoftPlus

    def testSoftPlus(self):
        engine, = PFAEngine.fromYaml("""
input: double
output: double
action: {m.link.softplus: input}
""")
        self.assertAlmostEqual(engine.action(2.2), 2.305083319768696, places = 5)

        engine, = PFAEngine.fromYaml("""
input: {type: array, items: double}
output: {type: array, items: double}
action: {m.link.softplus: input}
""")
        out = engine.action([1, 2, 3, 4])
        self.assertAlmostEqual(out[0], 1.31326168752 , places = 5)
        self.assertAlmostEqual(out[1], 2.12692801104 , places = 5)
        self.assertAlmostEqual(out[2], 3.04858735157 , places = 5)
        self.assertAlmostEqual(out[3], 4.01814992792 , places = 5)

        engine, = PFAEngine.fromYaml("""
input: {type: map, values: double}
output: {type: map, values: double}
action: {m.link.softplus: input}
""")
        out = engine.action({"one": 1, "two": 2, "three": 3, "four": 4})
        self.assertAlmostEqual(out["one"],   1.31326168752, places = 5)
        self.assertAlmostEqual(out["two"],   2.12692801104, places = 5)
        self.assertAlmostEqual(out["three"], 3.04858735157, places = 5)
        self.assertAlmostEqual(out["four"],  4.01814992792, places = 5)
开发者ID:nkhuyu,项目名称:hadrian,代码行数:29,代码来源:testLink.py

示例12: testLoglog

    def testLoglog(self):
        engine, = PFAEngine.fromYaml("""
input: double
output: double
action: {m.link.loglog: input}
""")
        self.assertAlmostEqual(engine.action(2.2), 1.203611803484212E-4,  places = 5)

        engine, = PFAEngine.fromYaml("""
input: {type: array, items: double}
output: {type: array, items: double}
action: {m.link.loglog: input}
""")
        out = engine.action([1, 2, 3, 4])
        self.assertAlmostEqual(out[0], 0.06598803584531254   , places = 5)
        self.assertAlmostEqual(out[1], 6.179789893310934E-4  , places = 5)
        self.assertAlmostEqual(out[2], 1.8921786948382924E-9 , places = 5)
        self.assertAlmostEqual(out[3], 1.9423376049564073E-24, places = 5)

        engine, = PFAEngine.fromYaml("""
input: {type: map, values: double}
output: {type: map, values: double}
action: {m.link.loglog: input}
""")
        out = engine.action({"one": 1, "two": 2, "three": 3, "four": 4})
        self.assertAlmostEqual(out["one"],   0.06598803584531254   , places = 5)
        self.assertAlmostEqual(out["two"],   6.179789893310934E-4  , places = 5)
        self.assertAlmostEqual(out["three"], 1.8921786948382924E-9 , places = 5)
        self.assertAlmostEqual(out["four"],  1.9423376049564073E-24, places = 5)
开发者ID:nkhuyu,项目名称:hadrian,代码行数:29,代码来源:testLink.py

示例13: testCloglog

    def testCloglog(self):
        engine, = PFAEngine.fromYaml("""
input: double
output: double
action: {m.link.cloglog: input}
""")
        self.assertAlmostEqual(engine.action(2.2), 0.9998796388196516, places = 5)

        engine, = PFAEngine.fromYaml("""
input: {type: array, items: double}
output: {type: array, items: double}
action: {m.link.cloglog: input}
""")
        out = engine.action([1, 2, 3, 4])
        self.assertAlmostEqual(out[0], 0.9340119641546875, places = 5)
        self.assertAlmostEqual(out[1], 0.9993820210106689, places = 5)
        self.assertAlmostEqual(out[2], 0.9999999981078213, places = 5)
        self.assertAlmostEqual(out[3], 1.0               , places = 5)

        engine, = PFAEngine.fromYaml("""
input: {type: map, values: double}
output: {type: map, values: double}
action: {m.link.cloglog: input}
""")
        out = engine.action({"one": 1, "two": 2, "three": 3, "four": 4})
        self.assertAlmostEqual(out["one"],   0.9340119641546875, places = 5)
        self.assertAlmostEqual(out["two"],   0.9993820210106689, places = 5)
        self.assertAlmostEqual(out["three"], 0.9999999981078213, places = 5)
        self.assertAlmostEqual(out["four"],  1.0               , places = 5)
开发者ID:nkhuyu,项目名称:hadrian,代码行数:29,代码来源:testLink.py

示例14: testRegMahalanobis

    def testRegMahalanobis(self):
        engine, = PFAEngine.fromYaml("""
input: {type: array, items: double}
output: double
action:
  stat.test.mahalanobis:
    - input
    - type: {type: array, items: double}
      value: [2.5, 2.5, 2.5]
    - type: {type: array, items: {type: array, items: double}}
      value: [[2.0, 0.0, 0.0],
              [0.0, 4.0, 0.0],
              [0.0, 0.0, 1.0]]
""")
        self.assertAlmostEqual(engine.action([1, 2, 3]), 1.19895788083, places = 5)

        engine, = PFAEngine.fromYaml("""
input: {type: map, values: double}
output: double
action:
  stat.test.mahalanobis:
    - input
    - type: {type: map, values: double}
      value: {one: 2.5, two: 2.5, three: 2.5}
    - type: {type: map, values: {type: map, values: double}}
      value: {one:   {one: 2.0, two: 0.0, three: 0.0},
              two:   {one: 0.0, two: 4.0, three: 0.0},
              three: {one: 0.0, two: 0.0, three: 1.0}}
""")
        self.assertAlmostEqual(engine.action({"one": 1, "two": 2, "three": 3}), 1.19895788083, places = 5)
开发者ID:nkhuyu,项目名称:hadrian,代码行数:30,代码来源:testTest.py

示例15: testBin

    def testBin(self):
        engine1, = PFAEngine.fromYaml('''
input: double
output: int
action:
  interp.bin: [input, 5, 100, 110]
''')
        self.assertEqual(engine1.action(100.0), 0)
        self.assertEqual(engine1.action(101.0), 0)
        self.assertEqual(engine1.action(101.999), 0)
        self.assertEqual(engine1.action(102.0), 1)
        self.assertEqual(engine1.action(109.999), 4)

        engine2, = PFAEngine.fromYaml('''
input: double
output: int
action:
  interp.bin: [input, 100, 2]
''')
        self.assertEqual(engine2.action(99.0), -1)
        self.assertEqual(engine2.action(99.999), -1)
        self.assertEqual(engine2.action(100.0), 0)
        self.assertEqual(engine2.action(101.0), 0)
        self.assertEqual(engine2.action(101.999), 0)
        self.assertEqual(engine2.action(102.0), 1)
        self.assertEqual(engine2.action(109.999), 4)
        self.assertEqual(engine2.action(110.0), 5)
        self.assertEqual(engine2.action(0.0), -50)
开发者ID:nkhuyu,项目名称:hadrian,代码行数:28,代码来源:testInterp.py


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