神经网络cost值不下降的原因

训练一个梯度下降的二分类模型,当神经网络是[n,20,4,1]的cost值是下降收敛的,
但是[n,20,7,5,1]cost值初始为0.69下降到0.64就不会下降了,这是为什么呢?

            贴一下代码:
import numpy as np
import matplotlib.pyplot as plt
import h5py

#参数初始化,将所有w/b都封装在一个dict中
def initialize_parameters(layer_dims):
    parameters = {}
    L = len(layer_dims)

    for i in range(1,L):
        parameters['w'+ str(i)] = np.random.randn(layer_dims[i],layer_dims[i-1])*0.01
        parameters['b'+ str(i)] = np.zeros((layer_dims[i],1))

        assert(parameters['w'+ str(i)]).shape == (layer_dims[i],layer_dims[i-1])
        assert(parameters['b'+ str(i)]).shape == (layer_dims[i],1)

    return parameters


#定义激活函数
def relu(Z):
    A=(Z+abs(Z))/2
    assert(A.shape == Z.shape)
    return A

def sigmoid(Z):
    A=1.0/(1+np.exp(-Z))
    assert(A.shape == Z.shape)
    return A

#向前传播
def forward_propagation(X,parameters):
    #caches存储了每一层计算得到的A,Z值
    caches = {}

    L=len(parameters)//2
    A_prev=X

    for i in range(1,L):
        Z=np.dot(parameters['w'+str(i)],A_prev)+parameters['b'+str(i)]
        A=relu(Z)
        caches['Z'+str(i)]=Z
        caches['A'+str(i)]=A
        #这一层计算得到的A需要保留,下一层计算Z要用
        A_prev=A

    #输出层的激活函数时sigmoid
    Z=np.dot(parameters['w'+str(L)],A_prev)+parameters['b'+str(L)]
    A=sigmoid(Z)

    caches['Z'+str(L)]=Z
    caches['A'+str(L)]=A

    #这里多存一个X是因为反向传播的时候要用到
    caches['A0'] = X

    return A,caches


#计算代价
def cpmpute_cost(A,Y):
    m=Y.shape[1]
    cost=-1/m*np.sum(np.multiply(np.log(A),Y)+np.multiply((1-Y),np.log(1-A)))
    cost=np.squeeze(cost)
    return cost


#relu函数的导数
def relu_back(Z,dA):
    deri = Z

    deri[Z < 0]=0
    deri[Z >=0]=1

    return deri

#反向传播
def back_propagation(Y,caches,parameters):
    #所有的dw和db
    grads={}

    L=len(caches)//2
    m=Y.shape[1]

    #AL其实就是一次迭代得到的预测值
    AL=caches['A'+str(L)]

    #因为sigmoid反向传和relu不同,所以单独处理
    dZ=AL-Y
    dW=np.dot(dZ,caches['A'+str(L-1)].T)/m
    db=np.sum(dZ,axis=1,keepdims=True)/m

    grads['dw'+str(L)]=dW
    grads['db'+str(L)]=db

    for i in reversed(range(1,L)):
        dA=np.dot(parameters['w'+str(i+1)].T,dZ)
        dZ=np.multiply(dA,relu_back(caches['Z'+str(i)],dA))
        dW=1.0/m * np.dot(dZ,caches['A'+str(i-1)].T)
        db=1.0/m * np.sum(dZ,axis=1,keepdims=True)

        grads['dw'+str(i)]=dW
        grads['db'+str(i)]=db

    return grads


#更新参数
def update_parameters(parameters, grads, alphs):
    L = len(parameters)//2
    for l in range(L):
        parameters['w'+str(l+1)] = parameters['w'+str(l+1)] - alphs * grads['dw'+str(l+1)]
        parameters['b'+str(l+1)] = parameters['b'+str(l+1)] - alphs * grads['db'+str(l+1)]
    return parameters


#模型预测
def predict(X,parameters):

    A2,caches=forward_propagation(X,parameters)

    temp=A2.shape[1]
    Y_pred=np.zeros([1,temp])

    for i in range(temp):
        if A2[:,i]>0.5:
            Y_pred[:,i]=1
        else:
            Y_pred[:,i]=0

    return Y_pred

#模型整合
def model(X,Y,layer_dims,iter_times,alphs,print_flag):
    np.random.seed(1)
    parameters=initialize_parameters(layer_dims)
    for i in range(0,iter_times):

        A,caches=forward_propagation(X,parameters)
        cost=cpmpute_cost(A,Y)
        grads=back_propagation(Y,caches,parameters)
        parameters=update_parameters(parameters,grads,alphs)

        if print_flag and i % 100 == 0:
            print('iteration at ',i,' cost :',cost)

    return parameters


n=train_data_finalX.shape[0]
layer_dims=[n,20,7,5,1]
parameters=model(train_data_finalX,train_data_finalY,layer_dims,2500,0.0075,True)

y_pred_train=predict(train_data_finalX,parameters)
print('train acc is ',np.mean(y_pred_train == train_data_finalY)*100,'%')    

y_pred_test=predict(test_data_finalX,parameters)
print('test acc is ',np.mean(y_pred_test == test_data_finalY)*100,'%')

结果类似这样,后面cost值变化很小,在小数点后5位
我试过增加迭代次数和增大学习因子,还是有这个问题

iteration at 0 cost : 0.6932015486338629
iteration at 100 cost : 0.6482987506672847
iteration at 200 cost : 0.6443527436694975
iteration at 300 cost : 0.6439059082659386
iteration at 400 cost : 0.6436651460852033
iteration at 500 cost : 0.6431109804509275

1个回答

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
为什么我的神经网络的COST一直起伏,不是持续往0收敛?

损失函数:cost=tf.reduce_mean(tf.square(pred - ys)) 梯度下降函数:optm=tf.train.GradientDescentOptimizer(0.01).minimize(cost) 数据集是应该没有问题的,从UCI上面下的 如果需要完整代码请告诉我,谢谢各位大佬了!

卷积神经网络训练loss变为nan

卷积神经网络训练,用的是mnist数据集,第一次训练前损失函数还是一个值,训练一次之后就变成nan了,使用的损失函数是ce = tf.nn.sparse_softmax_cross_entropy_with_logits(logits=y, labels=tf.argmax(y_, 1)),cem = tf.reduce.mean(ce),应该不会出现真数为零或负的情况,而且训练前loss是存在的,只是训练后变为nan,求各位大牛答疑解惑,感激不尽。![图片说明](https://img-ask.csdn.net/upload/201902/18/1550420090_522553.png)![图片说明](https://img-ask.csdn.net/upload/201902/18/1550420096_230838.png)![图片说明](https://img-ask.csdn.net/upload/201902/18/1550420101_914053.png)

这种时间序列预测问题用哪种神经网络比较合适呀

一个有裂缝的腔体在外部大幅压力变动的时候,由于腔体有裂缝导致内部压力出现变化,并且裂缝大小会随外部压力变化而变化。现在已知外部压力变化的数据,并且已经测得内部压力变化的数据。 现在想利用测的大量数据进行预测,希望预测出外部压力随机变化下的内部压力变化。**应该用哪种神经网络进行

神经网络模型加载后测试效果不对

tensorflow框架训练好的神经网络模型,加载之后再去测试准确率特别低 图中是我的加载方法 麻烦大神帮忙指正,是不是网络加载出现问题 首先手动重新构建了模型:以下代码省略了权值、偏置和网络搭建 ``` # 构建模型 pred = alex_net(x, weights, biases, keep_prob) # 定义损失函数和优化器 cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits_v2(labels=y,logits=pred))#softmax和交叉熵结合 optimizer = tf.train.AdamOptimizer(learning_rate=learning_rate).minimize(cost) # 评估函数 correct_pred = tf.equal(tf.argmax(pred, 1), tf.argmax(y, 1)) accuracy = tf.reduce_mean(tf.cast(correct_pred, tf.float32)) # 3.训练模型和评估模型 # 初始化变量 init = tf.global_variables_initializer() saver = tf.train.Saver() with tf.Session() as sess: # 初始化变量 sess.run(init) saver.restore(sess, tf.train.latest_checkpoint(model_dir)) pred_test=sess.run(pred,{x:test_x, keep_prob:1.0}) result=sess.run(tf.argmax(pred_test, 1)) ```

在网上找到一个DQN的神经网络代码。可以运行,但是没有读取模型的部分

代码可以运行,但是没用读取模型的代码,我在网上找了一段时间,还是没有找到教程。自己写的读写代码不能正常工作 这是原代码 ``` import pygame import random from pygame.locals import * import numpy as np from collections import deque import tensorflow as tf import cv2 BLACK = (0 ,0 ,0 ) WHITE = (255,255,255) SCREEN_SIZE = [320,400] BAR_SIZE = [50, 5] BALL_SIZE = [15, 15] # 神经网络的输出 MOVE_STAY = [1, 0, 0,0] MOVE_LEFT = [0, 1, 0,0] MOVE_RIGHT = [0, 0, 1,0] MOVE_RIGHT1=[0,0,0,1] class Game(object): def __init__(self): pygame.init() self.clock = pygame.time.Clock() self.screen = pygame.display.set_mode(SCREEN_SIZE) pygame.display.set_caption('Simple Game') self.ball_pos_x = SCREEN_SIZE[0]//2 - BALL_SIZE[0]/2 self.ball_pos_y = SCREEN_SIZE[1]//2 - BALL_SIZE[1]/2 self.ball_dir_x = -1 # -1 = left 1 = right self.ball_dir_y = -1 # -1 = up 1 = down self.ball_pos = pygame.Rect(self.ball_pos_x, self.ball_pos_y, BALL_SIZE[0], BALL_SIZE[1]) self.bar_pos_x = SCREEN_SIZE[0]//2-BAR_SIZE[0]//2 self.bar_pos = pygame.Rect(self.bar_pos_x, SCREEN_SIZE[1]-BAR_SIZE[1], BAR_SIZE[0], BAR_SIZE[1]) # action是MOVE_STAY、MOVE_LEFT、MOVE_RIGHT # ai控制棒子左右移动;返回游戏界面像素数和对应的奖励。(像素->奖励->强化棒子往奖励高的方向移动) def step(self, action): if action == MOVE_LEFT: self.bar_pos_x = self.bar_pos_x - 2 elif action == MOVE_RIGHT: self.bar_pos_x = self.bar_pos_x + 2 elif action == MOVE_RIGHT1: self.bar_pos_x = self.bar_pos_x + 1 else: pass if self.bar_pos_x < 0: self.bar_pos_x = 0 if self.bar_pos_x > SCREEN_SIZE[0] - BAR_SIZE[0]: self.bar_pos_x = SCREEN_SIZE[0] - BAR_SIZE[0] self.screen.fill(BLACK) self.bar_pos.left = self.bar_pos_x pygame.draw.rect(self.screen, WHITE, self.bar_pos) self.ball_pos.left += self.ball_dir_x * 2 self.ball_pos.bottom += self.ball_dir_y * 3 pygame.draw.rect(self.screen, WHITE, self.ball_pos) if self.ball_pos.top <= 0 or self.ball_pos.bottom >= (SCREEN_SIZE[1] - BAR_SIZE[1]+1): self.ball_dir_y = self.ball_dir_y * -1 if self.ball_pos.left <= 0 or self.ball_pos.right >= (SCREEN_SIZE[0]): self.ball_dir_x = self.ball_dir_x * -1 reward = 0 if self.bar_pos.top <= self.ball_pos.bottom and (self.bar_pos.left < self.ball_pos.right and self.bar_pos.right > self.ball_pos.left): reward = 1 # 击中奖励 elif self.bar_pos.top <= self.ball_pos.bottom and (self.bar_pos.left > self.ball_pos.right or self.bar_pos.right < self.ball_pos.left): reward = -1 # 没击中惩罚 # 获得游戏界面像素 screen_image = pygame.surfarray.array3d(pygame.display.get_surface()) #np.save(r'C:\Users\Administrator\Desktop\game\model\112454.npy',screen_image) pygame.display.update() # 返回游戏界面像素和对应的奖励 return reward, screen_image # learning_rate LEARNING_RATE = 0.99 # 更新梯度 INITIAL_EPSILON = 1.0 FINAL_EPSILON = 0.05 # 测试观测次数 EXPLORE = 500000 OBSERVE = 50000 # 存储过往经验大小 REPLAY_MEMORY = 500000 BATCH = 100 output = 4 # 输出层神经元数。代表3种操作-MOVE_STAY:[1, 0, 0] MOVE_LEFT:[0, 1, 0] MOVE_RIGHT:[0, 0, 1] input_image = tf.placeholder("float", [None, 80, 100, 4]) # 游戏像素 action = tf.placeholder("float", [None, output]) # 操作 # 定义CNN-卷积神经网络 参考:http://blog.topspeedsnail.com/archives/10451 def convolutional_neural_network(input_image): weights = {'w_conv1':tf.Variable(tf.zeros([8, 8, 4, 32])), 'w_conv2':tf.Variable(tf.zeros([4, 4, 32, 64])), 'w_conv3':tf.Variable(tf.zeros([3, 3, 64, 64])), 'w_fc4':tf.Variable(tf.zeros([3456, 784])), 'w_out':tf.Variable(tf.zeros([784, output]))} biases = {'b_conv1':tf.Variable(tf.zeros([32])), 'b_conv2':tf.Variable(tf.zeros([64])), 'b_conv3':tf.Variable(tf.zeros([64])), 'b_fc4':tf.Variable(tf.zeros([784])), 'b_out':tf.Variable(tf.zeros([output]))} conv1 = tf.nn.relu(tf.nn.conv2d(input_image, weights['w_conv1'], strides = [1, 4, 4, 1], padding = "VALID") + biases['b_conv1']) conv2 = tf.nn.relu(tf.nn.conv2d(conv1, weights['w_conv2'], strides = [1, 2, 2, 1], padding = "VALID") + biases['b_conv2']) conv3 = tf.nn.relu(tf.nn.conv2d(conv2, weights['w_conv3'], strides = [1, 1, 1, 1], padding = "VALID") + biases['b_conv3']) conv3_flat = tf.reshape(conv3, [-1, 3456]) fc4 = tf.nn.relu(tf.matmul(conv3_flat, weights['w_fc4']) + biases['b_fc4']) output_layer = tf.matmul(fc4, weights['w_out']) + biases['b_out'] return output_layer # 深度强化学习入门: https://www.nervanasys.com/demystifying-deep-reinforcement-learning/ # 训练神经网络 def train_neural_network(input_image): predict_action = convolutional_neural_network(input_image) argmax = tf.placeholder("float", [None, output]) gt = tf.placeholder("float", [None]) action = tf.reduce_sum(tf.multiply(predict_action, argmax), reduction_indices = 1) cost = tf.reduce_mean(tf.square(action - gt)) optimizer = tf.train.AdamOptimizer(1e-6).minimize(cost) game = Game() D = deque() _, image = game.step(MOVE_STAY) # 转换为灰度值 image = cv2.cvtColor(cv2.resize(image, (100, 80)), cv2.COLOR_BGR2GRAY) # 转换为二值 ret, image = cv2.threshold(image, 1, 255, cv2.THRESH_BINARY) input_image_data = np.stack((image, image, image, image), axis = 2) with tf.Session() as sess: sess.run(tf.initialize_all_variables()) saver = tf.train.Saver() n = 0 epsilon = INITIAL_EPSILON while True: action_t = predict_action.eval(feed_dict = {input_image : [input_image_data]})[0] argmax_t = np.zeros([output], dtype=np.int) if(random.random() <= INITIAL_EPSILON): maxIndex = random.randrange(output) else: maxIndex = np.argmax(action_t) argmax_t[maxIndex] = 1 if epsilon > FINAL_EPSILON: epsilon -= (INITIAL_EPSILON - FINAL_EPSILON) / EXPLORE for event in pygame.event.get(): #macOS需要事件循环,否则白屏 if event.type == QUIT: pygame.quit() sys.exit() reward, image = game.step(list(argmax_t)) image = cv2.cvtColor(cv2.resize(image, (100, 80)), cv2.COLOR_BGR2GRAY) ret, image = cv2.threshold(image, 1, 255, cv2.THRESH_BINARY) image = np.reshape(image, (80, 100, 1)) input_image_data1 = np.append(image, input_image_data[:, :, 0:3], axis = 2) D.append((input_image_data, argmax_t, reward, input_image_data1)) if len(D) > REPLAY_MEMORY: D.popleft() if n > OBSERVE: minibatch = random.sample(D, BATCH) input_image_data_batch = [d[0] for d in minibatch] argmax_batch = [d[1] for d in minibatch] reward_batch = [d[2] for d in minibatch] input_image_data1_batch = [d[3] for d in minibatch] gt_batch = [] out_batch = predict_action.eval(feed_dict = {input_image : input_image_data1_batch}) for i in range(0, len(minibatch)): gt_batch.append(reward_batch[i] + LEARNING_RATE * np.max(out_batch[i])) optimizer.run(feed_dict = {gt : gt_batch, argmax : argmax_batch, input_image : input_image_data_batch}) input_image_data = input_image_data1 n = n+1 if n % 100 == 0: saver.save(sess, 'D:/lolAI/model/game', global_step = n) # 保存模型 print(n, "epsilon:", epsilon, " " ,"action:", maxIndex, " " ,"reward:", reward) train_neural_network(input_image) ``` 这是我根据教程写的读取模型并且运行的代码 ``` import tensorflow as tf tf.reset_default_graph() with tf.Session() as sess: new_saver = tf.train.import_meta_graph('D:/lolAI/model/game-400.meta') new_saver.restore(sess, tf.train.latest_checkpoint('D:/lolAI/model')) print(sess.run(tf.initialize_all_variables())) ``` 代码我还没有看的很明白,希望大佬给点意见

怎么获取hevc CU块周边块的rd cost值

我是这样做的 Void TEncCu::compressCU( TComDataCU*& rpcCU ) double CostLeft = 0; //左边块的rd cost CostLeft = rpcCU->getCULeft()->getTotalCost( ); 我知道这样是错的,但是不知道怎么做

神经网络的M均方差向1收敛而不是向0收敛是什么原因?

``` with tf.name_scope('input_layer'): #输出层。将输出层权重、偏置、净输入放在一起 with tf.name_scope('weight_i'): Weights0 = tf.Variable(tf.random_normal([21, 8])) variable_summaries(Weights0) with tf.name_scope('bias_i'): biases0 = tf.Variable(tf.zeros([1, 8]) + 0.1) variable_summaries(biases0) with tf.name_scope('Wx_plus_b_i'): Wx_plus_b00 = tf.matmul(X, Weights0) + biases0 variable_summaries(Wx_plus_b00) l00 = tf.nn.sigmoid(Wx_plus_b00) with tf.name_scope('output_layer'): with tf.name_scope('weight_o'): Weights1 = tf.Variable(tf.random_normal([8, 1])) variable_summaries(Weights1) with tf.name_scope('bias_o'): biases1 = tf.Variable(tf.zeros([1, 1]) + 0.1) variable_summaries(biases1) with tf.name_scope('Wx_plus_b_o'): Wx_plus_b1 = tf.matmul(l00, Weights1) + biases1 variable_summaries(Wx_plus_b1) prediction = tf.nn.sigmoid(Wx_plus_b1) ``` 这是我的网络结构 ``` cost=tf.reduce_mean(tf.square(pred - ys)) optm=tf.train.GradientDescentOptimizer(0.01).minimize(cost) ``` 这是我的均方差函数和梯度下降函数 ![图片说明](https://img-ask.csdn.net/upload/201904/10/1554877016_12870.png)

Minimum Transport Cost

These are N cities in Spring country. Between each pair of cities there may be one transportation track or none. Now there is some cargo that should be delivered from one city to another. The transportation fee consists of two parts: The cost of the transportation on the path between these cities, and a certain tax which will be charged whenever any cargo passing through one city, except for the source and the destination cities. You must write a program to find the route which has the minimum cost. Input First is N, number of cities. N = 0 indicates the end of input. The data of path cost, city tax, source and destination cities are given in the input, which is of the form: a11 a12 ... a1N a21 a22 ... a2N ............... aN1 aN2 ... aNN b1 b2 ... bN c d e f ... g h where aij is the transport cost from city i to city j, aij = -1 indicates there is no direct path between city i and city j. bi represents the tax of passing through city i. And the cargo is to be delivered from city c to city d, city e to city f, ..., and g = h = -1. You must output the sequence of cities passed by and the total cost which is of the form: Output From c to d : Path: c-->c1-->......-->ck-->d Total cost : ...... ...... From e to f : Path: e-->e1-->..........-->ek-->f Total cost : ...... Note: if there are more minimal paths, output the lexically smallest one. Print a blank line after each test case. Sample Input 5 0 3 22 -1 4 3 0 5 -1 -1 22 5 0 9 20 -1 -1 9 0 4 4 -1 20 4 0 5 17 8 3 1 1 3 3 5 2 4 -1 -1 0 Sample Output From 1 to 3 : Path: 1-->5-->4-->3 Total cost : 21 From 3 to 5 : Path: 3-->4-->5 Total cost : 16 From 2 to 4 : Path: 2-->1-->5-->4 Total cost : 17

logistic regression costFunction问题

J = m^-1 * sum(((-1) * y.*log(h)).-((1- y).*log(1 - h))); 在matlab2014b里面提示运算符异常应该如何修改。

关于时间序列做预测的两个问题

1.假如说我有一份采样间隔是按天算的数据集,训练集1,2,3,4,5天,那如果要实现提前2天预测,那我的测试集应该选哪个,第7天?还是第6和7两天的?之前查了下网上对horizon说的都很模糊。 2.滞后性怎么体现呢?比如训练集1,2,3,4天,测试集第5天,那如果滞后一期,表示的是什么?预测的其实是第4天数据吗?

Minimal search cost

Problem Description As we know, we need to spend O(n) time in the abstract finding a key(every two keys are different) in a non-sorted array. But if we make up a BST(binary search tree) before, then for each access, you need to spend log(N) time to do it. And for each access, there exists a road from the root node to the target node, whose length Ci is the number of the edges of the road. Because there is an accessing frequency Fi for each key. And the total value of the tree is defined as following rule: SUM=Sigma(Ci*Fi), for i from 0 to N-1, N is the number of the keys. You need to find the minimal value M_SUM to make up a tree. Input There are a lot of cases. In each case, in the first line, there is an integer N to represent the number of keys. In the second line, there are N sorted integers Ki. In the third line, there are N integers Fi, which are the accessing frequency. 0<N<=1000, 0<=Fi<65536. Output For each case, just output the minimal search cost. Sample Input 5 1 2 3 4 5 2 5 4 9 6 Sample Output 23

如何在POS系统中实现COST计算方法(FIFO,LIFO)

<div class="post-text" itemprop="text"> <p>I have developed a POS system with purchasing and selling. When purchasing i am saving cost price for each products as a GRN with other details and update purchase quantity as a total for each item in the stocks table. But i dont have an idea to calculate costs for these products according to FIFO or LIFO.</p> <p><strong>GRN TABLE</strong></p> <pre><code>`id` `department_id` `grn_no` `grn_date` `supplier_id` `reference` `description` </code></pre> <p><strong>GRN DETAILS TABLE</strong></p> <pre><code>`id` `grn_id` `item_id` `quantity` `expiry_date` `cost_price` </code></pre> <p>Selling price set to newest price always.</p> <p><strong>STOCKS TABLE</strong></p> <pre><code>`id` `item_id` `department_id` `price` `wholesale_price` `quantity` </code></pre> <p>When i am selling, i am reducing stock quantity from stocks table. But i dont have idea to calculate cost price according to LIFO or FIFO. If someone know it, please guide me through.</p> <p><strong>DATA SAMPLE</strong></p> <pre><code>Jan 1 - Purchased item1 - 100 units at $10 Jan 10 - Purchased item1 - 100 Units at $11 Jan 20 - Purchased item1 - 100 Units at $9 Jan 30 - Purchased item1 - 100 Units at $12 </code></pre> <p><strong>EXPECTED RESULT</strong></p> <p><strong>Costing Report for Jan 10</strong></p> <pre><code>Total sales for item1 is 25 Units at XX cost according to FIFO Total sales for item1 is 30 Units at YY cost according to FIFO System has 150 Units from item1 as current stock and current cost is ZZ according to FIFO </code></pre> </div>

Matlab实现Logistic Regression时的一个小问题

Ng机器学习编程作业matlab实现LR时里有这样一段 %% ============= Part 3: Optimizing using fminunc ============= % In this exercise, you will use a built-in function (fminunc) to find the % optimal parameters theta. % Set options for fminunc options = optimset('GradObj', 'on', 'MaxIter', 400); % Run fminunc to obtain the optimal theta % This function will return theta and the cost [theta, cost] = ... fminunc(@(t)(costFunction(t, X, y)), initial_theta, options); ... ================================ 不是很能理解optimset和fminunc的用法 [theta, cost] = ... fminunc(@(t)(costFunction(t, X, y)), initial_theta, options); =============================== 我是matlab初学者,这里需要用这个函数来实现梯度下降算法,也就是迭代多次学习theta。请问在fminunc里是怎样实现迭代的呢?那个@t是什么意思?optimset里的‘GradObj’是什么意思? 跪等大神解救!

HM编码器如何打印最优深度为非64x64CU的rdcost

HM中的单位都是pCtu,在xcompresscu函数之后如何打印例如最优深度为32x32的rdcost?

从magento 1.9.2.3中的自定义属性“ship_cost”的值中删除多余的零

<div class="post-text" itemprop="text"> <p>I have a Custom Product Attribute named as 'ship_cost' with an input type 'text field'. While putting a value on back-end, it automatically adds four extra zeros after the decimal point.</p> <p>I want this price in 'Rs. 45.00' format but currently it is showing as 'Rs. 45.0000'.</p> <p>I have not worked with Magento for a long time, basically, I am a newbie.</p> </div>

错误在将数据插入到数据库时,列计数与第1行的值计数不匹配

<div class="post-text" itemprop="text"> <p>I have this e-commerce site I am working on. Now I keep getting that error every time I try to insert data to the db. I am trying to insert details on table buyer and message but I don't know where the error is.</p> <p>I don't know where the error is please help me out:</p> <p>My code:</p> <pre><code>$buyer_name = $_POST['name']; $address = $_POST['address']; $email = $_POST['email']; $mobile_no = $_POST['mobile_no']; $id_no = $_POST['id_no']; $total = $_POST['total']; echo '&lt;a href="index.php"&gt;Home&lt;/a&gt;&lt;br&gt;'; echo 'Thank you for shopping at our Thread online store. And the following is the data you enter.'; echo '&lt;p&gt;The total cost for the purchase of products is:Tsh '.$total. '/=, and the cost can be send through the M-Pesa mobile number +255 757 393 937, Airtel Money: # and Tigo-Pesa: #.&lt;/p&gt;'; echo '&lt;p&gt;And the goods will be sent to the address below:&lt;/p&gt;'; echo '&lt;p&gt;Name : '.$buyer_name. '&lt;br&gt;'; echo '&lt;p&gt;Address and Location : '.$address. '&lt;/p&gt;'; echo '&lt;p&gt;Total Price : '.$total. '&lt;/p&gt;'; echo '&lt;p&gt;With Details : &lt;/p&gt;'; $p = mysql_query("SELECT * FROM buyer"); $cek = mysql_fetch_array($p); $c1 = $cek['name']; $c2 = $cek['address']; $c3 = $cek['email']; $c4 = $cek['mobile_no']; $c5 = $cek['id_no']; if ($c1 == $buyer_name &amp;&amp; $c2 == $address &amp;&amp; $c3 == $email &amp;&amp; $c4 == $mobile_no &amp;&amp; $c5 == $id_no) { $i = 1; foreach($_SESSION as $name =&gt; $value) { if ($value &gt; 0) { if (substr($name, 0, 5) == 'cart_') { $id = substr($name, 5, (strlen($name) - 5)); $get = mysql_query("SELECT * FROM products WHERE product_id='$id'"); while ($get_row = mysql_fetch_assoc($get)) { $sub = $get_row['product_price'] * $value; echo ' &lt; table class = "table table-striped" &gt; &lt; thead &gt; &lt; tr &gt; &lt; th &gt; # &lt; /th&gt; &lt; th &gt; Product ID &lt; /th&gt; &lt; th &gt; Product Name &lt; /th&gt; &lt; th &gt; Quantity &lt; /th&gt; &lt; /tr&gt; &lt; /thead&gt; &lt; tbody &gt; &lt; tr &gt; &lt; td &gt; '.$i.' &lt; /td&gt; &lt; td &gt; '.$get_row[' product_id '].' &lt; /td&gt; &lt; td &gt; '.$get_row[' product_title '].' &lt; /td&gt; &lt; td &gt; '.$value.' &lt; /td&gt; &lt; /tr&gt; &lt; /tbody &lt; /table&gt;'; //&lt;p&gt;'.$i.' '.$get_row['product_id'].' '.$get_row['product_title'].' '.$value.' SubTotal : Tsh '.$sub.' /=&lt;/p&gt; $getBuyer = mysql_query("SELECT buyer.id, buyer.name, buyer.address, products.product_id, products.product_title FROM buyer, products WHERE name='$buyer_name' AND address='$address'") or die(mysql_error()); $data = mysql_fetch_array($getBuyer); $pemb = $data['id']; $na = $data['name']; $al = $data['address']; $ib = $get_row['product_id']; $nb = $get_row['product_title']; //echo $total; $i++; } } //@$total += $sub; mysql_query("INSERT INTO message VALUES('', '$pemb', '$na', '$al', '$ib', '$nb', '$value', '$sub', now()) ") or die(mysql_error()); } } } else { //Insert Data of the buyer to the db $query = mysql_query("INSERT INTO buyer VALUES( '$buyer_name', '$email', '$address', '$mobile_no', '$id_no')") or die(mysql_error()); $i = 1; foreach($_SESSION as $name =&gt; $value) { if ($value &gt; 0) { if (substr($name, 0, 5) == 'cart_') { $id = substr($name, 5, (strlen($name) - 5)); $get = mysql_query("SELECT * FROM products WHERE product_id='$id'"); while ($get_row = mysql_fetch_assoc($get)) { $sub = $get_row['product_price'] * $value; echo ' &lt; table class = "table table-striped" &gt; &lt; thead &gt; &lt; tr &gt; &lt; th &gt; # &lt; /th&gt; &lt; th &gt; Product ID &lt; /th&gt; &lt; th &gt; Product Name &lt; /th&gt; &lt; th &gt; Quantity &lt; /th&gt; &lt; /tr&gt; &lt; /thead&gt; &lt; tbody &gt; &lt; tr &gt; &lt; td &gt; '.$i.' &lt; /td&gt; &lt; td &gt; '.$get_row[' product_id '].' &lt; /td&gt; &lt; td &gt; '.$get_row[' product_title '].' &lt; /td&gt; &lt; td &gt; '.$value.' &lt; /td&gt; &lt; /tr&gt; &lt; /tbody &lt; /table&gt;'; $getBuyer = mysql_query(" SELECT buyer.id, buyer.name, buyer.address, products.product_id, products.product_title FROM buyer, products WHERE name='$buyer_name' AND address='$address'") or die(mysql_error()); $data = mysql_fetch_array($getBuyer); $pemb = $data['id']; $na = $data['name']; $al = $data['address']; $ib = $get_row['product_id']; $nb = $get_row['product_title']; //echo $total; $i++; } } //@$total += $sub; mysql_query("INSERT INTO message VALUES('', '$pemb', '$na', '$al', '$ib', '$nb', '$value', '$sub', now()) ") or die(mysql_error()); } } } /*if ($query) { header('location:index.php'); }*/ session_destroy(); </code></pre> </div>

复制一张excel 中的值给 另一个excel 的某个单元格, 显示执行成功,但目标excel中没有对应值

哈喽各位: 写了一个程序: 复制一个excel 中的某2列 并保持成元组形式, 并将元组中的值赋值到另一个excel 的目标单元格之中 我的代码如下: ``` import openpyxl import xlrd def get_infor(): book = xlrd.open_workbook('C:/Users/lenovo/Desktop/模板.xlsx') sheet = book.sheet_by_name('WRT模板') L =[] for i in range (3,sheet.nrows): # i 从第四列开始 PN = str(sheet.cell(i,3).value) Cost_USD = str(sheet.cell(i, 7).value) L.append((PN,Cost_USD)) #t=tuple(L) return L #print(L) t1= get_infor() # # print(t1) # # sh = t1[0][0] # print(sh) # def Open_excel(): workbook = openpyxl.load_workbook('C:/Users/lenovo/Desktop/文档模板/AU/Cost_AU.xlsx') sheet = workbook.worksheets[0] # 第一个页签 sheet['D2'] = t1[0][1] #sheet['A1'] = t1[1][2] print(sheet['D2'].value) print(sheet.title) Open_excel() ``` 显示 语句可以正常执行,并能够返回正确的值 (如图) ![图片说明](https://img-ask.csdn.net/upload/201908/23/1566549826_496765.png) 但 当我打开目标excel的时候,最指定的D2 单元格中 并没有显示出 新值 ![图片说明](https://img-ask.csdn.net/upload/201908/23/1566549948_819606.png) 大家知道这个怎么回事么? 以及该如何修改呢? 非常感谢!

客户端服务器用户密码加盐加密,遇到的问题

我是在一篇论文中看到的一种给密码加盐加密的方式,之前也有了解过一些加盐加密,下面是这篇论文中的加盐加密方式: 假定:注册阶段已完成,此时,客户端已拥有账号与密码; 服务器端已建立起用户密码库, 存储模式为( userid, password_hash ) , 盐值单独存放, 防止拕库, 存储模式为 (userid,salt_hash,cost),其中cost 字段为慢哈希代价,用来挃定客户 端的慢哈希速度,cost 值越大,web 端运行越慢。 则登彔阶段的协议描述为: (1)客户端以userid 収起登彔请求。 (2)服务器端响应,生成一随机盐值salt=random(),h(salt)存 储,选定cost 值,将cost、salt 収送。 (3)客户端计算r= PBKDF2( PRE, Password, Salt, cost, LEN), 収送。PRE 为随机函数,LEN 为辒出长度。 (4)服务端收到r,与自己计算的PBKDF2 (password, salt, cost)比较,若相等,则存储于password_hash 字段,通过认证。若不相等则丢弃。 想问第四步中服务器自己计算的password是从哪得到的,如果是上次存储的password_hash,那在password正确的情况下客户端计算出的r和服务器计算出的r应该不一样,因为每次登陆都会随机一个salt值,请各位大神帮忙看一下,这个方案具体是怎么考虑的,谢谢!

使用WordPress中的序列化数据更新元值不能正常工作

<div class="post-text" itemprop="text"> <p>I was wondering if someone could help with this. I'm trying to do a php query to update post meta values on Wordpress. Pb : the string has to be very long and full of unorthodox characters like double quotes. </p> <p>The result is somewhat strange as it gets updated but adds another serial around the value, breaking it, like this :</p> <p>s:5086:"<strong>a:28:{i:0;a:7:.....</strong></p> <p>Here's the initial query, if someone could figure out how to make it compliant that'd be amazing :</p> <pre><code>update_post_meta( $product_id, '_wc_booking_pricing', 'a:28:{i:0;a:7:{s:4:"type";s:6:"blocks";s:4:"cost";s:0:"";s:8:"modifier";s:0:"";s:9:"base_cost";s:5:"0.027";s:13:"base_modifier";s:5:"times";s:4:"from";s:1:"1";s:2:"to";s:1:"3";}i:1;a:7:{s:4:"type";s:6:"blocks";s:4:"cost";s:0:"";s:8:"modifier";s:0:"";s:9:"base_cost";s:13:"0.02914814815";s:13:"base_modifier";s:5:"times";s:4:"from";s:1:"4";s:2:"to";s:1:"4";}i:2;a:7:{s:4:"type";s:6:"blocks";s:4:"cost";s:0:"";s:8:"modifier";s:0:"";s:9:"base_cost";s:12:"0.0312962963";s:13:"base_modifier";s:5:"times";s:4:"from";s:1:"5";s:2:"to";s:1:"5";}i:3;a:7:{s:4:"type";s:6:"blocks";s:4:"cost";s:0:"";s:8:"modifier";s:0:"";s:9:"base_cost";s:13:"0.03344444444";s:13:"base_modifier";s:5:"times";s:4:"from";s:1:"6";s:2:"to";s:1:"6";}i:4;a:7:{s:4:"type";s:6:"blocks";s:4:"cost";s:0:"";s:8:"modifier";s:0:"";s:9:"base_cost";s:13:"0.03559259259";s:13:"base_modifier";s:5:"times";s:4:"from";s:1:"7";s:2:"to";s:1:"7";}i:5;a:7:{s:4:"type";s:6:"blocks";s:4:"cost";s:0:"";s:8:"modifier";s:0:"";s:9:"base_cost";s:13:"0.03774074074";s:13:"base_modifier";s:5:"times";s:4:"from";s:1:"8";s:2:"to";s:1:"8";}i:6;a:7:{s:4:"type";s:6:"blocks";s:4:"cost";s:0:"";s:8:"modifier";s:0:"";s:9:"base_cost";s:13:"0.03988888889";s:13:"base_modifier";s:5:"times";s:4:"from";s:1:"9";s:2:"to";s:1:"9";}i:7;a:7:{s:4:"type";s:6:"blocks";s:4:"cost";s:0:"";s:8:"modifier";s:0:"";s:9:"base_cost";s:13:"0.04203703704";s:13:"base_modifier";s:5:"times";s:4:"from";s:2:"10";s:2:"to";s:2:"10";}i:8;a:7:{s:4:"type";s:6:"blocks";s:4:"cost";s:0:"";s:8:"modifier";s:0:"";s:9:"base_cost";s:13:"0.04418518519";s:13:"base_modifier";s:5:"times";s:4:"from";s:2:"11";s:2:"to";s:2:"11";}i:9;a:7:{s:4:"type";s:6:"blocks";s:4:"cost";s:0:"";s:8:"modifier";s:0:"";s:9:"base_cost";s:13:"0.04633333333";s:13:"base_modifier";s:5:"times";s:4:"from";s:2:"12";s:2:"to";s:2:"12";}i:10;a:7:{s:4:"type";s:6:"blocks";s:4:"cost";s:0:"";s:8:"modifier";s:0:"";s:9:"base_cost";s:13:"0.04848148148";s:13:"base_modifier";s:5:"times";s:4:"from";s:2:"13";s:2:"to";s:2:"13";}i:11;a:7:{s:4:"type";s:6:"blocks";s:4:"cost";s:0:"";s:8:"modifier";s:0:"";s:9:"base_cost";s:13:"0.05062962963";s:13:"base_modifier";s:5:"times";s:4:"from";s:2:"14";s:2:"to";s:2:"14";}i:12;a:7:{s:4:"type";s:6:"blocks";s:4:"cost";s:0:"";s:8:"modifier";s:0:"";s:9:"base_cost";s:13:"0.05277777778";s:13:"base_modifier";s:5:"times";s:4:"from";s:2:"15";s:2:"to";s:2:"15";}i:13;a:7:{s:4:"type";s:6:"blocks";s:4:"cost";s:0:"";s:8:"modifier";s:0:"";s:9:"base_cost";s:13:"0.05492592593";s:13:"base_modifier";s:5:"times";s:4:"from";s:2:"16";s:2:"to";s:2:"16";}i:14;a:7:{s:4:"type";s:6:"blocks";s:4:"cost";s:0:"";s:8:"modifier";s:0:"";s:9:"base_cost";s:13:"0.05707407407";s:13:"base_modifier";s:5:"times";s:4:"from";s:2:"17";s:2:"to";s:2:"17";}i:15;a:7:{s:4:"type";s:6:"blocks";s:4:"cost";s:0:"";s:8:"modifier";s:0:"";s:9:"base_cost";s:13:"0.05922222222";s:13:"base_modifier";s:5:"times";s:4:"from";s:2:"18";s:2:"to";s:2:"18";}i:16;a:7:{s:4:"type";s:6:"blocks";s:4:"cost";s:0:"";s:8:"modifier";s:0:"";s:9:"base_cost";s:13:"0.06137037037";s:13:"base_modifier";s:5:"times";s:4:"from";s:2:"19";s:2:"to";s:2:"19";}i:17;a:7:{s:4:"type";s:6:"blocks";s:4:"cost";s:0:"";s:8:"modifier";s:0:"";s:9:"base_cost";s:13:"0.06351851852";s:13:"base_modifier";s:5:"times";s:4:"from";s:2:"20";s:2:"to";s:2:"20";}i:18;a:7:{s:4:"type";s:6:"blocks";s:4:"cost";s:0:"";s:8:"modifier";s:0:"";s:9:"base_cost";s:13:"0.06566666667";s:13:"base_modifier";s:5:"times";s:4:"from";s:2:"21";s:2:"to";s:2:"21";}i:19;a:7:{s:4:"type";s:6:"blocks";s:4:"cost";s:0:"";s:8:"modifier";s:0:"";s:9:"base_cost";s:13:"0.06781481481";s:13:"base_modifier";s:5:"times";s:4:"from";s:2:"22";s:2:"to";s:2:"22";}i:20;a:7:{s:4:"type";s:6:"blocks";s:4:"cost";s:0:"";s:8:"modifier";s:0:"";s:9:"base_cost";s:13:"0.06996296296";s:13:"base_modifier";s:5:"times";s:4:"from";s:2:"23";s:2:"to";s:2:"23";}i:21;a:7:{s:4:"type";s:6:"blocks";s:4:"cost";s:0:"";s:8:"modifier";s:0:"";s:9:"base_cost";s:13:"0.07211111111";s:13:"base_modifier";s:5:"times";s:4:"from";s:2:"24";s:2:"to";s:2:"24";}i:22;a:7:{s:4:"type";s:6:"blocks";s:4:"cost";s:0:"";s:8:"modifier";s:0:"";s:9:"base_cost";s:13:"0.07425925926";s:13:"base_modifier";s:5:"times";s:4:"from";s:2:"25";s:2:"to";s:2:"25";}i:23;a:7:{s:4:"type";s:6:"blocks";s:4:"cost";s:0:"";s:8:"modifier";s:0:"";s:9:"base_cost";s:13:"0.07640740741";s:13:"base_modifier";s:5:"times";s:4:"from";s:2:"26";s:2:"to";s:2:"26";}i:24;a:7:{s:4:"type";s:6:"blocks";s:4:"cost";s:0:"";s:8:"modifier";s:0:"";s:9:"base_cost";s:13:"0.07855555556";s:13:"base_modifier";s:5:"times";s:4:"from";s:2:"27";s:2:"to";s:2:"27";}i:25;a:7:{s:4:"type";s:6:"blocks";s:4:"cost";s:0:"";s:8:"modifier";s:0:"";s:9:"base_cost";s:12:"0.0807037037";s:13:"base_modifier";s:5:"times";s:4:"from";s:2:"28";s:2:"to";s:2:"28";}i:26;a:7:{s:4:"type";s:6:"blocks";s:4:"cost";s:0:"";s:8:"modifier";s:0:"";s:9:"base_cost";s:13:"0.08285185185";s:13:"base_modifier";s:5:"times";s:4:"from";s:2:"29";s:2:"to";s:2:"29";}i:27;a:7:{s:4:"type";s:6:"blocks";s:4:"cost";s:0:"";s:8:"modifier";s:0:"";s:9:"base_cost";s:5:"0.085";s:13:"base_modifier";s:5:"times";s:4:"from";s:2:"30";s:2:"to";s:2:"30";}}'); </code></pre> </div>

在中国程序员是青春饭吗?

今年,我也32了 ,为了不给大家误导,咨询了猎头、圈内好友,以及年过35岁的几位老程序员……舍了老脸去揭人家伤疤……希望能给大家以帮助,记得帮我点赞哦。 目录: 你以为的人生 一次又一次的伤害 猎头界的真相 如何应对互联网行业的「中年危机」 一、你以为的人生 刚入行时,拿着傲人的工资,想着好好干,以为我们的人生是这样的: 等真到了那一天,你会发现,你的人生很可能是这样的: ...

程序员请照顾好自己,周末病魔差点一套带走我。

程序员在一个周末的时间,得了重病,差点当场去世,还好及时挽救回来了。

C++(数据结构与算法)78:---分而治之

一、分而治之的思想 分而治之方法与软件设计的模块化方法非常相似 分而治之通常不用于解决问题的小实例,而要解决一个问题的大实例。一般步骤为: ①把一个大实例分为两个或多个更小的实例 ②分别解决每个小实例 ③把这些小实例的解组合成原始大实例的解 二、实际应用之找出假币 问题描述 一个袋子有16个硬币,其中只有一个是假币,这个假币比其他的真币重量轻(其他所有真币的重量都是相同的)...

springboot+jwt实现token登陆权限认证

一 前言 此篇文章的内容也是学习不久,终于到周末有时间码一篇文章分享知识追寻者的粉丝们,学完本篇文章,读者将对token类的登陆认证流程有个全面的了解,可以动态搭建自己的登陆认证过程;对小项目而已是个轻量级的认证机制,符合开发需求;更多精彩原创内容关注公主号知识追寻者,读者的肯定,就是对作者的创作的最大支持; 二 jwt实现登陆认证流程 用户使用账号和面发出post请求 服务器接受到请求后使用私...

技术大佬:我去,你写的 switch 语句也太老土了吧

昨天早上通过远程的方式 review 了两名新来同事的代码,大部分代码都写得很漂亮,严谨的同时注释也很到位,这令我非常满意。但当我看到他们当中有一个人写的 switch 语句时,还是忍不住破口大骂:“我擦,小王,你丫写的 switch 语句也太老土了吧!” 来看看小王写的代码吧,看完不要骂我装逼啊。 private static String createPlayer(PlayerTypes p...

win10暴力查看wifi密码

刚才邻居打了个电话说:喂小灰,你家wifi的密码是多少,我怎么连不上了。 我。。。 我也忘了哎,就找到了一个好办法,分享给大家: 第一种情况:已经连接上的wifi,怎么知道密码? 打开:控制面板\网络和 Internet\网络连接 然后右击wifi连接的无线网卡,选择状态 然后像下图一样: 第二种情况:前提是我不知道啊,但是我以前知道密码。 此时可以利用dos命令了 1、利用netsh wlan...

女程序员,为什么比男程序员少???

昨天看到一档综艺节目,讨论了两个话题:(1)中国学生的数学成绩,平均下来看,会比国外好?为什么?(2)男生的数学成绩,平均下来看,会比女生好?为什么?同时,我又联想到了一个技术圈经常讨...

副业收入是我做程序媛的3倍,工作外的B面人生是怎样的?

提到“程序员”,多数人脑海里首先想到的大约是:为人木讷、薪水超高、工作枯燥…… 然而,当离开工作岗位,撕去层层标签,脱下“程序员”这身外套,有的人生动又有趣,马上展现出了完全不同的A/B面人生! 不论是简单的爱好,还是正经的副业,他们都干得同样出色。偶尔,还能和程序员的特质结合,产生奇妙的“化学反应”。 @Charlotte:平日素颜示人,周末美妆博主 大家都以为程序媛也个个不修边幅,但我们也许...

MySQL数据库面试题(2020最新版)

文章目录数据库基础知识为什么要使用数据库什么是SQL?什么是MySQL?数据库三大范式是什么mysql有关权限的表都有哪几个MySQL的binlog有有几种录入格式?分别有什么区别?数据类型mysql有哪些数据类型引擎MySQL存储引擎MyISAM与InnoDB区别MyISAM索引与InnoDB索引的区别?InnoDB引擎的4大特性存储引擎选择索引什么是索引?索引有哪些优缺点?索引使用场景(重点)...

如果你是老板,你会不会踢了这样的员工?

有个好朋友ZS,是技术总监,昨天问我:“有一个老下属,跟了我很多年,做事勤勤恳恳,主动性也很好。但随着公司的发展,他的进步速度,跟不上团队的步伐了,有点...

我入职阿里后,才知道原来简历这么写

私下里,有不少读者问我:“二哥,如何才能写出一份专业的技术简历呢?我总感觉自己写的简历太烂了,所以投了无数份,都石沉大海了。”说实话,我自己好多年没有写过简历了,但我认识的一个同行,他在阿里,给我说了一些他当年写简历的方法论,我感觉太牛逼了,实在是忍不住,就分享了出来,希望能够帮助到你。 01、简历的本质 作为简历的撰写者,你必须要搞清楚一点,简历的本质是什么,它就是为了来销售你的价值主张的。往深...

程序员写出这样的代码,能不挨骂吗?

当你换槽填坑时,面对一个新的环境。能够快速熟练,上手实现业务需求是关键。但是,哪些因素会影响你快速上手呢?是原有代码写的不够好?还是注释写的不够好?昨夜...

带了6个月的徒弟当了面试官,而身为高级工程师的我天天修Bug......

即将毕业的应届毕业生一枚,现在只拿到了两家offer,但最近听到一些消息,其中一个offer,我这个组据说客户很少,很有可能整组被裁掉。 想问大家: 如果我刚入职这个组就被裁了怎么办呢? 大家都是什么时候知道自己要被裁了的? 面试软技能指导: BQ/Project/Resume 试听内容: 除了刷题,还有哪些技能是拿到offer不可或缺的要素 如何提升面试软实力:简历, 行为面试,沟通能...

优雅的替换if-else语句

场景 日常开发,if-else语句写的不少吧??当逻辑分支非常多的时候,if-else套了一层又一层,虽然业务功能倒是实现了,但是看起来是真的很不优雅,尤其是对于我这种有强迫症的程序"猿",看到这么多if-else,脑袋瓜子就嗡嗡的,总想着解锁新姿势:干掉过多的if-else!!!本文将介绍三板斧手段: 优先判断条件,条件不满足的,逻辑及时中断返回; 采用策略模式+工厂模式; 结合注解,锦...

!大部分程序员只会写3年代码

如果世界上都是这种不思进取的软件公司,那别说大部分程序员只会写 3 年代码,恐怕就没有程序员这种职业。

离职半年了,老东家又发 offer,回不回?

有小伙伴问松哥这个问题,他在上海某公司,在离职了几个月后,前公司的领导联系到他,希望他能够返聘回去,他很纠结要不要回去? 俗话说好马不吃回头草,但是这个小伙伴既然感到纠结了,我觉得至少说明了两个问题:1.曾经的公司还不错;2.现在的日子也不是很如意。否则应该就不会纠结了。 老实说,松哥之前也有过类似的经历,今天就来和小伙伴们聊聊回头草到底吃不吃。 首先一个基本观点,就是离职了也没必要和老东家弄的苦...

2020阿里全球数学大赛:3万名高手、4道题、2天2夜未交卷

阿里巴巴全球数学竞赛( Alibaba Global Mathematics Competition)由马云发起,由中国科学技术协会、阿里巴巴基金会、阿里巴巴达摩院共同举办。大赛不设报名门槛,全世界爱好数学的人都可参与,不论是否出身数学专业、是否投身数学研究。 2020年阿里巴巴达摩院邀请北京大学、剑桥大学、浙江大学等高校的顶尖数学教师组建了出题组。中科院院士、美国艺术与科学院院士、北京国际数学...

为什么你不想学习?只想玩?人是如何一步一步废掉的

不知道是不是只有我这样子,还是你们也有过类似的经历。 上学的时候总有很多光辉历史,学年名列前茅,或者单科目大佬,但是虽然慢慢地长大了,你开始懈怠了,开始废掉了。。。 什么?你说不知道具体的情况是怎么样的? 我来告诉你: 你常常潜意识里或者心理觉得,自己真正的生活或者奋斗还没有开始。总是幻想着自己还拥有大把时间,还有无限的可能,自己还能逆风翻盘,只不是自己还没开始罢了,自己以后肯定会变得特别厉害...

男生更看重女生的身材脸蛋,还是思想?

往往,我们看不进去大段大段的逻辑。深刻的哲理,往往短而精悍,一阵见血。问:产品经理挺漂亮的,有点心动,但不知道合不合得来。男生更看重女生的身材脸蛋,还是...

为什么程序员做外包会被瞧不起?

二哥,有个事想询问下您的意见,您觉得应届生值得去外包吗?公司虽然挺大的,中xx,但待遇感觉挺低,马上要报到,挺纠结的。

当HR压你价,说你只值7K,你该怎么回答?

当HR压你价,说你只值7K时,你可以流畅地回答,记住,是流畅,不能犹豫。 礼貌地说:“7K是吗?了解了。嗯~其实我对贵司的面试官印象很好。只不过,现在我的手头上已经有一份11K的offer。来面试,主要也是自己对贵司挺有兴趣的,所以过来看看……”(未完) 这段话主要是陪HR互诈的同时,从公司兴趣,公司职员印象上,都给予对方正面的肯定,既能提升HR的好感度,又能让谈判气氛融洽,为后面的发挥留足空间。...

面试:第十六章:Java中级开发

HashMap底层实现原理,红黑树,B+树,B树的结构原理 Spring的AOP和IOC是什么?它们常见的使用场景有哪些?Spring事务,事务的属性,传播行为,数据库隔离级别 Spring和SpringMVC,MyBatis以及SpringBoot的注解分别有哪些?SpringMVC的工作原理,SpringBoot框架的优点,MyBatis框架的优点 SpringCould组件有哪些,他们...

早上躺尸,晚上干活:硅谷科技公司这么流行迟到?

硅谷科技公司上班时间OPEN早已不是什么新鲜事,早九晚五是常态,但有很多企业由于不打卡,员工们10点、11点才“姗姗来迟”的情况也屡见不鲜。 这种灵活的考勤制度为人羡慕,甚至近年来,国内某些互联网企业也纷纷效仿。不过,硅谷普遍弹性的上班制度是怎么由来的呢?这种“流行性迟到”真的有那么轻松、悠哉吗? 《动态规划专题班》 课程试听内容: 动态规划的解题要领 动态规划三大类 求最值/计数/可行性 常...

面试阿里p7,被按在地上摩擦,鬼知道我经历了什么?

面试阿里p7被问到的问题(当时我只知道第一个):@Conditional是做什么的?@Conditional多个条件是什么逻辑关系?条件判断在什么时候执...

Python爬虫,高清美图我全都要(彼岸桌面壁纸)

爬取彼岸桌面网站较为简单,用到了requests、lxml、Beautiful Soup4

无代码时代来临,程序员如何保住饭碗?

编程语言层出不穷,从最初的机器语言到如今2500种以上的高级语言,程序员们大呼“学到头秃”。程序员一边面临编程语言不断推陈出新,一边面临由于许多代码已存在,程序员编写新应用程序时存在重复“搬砖”的现象。 无代码/低代码编程应运而生。无代码/低代码是一种创建应用的方法,它可以让开发者使用最少的编码知识来快速开发应用程序。开发者通过图形界面中,可视化建模来组装和配置应用程序。这样一来,开发者直...

面试了一个 31 岁程序员,让我有所触动,30岁以上的程序员该何去何从?

最近面试了一个31岁8年经验的程序猿,让我有点感慨,大龄程序猿该何去何从。

大三实习生,字节跳动面经分享,已拿Offer

说实话,自己的算法,我一个不会,太难了吧

程序员垃圾简历长什么样?

已经连续五年参加大厂校招、社招的技术面试工作,简历看的不下于万份 这篇文章会用实例告诉你,什么是差的程序员简历! 疫情快要结束了,各个公司也都开始春招了,作为即将红遍大江南北的新晋UP主,那当然要为小伙伴们做点事(手动狗头)。 就在公众号里公开征简历,义务帮大家看,并一一点评。《启舰:春招在即,义务帮大家看看简历吧》 一石激起千层浪,三天收到两百多封简历。 花光了两个星期的所有空闲时...

Java岗开发3年,公司临时抽查算法,离职后这几题我记一辈子

前几天我们公司做了一件蠢事,非常非常愚蠢的事情。我原以为从学校出来之后,除了找工作有测试外,不会有任何与考试有关的事儿。 但是,天有不测风云,公司技术总监、人事总监两位大佬突然降临到我们事业线,叫上我老大,给我们组织了一场别开生面的“考试”。 那是一个风和日丽的下午,我翘着二郎腿,左手端着一杯卡布奇诺,右手抓着我的罗技鼠标,滚动着轮轴,穿梭在头条热点之间。 “淡黄的长裙~蓬松的头发...

立即提问
相关内容推荐