コード例 #1
0
ファイル: programs.py プロジェクト: deccs/PLearn
    def __first_compilation_attempt(self):

        #######  First compilation attempt  ####################################
        
        targetdir, exec_name = os.path.split(self.getInternalExecPath())
        sanity_check, log_fname = os.path.split(self.__log_file_path)
        assert sanity_check == targetdir

        if sys.platform == 'win32':
            # When there are characters like '=' in a filenme, Windows can get
            # confused if the filename is not quoted.
            log_fname = '"%s"' % log_fname
                                 
        # Remove outdated log file
        assert not os.path.exists(exec_name)
        if os.path.exists(log_fname):
            os.remove(log_fname)
            
        elif not os.path.exists(targetdir):
            os.makedirs(targetdir)

        # Actual compilation
        moresh.pushd(targetdir)
        logging.debug("\nIn %s:"%os.getcwd())
        
        if sys.platform == 'win32':
            # We assume the compiler is pymake.
            if self.compiler != "pymake":
                raise Not_Implemented
            the_compiler = "python " + \
                os.path.join(ppath.ppath('PLEARNDIR'), 'scripts', 'pymake')
        else:
            the_compiler = self.compiler

        compile_options = ""
        if self.compile_options is not None:
            compile_options = self.compile_options

        compile_cmd= self.getCompileCommand(the_compiler, compile_options)

        logging.debug(compile_cmd)
        p= subprocess.Popen(compile_cmd, 
                            shell= True,
                            stdout= open(log_fname, 'w'),
                            stderr= subprocess.STDOUT)
        compile_exit_code= p.wait()
        logging.debug("compile_exit_code <- %d\n"%compile_exit_code)

        moresh.popd()

        # Report success of fail and remember that compilation was attempted
        self.__attempted_to_compile = True
        if compile_exit_code!=0 and os.path.exists(self.getInternalExecPath()):
            os.remove(self.getInternalExecPath())

        # Strip C++ execs
        if self.isCompilable() and self.compilationSucceeded():
            os.system("strip %s"%self.getInternalExecPath())
            
        return compile_exit_code==0
コード例 #2
0
ファイル: moresh.py プロジェクト: zbxzc35/PLearn
def cd(path=None):
    """Emulate shell's cd --- forwards the call to os.chdir().

    Mainly called as cd() as a shorthand to os.chdir( os.environ.get('HOME') ).  
    """
    if path is None:
        path = ppath.ppath('HOME')
    os.chdir(path)
コード例 #3
0
ファイル: moresh.py プロジェクト: deccs/PLearn
def cd( path = None ):
    """Emulate shell's cd --- forwards the call to os.chdir().

    Mainly called as cd() as a shorthand to os.chdir( os.environ.get('HOME') ).  
    """
    if path is None:
        path = ppath.ppath('HOME')
    os.chdir( path )
コード例 #4
0
ファイル: tutorial.py プロジェクト: deccs/PLearn
#
#  Imports
#
import inspect, os
from plearn.pyplearn                  import *
from plearn.pyplearn                  import _plargs_storage_readonly
from plearn_repr               import plearn_repr
from PyPLearnObject            import PLOption, PyPLearnObject
from plearn.utilities.Tutorial import *

#
#  Global variables
#
from plearn.utilities.ppath import ppath
LINEAR_REGRESSOR_SCRIPT = os.path.join(
    ppath("PLEARNDIR"),
    "plearn_learners/regressors/test/LinearRegressor/linear_regressor.pyplearn"
    )

def pyPLearnMagicModuleSubSection( indent = ' '*4 ):    
    from plearn import pyplearn
    pyplearn_magic_module = pyplearn.__dict__['__pyplearn_magic_module']                
    
    module_source = inspect.getsource( pyplearn_magic_module )
    module_source = module_source.replace( '\n', '\n'+(indent*2) )

    doc   = pyplearn_magic_module.__doc__
    line1 = doc.find('\n')
    return SubSection( 'L{%s<__pyplearn_magic_module>}' % doc[:line1],
                       doc[line1+1:] + '\n' + indent + 'Implementation::\n' +
                       (indent*2) + module_source
コード例 #5
0
ファイル: StatsCollector.py プロジェクト: deccs/PLearn
        
        m = array([[stats[k][i] for i in range(self.width())] for k in sk])

        _printMatrix(m, sk, self.fieldnames, os, pretty)
        
        print "\nCovariance Matrix:"
        _printMatrix(stats["COV"], self.fieldnames, self.fieldnames, os, pretty)
        print "\nCorrelation Matrix:"
        _printMatrix(stats["CORR"], self.fieldnames, self.fieldnames, os, pretty)


if __name__ == "__main__":
    from plearn.vmat.readAMat import readAMat
    ut,fieldnames = readAMat(
            os.path.join(
                ppath.ppath('PLEARNDIR'),
                'examples', 'data', 'test_suite',
                'top_100_test.amat'
                )
            )
    sc = StatsCollector(fieldnames)
    sc.update(ut)
    sc.printStats(sys.stdout, False)
    print "\nAfter accumulating some more:"
    sc.update(ut)
    sc.printStats(sys.stdout, False)
    print "\nAfter forgetting:"
    sc.forget(fieldnames)
    sc.printStats(sys.stdout, False)
コード例 #6
0
ファイル: programs.py プロジェクト: deccs/PLearn
from plearn.pyplearn.PyPLearnObject import PLOption

# PyTest modules
import core

## Hardcoded branch management:
## 
## @var plbranches: We call plearn branches the PLearn, LisaPLearn and apstatsoft libraries.
##
## The plbranches format is old and is inspired from a removed module
## (plpath). It may well be inappropriate: rethink all this when the
## branches will be moved to a config file.
plbranches = []
for mpath in ["PLEARNDIR", "APSTATSOFTDIR", "LISAPLEARNDIR"]:
    try:
        plbranches.append( ppath.ppath(mpath) )
    except:
        pass

#######  Helper Functions  ####################################################

def find_global_program(name):
    assert name != "source", "Do not use source, run .sh files instead."
    program_path = plcommand(name)

    if program_path is None:
        wlines = toolkit.command_output( "which %s"%name )
        if len(wlines) != 1:
            raise core.PyTestUsageError(
                "The only global programs currently supported are those found by 'which' "
                "or those found in a <plearn_branch>/commands/. Call 'which %s' resulted "
コード例 #7
0
ファイル: moresh.py プロジェクト: zbxzc35/PLearn
def pushd(path=None):
    if path is None:
        path = ppath.ppath('HOME')

    DIR_STACK.append(os.getcwd())
    os.chdir(path)
コード例 #8
0
    def __first_compilation_attempt(self):

        #######  First compilation attempt  ####################################

        targetdir, exec_name = os.path.split(self.getInternalExecPath())
        sanity_check, log_fname = os.path.split(self.__log_file_path)
        assert sanity_check == targetdir

        if sys.platform == 'win32':
            # When there are characters like '=' in a filenme, Windows can get
            # confused if the filename is not quoted.
            log_fname = '"%s"' % log_fname

        # Remove outdated log file
        assert not os.path.exists(exec_name)
        if os.path.exists(log_fname):
            os.remove(log_fname)

        elif not os.path.exists(targetdir):
            os.makedirs(targetdir)

        # Actual compilation
        moresh.pushd(targetdir)
        logging.debug("\nIn %s:" % os.getcwd())

        if sys.platform == 'win32':
            # We assume the compiler is pymake.
            if self.compiler != "pymake":
                raise Not_Implemented
            the_compiler = "python " + \
                os.path.join(ppath.ppath('PLEARNDIR'), 'scripts', 'pymake')
        else:
            the_compiler = self.compiler

        compile_options = ""
        if self.compile_options is not None:
            compile_options = self.compile_options

        compile_cmd = self.getCompileCommand(the_compiler, compile_options)

        logging.debug(compile_cmd)
        p = subprocess.Popen(compile_cmd,
                             shell=True,
                             stdout=open(log_fname, 'w'),
                             stderr=subprocess.STDOUT)
        compile_exit_code = p.wait()
        logging.debug("compile_exit_code <- %d\n" % compile_exit_code)

        moresh.popd()

        # Report success of fail and remember that compilation was attempted
        self.__attempted_to_compile = True
        if compile_exit_code != 0 and os.path.exists(
                self.getInternalExecPath()):
            os.remove(self.getInternalExecPath())

        # Strip C++ execs
        if self.isCompilable() and self.compilationSucceeded():
            os.system("strip %s" % self.getInternalExecPath())

        return compile_exit_code == 0
コード例 #9
0
from plearn.pyplearn.PyPLearnObject import PLOption

# PyTest modules
import core

## Hardcoded branch management:
##
## @var plbranches: We call plearn branches the PLearn, LisaPLearn and apstatsoft libraries.
##
## The plbranches format is old and is inspired from a removed module
## (plpath). It may well be inappropriate: rethink all this when the
## branches will be moved to a config file.
plbranches = []
for mpath in ["PLEARNDIR", "APSTATSOFTDIR", "LISAPLEARNDIR"]:
    try:
        plbranches.append(ppath.ppath(mpath))
    except:
        pass

#######  Helper Functions  ####################################################


def find_global_program(name):
    assert name != "source", "Do not use source, run .sh files instead."
    program_path = plcommand(name)

    if program_path is None:
        wlines = toolkit.command_output("which %s" % name)
        if len(wlines) != 1:
            raise core.PyTestUsageError(
                "The only global programs currently supported are those found by 'which' "
コード例 #10
0
ファイル: tutorial.py プロジェクト: zbxzc35/PLearn
#
#  Imports
#
import inspect, os
from plearn.pyplearn import *
from plearn.pyplearn import _plargs_storage_readonly
from plearn_repr import plearn_repr
from PyPLearnObject import PLOption, PyPLearnObject
from plearn.utilities.Tutorial import *

#
#  Global variables
#
from plearn.utilities.ppath import ppath
LINEAR_REGRESSOR_SCRIPT = os.path.join(
    ppath("PLEARNDIR"),
    "plearn_learners/regressors/test/LinearRegressor/linear_regressor.pyplearn"
)


def pyPLearnMagicModuleSubSection(indent=' ' * 4):
    from plearn import pyplearn
    pyplearn_magic_module = pyplearn.__dict__['__pyplearn_magic_module']

    module_source = inspect.getsource(pyplearn_magic_module)
    module_source = module_source.replace('\n', '\n' + (indent * 2))

    doc = pyplearn_magic_module.__doc__
    line1 = doc.find('\n')
    return SubSection(
        'L{%s<__pyplearn_magic_module>}' % doc[:line1], doc[line1 + 1:] +
コード例 #11
0
ファイル: moresh.py プロジェクト: deccs/PLearn
def pushd( path = None ):
    if path is None:
        path = ppath.ppath('HOME')
    
    DIR_STACK.append( os.getcwd() )
    os.chdir( path )
コード例 #12
0
            "N", "NMISSING", "NNONMISSING", "E", "V", "STDDEV", "STDERR",
            "SUM", "SUMSQ", "MIN", "ARGMIN", "MAX", "ARGMAX"
        ]

        m = array([[stats[k][i] for i in range(self.width())] for k in sk])

        _printMatrix(m, sk, self.fieldnames, os, pretty)

        print "\nCovariance Matrix:"
        _printMatrix(stats["COV"], self.fieldnames, self.fieldnames, os,
                     pretty)
        print "\nCorrelation Matrix:"
        _printMatrix(stats["CORR"], self.fieldnames, self.fieldnames, os,
                     pretty)


if __name__ == "__main__":
    from plearn.vmat.readAMat import readAMat
    ut, fieldnames = readAMat(
        os.path.join(ppath.ppath('PLEARNDIR'), 'examples', 'data',
                     'test_suite', 'top_100_test.amat'))
    sc = StatsCollector(fieldnames)
    sc.update(ut)
    sc.printStats(sys.stdout, False)
    print "\nAfter accumulating some more:"
    sc.update(ut)
    sc.printStats(sys.stdout, False)
    print "\nAfter forgetting:"
    sc.forget(fieldnames)
    sc.printStats(sys.stdout, False)