def jdpay_wap(): env_name, root_url, live_key, app_id = datagen.get_current_env() url = "{0}/v1/charges".format(root_url) # request body charge = Model.ChargeBase.ChargeDict charge['order_no'] = random_str(10) charge['subject'] = 'TestOrder4jdpay_wap' charge['body'] = 'appletest4Pay' charge['amount'] = 10 charge['channel'] = 'jdpay_wap' charge['currency'] = 'cny' charge['client_ip'] = '127.0.0.1' id = [('id', app_id)] extra = [("success_url", "http://pingxx.com"), ("fail_url", "htpps://pingxx.com")] charge['app'] = dict(id) charge['extra'] = dict(extra) mycharge = APIClient._http_call(url, "post", "json", "json", None, {"Authorization": "Bearer {0}".format(live_key)}, 30, **charge) print(mycharge) sshCmd.ssh_cmd("114.215.237.77", "56f27c2B", "echo "">/var/www/example/ziteng") threading._start_new_thread(sshCmd.ssh_cmd("114.215.237.77", "56f27c2B", "echo "">/var/www/example/ziteng")) time.sleep(5) Forward.forward_json(mycharge) ret = sshCmd.ssh_cmd("114.215.237.77", "56f27c2B", "echo "">/var/www/example/ziteng") print ret if int(filter(lambda x: x.isdigit(), ret)) > 1: print "The charge file had updated on %s" % ctime() else: print "forward the charge to update file again..." threading._start_new_thread(sshCmd.ssh_cmd("114.215.237.77", "56f27c2B", "echo "">/var/www/example/ziteng")) time.sleep(2) Forward.forward_json(mycharge)
def base(is_private,channel, needforward=True, **extra): if is_private == False: env_name, root_url, live_key, app_id = datagen.get_current_env() else: env_name, root_url, live_key, app_id = datagen.get_my_env() url = "{0}/v1/charges".format(root_url) # request body charge = Model.ChargeBase.ChargeDict() charge['order_no'] = random_str(10) charge['subject'] = "Autopay_TestOrder4{0}".format(channel) charge['body'] = "appletesting4Pay" charge['amount'] = 10 charge['channel'] = channel charge['currency'] = "cny" charge['client_ip'] = "127.0.0.1" id = [("id", app_id)] charge['app'] = dict(id) charge['extra'] = extra myCharge = APIClient._http_call(url, "POST", "json", "json", None, {"Authorization": "Bearer {0}".format(live_key)}, 30, **charge) print(myCharge) if (needforward): time.sleep(5) Forward.forward_json(myCharge) else: return myCharge
def DecideNextAction(): global lockMode Global.myRole = Constant.ATTACKER if GrabTurnKick.lockMode: GrabTurnKick.DecideNextAction() lockMode = True return lockMode = False if Global.ballY < Constant.FIELD_LENGTH/2: Forward.resetEachFrame() rAttacker.DecideNextAction() FWHead.DecideNextAction() return me_x = Global.selfLoc.getX() me_y = Global.selfLoc.getY() #ballToGoalDist = HelpMath.getDistanceBetween( \ # Global.ballX, Global.ballY, \ # Constant.TARGET_GOAL_X, Constant.TARGET_GOAL_Y) angleMeBallGoal = \ HelpMath.angleBetweenTwoPointsFromPivotPoint( \ me_x, me_y, \ Constant.TARGET_GOAL_X, Constant.TARGET_GOAL_Y, \ Global.ballX, Global.ballY ) distToGoal = HelpMath.getDistanceBetween(me_x, me_y, Constant.TARGET_GOAL_X, Constant.TARGET_GOAL_Y) MyTrack.DecideNextAction() # for head controlling if canDoKick() and distToGoal < 100: if isInRange(angleMeBallGoal, -KICK_MAX, -KICK_MIN): Kick.UPright() elif isInRange(angleMeBallGoal, KICK_MIN, KICK_MAX): Kick.UPleft() elif HelpTrack.inTargetGoalBox(Global.ballX, Global.ballY): # if ball in the goal box goalBoxKick(angleMeBallGoal) else: GrabTurnKick.DecideNextAction()
def bfb(): env_name, root_url, live_key, app_id = datagen.get_current_env() url = "{0}/v1/charges".format(root_url) # request body charge = Model.ChargeBase.Charge() charge.order_no = random_str(10) charge.channel = "bfb" myCharge = APIClient._http_call(url, "POST", "json", "json", None, {"Authorization": "Bearer {0}".format(live_key)}, 30, subject=charge.subject, body=charge.body, app={"id": charge.app.id}, amount=charge.amount, channel=charge.channel, client_ip=charge.client_ip, currency=charge.currency, order_no=charge.order_no) # Get the charge info(json) and send to another API for forward #And the demo app will receive the charge Info for pay #print(myCharge) Forward.forward_json(myCharge)
def predict(total_no_of_samples, parameters, test_data): prediction_result = np.zeros((1, total_no_of_samples)) feed_forward_result = fwd.deep_model_linear_activaiton_function( inputs=test_data, parameters=parameters) feed_forward_prediction = feed_forward_result[0] for i in range(prediction_result.shape[1]): prediction_result[0, i] = 1 if feed_forward_prediction[0, i] >= 0.5 else 0 return prediction_result
def yeepay_wap(): env_name, root_url, live_key, app_id = datagen.get_current_env() url = "{0}/v1/charges".format(root_url) # request body charge = Model.ChargeBase.ChargeDict() charge['order_no'] = random_str(10) charge['subject'] = "TestOrder4YeepayWap" charge['body'] = "appletesting4Pay" charge['amount'] = 10 charge['channel'] = "yeepay_wap" charge['currency'] = "cny" charge['client_ip'] = "127.0.0.1" id = [("id", app_id)] extra = [("product_category", "1"), ("identity_id", "d2:bf:11:78:09:69"), ("identity_type", "0"), ("terminal_type", "1"), ("terminal_id", "d2:bf:11:78:09:69"), ("user_ua", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:36.0) Gecko/20100101 Firefox/36.0"), ("result_url", "https://pingxx.com")] charge['extra'] = dict(extra) charge['app'] = dict(id) myCharge = APIClient._http_call(url, "post", "json", "json", None, {"Authorization": "Bearer {0}".format(live_key)}, 30, **charge) print(myCharge) sshCmd.ssh_cmd("114.215.237.77", "56f27c2B", "echo "">/var/www/example/ziteng.php") threading._start_new_thread(sshCmd.ssh_cmd, ("114.215.237.77", "56f27c2B", "php /var/www/example/client4ziteng.php")) time.sleep(5) Forward.forward_json(myCharge) ret = sshCmd.ssh_cmd("114.215.237.77", "56f27c2B", "echo $(stat -c %s /var/www/example/ziteng.php)") print ret if int(filter(lambda x: x.isdigit(), ret)) > 1: print "The charge file had updated on %s" % ctime() else: print "forward the charge to update the file again..." threading._start_new_thread(sshCmd.ssh_cmd, ("114.215.237.77", "56f27c2B", "php /var/www/example/client4ziteng.php")) time.sleep(2) Forward.forward_json(myCharge)
def bfb_wap(): env_name, root_url, live_key, app_id = datagen.get_current_env() url = "{0}/v1/charges".format(root_url) # request body charge = Model.ChargeBase.ChargeDict() charge['order_no'] = random_str(10) charge['subject'] = "TestOrder4bfbWap" charge['body'] = "appletesting4Pay" charge['amount'] = 10 charge['channel'] = "bfb_wap" charge['currency'] = "cny" charge['client_ip'] = "127.0.0.1" id = [("id", app_id)] extra = [("result_url", "http://pingxx.com"), ("bfb_login", "false")] charge['extra'] = dict(extra) charge['app'] = dict(id) myCharge = APIClient._http_call(url, "POST", "json", "json", None, {"Authorization": "Bearer {0}".format(live_key)}, 30, **charge) print(myCharge) sshCmd.ssh_cmd("114.215.237.77", "56f27c2B", "echo "">/var/www/example/ziteng.php") threading._start_new_thread(sshCmd.ssh_cmd, ("114.215.237.77", "56f27c2B", "php /var/www/example/client4ziteng.php")) time.sleep(5) Forward.forward_json(myCharge) ret = sshCmd.ssh_cmd("114.215.237.77", "56f27c2B", "echo $(stat -c %s /var/www/example/ziteng.php)") print ret if int(filter(lambda x: x.isdigit(), ret)) > 1: print "The charge file had updated on %s" % ctime() else: print "forward the charge to update the file again..." threading._start_new_thread(sshCmd.ssh_cmd, ("114.215.237.77", "56f27c2B", "php /var/www/example/client4ziteng.php")) time.sleep(2) Forward.forward_json(myCharge)
def alipay(): """ 1- Generate the charge via API 2- Forward the charge so that the demoapp will reflush """ env_name, root_url, live_key, app_id = datagen.get_current_env() url = "{0}/v1/charges".format(root_url) # request body charge = Model.ChargeBase.Charge() charge.order_no = random_str(10) # myCharge = APIClient._http_call(url,"POST","json","json",None,{"Authorization":"Bearer sk_live_vjfr90jj1q985KuPO84iP8KO"},30,charge.__dict__) myCharge = APIClient._http_call(url, "POST", "json", "json", None, {"Authorization": "Bearer {0}".format(live_key)}, 30, subject=charge.subject, body=charge.body, app={"id": charge.app.id}, amount=charge.amount, channel=charge.channel, client_ip=charge.client_ip, currency=charge.currency, order_no=charge.order_no) #Get the charge info(json) and send to another API for forward #And the demo app will receive the charge Info for pay print(myCharge) Forward.forward_alipay(myCharge)
def batchGradientDescent(inputData, labelData, parameters, num_iteration, batch_size, no_of_samples): logger.debug('batchGradientDescent is started with parameters:: \ninputData shape: %s \nlabelData: %s\nparameters length: %s\nnum_iteration %s\nbatch_size: %s\nno_of_samples: %s', inputData.shape, labelData.shape, len(parameters), num_iteration, batch_size, no_of_samples) cost_store_based_on_iteration =[] for i in range(0, num_iteration): logger.debug('iteration no {}'.format(i)) starting_counter = 0 ending_counter = starting_counter + 1 start_index = starting_counter * batch_size end_index = ending_counter * batch_size cost_store_based_on_batch = [] while(start_index< end_index): logger.debug('starting_counter is %s, ending_counter is %s, start_index is %s, end_index is %s', starting_counter, ending_counter, start_index, end_index) # forward propagation a, caches = forward.deep_model_linear_activaiton_function(inputs=inputData[:,start_index:end_index], parameters=parameters) # compute cost entropy_cost = cost.crossEntropyCost(totalNoOfSamples=batch_size, afterApplyingActivationFunction=a, inputLabelData=labelData[:,start_index:end_index]) cost_store_based_on_batch.append(entropy_cost); # backward propagation logger.debug("========================= backward propagation started!!!!!!!!! ===================") grads = back.L_model_backward(AL = a, Y = labelData[:,start_index:end_index], caches= caches) # update parameters parameters = update_parameters(parameters= parameters, grads= grads, learning_rate= 0.05) starting_counter = starting_counter + 1 ending_counter = ending_counter + 1 start_index = starting_counter * batch_size if start_index >= no_of_samples: break end_index = ending_counter * batch_size if end_index >= no_of_samples: end_index = no_of_samples - 1 cost_store_based_on_iteration.append(sum(cost_store_based_on_batch)) for x in range(len(cost_store_based_on_iteration)): logger.debug('total cost after iteration {} is {}'.format(x,cost_store_based_on_iteration[x])) return parameters,cost_store_based_on_iteration
InitialP = [0.5, 0.5] EmissionP = { 'a': [0.25, 0.1], 't': [0.25, 0.1], 'c': [0.25, 0.4], 'g': [0.25, 0.4] } for seq in ["aactgcacatgcggcgcgcccgcgctaat", "gggcgcgggcgccccgcg"]: # NB. Book and Lio's notes use integrated transition and initial # distribution matrix (initial step is transition from dummy state 0) # This is confusing, so I will separate them out. # Wiki has non-integrated Viterbi algorithm implementation # 1.1. Implement Forward algorithm fwd = Forward(TransitionP, EmissionP, InitialP) p = fwd.prob(seq) print "**************************************" print "Probability of", seq, ":", p print "Log probability:", -log(p) print "**************************************" # 1.2. Implement Viterbi algorithm vtb = Viterbi(TransitionP, EmissionP, InitialP) (prob, path) = vtb.maxSeq(seq) print "**************************************" print "Viterbi path:" print "P =", prob print seq print ''.join(str(i) for i in path) print "**************************************"
from math import log if __name__ == "__main__": TransitionP = [[0.8, 0.2], [0.4, 0.6]] InitialP = [0.5, 0.5] EmissionP = {"a": [0.25, 0.1], "t": [0.25, 0.1], "c": [0.25, 0.4], "g": [0.25, 0.4]} for seq in ["aactgcacatgcggcgcgcccgcgctaat", "gggcgcgggcgccccgcg"]: # NB. Book and Lio's notes use integrated transition and initial # distribution matrix (initial step is transition from dummy state 0) # This is confusing, so I will separate them out. # Wiki has non-integrated Viterbi algorithm implementation # 1.1. Implement Forward algorithm fwd = Forward(TransitionP, EmissionP, InitialP) p = fwd.prob(seq) print "**************************************" print "Probability of", seq, ":", p print "Log probability:", -log(p) print "**************************************" # 1.2. Implement Viterbi algorithm vtb = Viterbi(TransitionP, EmissionP, InitialP) (prob, path) = vtb.maxSeq(seq) print "**************************************" print "Viterbi path:" print "P =", prob print seq print "".join(str(i) for i in path) print "**************************************"
#これがmain関数 import getdata import Forward import initw w = initw.initweight() #w = [1,1,1.5] print("データ読み込み開始") a,b = getdata.get_data(4) #print(a) #print(b) print("=======================") print("読み込んだデータの計算開始") for i in b:#iが順番に読み出されるリスト。便利すぎんかpython print(i) ForwardFunction_class = Forward.ForwardFunction(w,i) d = ForwardFunction_class.forward() print(i,"の計算結果") print(d) print("=====================")
import time import Forward while True: Forward.go_forward(12, 13, 6) Forward.go_forward(20, 21, 26) time.sleep(2) Forward.go_forward(12, 13, 6).halt() Forward.go_forward(20, 21, 26).halt()