예제 #1
0
import numpy as np
from sepStatData import sepStatData as sep

training_trials = range(1, 16)
for train_ind in training_trials:
    if train_ind <= 8:
        ftrain = 'tcv_1_' + str(train_ind) + '0.npy'
    elif train_ind < 15:
        ftrain = 'tcv_' + str(train_ind - 7) + '_10.npy'
    elif train_ind == 15:
        ftrain = 'tcv_7_80.npy'

#    f_train_simulation = 'Simulation data/tcv' + os.path.altsep + ftrain
    f_train_simulation = 'manual/tcv' + os.path.altsep + ftrain
    data_train_simulation = np.load(f_train_simulation)
    X_train_simulation, coord_train_simulation, count = sep(
        data_train_simulation)

    f_train_experimental = 'Experimental data/tcv' + os.path.altsep + ftrain
    data_train_experimental = np.load(f_train_experimental)
    X_train_experimental, coord_train_experimental, count = sep(
        data_train_experimental)
    coord_train_experimental = coord_train_experimental.dot(10)

    if np.all(X_train_simulation == X_train_experimental):
        print('X are the same for ', str(train_ind), ' Trial')

    if np.all(coord_train_simulation == coord_train_experimental):
        print('Coord are the same for ', str(train_ind), ' Trial')

for test_ind in range(1, 6):
    ftest = 'test' + str(test_ind) + '.npy'
     C_entry = str(train_ind) + '0'
 elif train_ind < 15:
     ftrain = 'tcv_' + str(train_ind-7) + '_10.npy'
     B_entry = str(train_ind-7)
     C_entry = '10'
 elif train_ind == 15:
     ftrain = 'tcv_7_80.npy'
     B_entry = '7'
     C_entry = '80'
 
 time_training_start = time.time()
 f = 'manual/tcv' + os.path.altsep + ftrain
 data = np.load(f)
 ftrain = ftrain.split('.')[0]
 ## Separate data
 X,coord,count = sep(data) 
 # X is column 1-12, coord is column 13-14, count is column 15-17
 
 ## Preprocess
 scaler = StandardScaler()
 X = scaler.fit_transform(X)
 coord = scaler.fit_transform(coord)
 new_coord, train_coord_values, digits = turn_y_into_binary(coord)
 
 ## Neural Network Training
 clf = MLPClassifier(solver='lbfgs', alpha=1e-5,
                     hidden_layer_sizes=(NN_layer, ), random_state=1)
 #y = np.zeros()
 #y = complex(coord[:,1],coord[:,2])
 clf.fit(X, new_coord)
 
from calcStats import calcStats
#from calcStatsOneAxis import calcStatsOneAxis
import os
"""
In this code, we eliminate features that have low coorelation with magnet
location

"""

##Select training file name and load it
fname = 'tcv_7_80.npy'
f = 'Simulation data/tcv' + os.path.altsep + fname
data = np.load(f)
fname = fname.split('.')[0]
## Separate data
X, coord, count = sep(data)  # X is nx12, coord is nx2
"""
Preprocessing
- First ocmpute the cross-correlation matrix between X (sensor measurements
 and coord (X, Y), this is a 14 by 14 matrixm but we are only concerned with
the last two rows as they show coorelation between measurements and magnet
location. 
-Then fit a regressor for X using those measurement components that have 
correlate with X above a certain threshold, i.e., abs(correlation coeff) is 
greater than a thershold xthershold
same thing with Y
then predict X and y separately 
""" ""
C = np.append(X, coord, 1)

R = np.corrcoef(np.transpose(C))