Esempio n. 1
0
 def Find_al_max_on_05(self, r_0, r_1):
     al_max = 0.5
     r_2 = self.Lin_W_on_al(al_max, r_0, r_1)
     self.From_W_arr_to_Net(r_2)
     r_2["iq"], iq_Test_min, iq_Test_max = iq_test(self.net, X, Y)
     i_05 = r_2["iq"]
     aa = 2 * (2 * r_1["iq"] + 2 * r_0["iq"] - 4 * i_05)
     if aa < 0:
         al_max = (r_1["iq"] + 3 * r_0["iq"] - 4 * i_05) / aa
         r_2 = self.Lin_W_on_al(al_max, r_0, r_1)
         self.From_W_arr_to_Net(r_2)
         r_2["iq"], iq_Test_min, iq_Test_max = iq_test(self.net, X, Y)
     return al_max, r_2
Esempio n. 2
0
    def rec_test(self, rec_tmp):
        self.From_W_arr_to_Net(rec_tmp)
        rec_tmp['iq'], iq_Test_min, iq_Test_max = iq_test(
            self.net, self.X, self.Y)
        rec_tmp["norm"] = self.calc_norm_rec(rec_tmp)
        if rec_tmp["name"][0] == 'M':
            rec_tmp["name"] = 'C' + rec_tmp["name"]

        return rec_tmp
Esempio n. 3
0
    def Move_min_max_in_iq(self, tmp_matrix, step_min):
        for i in range(len(tmp_matrix)):
            if i != i_max:
                tmp_matrix[i]["iq_del"] = (tmp_matrix[i_max]['iq'] -
                                           tmp_matrix[i]['iq'])
                r1 = self.Rec_from_to(tmp_matrix[i], tmp_matrix[i_max])
                tmp_matrix[i]["step_max"] = self.calc_norm_rec(r1)

                if tmp_matrix[i]["step_max"] < 0.1 * step_min:
                    r1 = self.Net_Grad_to_rec(r1)
                    tmp_matrix[i] = self.Move_Rec_Point_on_M(
                        tmp_matrix[i], r1, step_min)
                    tmp_matrix[i]["step_max"] = self.calc_norm_rec(
                        self.Rec_from_to(tmp_matrix[i], tmp_matrix[i_max]))
                    tmp_matrix[i]['iq'], iq_Test_min, iq_Test_max = iq_test(
                        self.net, X, Y)
                    tmp_matrix[i]["iq_del"] = (tmp_matrix[i_max]['iq'] -
                                               tmp_matrix[i]['iq'])

                if tmp_matrix[i]["step_max"] < step_min:
                    tmp_matrix[i] = self.Move_Rec_Point_on_M(
                        tmp_matrix[i], r1, 3 * tmp_matrix[i]["step_max"])
                    tmp_matrix[i]["step_max"] = self.calc_norm_rec(
                        self.Rec_from_to(tmp_matrix[i], tmp_matrix[i_max]))
                    tmp_matrix[i]['iq'], iq_Test_min, iq_Test_max = iq_test(
                        self.net, X, Y)
                    tmp_matrix[i]["iq_del"] = (tmp_matrix[i_max]['iq'] -
                                               tmp_matrix[i]['iq'])

                if tmp_matrix[i]['iq'] < iq_min:
                    i_min = i
                    iq_min = tmp_matrix[i]['iq']
                if tmp_matrix[i]["step_max"] > 0:
                    i = i
                else:
                    tmp_matrix[i]["step_max"] = 1000
                    tmp_matrix[i]['iq'] = tmp_matrix[i_min]['iq']
                    tmp_matrix[i]["iq_del"] = tmp_matrix[i_min]['iq_del']

            else:
                tmp_matrix[i]["step_max"] = 0
                tmp_matrix[i]["iq_del"] = 0

        return i_min, i_max
Esempio n. 4
0
    def Find_max_on_2(self, r_0, r_1):
        r_2 = self.Lin_W_on_al(2, r_0, r_1)
        self.From_W_arr_to_Net(r_2)
        r_2["iq"], iq_Test_min, iq_Test_max = iq_test(self.net, X, Y)
        iq_2 = r_2["iq"]

        a = (r_0["iq"] + r_2["iq"] - 2 * r_1["iq"]) / 2
        b = r_1["iq"] - r_0["iq"] - a
        al_max = -b / (2 * a)
        extr = a * al_max * al_max + b * al_max + r_0["iq"]

        if ((r_2["iq"] > r_1["iq"]) and (r_2["iq"] > r_0["iq"])
                and (extr < r_2["iq"])):
            al_max = 2
            print(' ', r_2["name"], '->', '{0:.4f}'.format(r_0["iq"]),
                  '{0:.4f}'.format(r_1["iq"]), '{0:.4f}'.format(iq_2),
                  '---------->', '{0:.4f}'.format(r_2["iq"]))
            return r_2

        if ((extr < r_1["iq"]) and (extr < r_0["iq"])):
            if (r_0["iq"] < r_1["iq"]):
                al_max = 1.1
            else:
                al_max = -0.1

        if al_max > 15:
            al_max = 15
        if al_max < -2:
            al_max = -2
        al_max

        r_2 = Lin_W_on_al(al_max, r_0, r_1)
        self.From_W_arr_to_Net(r_2)
        r_2["iq"], iq_Test_min, iq_Test_max = iq_test(self.net, X, Y)
        print('   M_al :', r_2["name"], 'EXTR_2=', '{0:.3f}'.format(extr),
              '->', '{0:.3f}'.format(r_0["iq"]), '{0:.3f}'.format(r_1["iq"]),
              '{0:.3f}'.format(iq_2), '---------->',
              '{0:.3f}'.format(r_2["iq"]))
        return r_2
Esempio n. 5
0
 def Move_Rec_Point_on_M(self, Rec_P, Rec_M, KoefStep):
     R_1 = copy.deepcopy(Rec_P)
     for i in range(len(Rec_P["weights"])):
         for j in range(len(Rec_P["weights"][i])):
             for k in range(len(Rec_P["weights"][i][j])):
                 aa = KoefStep * Rec_M["weights"][i][j][k]
                 R_1["weights"][i][j][k] += aa
     self.From_W_arr_to_Net(R_1)
     R_1["iq"], iq_Test_min, iq_Test_max = iq_test(self.net, X, Y)
     R_1["name"] = Rec_P["name"]
     if R_1["name"][0] != 'M':
         R_1["name"] = 'M_' + R_1["name"]
     return R_1
Esempio n. 6
0
            ' ---- n_GR = ' + '{0:.2f}'.format(net.norm_G) +
            ' -----Learn_rate = ' + '{0:.4f}'.format(l_r))
        N_min, N_max = f.find_i_min_max_in_iq(W_array, N_min, N_max)
        f.print_w_arr(
            W_array, ' i = ' + str(i_epoch) + ' ii=' + str(ii_epoch) +
            ' ---2 n_GR = ' + '{0:.2f}'.format(net.norm_G) +
            ' -----Learn_rate = ' + '{0:.4f}'.format(l_r))

        IQ_in = W_array[N_max]['iq']

        f.X, f.Y, f.name_of_answer_array = f.sorted_Test_data(
            f.X, f.Y, f.name_of_answer_array)

        #con = input('Press any key...')

        net.iq, net.iq_min, net.iq_max = iq_test(f.net, f.X, f.Y)

        teacher.train(
            f.X,
            f.Y,
            25,  #learning_rate = [l_r, l_r_old],
            name_of_answer=name_of_answer_array,
            random_data=True,
            save_output_data=True)

        net.iq, net.iq_min, net.iq_max = f.iq_test(net, X, Y)

        R_train = f.Net_to_W_arr(W_array[N_max], 'tr_' + str(net.total_epoch))

        W_array.append(R_train)
        print(i_epoch, ii_epoch, " ---- End train -- ", R_train['name'],
Esempio n. 7
0
    def Find_max_on_Line(self, r_1, r_2):
        delta_al = 0.5
        almax_old = 0
        delta_s = 1000
        nn = 0

        if r_1['iq'] < r_2['iq']:
            r_min = r_1
            r_max = copy.deepcopy(r_2)
        else:
            r_min = r_2
            r_max = copy.deepcopy(r_1)

        while ((delta_al > 0.01) and (nn < 10) and delta_s > 1):
            nn += 1
            r_1_2 = self.Rec_from_to(r_min, r_max)
            delta_s = r_1_2['norm']
            almax, r_3 = self.Find_al_max_on_05(r_min, r_max)
            delta_al = math.fabs(r_3['iq'] - r_max['iq'])
            iq_min = r_min['iq']
            iq_max = r_max['iq']
            iq_new = r_3['iq']
            #print('{0:.5f}'.format(r_max['iq']),'{0:.5f}'.format(r_3['iq']), '{0:.5f}'.format(delta_al))

            if (r_3['iq'] > r_max['iq']):
                r_min = r_max
                r_max = copy.deepcopy(r_3)
                str_ = 'var_Best'
            else:
                str_ = 'var_0.95'
                almax = 0.95
                r_3 = self.Lin_W_on_al(0.95, r_min, r_max)
                self.From_W_arr_to_Net(r_3)
                r_3["iq"], iq_Test_min, iq_Test_max = iq_test(self.net, X, Y)
                iq_new = r_3["iq"]
                delta_al = math.fabs(r_3['iq'] - r_max['iq'])
                if (r_3['iq'] > r_max['iq']):
                    str_ = 'yes_0.95'
                    r_min = r_max
                    r_max = copy.deepcopy(r_3)
                else:
                    r_min = r_3
                    str_ = 'var_s_so'
            print(
                '   Find_on_Line  n=',
                nn,
                str_,
                "\t",
                '{0:.4f}'.format(iq_min),
                '{0:.4f}'.format(iq_max),
                '{0:.4f}'.format(iq_new),
                '<--al=',
                '{0:.2f}'.format(almax),
                ' delta=',
                '{0:.4f}'.format(delta_al),
                ' del_s=',
                '{0:.1f}'.format(delta_s),
            )
        r_max['name'] = 'FL_' + str(self.net.total_epoch)
        r_1_2 = self.Rec_from_to(r_min, r_max)
        #From_W_arr_to_Net(r_max)
        return nn, r_max, r_1_2
Esempio n. 8
0
    err_min = err_ - 3*sigma

    if err_max < 0:
        err_max = 0

    iq_min = (1 - err_max)*100
    iq_max = (1 - err_min)*100
    iq = (iq_min + iq_max)/2

    logging.info("%s | iq_test | iq: %s | iq_min: %s | iq_max: %s | nn_IQ: %s" %
                 (datetime.datetime.today().strftime("%Y-%m-%d-%H.%M.%S"),
                  iq, iq_min, iq_max, len(X)))

    return iq, iq_min, iq_max'''

net.load()

Y_ = []
X_ = []

for i in range(0, 1500):
    X, Y = random_()
    # Y = Image.open("canon/can_"+str(i)+".png").convert("L")
    # Y = np.array(Y)
    # Y = Y.flatten()/255

    Y_.append(Y)
    X_.append(net.forward(Y, training=True))

print(iq_test(net, X_, Y_))
Esempio n. 9
0
from netpy.nets import FeedForwardNet
from netpy.tools.functions import iq_test
import numpy as np

net = FeedForwardNet(name='N_al_gr')

net.load_net_data()
net.load_weights()

test_X = np.loadtxt('data_set/test_X.txt')
test_Y = np.loadtxt('data_set/test_Y.txt')

print(iq_test(net, test_X, test_Y))