Example #1
0
File: main.py Project: storgi/ASP
def main3():
    trainer = loadTrainer(False, 5)
    probSeq = Probability(-1,'', 1.0)
    probCon = Probability(-1,'', 1.0)

    io = IOHandler()
    b = Builder()
    inputStr = "3#843"
    text = "e the"

    tmp = ''

    i = 0

    for letter in inputStr:
        b.charSequenceProbablility(probSeq, letter, trainer)
        b.conditionalProbablility(probCon, letter, trainer)

        tmp += text[i]

        print("DEBUG Probability of word", tmp , "is ", probCon.getChild(tmp).getProbability(), probSeq.getChild(tmp).getProbability())


        #Check if input word is stil within range.  If not we can not calculate
        #probabilites
        i += 1
        if(i >= trainer.depth):
            print("DEBUG: Input word is bigger then depth of training corpus. Exiting now!")
            break

    print("DEBUG Probability of word", text , "is ", probCon.getChild(text).getProbability(), probSeq.getChild(text).getProbability())
    return True

#main3()
 def builder_for_target_image(self, target, image_id=None, template=None, parameters=None):
     builder = Builder()
     builder.customize_image_for_target(target, image_id, template, parameters)
     self.builders_lock.acquire()
     try:
         self.builders[builder.target_image.identifier] = builder
     finally:
         self.builders_lock.release()
     return builder
Example #3
0
    def test_uptodate(self):
        builder = Builder()

        dst = self.getPath("y")
        builder.applyRule(dst, self.srcPaths, lambda: catFiles(dst, self.srcPaths))
        self.assertEquals(1, countLines(dst))

        self.assertEquals(1, builder.numRules)
        self.assertEquals(0, builder.numMade)
 def builder_for_base_image(self, template, parameters=None):
     builder = Builder()
     builder.build_image_from_template(template, parameters=parameters)
     self.builders_lock.acquire()
     try:
         self.builders[builder.base_image.identifier] = builder
     finally:
         self.builders_lock.release()
     return builder
 def builder_for_provider_image(self, provider, credentials, target, image_id=None, template=None, parameters=None):
     builder = Builder()
     builder.create_image_on_provider(provider, credentials, target, image_id, template, parameters)
     self.builders_lock.acquire()
     try:
         self.builders[builder.provider_image.identifier] = builder
     finally:
         self.builders_lock.release()
     return builder
Example #6
0
	def __init__(self, train_data, predict_on, n_trees=20, max_depth=5, predictors=None):
		from Builder import Builder
		self.train_data = train_data
		self.n_trees = n_trees
		self.max_depth = max_depth
		self.predict_on = predict_on
		self.trees = []
		self.avg = sum(train_data[predict_on])/float(len(train_data))
		b = Builder()
		for n in xrange(n_trees):
			print "starting tree " + str(n+1)
			self.trees.append(b.build(train_data, predict_on, max_depth, predictors))
			print "finished tree " + str(n+1)
Example #7
0
    def test_build(self):
        builder = Builder()

        dst = self.getPath("123")
        builder.applyRule(dst, self.srcPaths, lambda: catFiles(dst, self.srcPaths))
        self.assert_(os.path.exists(dst))
        self.assertEquals(3, countLines(dst))

        dst = self.getPath("x")
        builder.applyRule(dst, self.srcPaths, lambda: catFiles(dst, self.srcPaths))
        self.assertEquals(3, countLines(dst))

        self.assertEquals(2, builder.numRules)
        self.assertEquals(2, builder.numMade)
def main():
  parser = argparse.ArgumentParser(description='Fator 7 StarWeb Builder.')
  parser.add_argument("absolute_path")
  parser.add_argument("--env", default="gisdesenv")
  parser.add_argument("--run", action="store_true")
  args = parser.parse_args()

  print("Local path.: {f}".format(f=args.absolute_path))
  print("Work dir...: {d}".format(d=os.environ['STARWEB_WORK_DIR']))
  print("Remote.path: {p}".format(p=os.environ['STARWEB_SHARE_PATH']))
  if args.run:
    print("Env........: {e}".format(e=args.env))
    print("Run........: {r}\n".format(r=args.run))
  else:
    print("Env........: {e}\n".format(e=args.env))

  builder = Builder(os.environ['STARWEB_SHARE_PATH'],
                    args.absolute_path,
                    os.environ['STARWEB_WORK_DIR'],
                    args.env,
                    args.run,
                    os.environ['STARWEB_USER'],
                    os.environ['STARWEB_PASSWORD'])
  if args.run:
    builder.run_script()
  else:
    builder.copy()
    builder.build()
Example #9
0
File: main.py Project: storgi/ASP
def main2():
    """ Read in a sentence and calculates its probability"""
    depth = 5
    trainer = loadTrainer(False, depth)
    b = Builder()
    sentence = "Did it ever rain in Steinfurt"
    probability = 1.0

    for i in range(0, len(sentence) - depth):
        word = ''
        probCon = Probability(-1, '', 1.0)
        for j in range(0, depth):
            word += sentence[i + j]
            b.conditionalProbablility(probCon, IOHandler().mapCharacter(sentence[i + j]), trainer)
            probability = probability * probCon.getChild(word).getProbability()

    print("DEBUG: Probablility of \"", sentence, "\" is ", str(probability))
    return True
Example #10
0
    def __init__(self, func, testtype, learn_type='hPES', nperd=30,
                 learn_rate=5e-5, supervision_ratio=0.5,
                 oja=False, seed=None):
        if func == 'channel':
            self.func = LearnBuilder.channel
            self.in_d = 3
            self.out_d = 3
            self.runlength = 30.0
        elif func == 'conv':
            self.func = LearnBuilder.convolution
            self.in_d = 6
            self.out_d = 3
            self.runlength = 80.0
        else:
            raise Exception('Function %s not supported' % func)

        if testtype == 'full':
            if func == 'conv':
                self.train = 4.0
                self.test = 5.0
            elif func == 'channel':
                self.train = 0.5
                self.test = 2.0
        elif testtype == 'one':
            self.train = self.runlength
            self.test = 20.0
        else:
            raise Exception('Test type %s not supported' % testtype)

        self.testtype = testtype
        self.learn_type = learn_type
        self.nperd = nperd
        self.supervision_ratio = supervision_ratio
        self.oja = oja
        self.learn_rate = learn_rate

        # If no seed passed in, we'll generate one
        if seed is None:
            seed = random.randint(0, 0x7fffffff)
        self.seed = seed

        Builder.__init__(self)
Example #11
0
    def train(self):
        # Normalize the weights of the event sample
        sumWeights = 0
        for iSample in range(len(self.eventSample)):
            sumWeights += self.eventSample[iSample][1]
        for iSample in range(len(self.eventSample)):
            self.eventSample[iSample][1] /= sumWeights
        builder = Builder();
        # Build the forest
        for iTree in range(self.numTrees):
            print("Tree:", iTree)
            # Boost the event weights
            if iTree!=0:
                for iSample in range(len(self.eventSample)):
                    out = self.trees[iTree-1].evaluate(self.eventSample[iSample][0])
                    self.eventSample[iSample][1] *= np.exp(-out*self.treeWeights[iTree-1]*self.eventSample[iSample][2])
            # Train tree
            tree = builder.build(self.eventSample, self.treeDepth, self.numCuts, self.minNodeSize)
            self.trees.append(tree)
            # Set tree weight
            if iTree==0:
                self.treeWeights.append(1)
            else:
                err = 0
                for iSample in range(len(self.eventSample)):
                    out = self.trees[iTree].evaluate(self.eventSample[iSample][0])
                    if out!=self.eventSample[iSample][2]:
                        err += self.eventSample[iSample][1]
                self.treeWeights.append(0.5*np.log((1.0-err)/err))

            # Test trained trees
            numTrue = 0
            numFalse = 0
            for iSample in range(len(self.eventSample)):
                out = self.evaluate(self.eventSample[iSample][0])
                if out==self.eventSample[iSample][2]:
                    numTrue += 1
                else:
                    numFalse += 1
            print("Eff:", numTrue/(numTrue+numFalse))
Example #12
0
File: main.py Project: storgi/ASP
def main():
    trainer = loadTrainer(False, 5)
    probSeq = Probability(-1,'', 1.0)
    probCon = Probability(-1,'', 1.0)

    io = IOHandler()
    b = Builder()
    inputStr = io.getInput()

    i = 0

    while(inputStr != False):
        b.charSequenceProbablility(probSeq, inputStr, trainer)
        b.conditionalProbablility(probCon, inputStr, trainer)

        #Check if input word is stil within range.  If not we can not calculate
        #probabilites
        i += 1
        if(i >= trainer.depth):
            print("DEBUG: Input word is bigger then depth of training corpus. Exiting now!")
            break

        inputStr = io.getInput()
    return True
Example #13
0
 def __init__(self, top_level_dir, repos, jobs=1, sudo_creds=None):
     """
     :param top_level_dir: the directory that holds all the cloned
                           repositories according to manifest
                           example: <top_level_dir>/on-http/...
                                                   /on-tftp/...
     :param repos: a list of repositories to be build
     :param jobs: Number of parallel jobs(build debian packages) to run.
     :param sudo_creds: the environment variable name of sudo credentials.
                        for example: SUDO_CRED=username:password
     :return: None
     """
     self.top_level_dir = top_level_dir
     self._repos = repos
     self._jobs = jobs
     self._sudo_creds = sudo_creds
     self._builder = Builder(self._jobs)        
Example #14
0
    def run(self, name, logdir):
        import nef
        if self.net is None:
            self.make()

        fn = Builder.write_param_file(name, self.params, logdir)

        lognode = nef.Log(self.net, "log", dir=logdir,
                          filename='%s.csv' % fn, interval=0.01)
        lognode.add('switch', origin='origin', tau=0.0)
        lognode.add('actual error')

        if self.testtype == 'full':
            length = LearnBuilder.get_full_length(
                self.runlength, self.train, self.test)
        elif self.testtype == 'one':
            length = self.train + self.test

        self.net.network.run(0, length)
        self.net.network.removeStepListener(lognode)
Example #15
0
 def _splittag(self, path):
     tag, attribs = Builder._splittag(self, path)
     theattribs = []
     for key, value in attribs:
         theattribs.append((key, value))
     return tag, theattribs
Example #16
0
 def __init__(self, d = {}):
     Builder.__init__(self, d)
Example #17
0
 def builder_for_provider_image(self, provider, credentials, target, image_id=None, template=None, parameters=None):
     builder = Builder()
     builder.create_image_on_provider(provider, credentials, target, image_id, template, parameters)
     self.builders[builder.provider_image.identifier] = builder
     return builder
Example #18
0
 def builder_for_target_image(self, target, image_id=None, template=None, parameters=None):
     builder = Builder()
     builder.customize_image_for_target(target, image_id, template, parameters)
     self.builders[builder.target_image.identifier] = builder
     return builder
Example #19
0
 def __init__(self, name = 'GNU makefile for g++/gcc', buildTool = 'make', 
              buildToolOptions = '-f'):
     Builder.__init__(self, name, buildTool, buildToolOptions)
Example #20
0
class DebianBuilder(object):
    """
    This is a class that builds the debian packages. 
    It assumes that the repository is cloned successfully and is accessible for the tool.
    """
    def __init__(self, top_level_dir, repos, jobs=1, sudo_creds=None):
        """
        :param top_level_dir: the directory that holds all the cloned
                              repositories according to manifest
                              example: <top_level_dir>/on-http/...
                                                      /on-tftp/...
        :param repos: a list of repositories to be build
        :param jobs: Number of parallel jobs(build debian packages) to run.
        :param sudo_creds: the environment variable name of sudo credentials.
                           for example: SUDO_CRED=username:password
        :return: None
        """
        self.top_level_dir = top_level_dir
        self._repos = repos
        self._jobs = jobs
        self._sudo_creds = sudo_creds
        self._builder = Builder(self._jobs)        

    @property
    def top_level_dir(self):
        return self._top_level_dir

    @top_level_dir.setter
    def top_level_dir(self, top_level_dir):
        """
        Setter for the repository directory
        :param top_level_dir: the directory that holds all the cloned
                              repositories according to manifest
                              example: <top_level_dir>/on-http/...
                                                      /on-tftp/...
        :return: None
        """
        if os.path.isdir(top_level_dir):
            self._top_level_dir = os.path.abspath(top_level_dir)
        else:
            raise ValueError("The path provided '{dir}' is not a directory."
                             .format(dir=top_level_dir))

    def generate_tasks(self):
        """
        Generate a list of tasks to be perform.
        An example of task:
                   {
                    'name': repo,
                    'data': {
                             'commands': [command1, ...], #command1 is an instance of BuildCommand
                             'env_file': on-http.version
                            }
                   }
        
        """
        tasks = []
        for repo in self._repos:
            task = {
                    'name': repo,
                    'data': {
                             'commands': [],
                             'env_file': None
                            }
                   }
            command_name = './HWIMO-BUILD'
            path = os.path.abspath(os.path.join(self._top_level_dir, repo))
            if not os.path.exists(path):
                raise ValueError("Repository {0} doesn't exist under {1}"
                                 .format(repo, self._top_level_dir))
            command = BuildCommand(command_name, path)
            if repo == "on-imagebuilder" and self._sudo_creds:
                command.use_sudo = True
                command.sudo_creds = self._sudo_creds
            task['data']['commands'].append(command)

            version_file = "{0}.version".format(repo)
            version_path = os.path.abspath(os.path.join(path, version_file))
            if os.path.exists(version_path):
                task['data']['env_file'] = version_path

            print "[Info] Execute command {0} for repo {1}.".format( command_name, repo )
            tasks.append(task)

        return tasks

    def blind_build_all(self):
        """
        Iterate through the first layer subdirectory of top_level_dir and
        if found HWIMO-BUILD, then execute the script.
        """
        try:
            tasks = self.generate_tasks()
            for task in tasks:
                self._builder.add_task(task['data'], task['name'])
            self._builder.finish()
        except Exception, e:
            raise RuntimeError("Failed to build all debian packages due to \n{0}".format(e))
Example #21
0
import os.path
import sys
# I make a symlink `trevor` in the nengo directory, pointing to scriptdir
sys.path.append('trevor/nengo')  
from Builder import Builder
from LearnBuilder import LearnBuilder

scriptdir = os.path.expanduser("~/nengo-latest/trevor/nengo")
logdir = os.path.expanduser("~/Programming/cogsci2013/results/")

if False:
    builder = LearnBuilder('channel')
    builder.view(True)
else:
    name = sys.argv[1]
    testtype = sys.argv[2]
    params = Builder.parse_params(sys.argv[3:])
    if testtype == 'full':
        logdir = logdir + "functions-test"
    elif testtype == 'one':
        logdir = logdir + "functions-optimize"
    builder = LearnBuilder(name, testtype, **params)
    builder.run(name, logdir)
Example #22
0
from Builder import Builder

copyright = '(C) UtgDev'
minified = 'JSONPageBuilder'
jsfolder = ['/js/libs/jquery', '/js/libs', '/js/libs/bootstrap', '/js/libs/moment','/js/libs/moment/extensions','/js/helpers','/js/fixtures','/js/pagebuilder','/js/pagebuilder/extensions', '/js']
removeTemp = False
debug = True

builder = Builder(copyright, minified, jsfolder, removeTemp, debug)
builder.build()
Example #23
0
 def builder_for_base_image(self, template, parameters=None):
     builder = Builder()
     builder.build_image_from_template(template)
     self.builders[builder.base_image.identifier] = builder
     return builder