Exemplo n.º 1
0
    def run(self):
        """Run the learner.

        Returns a LearnerResult instance. Also sets self.result to that
        instance.  
        
        """

        # max_time and max_iterations are mutually exclusive stopping critera
        if 'max_time' not in self.options:
            _stop = self._stop_after_iterations
        else:
            _stop = self._stop_after_time
            
        self.stats = GreedyLearnerStatistics()
        self.result = result.LearnerResult(self)
        self.evaluator = evaluator.fromconfig(self.data, self.seed, self.prior)
        self.evaluator.score_network(self.seed.copy())

        first = True
        self.result.start_run()
        while not _stop():
            self._run_without_restarts(_stop, self._restart, 
                                       randomize_net=(not first))
            first = False
        self.result.stop_run()

        return self.result
Exemplo n.º 2
0
    def setUp(self):
        nodes = [data.Variable(x) for x in range(5)] 
        nets = ("0,1", "1,0" , "1,2;2,3", "4,1;1,2", "4,2;4,3")
        scores = (-10.5, -11, -8.5, -12, -13)

        self.result1 = result.LearnerResult(size=0)
        self.result1.nodes = nodes
        self.result1.start_run()
        for n,s in zip(nets, scores):
            self.result1.add_network(network.Network(nodes, n), s)

        self.result2 = result.LearnerResult(size=0)
        self.result2.nodes = nodes
        self.result2.start_run()
        self.result2.add_network(network.Network(nodes, "1,2;2,3;3,4"), -6)
        self.result2.add_network(network.Network(nodes, "1,2;2,3;3,4;0,4;0,2"), -5.5)
        self.result2.add_network(network.Network(nodes, "0,1"), -10.5)
Exemplo n.º 3
0
    def run(self):
        self.result = result.LearnerResult(self)
        self.evaluator = evaluator.fromconfig(self.data, prior_=self.prior)

        self.result.start_run()
        for net in self.networks:
            self.result.add_network(net, self.evaluator.score_network(net))
        self.result.stop_run()
        return self.result
Exemplo n.º 4
0
 def setUp(self):
     nodes = [data.Variable(x) for x in range(5)] 
     self.result = result.LearnerResult(size=self.size)
     self.result.nodes = nodes
     
     self.result.start_run()
     nets = ("0,1", "1,0" , "1,2;2,3", "4,1;1,2", "4,2;4,3")
     scores = (-10.5, -11, -8.5, -12, -13)
     for n,s in zip(nets, scores):
         self.result.add_network(network.Network(nodes, n), s)
Exemplo n.º 5
0
    def run(self):
        self.result = result.LearnerResult(self)
        self.evaluator = evaluator.fromconfig(self.data, prior_=self.prior)
        self.result.start_run()

        # algorithm here!
        print 'Yay! Nothing to see here...'
        # get prior!
        # complete datasets!
        # self.evaluator.score_network()

        self.result.stop_run()
        return self.result
Exemplo n.º 6
0
    def run(self):
        """Run the learner."""

        self.stats = SALearnerStatistics(self.start_temp, self.delta_temp, 
                                         self.max_iters_at_temp)
        self.result =  result.LearnerResult(self)
        self.evaluator = evaluator.fromconfig(self.data, self.seed, self.prior)
        self.evaluator.score_network(self.seed.copy())

        self.result.start_run()
        curscore = self.evaluator.score_network()
        
        # temperature decays exponentially, so we'll never get to 0. 
        # So, we continue until temp < 1
        while self.stats.temp >= 1:
            try:
                newscore = self._alter_network_randomly_and_score()
            except CannotAlterNetworkException:
                return

            self.result.add_network(self.evaluator.network, newscore)

            if self._accept(newscore):
                # set current score
                self.stats.current_score = newscore
                if self.stats.current_score > self.stats.best_score:
                    self.stats.best_score = self.stats.current_score
            else:
                # undo network alteration
                self.evaluator.restore_network()

            # temp not updated EVERY iteration. just whenever criteria met.
            self.stats.update() 

        self.result.stop_run()
        return self.result