Example #1
0
 def init_weights_randomly(self, vmin= -0.25, vmax=0.25):
     '''
     initialize the perceptron with random weights between [vmin ; vmax]
     returns None
     '''
     self.weights = [randmm(vmin, vmax) for _ in range(self.nbr_input)]
     
     if(self._enable_bias):
         self.bias = randmm(vmin, vmax)
     self._last_weights = list(self.weights) #_last_weights is used by the momentum algo
     self._last_bias = self.bias
     self._weights_updated = True
Example #2
0
    def init_weights_randomly(self, vmin=-0.25, vmax=0.25):
        '''
        initialize the perceptron with random weights between [vmin ; vmax]
        returns None
        '''
        self.weights = [randmm(vmin, vmax) for _ in range(self.nbr_input)]

        if (self._enable_bias):
            self.bias = randmm(vmin, vmax)
        self._last_weights = list(
            self.weights)  #_last_weights is used by the momentum algo
        self._last_bias = self.bias
        self._weights_updated = True
Example #3
0
 def _line_to_list(self, line):
     lstring = list(line.replace(" ", "").replace("\n", ""))
                  
     result = []
     for sym in lstring:
         for key in self._rules:
             if(sym == key):
                 if(len(self._rules[key]) == 1):
                     result += [self._rules[key][0]]
                 else:
                     result += [randmm(self._rules[key][0], self._rules[key][1])]
     return result
Example #4
0
    def _line_to_list(self, line):
        lstring = list(line.replace(" ", "").replace("\n", ""))

        result = []
        for sym in lstring:
            for key in self._rules:
                if (sym == key):
                    if (len(self._rules[key]) == 1):
                        result += [self._rules[key][0]]
                    else:
                        result += [
                            randmm(self._rules[key][0], self._rules[key][1])
                        ]
        return result
Example #5
0
    def __init__(self, control):
        self.nbr_input = control.nbr_input
        self.learning_rate = control.learning_rate
        self.momentum = control.momentum
        self.temperature = control.temperature
        self._ntype = control._ntype
        self._enable_bias = control._enable_bias

        self.weights = []
        for w in control.weights:
            self.weights.append(w)

        for _ in range(20):
            self.weights.append(randmm(-1, 1))

        self.bias = control.bias
        self._last_bias = control._last_bias

        self._last_weights = list(self.weights)

        self._weights_updated = True
        self._last_inputs = []
Example #6
0
    def __init__(self, control):
        self.nbr_input = control.nbr_input
        self.learning_rate = control.learning_rate
        self.momentum = control.momentum
        self.temperature = control.temperature
        self._ntype = control._ntype
        self._enable_bias = control._enable_bias
        

        self.weights = []        
        for w in control.weights:
            self.weights.append(w)
        
        for _ in range(20):
            self.weights.append(randmm(-1, 1))
        
        self.bias = control.bias
        self._last_bias = control._last_bias
        
        self._last_weights = list(self.weights)
        
        self._weights_updated = True
        self._last_inputs = []
Example #7
0
 def init_weights_randomly(self, vmin=-0.25, vmax=0.25):
     self.weights = [randmm(vmin, vmax) for _ in range(self.nbr_input)]
     self.bias = randmm(vmin, vmax)
Example #8
0
     ho.init_weights_randomly(-1, 1)
     high_order.append(ho)
 
 
 #trials
 wins = []
 wagers = []
 
 last_output = [ [0 for _ in range(5)] for _ in range(nbr_network)]
 for epoch in range(nbr_epoch):
     nbr_win = 0
     nbr_gwager = 0
     for net in range(nbr_network):
         for trial in range(nbr_trial):
             for i in range(len(last_output[net])):
                 last_output[net][i] += randmm(0.01, 0.03)
     
             bet = index_max(first_order[net].calc_output(last_output[net]))
             
             for i in range(len(first_order[net].stateHiddenNeurons)):
                     first_order[net].stateHiddenNeurons[i] += randmm(0.01, 0.03)
             
             wager = index_max(high_order[net].calc_output(first_order[net].stateHiddenNeurons))
             
             win = deck(bet)
             
             if((win[0] and wager == 0)):
                     nbr_gwager += 1
             
             if(win[0]):                    
                 high_order[net].train(first_order[net].stateHiddenNeurons, [1. , grid])
Example #9
0
 def init_weights_randomly(self, vmin= -0.25, vmax=0.25):
     self.weights = [randmm(vmin, vmax) for _ in range(self.nbr_input)]
     self.bias = randmm(vmin, vmax)
Example #10
0
File: IGT.py Project: kryptine/anne
        ho = MultilayerPerceptron(40, 40, 2, grid, 0.0003, 0., 1., False, True)
        ho.init_weights_randomly(-1, 1)
        high_order.append(ho)

    #trials
    wins = []
    wagers = []

    last_output = [[0 for _ in range(5)] for _ in range(nbr_network)]
    for epoch in range(nbr_epoch):
        nbr_win = 0
        nbr_gwager = 0
        for net in range(nbr_network):
            for trial in range(nbr_trial):
                for i in range(len(last_output[net])):
                    last_output[net][i] += randmm(0.01, 0.03)

                bet = index_max(first_order[net].calc_output(last_output[net]))

                for i in range(len(first_order[net].stateHiddenNeurons)):
                    first_order[net].stateHiddenNeurons[i] += randmm(
                        0.01, 0.03)

                wager = index_max(high_order[net].calc_output(
                    first_order[net].stateHiddenNeurons))

                win = deck(bet)

                if ((win[0] and wager == 0)):
                    nbr_gwager += 1