コード例 #1
0
ファイル: test_declass.py プロジェクト: mahmoudimus/pydron
 def test_passthrough(self):
     src = """
     def test():
         x = __pydron_new_cell__('x')
         x.cell_contents = 42
         class X(object):
             def foo__U0(x, self):
                   print x.cell_contents
             foo = __pydron_wrap_closure__(foo__U0, (x__P1,))
             __pydron_members__ = 123
                 
     """
     expected = """
     def test():
         x = __pydron_new_cell__('x')
         x.cell_contents = 42
         def class_X__U0(x__P1):
             def foo__U0(x, self):
                   print x.cell_contents
             foo = __pydron_wrap_closure__(foo__U0, (x__P1,))
             __pydron_members__ = 123
             return __pydron_members__
         X = __pydron_read_global__('type')('X', (object,), class_X__U0(x))
     """
     utils.compare(src, expected, declass.DeClass)
コード例 #2
0
 def test_passthrough(self):
     src = """
     def test():
         x = __pydron_new_cell__('x')
         x.cell_contents = 42
         class X(object):
             def foo__U0(x, self):
                   print x.cell_contents
             foo = __pydron_wrap_closure__(foo__U0, (x__P1,))
             __pydron_members__ = 123
                 
     """
     expected = """
     def test():
         x = __pydron_new_cell__('x')
         x.cell_contents = 42
         def class_X__U0(x__P1):
             def foo__U0(x, self):
                   print x.cell_contents
             foo = __pydron_wrap_closure__(foo__U0, (x__P1,))
             __pydron_members__ = 123
             return __pydron_members__
         X = __pydron_read_global__('type')('X', (object,), class_X__U0(x))
     """
     utils.compare(src, expected, declass.DeClass)
コード例 #3
0
    def _rename_file(self):
        """Batch renames an image sequence of a single file. If self.input_dir
            is the same as self.output_dir the original file gets renamed,
            otherwise the file gets renamed and moved to the new location."""
        _, ext = os.path.splitext(self.input_fname)
        out_root = self.output_root

        if "%%" in out_root:
            out_root = out_root.replace("%%", "%")

        destination_path = os.path.join(self.output_dir, out_root + ext)
        if compare(self.input_dir, self.output_dir):  # rename files only
            try:
                shutil.move(self.input_path, destination_path)
            except OSError as e:
                raise e
        else:  # move and rename files
            try:
                shutil.copy(self.input_path, destination_path)
            except OSError as e:
                raise e

        rc, msg = is_file(destination_path)
        if not rc:
            e = "Unable to move and rename file from {}. "
            if compare(self.input_dir, self.output_dir):
                e = "Unable to rename file from {}. "
            e += msg
            raise RuntimeError(e.format(self.input_dir))
コード例 #4
0
def test_rhf_vs_uhf_screening():
    """Checks difference between the number of shell quartets screened with Density screening in RHF vs UHF. 
    Difference should be 0, mathematically. Default threshhold of 1.0E-12 is used"""

    mol = psi4.geometry("""
        0 1
        O  -1.551007  -0.114520   0.000000
        H  -1.934259   0.762503   0.000000
        H  -0.599677   0.040712   0.000000
        O   1.350625   0.111469   0.000000
        H   1.680398  -0.373741  -0.758561
        H   1.680398  -0.373741   0.758561
        symmetry c1
        no_reorient
        no_com
    """)

    # run rhf calculation 
    psi4.set_options({ 
        "scf_type": "direct", 
        "screening" : 'density', 
        "df_scf_guess" : False,
        "integral_package": 'libint2', 
        "ints_tolerance" : 1e-12, 
        "reference" : "rhf",
        "save_jk": True,
        "bench" : 1 

    })
    rhf_energy, rhf_wfn = psi4.energy('hf/DZ', return_wfn=True)

    # run uhf calculation 
    psi4.set_options({ 
        "scf_type": "direct", 
        "screening" : 'density', 
        "df_scf_guess" : False,
        "integral_package": 'libint2', 
        "ints_tolerance" : 1e-12, 
        "reference" : "uhf",
        "save_jk": True,
        "bench" : 1

    })
    uhf_energy, uhf_wfn = psi4.energy('hf/DZ', return_wfn=True)

    # prep for comparing results to expected values
    rhf_computed_shells = rhf_wfn.jk().computed_shells_per_iter()
    uhf_computed_shells = uhf_wfn.jk().computed_shells_per_iter()
    
    computed_shells_expected = [13171, 19618, 19665, 19657, 19661, 19661, 19663, 19663, 19663]

    # compare iteration counts of runs with computed shell quartet array lengths
    # iteration_+1 is used to account for computed_shells arrays including SAD guess results
    assert(len(computed_shells_expected) == rhf_wfn.iteration_+1)
    assert(len(computed_shells_expected) == uhf_wfn.iteration_+1)

    # actually compare results with expected values
    assert compare(computed_shells_expected, rhf_computed_shells, 'Schwarz Computed Shells Count, Cutoff 1.0e-12')
    assert compare(computed_shells_expected, uhf_computed_shells, 'Density Computed Shells Count, Cutoff 1.0e-12')
コード例 #5
0
 def testImportNested(self):
     src = """
     import x.y
     """
     expected = """
     x = __import__('x.y', globals(), None, None)
     """
     utils.compare(src, expected, deimport.DeImport)
コード例 #6
0
 def testModImport(self):
     src = """
     import x
     """
     expected = """
     x = __import__('x', globals(), None, None)
     """
     utils.compare(src, expected, deimport.DeImport)
コード例 #7
0
 def testImportAlias(self):
     src = """
     import x as y
     """
     expected = """
     y = __import__('x', globals(), None, None)
     """
     utils.compare(src, expected, deimport.DeImport)
コード例 #8
0
ファイル: test_deimport.py プロジェクト: mahmoudimus/pydron
 def testImportAlias(self):
     src = """
     import x as y
     """
     expected = """
     y = __import__('x', globals(), None, None)
     """
     utils.compare(src, expected, deimport.DeImport)
コード例 #9
0
ファイル: test_deimport.py プロジェクト: mahmoudimus/pydron
 def testImportNested(self):
     src = """
     import x.y
     """
     expected = """
     x = __import__('x.y', globals(), None, None)
     """
     utils.compare(src, expected, deimport.DeImport)
コード例 #10
0
ファイル: test_deimport.py プロジェクト: mahmoudimus/pydron
 def testModImport(self):
     src = """
     import x
     """
     expected = """
     x = __import__('x', globals(), None, None)
     """
     utils.compare(src, expected, deimport.DeImport)
コード例 #11
0
 def testImportFromPureRelative(self):
     src = """
     from . import y
     """
     expected = """
     module__U0 = __import__(None, globals(), None, ('y',), 1)
     y = module__U0.y
     """
     utils.compare(src, expected, deimport.DeImport)
コード例 #12
0
 def testImportFromRelative2(self):
     src = """
     from ..x import y
     """
     expected = """
     module__U0 = __import__('x', globals(), None, ('y',), 2)
     y = module__U0.y
     """
     utils.compare(src, expected, deimport.DeImport)
コード例 #13
0
ファイル: test_deimport.py プロジェクト: mahmoudimus/pydron
 def testImportFromNested(self):
     src = """
     from a.b.c import y
     """
     expected = """
     module__U0 = __import__('a.b.c', globals(), None, ('y',))
     y = module__U0.y
     """
     utils.compare(src, expected, deimport.DeImport)
コード例 #14
0
 def testImportMultiple(self):
     src = """
     import x, y
     """
     expected = """
     x = __import__('x', globals(), None, None)
     y = __import__('y', globals(), None, None)
     """
     utils.compare(src, expected, deimport.DeImport)
コード例 #15
0
ファイル: test_deimport.py プロジェクト: mahmoudimus/pydron
 def testImportFromRelative2(self):
     src = """
     from ..x import y
     """
     expected = """
     module__U0 = __import__('x', globals(), None, ('y',), 2)
     y = module__U0.y
     """
     utils.compare(src, expected, deimport.DeImport)
コード例 #16
0
ファイル: test_deimport.py プロジェクト: mahmoudimus/pydron
 def testImportFromPureRelative(self):
     src = """
     from . import y
     """
     expected = """
     module__U0 = __import__(None, globals(), None, ('y',), 1)
     y = module__U0.y
     """
     utils.compare(src, expected, deimport.DeImport)
コード例 #17
0
ファイル: test_deimport.py プロジェクト: mahmoudimus/pydron
 def testImportMultiple(self):
     src = """
     import x, y
     """
     expected = """
     x = __import__('x', globals(), None, None)
     y = __import__('y', globals(), None, None)
     """
     utils.compare(src, expected, deimport.DeImport)
コード例 #18
0
ファイル: test_deimport.py プロジェクト: mahmoudimus/pydron
 def testImportFromAs(self):
     src = """
     from x import y as z
     """
     expected = """
     module__U0 = __import__('x', globals(), None, ('y',))
     z = module__U0.y
     """
     utils.compare(src, expected, deimport.DeImport)
コード例 #19
0
 def testImportFromNested(self):
     src = """
     from a.b.c import y
     """
     expected = """
     module__U0 = __import__('a.b.c', globals(), None, ('y',))
     y = module__U0.y
     """
     utils.compare(src, expected, deimport.DeImport)
コード例 #20
0
 def testImportFromAs(self):
     src = """
     from x import y as z
     """
     expected = """
     module__U0 = __import__('x', globals(), None, ('y',))
     z = module__U0.y
     """
     utils.compare(src, expected, deimport.DeImport)
コード例 #21
0
    def step_statictics(simu, network, plot, inputs, outputs):
        entire_FoN = inputs + network['FoN'].stateHiddenNeurons + network[
            'FoN'].stateOutputNeurons
        entire_FoN2 = inputs + network['FoN2'].stateHiddenNeurons + network[
            'FoN2'].stateOutputNeurons

        lin = simu.examples.ninputs
        lhi = lin + lin // 4
        lout = lhi + simu.examples.noutputs

        #rms
        simu.rms('FoN', inputs, outputs)
        simu.rms('SoN', network['FoN'].stateHiddenNeurons, entire_FoN)

        plot['SoN_rms_input'] += network['SoN'].calc_RMS_range(
            network['FoN'].stateHiddenNeurons, entire_FoN, 0,
            lin) / lout * (lin - 0)
        plot['SoN_rms_hidden'] += network['SoN'].calc_RMS_range(
            network['FoN'].stateHiddenNeurons, entire_FoN, lin,
            lhi) / lout * (lhi - lin)
        plot['SoN_rms_output'] += network['SoN'].calc_RMS_range(
            network['FoN'].stateHiddenNeurons, entire_FoN, lhi,
            lout) / lout * (lout - lhi)

        simu.rms('FoN2', inputs, outputs)
        simu.rms('SoN2', network['FoN2'].stateHiddenNeurons, entire_FoN2)

        plot['SoN2_rms_input'] += network['SoN2'].calc_RMS_range(
            network['FoN2'].stateHiddenNeurons, entire_FoN2, 0,
            lin) / lout * (lin - 0)
        plot['SoN2_rms_hidden'] += network['SoN2'].calc_RMS_range(
            network['FoN2'].stateHiddenNeurons, entire_FoN2, lin,
            lhi) / lout * (lhi - lin)
        plot['SoN2_rms_output'] += network['SoN2'].calc_RMS_range(
            network['FoN2'].stateHiddenNeurons, entire_FoN2, lhi,
            lout) / lout * (lout - lhi)

        #err
        simu.err('FoN', outputs)
        plot['SoN_err_input'] += 1 - compare(
            inputs, network['SoN'].stateOutputNeurons[0:lin])
        if (not compare_f(network['FoN'].stateHiddenNeurons,
                          network['SoN'].stateOutputNeurons[lin:lhi], 0.3)):
            plot['SoN_err_hidden'] += 1
        if (index_max(network['SoN'].stateOutputNeurons[lhi:lout]) !=
                index_max(network['FoN'].stateOutputNeurons)):
            plot['SoN_err_output'] += 1

        simu.err('FoN2', outputs)
        plot['SoN2_err_input'] += 1 - compare(
            inputs, network['SoN2'].stateOutputNeurons[0:lin])
        if (not compare_f(network['FoN2'].stateHiddenNeurons,
                          network['SoN2'].stateOutputNeurons[lin:lhi], 0.3)):
            plot['SoN2_err_hidden'] += 1
        if (index_max(network['SoN'].stateOutputNeurons[lhi:lout]) !=
                index_max(network['FoN2'].stateOutputNeurons)):
            plot['SoN2_err_output'] += 1
コード例 #22
0
ファイル: test_deglobal.py プロジェクト: mahmoudimus/pydron
 def test_read_implicit(self):
     src = """
     def test():
         print x
     """
     expected = """
     def test():
         print __pydron_read_global__('x')
     """
     utils.compare(src, expected, deglobal.DeGlobal)
コード例 #23
0
 def test_parameter(self):
     src = """
     def test(x):
         pass
     """
     expected = """
     def test(x):
         pass
     """
     utils.compare(src, expected, deunbound.DeUnbound)
コード例 #24
0
ファイル: test_deimport.py プロジェクト: mahmoudimus/pydron
 def testImportFromMultiple(self):
     src = """
     from x import y, z
     """
     expected = """
     module__U0 = __import__('x', globals(), None, ('y', 'z'))
     y = module__U0.y
     z = module__U0.z
     """
     utils.compare(src, expected, deimport.DeImport)
コード例 #25
0
 def testImportFromMultiple(self):
     src = """
     from x import y, z
     """
     expected = """
     module__U0 = __import__('x', globals(), None, ('y', 'z'))
     y = module__U0.y
     z = module__U0.z
     """
     utils.compare(src, expected, deimport.DeImport)
コード例 #26
0
ファイル: test_deglobal.py プロジェクト: mahmoudimus/pydron
 def test_False(self):
     src = """
     def test():
         return None
     """
     expected = """
     def test():
         return None
     """
     utils.compare(src, expected, deglobal.DeGlobal)
コード例 #27
0
 def testImportFromStar(self):
     src = """
     from x import *
     """
     expected = """
     module__U0 = __import__('x', globals(), None, ('*',))
     for module_element__U0 in getattr(module__U0, '__all__', dir(module__U0)):
         globals()[module_element__U0] = getattr(module__U0, module_element__U0)
     """
     utils.compare(src, expected, deimport.DeImport)
コード例 #28
0
 def test_read_implicit(self):
     src = """
     def test():
         print x
     """
     expected = """
     def test():
         print __pydron_read_global__('x')
     """
     utils.compare(src, expected, deglobal.DeGlobal)
コード例 #29
0
 def test_False(self):
     src = """
     def test():
         return None
     """
     expected = """
     def test():
         return None
     """
     utils.compare(src, expected, deglobal.DeGlobal)
コード例 #30
0
 def test_builtin(self):
     src = """
     def test():
         globals()
     """
     expected = """
     def test():
         __pydron_read_global__('globals')()
     """
     utils.compare(src, expected, deglobal.DeGlobal)
コード例 #31
0
 def test_parameter(self):
     src = """
     def test(x):
         pass
     """
     expected = """
     def test(x):
         pass
     """
     utils.compare(src, expected, deunbound.DeUnbound)
コード例 #32
0
ファイル: test_deimport.py プロジェクト: mahmoudimus/pydron
 def testImportFromStar(self):
     src = """
     from x import *
     """
     expected = """
     module__U0 = __import__('x', globals(), None, ('*',))
     for module_element__U0 in getattr(module__U0, '__all__', dir(module__U0)):
         globals()[module_element__U0] = getattr(module__U0, module_element__U0)
     """
     utils.compare(src, expected, deimport.DeImport)
コード例 #33
0
ファイル: test_utils.py プロジェクト: topleft/book2-exercises
    def test_compare(self):
        """ Tests the compare funciton """

        a, b = "test123", "test123"
        compare_result_true = compare(a, b)
        self.assertTrue(compare_result_true)

        a, b = "test123", "test456"
        compare_result_false = compare(a, b)
        self.assertFalse(compare_result_false)
コード例 #34
0
    def test_compare(self):
        """ Tests the compare funciton """

        a, b = 'test123', 'test123'
        compare_result_true = compare(a, b)
        self.assertTrue(compare_result_true)

        a, b = 'test123', 'test456'
        compare_result_false = compare(a, b)
        self.assertFalse(compare_result_false)
コード例 #35
0
ファイル: test_deglobal.py プロジェクト: mahmoudimus/pydron
 def test_builtin(self):
     src = """
     def test():
         globals()
     """
     expected = """
     def test():
         __pydron_read_global__('globals')()
     """
     utils.compare(src, expected, deglobal.DeGlobal)
コード例 #36
0
ファイル: expB2.py プロジェクト: matthieu637/anne
    def step_statictics(simu, network, plot, inputs, outputs):
        entire_FoN = inputs + network["FoN"].stateHiddenNeurons + network["FoN"].stateOutputNeurons
        entire_FoN2 = inputs + network["FoN2"].stateHiddenNeurons + network["FoN2"].stateOutputNeurons

        lin = simu.examples.ninputs
        lhi = lin + lin // 4
        lout = lhi + simu.examples.noutputs

        # rms
        simu.rms("FoN", inputs, outputs)
        simu.rms("SoN", network["FoN"].stateHiddenNeurons, entire_FoN)

        plot["SoN_rms_input"] += (
            network["SoN"].calc_RMS_range(network["FoN"].stateHiddenNeurons, entire_FoN, 0, lin) / lout * (lin - 0)
        )
        plot["SoN_rms_hidden"] += (
            network["SoN"].calc_RMS_range(network["FoN"].stateHiddenNeurons, entire_FoN, lin, lhi) / lout * (lhi - lin)
        )
        plot["SoN_rms_output"] += (
            network["SoN"].calc_RMS_range(network["FoN"].stateHiddenNeurons, entire_FoN, lhi, lout)
            / lout
            * (lout - lhi)
        )

        simu.rms("FoN2", inputs, outputs)
        simu.rms("SoN2", network["FoN2"].stateHiddenNeurons, entire_FoN2)

        plot["SoN2_rms_input"] += (
            network["SoN2"].calc_RMS_range(network["FoN2"].stateHiddenNeurons, entire_FoN2, 0, lin) / lout * (lin - 0)
        )
        plot["SoN2_rms_hidden"] += (
            network["SoN2"].calc_RMS_range(network["FoN2"].stateHiddenNeurons, entire_FoN2, lin, lhi)
            / lout
            * (lhi - lin)
        )
        plot["SoN2_rms_output"] += (
            network["SoN2"].calc_RMS_range(network["FoN2"].stateHiddenNeurons, entire_FoN2, lhi, lout)
            / lout
            * (lout - lhi)
        )

        # err
        simu.err("FoN", outputs)
        plot["SoN_err_input"] += 1 - compare(inputs, network["SoN"].stateOutputNeurons[0:lin])
        if not compare_f(network["FoN"].stateHiddenNeurons, network["SoN"].stateOutputNeurons[lin:lhi], 0.3):
            plot["SoN_err_hidden"] += 1
        if index_max(network["SoN"].stateOutputNeurons[lhi:lout]) != index_max(network["FoN"].stateOutputNeurons):
            plot["SoN_err_output"] += 1

        simu.err("FoN2", outputs)
        plot["SoN2_err_input"] += 1 - compare(inputs, network["SoN2"].stateOutputNeurons[0:lin])
        if not compare_f(network["FoN2"].stateHiddenNeurons, network["SoN2"].stateOutputNeurons[lin:lhi], 0.3):
            plot["SoN2_err_hidden"] += 1
        if index_max(network["SoN"].stateOutputNeurons[lhi:lout]) != index_max(network["FoN2"].stateOutputNeurons):
            plot["SoN2_err_output"] += 1
コード例 #37
0
ファイル: test_deglobal.py プロジェクト: mahmoudimus/pydron
 def test_delete_non_global(self):
     src = """
     def test():
         del x, y
     """
     expected = """
     def test():
         del x
         del y
     """
     utils.compare(src, expected, deglobal.DeGlobal)
コード例 #38
0
 def test_class(self):
     src = """
     class test(object):
         x = 1
     """
     expected = """
     class test(__pydron_unbound_check__(object)):
         x = __pydron_unbound__
         x = 1
     """
     utils.compare(src, expected, deunbound.DeUnbound)
コード例 #39
0
 def test_None(self):
     src = """
     def test():
         x = None
     """
     expected = """
     def test():
         x = __pydron_unbound__
         x = None
     """
     utils.compare(src, expected, deunbound.DeUnbound)
コード例 #40
0
 def test_assign_explicit(self):
     src = """
     def test():
         global x
         x = 1
     """
     expected = """
     def test():
         __pydron_assign_global__('x', 1)
     """
     utils.compare(src, expected, deglobal.DeGlobal)
コード例 #41
0
ファイル: test_deglobal.py プロジェクト: mahmoudimus/pydron
 def test_delete(self):
     src = """
     def test():
         global x
         del x
     """
     expected = """
     def test():
         __pydron_delete_global__('x')
     """
     utils.compare(src, expected, deglobal.DeGlobal)
コード例 #42
0
def filter_normalization(obj, lothreshold, hithreshold, config=None):
    """
    This function takes an object with normalization integration information
    and a threshold and creates a mask file containing the pixel IDs that do
    not make it above the threshold.

    @param obj: The object containing the normalization information
    @type obj: C{SOM.SOM}

    @param lothreshold: The value below which a pixel will be masked.
    @type lothreshold: C{float}

    @param hithreshold: The value above which a pixel will be masked.
    @type hithreshold: C{float}    

    @param config: The object holding the DR configuration
    @type config: L{hlr_utils.Configure}


    @raise TypeError: The incoming object is not a C{SOM}.
    """
    import hlr_utils

    o_descr = hlr_utils.get_descr(obj)
    if o_descr != "SOM":
        raise TypeError("Only SOMs are allowed in this function!")

    if config is None:
        # Make mask file name from object information
        instname = obj.attr_list.inst.get_name()
        runnum = obj.attr_list["run_number"]
        outfile = "%s_%s_mask.dat" % (instname, str(runnum))
    else:
        # Make mask file name from configuration information
        outfile = hlr_utils.ext_replace(config.output, config.ext_replacement,
                                        "dat")
        outfile = hlr_utils.add_tag(outfile, "mask")

    ofile = open(outfile, "w")

    import SOM
    import utils

    len_obj = hlr_utils.get_length(obj)
    for i in xrange(len_obj):
        norm = hlr_utils.get_value(obj, i, o_descr)
        if utils.compare(norm, lothreshold) <= 0 or \
               utils.compare(norm, hithreshold) >= 0:
            map_so = hlr_utils.get_map_so(obj, None, i)
            pix_id = SOM.NeXusId.fromString(str(map_so.id)).toJoinedStr()

            print >> ofile, pix_id

    ofile.close()
コード例 #43
0
 def test_delete_non_global(self):
     src = """
     def test():
         del x, y
     """
     expected = """
     def test():
         del x
         del y
     """
     utils.compare(src, expected, deglobal.DeGlobal)
コード例 #44
0
 def test_delete(self):
     src = """
     def test():
         global x
         del x
     """
     expected = """
     def test():
         __pydron_delete_global__('x')
     """
     utils.compare(src, expected, deglobal.DeGlobal)
コード例 #45
0
 def test_class(self):
     src = """
     class test(object):
         x = 1
     """
     expected = """
     class test(__pydron_unbound_check__(object)):
         x = __pydron_unbound__
         x = 1
     """
     utils.compare(src, expected, deunbound.DeUnbound)
コード例 #46
0
 def test_assignment(self):
     src = """
     def test():
         x = 1
     """
     expected = """
     def test():
         x = __pydron_unbound__
         x = 1
     """
     utils.compare(src, expected, deunbound.DeUnbound)
コード例 #47
0
 def test_None(self):
     src = """
     def test():
         x = None
     """
     expected = """
     def test():
         x = __pydron_unbound__
         x = None
     """
     utils.compare(src, expected, deunbound.DeUnbound)
コード例 #48
0
ファイル: test_deglobal.py プロジェクト: mahmoudimus/pydron
 def test_assign_explicit(self):
     src = """
     def test():
         global x
         x = 1
     """
     expected = """
     def test():
         __pydron_assign_global__('x', 1)
     """
     utils.compare(src, expected, deglobal.DeGlobal)
コード例 #49
0
 def test_assignment(self):
     src = """
     def test():
         x = 1
     """
     expected = """
     def test():
         x = __pydron_unbound__
         x = 1
     """
     utils.compare(src, expected, deunbound.DeUnbound)
コード例 #50
0
ファイル: test_simple.py プロジェクト: georgebisbas/joey
def test_forward_pass(net_arguments):
    net, pytorch_net, layers = net_arguments
    input_data = np.array(
        [[[[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]],
          [[-1, -2, 0, 1], [-2, -3, 1, 2], [3, 4, 2, -1], [-2, -3, -4, 9]]]],
        dtype=np.float64)

    outputs = net.forward(input_data)
    pytorch_outputs = pytorch_net(torch.from_numpy(input_data))

    compare(outputs, nn.Softmax(dim=1)(pytorch_outputs))
コード例 #51
0
    def custom_sort(c1, c2):
        compare_qt_restricoes = compare(c1.qt_restricoes, c2.qt_restricoes)
        compare_aptidao_dist = compare(c1.aptidao_dist, c2.aptidao_dist)
        compare_aptidao_cars = compare(c1.aptidao_cars, c2.aptidao_cars)

        if compare_qt_restricoes == 0:
            if compare_aptidao_dist == 0:
                return compare_aptidao_cars
            else:
                return compare_aptidao_dist
        else:
            return compare_qt_restricoes
コード例 #52
0
 def test_builtin(self):
     src = """
     def test():
         __pydron_var__ = 1
         print __pydron_var__
     """
     expected = """
     def test():
         __pydron_var__ = 1
         print __pydron_var__
     """
     utils.compare(src, expected, deunbound.DeUnbound)
コード例 #53
0
def test_training_sgd(net_arguments, mnist):
    mnist_train, _ = mnist
    iterations = 100

    net, pytorch_net, layers = net_arguments

    optimizer = optim.SGD(net.pytorch_parameters, lr=0.001, momentum=0.9)
    pytorch_optimizer = optim.SGD(pytorch_net.parameters(),
                                  lr=0.001,
                                  momentum=0.9)

    criterion = nn.CrossEntropyLoss()

    for i, data in enumerate(mnist_train, 0):
        images, labels = data

        def loss_grad(layer, b):
            gradients = []

            for j in range(10):
                result = layer.result.data[j, b]
                if j == labels[b]:
                    result -= 1
                gradients.append(result)

            return gradients

        images = images.double()

        net.forward(images.numpy())
        net.backward(loss_grad, optimizer)

        pytorch_optimizer.zero_grad()
        pytorch_outputs = pytorch_net(images)
        pytorch_loss = criterion(pytorch_outputs, labels)
        pytorch_loss.backward()
        pytorch_optimizer.step()

        if i == iterations - 1:
            break

    pytorch_layers = [
        pytorch_net.conv1, pytorch_net.conv2, pytorch_net.fc1, pytorch_net.fc2,
        pytorch_net.fc3
    ]
    devito_layers = [layers[0], layers[2], layers[5], layers[6], layers[7]]

    for i in range(len(pytorch_layers)):
        pytorch_layer = pytorch_layers[i]
        devito_layer = devito_layers[i]

        compare(devito_layer.kernel.data, pytorch_layer.weight)
        compare(devito_layer.bias.data, pytorch_layer.bias)
コード例 #54
0
 def test_builtin(self):
     src = """
     def test():
         __pydron_var__ = 1
         print __pydron_var__
     """
     expected = """
     def test():
         __pydron_var__ = 1
         print __pydron_var__
     """
     utils.compare(src, expected, deunbound.DeUnbound)
コード例 #55
0
def filter_normalization(obj, lothreshold, hithreshold, config=None):
    """
    This function takes an object with normalization integration information
    and a threshold and creates a mask file containing the pixel IDs that do
    not make it above the threshold.

    @param obj: The object containing the normalization information
    @type obj: C{SOM.SOM}

    @param lothreshold: The value below which a pixel will be masked.
    @type lothreshold: C{float}

    @param hithreshold: The value above which a pixel will be masked.
    @type hithreshold: C{float}    

    @param config: The object holding the DR configuration
    @type config: L{hlr_utils.Configure}


    @raise TypeError: The incoming object is not a C{SOM}.
    """
    import hlr_utils

    o_descr = hlr_utils.get_descr(obj)
    if o_descr != "SOM":
        raise TypeError("Only SOMs are allowed in this function!")

    if config is None:
        # Make mask file name from object information
        instname = obj.attr_list.inst.get_name()
        runnum = obj.attr_list["run_number"]
        outfile = "%s_%s_mask.dat" % (instname, str(runnum))
    else:
        # Make mask file name from configuration information
        outfile = hlr_utils.ext_replace(config.output, config.ext_replacement, "dat")
        outfile = hlr_utils.add_tag(outfile, "mask")

    ofile = open(outfile, "w")

    import SOM
    import utils

    len_obj = hlr_utils.get_length(obj)
    for i in xrange(len_obj):
        norm = hlr_utils.get_value(obj, i, o_descr)
        if utils.compare(norm, lothreshold) <= 0 or utils.compare(norm, hithreshold) >= 0:
            map_so = hlr_utils.get_map_so(obj, None, i)
            pix_id = SOM.NeXusId.fromString(str(map_so.id)).toJoinedStr()

            print >> ofile, pix_id

    ofile.close()
コード例 #56
0
 def test_use(self):
     src = """
     def test():
         x = 1
         print x
     """
     expected = """
     def test():
         x = __pydron_unbound__
         x = 1
         print __pydron_unbound_check__(x)
     """
     utils.compare(src, expected, deunbound.DeUnbound)
コード例 #57
0
 def test_delete(self):
     src = """
     def test():
         x = 1
         del x
     """
     expected = """
     def test():
         x = __pydron_unbound__
         x = 1
         x = __pydron_unbound__
     """
     utils.compare(src, expected, deunbound.DeUnbound)
コード例 #58
0
 def test_delete_mix(self):
     src = """
     def test():
         global y
         del x, y, z
     """
     expected = """
     def test():
         del x
         __pydron_delete_global__('y')
         del z
     """
     utils.compare(src, expected, deglobal.DeGlobal)
コード例 #59
0
 def test_assign_mixed(self):
     src = """
     def test():
         global x
         x = 1
         print x
     """
     expected = """
     def test():
         __pydron_assign_global__('x', 1)
         print __pydron_read_global__('x')
     """
     utils.compare(src, expected, deglobal.DeGlobal)
コード例 #60
0
 def test_ClassDef(self):
     src = """
     def test():
         global x
         class x():
             pass
     """
     expected = """
     def test():
         class x__U0():
             pass
         __pydron_assign_global__('x', x__U0)
     """
     utils.compare(src, expected, deglobal.DeGlobal)