From 6c0a5b4204d7802a71e297c3f5f06febb719b028 Mon Sep 17 00:00:00 2001 From: Sai Raghava Reddy Ganapaa Date: Tue, 3 Sep 2019 08:57:18 +0200 Subject: [PATCH] optimising knowledge trnsfer and fixing bugs --- .../knowledge_transfer.cpython-36.pyc | Bin 4925 -> 6205 bytes .../__pycache__/leg_dynamics.cpython-36.pyc | Bin 12265 -> 13959 bytes .../__pycache__/my_network.cpython-36.pyc | Bin 4502 -> 4665 bytes spider_control/control1.py | 58 ++++-- spider_control/knowledge_transfer.py | 168 +++++++++--------- spider_control/kt.py | 117 ++++++++++++ spider_control/leg_dynamics.py | 71 ++++---- spider_control/my_network.py | 55 +++--- 8 files changed, 311 insertions(+), 158 deletions(-) create mode 100644 spider_control/kt.py diff --git a/spider_control/__pycache__/knowledge_transfer.cpython-36.pyc b/spider_control/__pycache__/knowledge_transfer.cpython-36.pyc index 90fc436f5673227f820a46330373198e92a546a7..4a1553cc388fa8b34a2971295172a0a9547783df 100644 GIT binary patch literal 6205 zcmcgwOOG5^6|Q$xSNF{HjK}uGcI-ApfsP`NoJ0tT1UnDo0AWJnyi_PD)%30DuAb_u z&aLVhPtzkL#t{;d$%YL<`~WtrLHq*N+1(vtWwBw2Sn-`(k7>8t77|ga)%V=Txvz7- zd+s^s#g!HJuV2O=|NDZX{6m@hbmVX1pS_EODNKzOPnA^jbWkleMy6+~MVsYWvd#8v zP(5}=4X>dpw-shE^Pa-Y6U}p(#q4{E*JSD)rRzMvxXMmf71sD@9H%*QjU?rxAdaSC zj~c75UdnG#6Ut?H8dI5u!SudDzdfDl%($m|n2uSfH<`^GP>VH~3u@PVP1XXR!&cZT z>Kkm0wLx9B&Ne`s>Z^4&JyDmGj?9}B3Q?S0qP9M|CumAJSKi&TO^xloGCX7)SB*Mya#=?V=<6k!_ z)|>q=en;P5Zj_n7-RQq4zb|ieU12BTgr`X+tT;Fdc_y@cPh86RBkqRQLwS zf8N|4q@!?q6!mzzo95eC*?yGxhuL<xX{MgCyGv z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waFIVC9*!ZWGO6FIT}jX&j6q=MQ*1w1qindRksiWfY62G4R*({P7TyD zd*YPp)=4B-Ti$8`znSM5;~PlI9-96@10PIX01E-O`<0EuA{W)?Gb#=mcB9;{@~-?95K+ z9&nBD3U0te&R*3CQ>s_(@H2y;x(heMqd4zxi+2e}$`aRT`W8(Tal)fXH7XAJ7;4!C zg_3G+#a)7SX!;IKxc+J|t`OldHPk5@71i^KdqjPKChBZdffwHf)NfY)(H(^79g~!2#9rLL4mr z8YT?^)#>&Try08`xn_?@a6BEgUl=+eoL97kF8S43FlF9lH- zDoA|F!}%5_S9f3Rxoy{Vx~^;Y9M^8&RvZHcD*cGv#(0d8{|OVNZROl>c&;Dl;w509 zI|P+Zfpuo0RpX#ppuJJk5P(bCJD}O1{kEoAYqa~IG0+w@&0eGR3WGbP_7{!2f5nyd z53m?4)u;oCELw+=c#mKeVLt=3us={YhsAAbXwt0kLb^-Dyy^hGbUxjWMBl6f1}#R0 zRwhpKNZ|m^8f$< diff --git a/spider_control/__pycache__/leg_dynamics.cpython-36.pyc b/spider_control/__pycache__/leg_dynamics.cpython-36.pyc index f29e93f23fa120e1a5be7850fbbdc0ec1ba77e6d..e3acb690c50ce73879f6e6c7fcd3c35ad26aca41 100644 GIT binary patch literal 13959 zcmeHOTaOz_74Ej(w#ReHB$>=L7iY7#*-Ns?YFGI(HUzXt+g6{tol}={ zsj9A1-dS9%{q}>skAC)T!}#17c#4SM#~Zu{APix8hHY|Ku!{%_Ua4c*mYI}UcA3j6 zc7?;LU47pWMN#_H5T$1Ydrp`i8r#+}>M|Z~o3V9p~3u7OE`UHBqtWTZX-WcMQDTHUl zvN(+uuZhDOn&uoM_?2^Vz+omBb7RsrXxXgZluH85xcd6#&hs2v~?pfJH(1B|-V% z8DLpZennV-RZ#|<69#%zdDzGyVf;k9NX{J7n99tYO~zj-Y5lJL;_YRd-3ol`K86O4VFz(%VV?D^4Ki3JT^tj zlloK|ZJe@vNh?348SnCF|7Pn)X4UfrIk7?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8?|@D$FsWMyO-YXr?&^8V)`4O1|=-QC@behiWD zbtH!QPxFuF2hWjG$W{NXn$OPV_jdBHYSHFDT@<$^TyY%wV-ScU*+bojS1kGoZ_HIj(@71wBP0HlB{F2L*gv8#|1)Id%FRhnV`*1Nnp1(<46JLNJ*Q`9M>=A|Kh3hUEvS^gGfke~Jt%jUB) zd8A1l8}$ox(ig{meb-GYuG{H(djZi^*L`oV8KgPlD|kx-n>3pZ`za;+?xy%E^8$BW z&|Yo>yEp5oGB!5%!nEtZ2DYeBLMP+|pFd^8Olp%yRE!O?LDbun9F0zljwSr2J~yuV15Lycbo5O~@|zS^oxe Cy9Js6 diff --git a/spider_control/__pycache__/my_network.cpython-36.pyc b/spider_control/__pycache__/my_network.cpython-36.pyc index 32a928f6c5f7d2830aefab3bcb2233486822aac8..1da9b53fd8d9cb90cccee872aab7df580ff333ac 100644 GIT binary patch literal 4665 zcma)9%WvGq8Rzi54@s++ZP~KDcAT`^hhT=xT>lioq2Hym|$+xhr?Xvli z=nbPh?Bz!yJU#w69gowb-HU@PYxA%lB~dbH=fkia%<;9;zQiTrkqF{;66UW`@uD5w z5AU~=qw!%Vh=ZtUlC`6x9R|H&I}T1j2ogTWBXL>JR7XL*jqhW8*_XPe6|B&Ft%2Y;t`8wz#nX+uU4$9d0eaF1Hup8g~}pI(HY~M&2B)j8;c$=v#%( zYki&9-_ripzmu}DL}}d6=H_kwPwEz^+hkL|Dp$Fp;57wbRd7qe*A%?2;2pr%ab70+ z7J9~O1MGHmg>SqyvFjU(ZY|NTD*CRX+cP?LkNKLEa!qmFR9wzGxpoxSEl{_4Yo^QX zCAhr=-&un10w!Ht^z*vhR`TCd^x6`=t?2g@y*{H$OGr)bD4zEf581g|mgJJGRNm*CJ^eCT=hY>H=6dq&0mnM1X97aJ#Gh8_!{%S~(-}=kbf1bWM=;)p~4uizAvz+trc<|*P>G|qF4gPj8*q6`O z2OYCClVBWr7SB&6p;&<=uYm~9qacn>L(%zOX;%SRIx2WeyN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>?VcNp7GooBwX7)7Z`#J-GY(Z3nFmdp=sq4R&J5 zv)XnO9K!YcD@oUCV$y+F@Vr>{JB}Yg^oNyyja8{&f)hIEX};g`Pq~ zqlLouO>B6L^6Pk{RpCzo&!0v?+QGAu@KsceCi6pKhQ9gZFNGOlkbb%F>zA%aGV~>M zGYy6A8nVT?wa*_%0E%N7O4+n|4Fx!?v0`<*w#U+WokH;qB+2AX17}R1RUg(PEq}I4 z?P|{roUXf{j(iynUj$MsKqLIgZ|6p$263!-o(VqQiLRHv&|W~G2*969bB~MxH2@}+ z{3!afbQStMS6+R85#3)wlBAQQki_~N%Ftc%a()ZBSCO1~O*mXXj(->Usr7L|H7W_( gyq1f;Dqk)p^Dle7c6Xn@6#ZI$xioGcRi;+{1!21DTL1t6 diff --git a/spider_control/control1.py b/spider_control/control1.py index 5dab368..fda6c34 100755 --- a/spider_control/control1.py +++ b/spider_control/control1.py @@ -21,61 +21,89 @@ from std_msgs.msg import Float64 from std_msgs.msg import Header from sklearn.multiclass import OneVsRestClassifier from sklearn.svm import LinearSVC +#from pydrive.auth import GoogleAuth +#from pydrive.drive import GoogleDrive + +#microbot = GoogleAuth() +#microbot.LocalWebserverAuth() +#drive = GoogleDrive(microbot) g_joint_states = None g_positions = None g_pos1 = None tactile_output = None + def tactile_callback(msg): global tactile_output tactile_output = msg.data def joint_callback(data, args): + global g_positions + global g_joint_states + global g_pos1 simulation_mode = args[0] #to distinguish between training and testing model_number = args[1]#to distiguish between the type of model to train incase of training - out = kt.one_hot_encoding(model_number) + ou = tf.one_hot([model_number-1], 4) + with tf.Session() as session: + out = session.run(ou) + #out = kt.one_hot_encoding(model_number) + rospy.loginfo(data.position)#testing pub_msg = JointState() # Make a new msg to publish results pub_msg.header = Header() pub_msg.name = data.name pub_msg.velocity = [10] * len(data.name) pub_msg.effort = [100] * len(data.name) g_positions = data.position - model1 = nn.Architecture(3, 24) - model2 = nn.Architecture(3, 24) - model3 = nn.Architecture(3, 24) - model4 = nn.Architecture(3, 24) velocity = 10*len(data.name) effort = 10*len(data.name) - leg = ld.Leg_attribute(g_positions, velocity, effort, tactile_output) - knowledge = kt.MultiClassLogistic(8, 3) - carollis_inp = leg.carollis_input(g_positions) + carollis_inp = leg.carollis_input() + print("carollis input is ")#testing + print(carollis_inp) knowledge_out = knowledge.run(carollis_inp) - model_num = knowledge_out.index(max(knowledge_out)) + model_num = np.where(knowledge_out == np.amax(knowledge_out)) reward = leg.leg_run() if(model_num == 0): - pub_msg.position = model1.nn_run(g_positions) + new_position = model1.nn_run(g_positions) + pub_msg.position = new_position model1.nn_learn(reward) elif(model_num == 1): - pub_msg.position = model2.nn_run(g_positions) + new_position = model2.nn_run(g_positions) + pub_msg.position = new_position model2.nn_learn(reward) elif(model_num == 2): - pub_msg.position = model3.nn_run(g_positions) + new_position = model3.nn_run(g_positions) + pub_msg.position = new_position model3.nn_learn(reward) elif(model_num == 3): - pub_msg.position = model4.nn_run(g_positions) + new_position = model4.nn_run(g_positions) + pub_msg.position = new_position model4.nn_learn(reward) if(simulation_mode == 'train'): knowledge.learn(out, knowledge_out) + leg.update_angles(new_position) + leg.update_effort(effort) + leg.update_velocity(velocity) + leg.update_tactile(tactile_output) joint_pub.publish(pub_msg) if __name__=='__main__': + model1 = nn.Architecture(3, 24, 1) + model2 = nn.Architecture(3, 24, 2) + model3 = nn.Architecture(3, 24, 3) + model4 = nn.Architecture(3, 24, 4) + knowledge = kt.MultiClassLogistic(8, 3) + pos = np.random.uniform(low = 0, high =2.5, size=24) + vel = 10 + eff = 100 + tact = np.zeros(8) + leg = ld.Leg_attribute(pos, vel, eff, tact) mode=input('please enter whether you want to test or train ?') if(mode == 'train'): - model_num = input('please enter the model you wish to train i.e. 1, 2, 3, 4') + model_number = int(input('please enter the model you wish to train i.e. 1, 2, 3, 4 \n ')) rospy.init_node('joint_logger_node', anonymous = True) rospy.Subscriber("/sr_tactile/touch/ff", Float64, tactile_callback) - rospy.Subscriber("joint_states", JointState, joint_callback, (mode, model_num)) + rospy.Subscriber("joint_states", JointState, joint_callback, (mode, model_number)) joint_pub = rospy.Publisher('target_joint_states', JointState, queue_size = 10) rospy.spin() diff --git a/spider_control/knowledge_transfer.py b/spider_control/knowledge_transfer.py index fb7c928..0f1b10c 100755 --- a/spider_control/knowledge_transfer.py +++ b/spider_control/knowledge_transfer.py @@ -5,43 +5,21 @@ from matplotlib import pyplot #import pyplot as plt import math import time +from sklearn.preprocessing import normalize class MultiClassLogistic: def __init__(self, neurons, layers): self.neurons = neurons self.layers = layers - global weight_in, weight_hid, weight_out, bias_hid, bias_in, bias_out - #self.weight_in = weight_in - #self.weight_hid = weight_hid - #self.weight_out = weight_out - #self.bias_hid = bias_hid - #self.bias_out = bias_out - #self.bias_in = bias_in - #self.neuron_input = tf.compat.v1.placeholder(tf.float32, shape=(neurons, 1)) - #self.neuron_hidden = tf.compat.v1.placeholder(tf.float32, shape=(neurons/4, 1)) - #self.neuron_out = tf.compat.v1.placeholder(tf.float32, shape=(4, 1))#four neurons in output layer because of the four quadrants - self.neuron_input = tf.compat.v1.placeholder(tf.float32, shape=(neurons, 1)) - self.weight_in = tf.get_variable("weight_in", [neurons, 1]) - self.neuron_hid = tf.compat.v1.placeholder(tf.float32, shape=(int(neurons/2), 1)) - self.weight_hid = tf.get_variable("weight_hid", [int(neurons/2), int(neurons/2)]) - self.neuron_out = tf.compat.v1.placeholder(tf.float32, shape=(4, 1)) - self.weight_out = tf.get_variable("weight_out", [4, 2]) - self.weights1 = np.random.rand(neurons, 1)#weights of input layer - self.weights2 = np.random.rand(int(neurons/2), int(neurons/2))#weights for hidden layer, number of neurons in hidden layer is identified by the quadrant concept - self.weights3 = np.random.rand(4, 2)#weights for output layer - self.bias_in =tf.random_normal((neurons, 1), dtype = tf.float32, seed = 2009) - self.bias_hid = tf.random_normal((int(neurons/2), 1), dtype = tf.float32, seed = 2509) - self.bias_out = tf.random_normal((4, 1), dtype=tf.float32, seed = 1234) - with tf.Session() as session1: - session1.run(self.weight_in, feed_dict={self.weight_in:self.weights1}) - with tf.Session() as session2: - session2.run(self.weight_hid, feed_dict={self.weight_hid:self.weights2}) - with tf.Session() as session3: - session3.run(self.weight_out, feed_dict={self.weight_out:self.weights3}) - with tf.Session() as session4: - bias_in, bias_hid, bias_out = session4.run([self.bias_in, self.bias_hid, self.bias_out]) - + self.weight_initer = tf.truncated_normal_initializer(mean=0.0, stddev=0.01) + self.weight_initer1 = tf.truncated_normal_initializer(mean=1.0, stddev=0.01) + self.weight_initer2 = tf.truncated_normal_initializer(mean=2.0, stddev=0.01) + self.bias_initer =tf.truncated_normal_initializer(mean=0.1, stddev=0.01) + self.bias_initer1 =tf.truncated_normal_initializer(mean=0.2, stddev=0.01) + self.bias_initer2 =tf.truncated_normal_initializer(mean=0.3, stddev=0.01) + + #defining input function that can accept the output from previous layer and can calculate the input for present layer def input_function(self, a = [], b = [], c = []): @@ -52,22 +30,13 @@ class MultiClassLogistic: n_input = sess.run(add) return n_input #function that returns the softmax of the output layer or any given array of neurons - def out_softmax(self, neuron_out = []): + def out_softmax(self, neuron_out): output = tf.nn.softmax(neuron_out) with tf.Session() as sess: out = sess.run(output) return out - #def output_func(self, ): - - def activation(self, a): - 'where a is the input of the neuron and the activation function is modelled as rectified linear output' - if(a>=0): - b = a - else: - b = 0 - return b - def kt_learning(self, learning_rate, n_out = [], n_preferred = []): + def kt_learning(self, learning_rate, n_out , n_preferred): 'where n_out is the actual output and n_preffered is the prefered output of the network' loss = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(labels=n_out, logits=n_preferred)) optimizer = tf.train.GradientDescentOptimizer(learning_rate).minimize(loss) @@ -76,10 +45,9 @@ class MultiClassLogistic: return def get_neuron(self, a, b): - 'while a being the name of the neuron and b being the value of that neuron' + #'while a being the name of the neuron and b being the value of that neuron' with tf.Session() as sess_n: sess_n.run(a, feed_dict={a: b}) - return 'a function to findout the input of the neurn giving its weights and biases, can only be used in neurons in hidden and output layer' def input_method(self, a=[], b=[], c=[]): multiplication = tf.multiply(a, b) @@ -89,56 +57,94 @@ class MultiClassLogistic: out = sess.run(add) return out def normalization(self, inputs): - a_min = min(a) - a_max = max(a) - for i in range(len(a)): - a[i] = (a[i]-a_min)/(a_max-a_min) + a_min = min(inputs) + a_max = max(inputs) + for i in range(len(inputs)): + inputs[i] = (inputs[i]-a_min)/(a_max-a_min) + + def input_weight(self): + with tf.compat.v1.variable_scope("weight_in", reuse=tf.compat.v1.AUTO_REUSE): + v = tf.compat.v1.get_variable("weight_input", dtype=tf.float64, shape=[self.neurons, 1], initializer=self.weight_initer) + return v + + def hid_weight(self): + with tf.compat.v1.variable_scope("weight_hid", reuse=tf.compat.v1.AUTO_REUSE): + v = tf.compat.v1.get_variable("weight_hidden", dtype=tf.float64, shape=[self.neurons, 1], initializer=self.weight_initer1) + return v - def run(self, carollis_input = []): - self.normalization(carollis_input) - self.get_neuron(self.neuron_input, carollis_input) + def out_weight(self): + with tf.compat.v1.variable_scope("weight_out", reuse=tf.compat.v1.AUTO_REUSE): + v = tf.compat.v1.get_variable("weight_input", dtype=tf.float64, shape=[4, 2], initializer=self.weight_initer2) + return v + + def bias_in(self): + with tf.compat.v1.variable_scope("bias_in", reuse=tf.compat.v1.AUTO_REUSE): + v = tf.compat.v1.get_variable("bias_input", dtype=tf.float64, shape=[self.neurons, 1], initializer=self.bias_initer) + return v + + def bias_hid(self): + with tf.compat.v1.variable_scope("bias_hidd", reuse=tf.compat.v1.AUTO_REUSE): + v = tf.compat.v1.get_variable("bias_hidden", dtype=tf.float64, shape=[self.neurons, 1], initializer=self.bias_initer1) + return v + + def bias_out(self): + with tf.compat.v1.variable_scope("bias_outt", reuse=tf.compat.v1.AUTO_REUSE): + v = tf.compat.v1.get_variable("bias_out", dtype=tf.float64, shape=[4, 1], initializer=self.bias_initer2) + return v + def run(self, carollis_input): + c_in=normalize(carollis_input, axis = 0) + print('normalized carollis input is \n') + print(c_in) + c_in = np.array(c_in) + c_input = tf.compat.v1.convert_to_tensor(c_in, tf.float64) #'finding the output of the input layer' - knowledge_input = self.input_function(self.neuron_input, - self.weight_in, - self.bias_in) - #'calculating the input for the hidden layer' - tf.reshape(knowledge_input, [4, 2]) - knowledge_hidden = self.input_method(knowledge_input, self.weight_hid, - self.bias_hid) - #'feeding in the input value of hidden neurons' - self.get_neuron(self.neuron_hid, knowledge_hidden) + weight_i = self.input_weight() + weight_h = self.hid_weight() + weight_o = self.out_weight() + bias_i = self.bias_in() + bias_h = self.bias_hid() + bias_o = self.bias_out() + init = tf.global_variables_initializer() + sess = tf.Session() + sess.run(init) + knowledge_input = tf.add(tf.multiply(c_input, weight_i), bias_i) + sess.run(knowledge_input) + knowledge_hidden = tf.nn.leaky_relu(knowledge_input, alpha=0.01) #'calculating the output of hidden layer' - knowledge_hidden_out = self.activation(self.neuron_hid) + knowledge_hidden_output = 3.14*(tf.add(tf.multiply(knowledge_hidden, weight_h), bias_h))#input function of hidden layer + knowledge_hidden_out = tf.nn.leaky_relu(knowledge_hidden_output, alpha=0.01, name='leaky_relu') + + sess.run(knowledge_hidden_out) #'calculating the input of output layer' - np.reshape(knowledge_hidden_out, [2, 2]) - extra = np.array(knowledge_hidden_out(1, 3), knowledge_hidden_out(2, 4)) - knowledge_out = tf.concat([knowledge_hidden_out, extra], axis=0) - in_out = self.input_method(knowledge_out, self.weight_out, self.bias_out) - with tf.Session as s: - s.run(in_out) - #'feeding the input value of output neurons' - self.get_neuron(self.neuron_out, in_out) + knowledge_hidden_out = tf.reshape(knowledge_hidden_out, [4, 2])#for quadrant method + out_mult = tf.multiply(knowledge_hidden_out, weight_o) + out_add = tf.add(out_mult[:, 0], out_mult[:, 1]) + in_out = tf.add(out_add, bias_o) + #i_o = sess.run(in_out) + #r_i_o = np.reshape(i_o, (8, 1)) + #outt = np.add(r_i_o[0:4, 0], r_i_o[4:8, 0]) + #outt = np.reshape(outt, (4, 1)) + #out_multt = tf.placeholder(tf.float64, shape=(4, 1)) + #in_outt = tf.add(out_multt, bias_o) + output = sess.run(in_out) + #output = sess.run(in_out) #'finding the softmax output of the neurons' - softmax_output = np.array(4) - softmax_output = self.out_softmax(self.neuron_out) # this gives the softmax output and stores it in the newly created array - return softmax_output + softmax_output = tf.nn.softmax(in_out) + output = sess.run(softmax_output) + return output def learn(self, preferred_out, soft_out): self.kt_learning(0.1, soft_out, preferred_out) def one_hot_encoding(model_type): - a_1 = np.zeros((4)) + a_1 = np.zeros((3)) if (model_type == 1): - - hot_encoded_matrix = np.insert(a_1, 0, 1, axis=0)#insert 1 in the first coloumn in x axis + hot_encoded_matrix = np.insert(a_1, 0, 1, axis=None)#insert 1 in the first coloumn in x axis elif(model_type == 2): - - hot_encoded_matrix = np.insert(a_1, 1, 1, axis=0) + hot_encoded_matrix = np.insert(a_1, 1, 1, axis=None) elif(model_type == 3): - - hot_encoded_matrix = np.insert(a_1, 2, 1, axis=0) + hot_encoded_matrix = np.insert(a_1, 2, 1, axis=None) elif(model_type == 4): - - hot_encoded_matrix = np.insert(a_1, 3, 1, axis=0) + hot_encoded_matrix = np.insert(a_1, 3, 1, axis=None) else: raise ValueError(f"Value {model_type} is not a valid model number") return hot_encoded_matrix \ No newline at end of file diff --git a/spider_control/kt.py b/spider_control/kt.py new file mode 100644 index 0000000..ad7ba6e --- /dev/null +++ b/spider_control/kt.py @@ -0,0 +1,117 @@ +#!/usr/bin/python3 +import tensorflow as tf +import numpy as np +from matplotlib import pyplot +#import pyplot as plt +import math +import time + +class MultiClassLogistic: + + def __init__(self, neurons, layers): + self.neurons = neurons + self.layers = layers + self.mygraph = tf.Graph() + self.weight_initer = tf.truncated_normal_initializer(mean=0.0, stddev=0.01) + self.neuron_input = tf.compat.v1.placeholder(tf.float32, shape=(self.neurons, 1)) + self.weight_in = tf.get_variable(name="Weight_input", dtype=tf.float64, shape=[self.neurons, 1], initializer=self.weight_initer) + self.neuron_hid = tf.compat.v1.placeholder(tf.float32, shape=(int(self.neurons/2), 1)) + self.weight_initer1 = tf.truncated_normal_initializer(mean=1.0, stddev=0.01) + self.weight_hid = tf.get_variable(name="Weight_hidden", dtype=tf.float64, shape=[self.neurons, 1], initializer=self.weight_initer1) + self.neuron_out = tf.compat.v1.placeholder(tf.float32, shape=(4, 1)) + self.weight_initer2 = tf.truncated_normal_initializer(mean=2.0, stddev=0.01) + self.weight_out = tf.get_variable(name="Weight_output", dtype=tf.float64, shape=[4, 2], initializer=self.weight_initer2) + self.bias_initer =tf.truncated_normal_initializer(mean=0.1, stddev=0.01) + self.bias_in =tf.get_variable(name="Bias_input", dtype=tf.float64, shape=[self.neurons, 1], initializer=self.bias_initer) + self.bias_initer1 =tf.truncated_normal_initializer(mean=0.2, stddev=0.01) + self.bias_hid = tf.get_variable(name="Bias_hidden", dtype=tf.float64, shape=[self.neurons, 1], initializer=self.bias_initer1) + self.bias_initer2 =tf.truncated_normal_initializer(mean=0.3, stddev=0.01) + self.bias_out = tf.get_variable(name="Bias_output", dtype=tf.float64, shape=[4, 1], initializer=self.bias_initer2) + + #defining input function that can accept the output from previous layer and can calculate the input for present layer + + #def input_function(self, a = [], b = [], c = []): + # 'where b=output value of neurons from previous layer, a = weights of neurons from the present layer, c = bias' + # multiplication = tf.multiply(a, b) + # add = tf.add(multiplication, c) + # sess = tf.Session() + # n_input = sess.run(add) + # return n_input + #function that returns the softmax of the output layer or any given array of neurons + def out_softmax(self, neuron_out = []): + output = tf.nn.softmax(neuron_out) + with tf.Session() as sess: + out = sess.run(output) + return out + + def kt_learning(self, learning_rate, n_out = [], n_preferred = []): + 'where n_out is the actual output and n_preffered is the prefered output of the network' + loss = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(labels=n_out, logits=n_preferred)) + optimizer = tf.train.GradientDescentOptimizer(learning_rate).minimize(loss) + with tf.Session() as sess: + sess.run(optimizer) + return + + #def get_neuron(self, a, b): + # #'while a being the name of the neuron and b being the value of that neuron' + # with tf.Session() as sess_n: + # sess_n.run(a, feed_dict={a: b}) + #'a function to findout the input of the neurn giving its weights and biases, can only be used in neurons in hidden and output layer' + #def input_method(self, a=[], b=[], c=[]): + # multiplication = tf.multiply(a, b) + # d = tf.reduce_sum(multiplication, 0) + # add = tf.add(d, c) + # with tf.Session() as sess: + # out = sess.run(add) + # return out + def normalization(self, inputs): + a_min = min(inputs) + a_max = max(inputs) + for i in range(len(inputs)): + inputs[i] = (inputs[i]-a_min)/(a_max-a_min) + + def run(self, carollis_input): + self.normalization(carollis_input) + #'finding the output of the input layer' + #with tf.Session() as sess1_2: + + knowledge_input = tf.add(tf.multiply(carollis_input, self.weight_in), self.bias_in) + + #'calculating the input for the hidden layer' + knowledge_hidden = tf.add(tf.multiply(knowledge_input, self.weight_in), self.bias_hid) + #'calculating the output of hidden layer' + knowledge_hidden_output = 3.14*(tf.add(tf.multiply(knowledge_hidden, self.weight_hid), self.bias_hid))#input function of hidden layer + knowledge_hidden_out = tf.nn.leaky_relu(knowledge_hidden_output, alpha=0.01, name='leaky_relu') + + with tf.Session() as sess1_2: + knowledge_hidden_out1 = sess1_2.run(knowledge_hidden_out) + #'calculating the input of output layer' + tf.reshape(knowledge_hidden_out1, [4, 2])#for quadrant method + in_out = tf.add(tf.multiply(knowledge_hidden_out1, self.weight_out), self.bias_out) + with tf.Session() as s: + s.run(in_out) + #'finding the softmax output of the neurons' + softmax_output = np.array(4) + softmax_output = self.out_softmax(in_out) # this gives the softmax output and stores it in the newly created array + return softmax_output + def learn(self, preferred_out, soft_out): + self.kt_learning(0.1, soft_out, preferred_out) + +def one_hot_encoding(model_type): + a_1 = np.zeros((3)) + if (model_type == 1): + hot_encoded_matrix = np.insert(a_1, 0, 1, axis=None)#insert 1 in the first coloumn in x axis + elif(model_type == 2): + hot_encoded_matrix = np.insert(a_1, 1, 1, axis=None) + elif(model_type == 3): + hot_encoded_matrix = np.insert(a_1, 2, 1, axis=None) + elif(model_type == 4): + hot_encoded_matrix = np.insert(a_1, 3, 1, axis=None) + else: + raise ValueError(f"Value {model_type} is not a valid model number") + return hot_encoded_matrix + +if __name__=='__main__': + knowledge = MultiClassLogistic(8, 3) + io = np.array([6.45, 4.54, 7, 8.98, 8.88, 12.34, 25.76, 1.67]) + knowledge_out = knowledge.run(io) \ No newline at end of file diff --git a/spider_control/leg_dynamics.py b/spider_control/leg_dynamics.py index 8fa66f8..d6e21b6 100755 --- a/spider_control/leg_dynamics.py +++ b/spider_control/leg_dynamics.py @@ -26,31 +26,42 @@ class Leg_attribute: self.velocity = velocity # vector containing joint velocities self.j_efforts = effort # vector containing efforts of each joint in the leg self.tactile = tactile + self.m = 0.3 + self.g = 9.8 + self.r = 0.1 + self.l = 0.4 + self.L = 0.6 + self.M = 2.8 + def update_angles(self, angles): + self.j_angles = angles + def update_velocity(self, veloc): + self.velocity = veloc + def update_tactile(self, tac): + self.tactile = tac + def update_effort(self, ef): + self.j_effort = ef + - def give_angles(self, j_angles): - a = j_angles - return a - - def x_left_com(self, a, b, c, d, joint_angles = []): - return (1/(2*(a+6*b)))*(a*d+2*b*c(3*(math.cos(joint_angles[2])+math.cos(joint_angles[8])+math.cos(joint_angles[14])+math.cos(joint_angles[20]))+2*(math.cos(joint_angles[1])+math.cos(joint_angles[7])+math.cos(joint_angles[13])+math.cos(joint_angles[19]))+math.cos(joint_angles[0])+math.cos(joint_angles[6])+math.cos(joint_angles[12])+math.cos(joint_angles[18]))) + def x_left_com(self): + return (1/(2*(self.M/2+6*self.g)))*(self.M/2*self.l+2*self.g*self.r*(3*(math.cos(self.j_angles[2])+math.cos(self.j_angles[8])+math.cos(self.j_angles[14])+math.cos(self.j_angles[20]))+2*(math.cos(self.j_angles[1])+math.cos(self.j_angles[7])+math.cos(self.j_angles[13])+math.cos(self.j_angles[19]))+math.cos(self.j_angles[0])+math.cos(self.j_angles[6])+math.cos(self.j_angles[12])+math.cos(self.j_angles[18]))) #a,b,c,d,e,f,j,k,l,m,n,o,p are respectively m_b,m_l,L,x_body_com/y_body_com,theta_1_1,theta_1_2,...theta_8_3 - def y_left_com(self, a, b, c, d, joint_angles = []): - return (1/(2*(a+6*b)))*(a*d+2*b*c(3*(math.sin(joint_angles[2])+3*math.sin(joint_angles[8])+math.sin(joint_angles[14])+math.sin(joint_angles[20]))+2*(math.sin(joint_angles[1])+math.sin(joint_angles[7])+math.sin(joint_angles[13])+math.sin(joint_angles[19]))+math.sin(joint_angles[0])+math.sin(joint_angles[6])+math.sin(joint_angles[12])+math.sin(joint_angles[18]))) + def y_left_com(self): + return (1/(2*(self.M/2+6*self.g)))*(self.M/2*self.l+2*self.g*self.r*(3*(math.sin(self.j_angles[2])+3*math.sin(self.j_angles[8])+math.sin(self.j_angles[14])+math.sin(self.j_angles[20]))+2*(math.sin(self.j_angles[1])+math.sin(self.j_angles[7])+math.sin(self.j_angles[13])+math.sin(self.j_angles[19]))+math.sin(self.j_angles[0])+math.sin(self.j_angles[6])+math.sin(self.j_angles[12])+math.sin(self.j_angles[18]))) - def x_right_com(self, a, b, c, d, joint_angles = []): - return (1/(2*(a+6*b)))*(3*a*d+2*b*c*(3*math.cos(joint_angles[5])+3*math.cos(joint_angles[11])+3*math.cos(joint_angles[17])+3*math.cos(joint_angles[23])+2*math.cos(joint_angles[4])+2*math.cos(joint_angles[10])+2*math.cos(joint_angles[16])+2*math.cos(joint_angles[22])+math.cos(joint_angles[3])+math.cos(joint_angles[9])+math.cos(joint_angles[15])+math.cos(joint_angles[21]))) + def x_right_com(self): + return (1/(2*(self.M/2+6*self.g)))*(3*self.M/2*self.l+2*self.g*self.r*(3*math.cos(self.j_angles[5])+3*math.cos(self.j_angles[11])+3*math.cos(self.j_angles[17])+3*math.cos(self.j_angles[23])+2*math.cos(self.j_angles[4])+2*math.cos(self.j_angles[10])+2*math.cos(self.j_angles[16])+2*math.cos(self.j_angles[22])+math.cos(self.j_angles[3])+math.cos(self.j_angles[9])+math.cos(self.j_angles[15])+math.cos(self.j_angles[21]))) - def y_right_com(self, a, b, c, d, joint_angles = []): - return (1/(2*(a+6*b)))*(3*a*d+2*b*c*(3*math.sin(joint_angles[5])+3*math.sin(joint_angles[11])+3*math.sin(joint_angles[17])+3*math.sin(joint_angles[23])+2*math.sin(joint_angles[4])+2*math.sin(joint_angles[10])+2*math.sin(joint_angles[16])+2*math.sin(joint_angles[22])+math.sin(joint_angles[3])+math.sin(joint_angles[9])+math.sin(joint_angles[15])+math.sin(joint_angles[21]))) + def y_right_com(self): + return (1/(2*(self.M/2+6*self.g)))*(3*self.M/2*self.l+2*self.g*self.r*(3*math.sin(self.j_angles[5])+3*math.sin(self.j_angles[11])+3*math.sin(self.j_angles[17])+3*math.sin(self.j_angles[23])+2*math.sin(self.j_angles[4])+2*math.sin(self.j_angles[10])+2*math.sin(self.j_angles[16])+2*math.sin(self.j_angles[22])+math.sin(self.j_angles[3])+math.sin(self.j_angles[9])+math.sin(self.j_angles[15])+math.sin(self.j_angles[21]))) - def x_system_com(self, a, b, c, d, joint_angles = []): - return (1/(a+6*b*c))*(2*a*d+b*c*(3*(math.cos(joint_angles[2])+math.cos(joint_angles[5])+math.cos(joint_angles[8])+math.cos(joint_angles[11])+math.cos(joint_angles[14])+math.cos(joint_angles[17])+math.cos(joint_angles[20])+math.cos(joint_angles[23]))+2*(math.cos(joint_angles[1])+math.cos(joint_angles[4])+math.cos(joint_angles[7])+math.cos(joint_angles[10])+math.cos(joint_angles[13])+math.cos(joint_angles[16])+math.cos(joint_angles[19])+math.cos(joint_angles[22]))+math.cos(joint_angles[0])+math.cos(joint_angles[3])+math.cos(joint_angles[6])+math.cos(joint_angles[9])+math.cos(joint_angles[12])+math.cos(joint_angles[15])+math.cos(joint_angles[18])+math.cos(joint_angles[21]))) + def x_system_com(self): + return (1/(self.M/2+6*self.g*self.r))*(2*self.M/2*self.l+self.g*self.r*(3*(math.cos(self.j_angles[2])+math.cos(self.j_angles[5])+math.cos(self.j_angles[8])+math.cos(self.j_angles[11])+math.cos(self.j_angles[14])+math.cos(self.j_angles[17])+math.cos(self.j_angles[20])+math.cos(self.j_angles[23]))+2*(math.cos(self.j_angles[1])+math.cos(self.j_angles[4])+math.cos(self.j_angles[7])+math.cos(self.j_angles[10])+math.cos(self.j_angles[13])+math.cos(self.j_angles[16])+math.cos(self.j_angles[19])+math.cos(self.j_angles[22]))+math.cos(self.j_angles[0])+math.cos(self.j_angles[3])+math.cos(self.j_angles[6])+math.cos(self.j_angles[9])+math.cos(self.j_angles[12])+math.cos(self.j_angles[15])+math.cos(self.j_angles[18])+math.cos(self.j_angles[21]))) - def y_system_com(self, a, b, c, d, joint_angles = []): - return (1/(a+6*b*c))*(2*a*d+b*c*(3*(math.sin(joint_angles[2])+math.sin(joint_angles[5])+math.sin(joint_angles[8])+math.sin(joint_angles[11])+math.sin(joint_angles[14])+math.sin(joint_angles[17])+math.sin(joint_angles[20])+math.sin(joint_angles[23]))+2*(math.sin(joint_angles[1])+math.sin(joint_angles[4])+math.sin(joint_angles[7])+math.sin(joint_angles[10])+math.sin(joint_angles[13])+math.sin(joint_angles[16])+math.sin(joint_angles[19])+math.sin(joint_angles[22]))+math.sin(joint_angles[0])+math.sin(joint_angles[3])+math.sin(joint_angles[6])+math.sin(joint_angles[9])+math.sin(joint_angles[12])+math.sin(joint_angles[15])+math.sin(joint_angles[18])+math.sin(joint_angles[21]))) + def y_system_com(self): + return (1/(self.M/2+6*self.g*self.r))*(2*self.M/2*self.l+self.g*self.r*(3*(math.sin(self.j_angles[2])+math.sin(self.j_angles[5])+math.sin(self.j_angles[8])+math.sin(self.j_angles[11])+math.sin(self.j_angles[14])+math.sin(self.j_angles[17])+math.sin(self.j_angles[20])+math.sin(self.j_angles[23]))+2*(math.sin(self.j_angles[1])+math.sin(self.j_angles[4])+math.sin(self.j_angles[7])+math.sin(self.j_angles[10])+math.sin(self.j_angles[13])+math.sin(self.j_angles[16])+math.sin(self.j_angles[19])+math.sin(self.j_angles[22]))+math.sin(self.j_angles[0])+math.sin(self.j_angles[3])+math.sin(self.j_angles[6])+math.sin(self.j_angles[9])+math.sin(self.j_angles[12])+math.sin(self.j_angles[15])+math.sin(self.j_angles[18])+math.sin(self.j_angles[21]))) def mid_point_x(self, x_left, x_right): 'in order to calculate whether the syste com is normal to the line between left and right com' @@ -76,11 +87,11 @@ class Leg_attribute: term = term_1 +term_2 + term_3 return term - def tactile_run(self, tactile_sub = []): + def tactile_run(self): score = 0 total = 0 - for element in range(0, len(tactile_sub)): - if(tactile_sub[element]>0.5): + for element in range(0, len(self.tactile)): + if(self.tactile[element]>0.5): total +=1 if(total>3): score = total @@ -121,24 +132,18 @@ class Leg_attribute: term6 = term_6_1+term_6_2+term_6_3 term7 = term_7_1+term_7_2+term_7_3 term8 = term_8_1+term_8_2+term_8_3 - term = np.array([term1, term2, term3, term4, term5, term6, term7, term8]) + term = np.array([[term1], [term2], [term3], [term4], [term5], [term6], [term7], [term8]], dtype=np.float32) return term def leg_run(self): - m = 0.3 - g = 9.8 - r = 0.1 - l = 0.4 - L = 0.6 - M = 2.8 - x_l_com = self.x_left_com(M/2, g, r, l, self.j_angles) - y_l_com = self.y_left_com(M/2, g, r, l, self.j_angles) - x_r_com = self.x_right_com(M/2, g, r, l, self.j_angles) - y_r_com = self.y_right_com(M/2, g, r, l, self.j_angles) - x_s_com = self.x_system_com(M, g, r, l, self.j_angles) - y_s_com = self.y_system_com(M, g, r, l, self.j_angles) + x_l_com = self.x_left_com() + y_l_com = self.y_left_com() + x_r_com = self.x_right_com() + y_r_com = self.y_right_com() + x_s_com = self.x_system_com() + y_s_com = self.y_system_com() x_m_com = self.mid_point_x(x_l_com, x_r_com) y_m_com = self.mid_point_y(y_l_com, y_r_com) reward_stability = self.slope(x_m_com, y_m_com, x_s_com, y_s_com) - reward_tactile = self.tactile_run(self.tactile) + reward_tactile = self.tactile_run() reward = reward_stability+reward_tactile return reward \ No newline at end of file diff --git a/spider_control/my_network.py b/spider_control/my_network.py index d79aeb5..e0aa889 100755 --- a/spider_control/my_network.py +++ b/spider_control/my_network.py @@ -12,41 +12,38 @@ import leg_dynamics as ld class Architecture: 'Common class defining the architecture of the neural network i.e. number of neurons in each layer and number of layers' - def __init__(self, layers, neurons): + def __init__(self, layers, neurons, number): self.layers = layers self.neurons = neurons - #global neuron_i - #global neuron_o - #global neuron_h - #global neuron_h_c - #global weights_i - #global weights_o - #global weights_h - #global weights_h_c - #global bias_i - #global bias_o - #global bias_h - #global bias_h_c + self.number = number#number of the model + self.weight_in = 'weight_in'+str(self.number) + self.weight_out = 'weight_out'+str(self.number) + self.weight_hid = 'weight_hid'+str(self.number) + self.weight_hid_cont = 'weight_hid_cont'+str(self.number) + self.bias_in = 'bias_in'+str(self.number) + self.bias_out = 'bias_out'+str(self.number) + self.bias_hid = 'bias_hid'+str(self.number) + self.bias_hid_con = 'bias_hid_con'+str(self.number) self.neuron_i = tf.compat.v1.placeholder(tf.float32, shape=(neurons, 1)) # _input layer neurons self.neuron_o = tf.compat.v1.placeholder(tf.float32, shape=(neurons, 1)) # output layer neurons self.neuron_h = tf.compat.v1.placeholder(tf.float32, shape=(neurons/3, 1)) # hidden layer neurons, only 8 neurons because there are eight legs self.neuron_h_c = tf.compat.v1.placeholder(tf.float32, shape=(neurons/3, 1)) # context layer neurons, only 8 neurons because there are eight in hidden layer - self.weights_i = tf.compat.v1.placeholder(tf.float32, shape=(neurons, layers)) # weights of input layer neurons - self.weights_o = tf.compat.v1.placeholder(tf.float32, shape=(neurons, layers)) # weights of output layer neurons - self.weights_h = tf.compat.v1.placeholder(tf.float32, shape=(neurons/3, layers)) # weights of hidden layer neurons - self.weights_h_c = tf.compat.v1.placeholder(tf.float32, shape=(neurons/3, layers)) # weights of context layer neurons - self.bias_i = tf.random_uniform((neurons, 1), minval = 0, maxval = 1, dtype = tf.float32, seed=9999) #biases of each neurons - self.bias_o = tf.random_uniform((neurons, 1), minval = 0, maxval = 1, dtype = tf.float32, seed = 1111) - self.bias_h = tf.random_uniform((int(neurons/3), 1), minval = 0, maxval = 1, dtype = tf.float32, seed=2222) - self.bias_h_c = tf.random_uniform((8, 1), minval = 0, maxval = 1, dtype = tf.float32, seed=3333) - def weight_initialize (self, neurons): - weights1 = tf.Variable(tf.random_uniform((neurons, 1), minval=0, maxval=1, dtype=tf.float32, seed=7273)) - weights2 = tf.Variable(tf.random_uniform((neurons, 1), minval=0, maxval=1, dtype=tf.float32, seed=3000)) - weights3h=tf.Variable(tf.random_uniform((neurons/3, neurons/6), minval=0, maxval=1, dtype=tf.float32, seed= 119)) - weights3c=tf.Variable(tf.random_uniform((neurons/3, 1), minval=0, maxval=1, dtype=tf.float32, seed=1508)) - sess=tf.Session() - weights_i, weights_o, weights_h, weights_h_c = sess.run(weights1, weights2, weights3h, weights3c) - return weights_i, weights_o, weights_h, weights_h_c + self.weight_initer = tf.truncated_normal_initializer(mean=1.0, stddev=0.01) + self.weight_initer1 = tf.truncated_normal_initializer(mean=1.0, stddev=0.05) + self.weight_initer2 = tf.truncated_normal_initializer(mean=1.0, stddev=0.1) + self.weight_initer3 = tf.truncated_normal_initializer(mean=1.0, stddev=0.15) + self.weights_i = tf.get_variable(name=self.weight_in ,dtype=tf.float32, shape=[self.neurons, 1], initializer=self.weight_initer) # weights of input layer neurons + self.weights_o = tf.get_variable(name=self.weight_out, dtype=tf.float32, shape=[self.neurons, 1], initializer=self.weight_initer1) # weights of output layer neurons + self.weights_h = tf.get_variable(name=self.weight_hid, dtype=tf.float32, shape=[self.neurons/3, self.layers], initializer=self.weight_initer2) # weights of hidden layer neurons + self.weights_h_c = tf.get_variable(name=self.weight_hid_cont, dtype=tf.float32, shape=[self.neurons/3, self.layers], initializer=self.weight_initer3) # weights of context layer neurons + self.bias_initer =tf.truncated_normal_initializer(mean=0.1, stddev=0.01) + self.bias_initer1 =tf.truncated_normal_initializer(mean=0.1, stddev=0.01) + self.bias_initer2 =tf.truncated_normal_initializer(mean=0.1, stddev=0.01) + self.bias_initer3 =tf.truncated_normal_initializer(mean=0.1, stddev=0.01) + self.bias_i = tf.get_variable(name=self.bias_in, dtype=tf.float32, shape=[self.neurons, 1], initializer=self.bias_initer) #biases of each neurons + self.bias_o = tf.get_variable(name=self.bias_out, dtype=tf.float32, shape=[self.neurons, 1], initializer=self.bias_initer1) + self.bias_h = tf.get_variable(name=self.bias_hid, dtype=tf.float32, shape=[self.neurons/3, 1], initializer=self.bias_initer2) + self.bias_h_c = tf.get_variable(name=self.bias_hid_con, dtype=tf.float32, shape=[self.neurons/3, 1], initializer=self.bias_initer3) # get neuron value method helps us to write the joint angles to the individual neurons which we can later use for learning def get_neuron_value(self, a, b): with tf.Session() as sess_n: -- GitLab