问:
Computing the Jacobian Matrix in Tensorflow
I am trying to compute Jacobian Matrix in Tensorflow for the following Network:
but It didn't work with my Neural Network!

I found jacobian Matrix code in https://medium.com/unit8-machine-learning-publication/computing-the-jacobian-matrix-of-a-neural-network-in-python-4f162e5db180

Unfortunately it doesn't work with my network ... the problem message is "ValueError: Cannot feed value of shape (1, 51000) for Tensor 'dense_1_input:0', which has shape '(?, 6)'"

I think that is the problem in the loop function inside jacobian_tensorflow function?

```<code># Importing some Libraries
from keras.models import Sequential
from keras.layers import Dense
from keras.optimizers import SGD
import numpy as np
import statsmodels.api as sm
from sklearn.metrics import mean_squared_error
import matplotlib.pyplot as plt
from tqdm import tqdm
import tensorflow as tf
# Simulation of some data
np.random.seed (245)
nobs =10000

# Definition normalverteilte Features
x1= np.random.normal(size=nobs ,scale=1)
x2= np.random.normal(size=nobs ,scale=1)
x3= np.random.normal(size=nobs ,scale=1)
x4= np.random.normal(size=nobs ,scale=1)
x5= np.random.normal(size=nobs ,scale=1)

# Features
X= np.c_[np.ones((nobs ,1)),x1,x2,x3,x4,x5]

y= np.cos(x1) + np.sin(x2) + 2*x3 + x4 + 0.01*x5 + np.random.normal(size=nobs , scale=0.01)

#Learningrate
LR=0.05

# Number of Neurons
Neuron_Out=1
Neuron_Hidden1=64
Neuron_Hidden2=32

#The Activation function
Activate_output='linear' # für letzte Schicht verwende ich linear
Activate_hidden='relu' # unterschied ist Hidden-Layer-Neuronen werden nicht linear transformiert

#The Optimizer
Optimizer= SGD(lr=LR)

# The loss function
loss='mean_squared_error'

# Splitting Data
from sklearn.model_selection import train_test_split
x_train , x_test , y_train , y_test = train_test_split(X, y, test_size =0.15, random_state =77)

## Neural Network
from tensorflow import set_random_seed
set_random_seed (245)
# As in Medium Essa
sess = tf.InteractiveSession()
sess.run(tf.initialize_all_variables())

#Initialize the ANN
model_ANN= Sequential()

# Hidden Layer-> hier wird Hidden Layer definiert-> Anzahl der Neuronen hier sind 64, 32
# input ist 6 (also 1,x1,x2,x3,x4,x5)-> one is the first column in X Matrix
model_ANN.add(Dense(Neuron_Hidden1, activation=Activate_hidden, input_shape=(6,), use_bias=True))
model_ANN.add(Dense(Neuron_Hidden2, activation=Activate_hidden, use_bias=True))

#Output Layer-> hier wird Output-Layer defniniert
model_ANN.add(Dense(Neuron_Out, activation=Activate_output,use_bias=True))
model_ANN.summary()

#Fit the model
history_ANN=model_ANN.fit(
x_train, # training data
y_train, # training targets
epochs=125)

def jacobian_tensorflow(x):
    jacobian_matrix = []
    for m in range(Neuron_Out):
        # We iterate over the M elements of the output vector
        grad_func = tf.gradients(model_ANN.output[:, m], model_ANN.input)
        gradients = sess.run(grad_func, feed_dict={model_ANN.input: x.reshape((1, x.size))})
        jacobian_matrix.append(gradients[0][0,:])

    return np.array(jacobian_matrix)

#Jacobian matrix computation
def jacobian_tensorflow(x):
    jacobian_matrix = []
    for m in range(Neuron_Out):
        # We iterate over the M elements of the output vector
        grad_func = tf.gradients(model_ANN.output[:, m], model_ANN.input)
        gradients = sess.run(grad_func, feed_dict={model_ANN.input: x.reshape((1, x.size))})
        jacobian_matrix.append(gradients[0][0,:])

    return np.array(jacobian_matrix)

jacobian_tensorflow(x_train)
</code>```

How I could use Jacobian Computation Function for my Network?

Thanks in Advance

答:
I have modified your code to fix the error and now its working. There were few errors like compile statement missing, function defined twice and forcing the reshape of input for the Dense layer even though the shape was good for feed_dict in jacobian_tensorflow function. Have added comments in the code for changes.

Fixed Code -

```<code>%tensorflow_version 1.x
# Importing some Libraries
from keras.models import Sequential
from keras.layers import Dense
from keras.optimizers import SGD
import numpy as np
import statsmodels.api as sm
from sklearn.metrics import mean_squared_error
import matplotlib.pyplot as plt
from tqdm import tqdm
import tensorflow as tf
# Simulation of some data
np.random.seed (245)
nobs =10000

# Definition normalverteilte Features
x1= np.random.normal(size=nobs ,scale=1)
x2= np.random.normal(size=nobs ,scale=1)
x3= np.random.normal(size=nobs ,scale=1)
x4= np.random.normal(size=nobs ,scale=1)
x5= np.random.normal(size=nobs ,scale=1)

# Features
X= np.c_[np.ones((nobs ,1)),x1,x2,x3,x4,x5]

y= np.cos(x1) + np.sin(x2) + 2*x3 + x4 + 0.01*x5 + np.random.normal(size=nobs , scale=0.01)

#Learningrate
LR=0.05

# Number of Neurons
Neuron_Out=1
Neuron_Hidden1=64
Neuron_Hidden2=32

#The Activation function
Activate_output='linear' # für letzte Schicht verwende ich linear
Activate_hidden='relu' # unterschied ist Hidden-Layer-Neuronen werden nicht linear transformiert

#The Optimizer
Optimizer= SGD(lr=LR)

# The loss function
loss='mean_squared_error'

# Splitting Data
from sklearn.model_selection import train_test_split
x_train , x_test , y_train , y_test = train_test_split(X, y, test_size =0.15, random_state =77)

## Neural Network
from tensorflow import set_random_seed
set_random_seed (245)
# As in Medium Essa
sess = tf.InteractiveSession()
sess.run(tf.initialize_all_variables())

#Initialize the ANN
model_ANN= Sequential()

# Hidden Layer-> hier wird Hidden Layer definiert-> Anzahl der Neuronen hier sind 64, 32
# input ist 6 (also 1,x1,x2,x3,x4,x5)-> one is the first column in X Matrix
model_ANN.add(Dense(Neuron_Hidden1, activation=Activate_hidden, input_shape=(6,), use_bias=True))
model_ANN.add(Dense(Neuron_Hidden2, activation=Activate_hidden, use_bias=True))

#Output Layer-> hier wird Output-Layer defniniert
model_ANN.add(Dense(Neuron_Out, activation=Activate_output,use_bias=True))
model_ANN.summary()

# Added the compile statement
model_ANN.compile(loss=loss, optimizer=Optimizer, metrics=['accuracy'])

#Fit the model
history_ANN=model_ANN.fit(
x_train, # training data
y_train, # training targets
epochs=125)

#Jacobian matrix computation
def jacobian_tensorflow(x):
    jacobian_matrix = []
    for m in range(Neuron_Out):
        # We iterate over the M elements of the output vector
        grad_func = tf.gradients(model_ANN.output[:, m],model_ANN.input)
        gradients = sess.run(grad_func, feed_dict={model_ANN.input: x})  # Removed x.reshape((1, x.size)) as reshape is not required bcoz dense accepts the shape
        jacobian_matrix.append(gradients[0][0,:])

    return np.array(jacobian_matrix)

jacobian_tensorflow(x_train)
</code>```

Output -

```<code>/tensorflow-1.15.2/python3.6/tensorflow_core/python/client/session.py:1750: UserWarning: An interactive session is already active. This can cause out-of-memory errors in some cases. You must explicitly call `InteractiveSession.close()` to release resources held by the other session(s).
  warnings.warn('An interactive session is already active. This can '
Model: "sequential_4"
_________________________________________________________________
Layer (type)                 Output Shape              Param #
=================================================================
dense_10 (Dense)             (None, 64)                448
_________________________________________________________________
dense_11 (Dense)             (None, 32)                2080
_________________________________________________________________
dense_12 (Dense)             (None, 1)                 33
=================================================================
Total params: 2,561
Trainable params: 2,561
Non-trainable params: 0
_________________________________________________________________
Epoch 1/125
8500/8500 [==============================] - 1s 82us/step - loss: 0.1999 - accuracy: 0.0000e+00
Epoch 2/125
8500/8500 [==============================] - 1s 79us/step - loss: 0.0501 - accuracy: 0.0000e+00
Epoch 3/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0277 - accuracy: 0.0000e+00
Epoch 4/125
8500/8500 [==============================] - 1s 79us/step - loss: 0.0219 - accuracy: 0.0000e+00
Epoch 5/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0190 - accuracy: 0.0000e+00
Epoch 6/125
8500/8500 [==============================] - 1s 79us/step - loss: 0.0114 - accuracy: 0.0000e+00
Epoch 7/125
8500/8500 [==============================] - 1s 78us/step - loss: 0.0138 - accuracy: 0.0000e+00
Epoch 8/125
8500/8500 [==============================] - 1s 81us/step - loss: 0.0092 - accuracy: 0.0000e+00
Epoch 9/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0072 - accuracy: 0.0000e+00
Epoch 10/125
8500/8500 [==============================] - 1s 79us/step - loss: 0.0073 - accuracy: 0.0000e+00
Epoch 11/125
8500/8500 [==============================] - 1s 79us/step - loss: 0.0065 - accuracy: 0.0000e+00
Epoch 12/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0070 - accuracy: 0.0000e+00
Epoch 13/125
8500/8500 [==============================] - 1s 78us/step - loss: 0.0055 - accuracy: 0.0000e+00
Epoch 14/125
8500/8500 [==============================] - 1s 78us/step - loss: 0.0055 - accuracy: 0.0000e+00
Epoch 15/125
8500/8500 [==============================] - 1s 79us/step - loss: 0.0055 - accuracy: 0.0000e+00
Epoch 16/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0057 - accuracy: 0.0000e+00
Epoch 17/125
8500/8500 [==============================] - 1s 79us/step - loss: 0.0045 - accuracy: 0.0000e+00
Epoch 18/125
8500/8500 [==============================] - 1s 79us/step - loss: 0.0052 - accuracy: 0.0000e+00
Epoch 19/125
8500/8500 [==============================] - 1s 79us/step - loss: 0.0055 - accuracy: 0.0000e+00
Epoch 20/125
8500/8500 [==============================] - 1s 79us/step - loss: 0.0040 - accuracy: 0.0000e+00
Epoch 21/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0045 - accuracy: 0.0000e+00
Epoch 22/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0040 - accuracy: 0.0000e+00
Epoch 23/125
8500/8500 [==============================] - 1s 78us/step - loss: 0.0041 - accuracy: 0.0000e+00
Epoch 24/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0044 - accuracy: 0.0000e+00
Epoch 25/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0037 - accuracy: 0.0000e+00
Epoch 26/125
8500/8500 [==============================] - 1s 78us/step - loss: 0.0046 - accuracy: 0.0000e+00
Epoch 27/125
8500/8500 [==============================] - 1s 79us/step - loss: 0.0042 - accuracy: 0.0000e+00
Epoch 28/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0039 - accuracy: 0.0000e+00
Epoch 29/125
8500/8500 [==============================] - 1s 78us/step - loss: 0.0037 - accuracy: 0.0000e+00
Epoch 30/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0042 - accuracy: 0.0000e+00
Epoch 31/125
8500/8500 [==============================] - 1s 79us/step - loss: 0.0033 - accuracy: 0.0000e+00
Epoch 32/125
8500/8500 [==============================] - 1s 79us/step - loss: 0.0032 - accuracy: 0.0000e+00
Epoch 33/125
8500/8500 [==============================] - 1s 78us/step - loss: 0.0033 - accuracy: 0.0000e+00
Epoch 34/125
8500/8500 [==============================] - 1s 79us/step - loss: 0.0038 - accuracy: 0.0000e+00
Epoch 35/125
8500/8500 [==============================] - 1s 78us/step - loss: 0.0035 - accuracy: 0.0000e+00
Epoch 36/125
8500/8500 [==============================] - 1s 78us/step - loss: 0.0032 - accuracy: 0.0000e+00
Epoch 37/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0032 - accuracy: 0.0000e+00
Epoch 38/125
8500/8500 [==============================] - 1s 78us/step - loss: 0.0032 - accuracy: 0.0000e+00
Epoch 39/125
8500/8500 [==============================] - 1s 79us/step - loss: 0.0032 - accuracy: 0.0000e+00
Epoch 40/125
8500/8500 [==============================] - 1s 81us/step - loss: 0.0028 - accuracy: 0.0000e+00
Epoch 41/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0032 - accuracy: 0.0000e+00
Epoch 42/125
8500/8500 [==============================] - 1s 77us/step - loss: 0.0029 - accuracy: 0.0000e+00
Epoch 43/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0029 - accuracy: 0.0000e+00
Epoch 44/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0029 - accuracy: 0.0000e+00
Epoch 45/125
8500/8500 [==============================] - 1s 79us/step - loss: 0.0028 - accuracy: 0.0000e+00
Epoch 46/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0031 - accuracy: 0.0000e+00
Epoch 47/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0025 - accuracy: 0.0000e+00
Epoch 48/125
8500/8500 [==============================] - 1s 79us/step - loss: 0.0022 - accuracy: 0.0000e+00
Epoch 49/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0027 - accuracy: 0.0000e+00
Epoch 50/125
8500/8500 [==============================] - 1s 79us/step - loss: 0.0028 - accuracy: 0.0000e+00
Epoch 51/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0024 - accuracy: 0.0000e+00
Epoch 52/125
8500/8500 [==============================] - 1s 78us/step - loss: 0.0024 - accuracy: 0.0000e+00
Epoch 53/125
8500/8500 [==============================] - 1s 79us/step - loss: 0.0023 - accuracy: 0.0000e+00
Epoch 54/125
8500/8500 [==============================] - 1s 78us/step - loss: 0.0026 - accuracy: 0.0000e+00
Epoch 55/125
8500/8500 [==============================] - 1s 81us/step - loss: 0.0023 - accuracy: 0.0000e+00
Epoch 56/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0020 - accuracy: 0.0000e+00
Epoch 57/125
8500/8500 [==============================] - 1s 78us/step - loss: 0.0024 - accuracy: 0.0000e+00
Epoch 58/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0022 - accuracy: 0.0000e+00
Epoch 59/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0021 - accuracy: 0.0000e+00
Epoch 60/125
8500/8500 [==============================] - 1s 78us/step - loss: 0.0022 - accuracy: 0.0000e+00
Epoch 61/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0020 - accuracy: 0.0000e+00
Epoch 62/125
8500/8500 [==============================] - 1s 81us/step - loss: 0.0022 - accuracy: 0.0000e+00
Epoch 63/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0022 - accuracy: 0.0000e+00
Epoch 64/125
8500/8500 [==============================] - 1s 82us/step - loss: 0.0023 - accuracy: 0.0000e+00
Epoch 65/125
8500/8500 [==============================] - 1s 81us/step - loss: 0.0023 - accuracy: 0.0000e+00
Epoch 66/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0018 - accuracy: 0.0000e+00
Epoch 67/125
8500/8500 [==============================] - 1s 81us/step - loss: 0.0021 - accuracy: 0.0000e+00
Epoch 68/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0020 - accuracy: 0.0000e+00
Epoch 69/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0020 - accuracy: 0.0000e+00
Epoch 70/125
8500/8500 [==============================] - 1s 81us/step - loss: 0.0018 - accuracy: 0.0000e+00
Epoch 71/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0019 - accuracy: 0.0000e+00
Epoch 72/125
8500/8500 [==============================] - 1s 79us/step - loss: 0.0018 - accuracy: 0.0000e+00
Epoch 73/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0018 - accuracy: 0.0000e+00
Epoch 74/125
8500/8500 [==============================] - 1s 81us/step - loss: 0.0018 - accuracy: 0.0000e+00
Epoch 75/125
8500/8500 [==============================] - 1s 81us/step - loss: 0.0019 - accuracy: 0.0000e+00
Epoch 76/125
8500/8500 [==============================] - 1s 81us/step - loss: 0.0018 - accuracy: 0.0000e+00
Epoch 77/125
8500/8500 [==============================] - 1s 83us/step - loss: 0.0016 - accuracy: 0.0000e+00
Epoch 78/125
8500/8500 [==============================] - 1s 79us/step - loss: 0.0019 - accuracy: 0.0000e+00
Epoch 79/125
8500/8500 [==============================] - 1s 79us/step - loss: 0.0019 - accuracy: 0.0000e+00
Epoch 80/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0016 - accuracy: 0.0000e+00
Epoch 81/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0018 - accuracy: 0.0000e+00
Epoch 82/125
8500/8500 [==============================] - 1s 81us/step - loss: 0.0017 - accuracy: 0.0000e+00
Epoch 83/125
8500/8500 [==============================] - 1s 81us/step - loss: 0.0017 - accuracy: 0.0000e+00
Epoch 84/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0016 - accuracy: 0.0000e+00
Epoch 85/125
8500/8500 [==============================] - 1s 82us/step - loss: 0.0017 - accuracy: 0.0000e+00
Epoch 86/125
8500/8500 [==============================] - 1s 81us/step - loss: 0.0017 - accuracy: 0.0000e+00
Epoch 87/125
8500/8500 [==============================] - 1s 83us/step - loss: 0.0017 - accuracy: 0.0000e+00
Epoch 88/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0016 - accuracy: 0.0000e+00
Epoch 89/125
8500/8500 [==============================] - 1s 82us/step - loss: 0.0016 - accuracy: 0.0000e+00
Epoch 90/125
8500/8500 [==============================] - 1s 81us/step - loss: 0.0018 - accuracy: 0.0000e+00
Epoch 91/125
8500/8500 [==============================] - 1s 81us/step - loss: 0.0015 - accuracy: 0.0000e+00
Epoch 92/125
8500/8500 [==============================] - 1s 82us/step - loss: 0.0014 - accuracy: 0.0000e+00
Epoch 93/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0016 - accuracy: 0.0000e+00
Epoch 94/125
8500/8500 [==============================] - 1s 81us/step - loss: 0.0016 - accuracy: 0.0000e+00
Epoch 95/125
8500/8500 [==============================] - 1s 83us/step - loss: 0.0014 - accuracy: 0.0000e+00
Epoch 96/125
8500/8500 [==============================] - 1s 81us/step - loss: 0.0014 - accuracy: 0.0000e+00
Epoch 97/125
8500/8500 [==============================] - 1s 81us/step - loss: 0.0016 - accuracy: 0.0000e+00
Epoch 98/125
8500/8500 [==============================] - 1s 81us/step - loss: 0.0015 - accuracy: 0.0000e+00
Epoch 99/125
8500/8500 [==============================] - 1s 81us/step - loss: 0.0014 - accuracy: 0.0000e+00
Epoch 100/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0015 - accuracy: 0.0000e+00
Epoch 101/125
8500/8500 [==============================] - 1s 81us/step - loss: 0.0014 - accuracy: 0.0000e+00
Epoch 102/125
8500/8500 [==============================] - 1s 82us/step - loss: 0.0015 - accuracy: 0.0000e+00
Epoch 103/125
8500/8500 [==============================] - 1s 81us/step - loss: 0.0013 - accuracy: 0.0000e+00
Epoch 104/125
8500/8500 [==============================] - 1s 81us/step - loss: 0.0014 - accuracy: 0.0000e+00
Epoch 105/125
8500/8500 [==============================] - 1s 81us/step - loss: 0.0013 - accuracy: 0.0000e+00
Epoch 106/125
8500/8500 [==============================] - 1s 81us/step - loss: 0.0012 - accuracy: 0.0000e+00
Epoch 107/125
8500/8500 [==============================] - 1s 82us/step - loss: 0.0014 - accuracy: 0.0000e+00
Epoch 108/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0012 - accuracy: 0.0000e+00
Epoch 109/125
8500/8500 [==============================] - 1s 81us/step - loss: 0.0013 - accuracy: 0.0000e+00
Epoch 110/125
8500/8500 [==============================] - 1s 81us/step - loss: 0.0012 - accuracy: 0.0000e+00
Epoch 111/125
8500/8500 [==============================] - 1s 81us/step - loss: 0.0012 - accuracy: 0.0000e+00
Epoch 112/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0011 - accuracy: 0.0000e+00
Epoch 113/125
8500/8500 [==============================] - 1s 81us/step - loss: 0.0014 - accuracy: 0.0000e+00
Epoch 114/125
8500/8500 [==============================] - 1s 81us/step - loss: 0.0011 - accuracy: 0.0000e+00
Epoch 115/125
8500/8500 [==============================] - 1s 79us/step - loss: 0.0012 - accuracy: 0.0000e+00
Epoch 116/125
8500/8500 [==============================] - 1s 82us/step - loss: 0.0013 - accuracy: 0.0000e+00
Epoch 117/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0013 - accuracy: 0.0000e+00
Epoch 118/125
8500/8500 [==============================] - 1s 82us/step - loss: 0.0011 - accuracy: 0.0000e+00
Epoch 119/125
8500/8500 [==============================] - 1s 79us/step - loss: 0.0012 - accuracy: 0.0000e+00
Epoch 120/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0012 - accuracy: 0.0000e+00
Epoch 121/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0011 - accuracy: 0.0000e+00
Epoch 122/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0011 - accuracy: 0.0000e+00
Epoch 123/125
8500/8500 [==============================] - 1s 82us/step - loss: 0.0012 - accuracy: 0.0000e+00
Epoch 124/125
8500/8500 [==============================] - 1s 81us/step - loss: 0.0011 - accuracy: 0.0000e+00
Epoch 125/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0018 - accuracy: 0.0000e+00
array([[ 0.6434634 , -0.09752402,  0.8342059 ,  1.6331654 ,  0.82901144,
        -0.00917255]], dtype=float32)
</code>```

Hope this answers your question. Happy Learning.

Body:
I am trying to compute Jacobian Matrix in Tensorflow for the following Network:
but It didn't work with my Neural Network!

I found jacobian Matrix code in https://medium.com/unit8-machine-learning-publication/computing-the-jacobian-matrix-of-a-neural-network-in-python-4f162e5db180

Unfortunately it doesn't work with my network ... the problem message is "ValueError: Cannot feed value of shape (1, 51000) for Tensor 'dense_1_input:0', which has shape '(?, 6)'"

I think that is the problem in the loop function inside jacobian_tensorflow function?

# Importing some Libraries
from keras.models import Sequential
from keras.layers import Dense
from keras.optimizers import SGD
import numpy as np
import statsmodels.api as sm
from sklearn.metrics import mean_squared_error
import matplotlib.pyplot as plt
from tqdm import tqdm
import tensorflow as tf
# Simulation of some data
np.random.seed (245)
nobs =10000

# Definition normalverteilte Features
x1= np.random.normal(size=nobs ,scale=1)
x2= np.random.normal(size=nobs ,scale=1)
x3= np.random.normal(size=nobs ,scale=1)
x4= np.random.normal(size=nobs ,scale=1)
x5= np.random.normal(size=nobs ,scale=1)

# Features
X= np.c_[np.ones((nobs ,1)),x1,x2,x3,x4,x5]

y= np.cos(x1) + np.sin(x2) + 2*x3 + x4 + 0.01*x5 + np.random.normal(size=nobs , scale=0.01)

#Learningrate
LR=0.05

# Number of Neurons
Neuron_Out=1
Neuron_Hidden1=64
Neuron_Hidden2=32

#The Activation function
Activate_output='linear' # für letzte Schicht verwende ich linear
Activate_hidden='relu' # unterschied ist Hidden-Layer-Neuronen werden nicht linear transformiert

#The Optimizer
Optimizer= SGD(lr=LR)

# The loss function
loss='mean_squared_error'

# Splitting Data
from sklearn.model_selection import train_test_split
x_train , x_test , y_train , y_test = train_test_split(X, y, test_size =0.15, random_state =77)

## Neural Network
from tensorflow import set_random_seed
set_random_seed (245)
# As in Medium Essa
sess = tf.InteractiveSession()
sess.run(tf.initialize_all_variables())

#Initialize the ANN
model_ANN= Sequential()

# Hidden Layer-> hier wird Hidden Layer definiert-> Anzahl der Neuronen hier sind 64, 32
# input ist 6 (also 1,x1,x2,x3,x4,x5)-> one is the first column in X Matrix
model_ANN.add(Dense(Neuron_Hidden1, activation=Activate_hidden, input_shape=(6,), use_bias=True))
model_ANN.add(Dense(Neuron_Hidden2, activation=Activate_hidden, use_bias=True))

#Output Layer-> hier wird Output-Layer defniniert
model_ANN.add(Dense(Neuron_Out, activation=Activate_output,use_bias=True))
model_ANN.summary()

#Fit the model
history_ANN=model_ANN.fit(
x_train, # training data
y_train, # training targets
epochs=125)

def jacobian_tensorflow(x):
    jacobian_matrix = []
    for m in range(Neuron_Out):
        # We iterate over the M elements of the output vector
        grad_func = tf.gradients(model_ANN.output[:, m], model_ANN.input)
        gradients = sess.run(grad_func, feed_dict={model_ANN.input: x.reshape((1, x.size))})
        jacobian_matrix.append(gradients[0][0,:])

    return np.array(jacobian_matrix)

#Jacobian matrix computation
def jacobian_tensorflow(x):
    jacobian_matrix = []
    for m in range(Neuron_Out):
        # We iterate over the M elements of the output vector
        grad_func = tf.gradients(model_ANN.output[:, m], model_ANN.input)
        gradients = sess.run(grad_func, feed_dict={model_ANN.input: x.reshape((1, x.size))})
        jacobian_matrix.append(gradients[0][0,:])

    return np.array(jacobian_matrix)

jacobian_tensorflow(x_train)

How I could use Jacobian Computation Function for my Network?

Thanks in Advance

Body:
I have modified your code to fix the error and now its working. There were few errors like compile statement missing, function defined twice and forcing the reshape of input for the Dense layer even though the shape was good for feed_dict in jacobian_tensorflow function. Have added comments in the code for changes.

Fixed Code -

%tensorflow_version 1.x
# Importing some Libraries
from keras.models import Sequential
from keras.layers import Dense
from keras.optimizers import SGD
import numpy as np
import statsmodels.api as sm
from sklearn.metrics import mean_squared_error
import matplotlib.pyplot as plt
from tqdm import tqdm
import tensorflow as tf
# Simulation of some data
np.random.seed (245)
nobs =10000

# Definition normalverteilte Features
x1= np.random.normal(size=nobs ,scale=1)
x2= np.random.normal(size=nobs ,scale=1)
x3= np.random.normal(size=nobs ,scale=1)
x4= np.random.normal(size=nobs ,scale=1)
x5= np.random.normal(size=nobs ,scale=1)

# Features
X= np.c_[np.ones((nobs ,1)),x1,x2,x3,x4,x5]

y= np.cos(x1) + np.sin(x2) + 2*x3 + x4 + 0.01*x5 + np.random.normal(size=nobs , scale=0.01)

#Learningrate
LR=0.05

# Number of Neurons
Neuron_Out=1
Neuron_Hidden1=64
Neuron_Hidden2=32

#The Activation function
Activate_output='linear' # für letzte Schicht verwende ich linear
Activate_hidden='relu' # unterschied ist Hidden-Layer-Neuronen werden nicht linear transformiert

#The Optimizer
Optimizer= SGD(lr=LR)

# The loss function
loss='mean_squared_error'

# Splitting Data
from sklearn.model_selection import train_test_split
x_train , x_test , y_train , y_test = train_test_split(X, y, test_size =0.15, random_state =77)

## Neural Network
from tensorflow import set_random_seed
set_random_seed (245)
# As in Medium Essa
sess = tf.InteractiveSession()
sess.run(tf.initialize_all_variables())

#Initialize the ANN
model_ANN= Sequential()

# Hidden Layer-> hier wird Hidden Layer definiert-> Anzahl der Neuronen hier sind 64, 32
# input ist 6 (also 1,x1,x2,x3,x4,x5)-> one is the first column in X Matrix
model_ANN.add(Dense(Neuron_Hidden1, activation=Activate_hidden, input_shape=(6,), use_bias=True))
model_ANN.add(Dense(Neuron_Hidden2, activation=Activate_hidden, use_bias=True))

#Output Layer-> hier wird Output-Layer defniniert
model_ANN.add(Dense(Neuron_Out, activation=Activate_output,use_bias=True))
model_ANN.summary()

# Added the compile statement
model_ANN.compile(loss=loss, optimizer=Optimizer, metrics=['accuracy'])

#Fit the model
history_ANN=model_ANN.fit(
x_train, # training data
y_train, # training targets
epochs=125)

#Jacobian matrix computation
def jacobian_tensorflow(x):
    jacobian_matrix = []
    for m in range(Neuron_Out):
        # We iterate over the M elements of the output vector
        grad_func = tf.gradients(model_ANN.output[:, m],model_ANN.input)
        gradients = sess.run(grad_func, feed_dict={model_ANN.input: x})  # Removed x.reshape((1, x.size)) as reshape is not required bcoz dense accepts the shape
        jacobian_matrix.append(gradients[0][0,:])

    return np.array(jacobian_matrix)

jacobian_tensorflow(x_train)

Output -

/tensorflow-1.15.2/python3.6/tensorflow_core/python/client/session.py:1750: UserWarning: An interactive session is already active. This can cause out-of-memory errors in some cases. You must explicitly call `InteractiveSession.close()` to release resources held by the other session(s).
  warnings.warn('An interactive session is already active. This can '
Model: "sequential_4"
_________________________________________________________________
Layer (type)                 Output Shape              Param #
=================================================================
dense_10 (Dense)             (None, 64)                448
_________________________________________________________________
dense_11 (Dense)             (None, 32)                2080
_________________________________________________________________
dense_12 (Dense)             (None, 1)                 33
=================================================================
Total params: 2,561
Trainable params: 2,561
Non-trainable params: 0
_________________________________________________________________
Epoch 1/125
8500/8500 [==============================] - 1s 82us/step - loss: 0.1999 - accuracy: 0.0000e+00
Epoch 2/125
8500/8500 [==============================] - 1s 79us/step - loss: 0.0501 - accuracy: 0.0000e+00
Epoch 3/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0277 - accuracy: 0.0000e+00
Epoch 4/125
8500/8500 [==============================] - 1s 79us/step - loss: 0.0219 - accuracy: 0.0000e+00
Epoch 5/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0190 - accuracy: 0.0000e+00
Epoch 6/125
8500/8500 [==============================] - 1s 79us/step - loss: 0.0114 - accuracy: 0.0000e+00
Epoch 7/125
8500/8500 [==============================] - 1s 78us/step - loss: 0.0138 - accuracy: 0.0000e+00
Epoch 8/125
8500/8500 [==============================] - 1s 81us/step - loss: 0.0092 - accuracy: 0.0000e+00
Epoch 9/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0072 - accuracy: 0.0000e+00
Epoch 10/125
8500/8500 [==============================] - 1s 79us/step - loss: 0.0073 - accuracy: 0.0000e+00
Epoch 11/125
8500/8500 [==============================] - 1s 79us/step - loss: 0.0065 - accuracy: 0.0000e+00
Epoch 12/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0070 - accuracy: 0.0000e+00
Epoch 13/125
8500/8500 [==============================] - 1s 78us/step - loss: 0.0055 - accuracy: 0.0000e+00
Epoch 14/125
8500/8500 [==============================] - 1s 78us/step - loss: 0.0055 - accuracy: 0.0000e+00
Epoch 15/125
8500/8500 [==============================] - 1s 79us/step - loss: 0.0055 - accuracy: 0.0000e+00
Epoch 16/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0057 - accuracy: 0.0000e+00
Epoch 17/125
8500/8500 [==============================] - 1s 79us/step - loss: 0.0045 - accuracy: 0.0000e+00
Epoch 18/125
8500/8500 [==============================] - 1s 79us/step - loss: 0.0052 - accuracy: 0.0000e+00
Epoch 19/125
8500/8500 [==============================] - 1s 79us/step - loss: 0.0055 - accuracy: 0.0000e+00
Epoch 20/125
8500/8500 [==============================] - 1s 79us/step - loss: 0.0040 - accuracy: 0.0000e+00
Epoch 21/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0045 - accuracy: 0.0000e+00
Epoch 22/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0040 - accuracy: 0.0000e+00
Epoch 23/125
8500/8500 [==============================] - 1s 78us/step - loss: 0.0041 - accuracy: 0.0000e+00
Epoch 24/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0044 - accuracy: 0.0000e+00
Epoch 25/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0037 - accuracy: 0.0000e+00
Epoch 26/125
8500/8500 [==============================] - 1s 78us/step - loss: 0.0046 - accuracy: 0.0000e+00
Epoch 27/125
8500/8500 [==============================] - 1s 79us/step - loss: 0.0042 - accuracy: 0.0000e+00
Epoch 28/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0039 - accuracy: 0.0000e+00
Epoch 29/125
8500/8500 [==============================] - 1s 78us/step - loss: 0.0037 - accuracy: 0.0000e+00
Epoch 30/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0042 - accuracy: 0.0000e+00
Epoch 31/125
8500/8500 [==============================] - 1s 79us/step - loss: 0.0033 - accuracy: 0.0000e+00
Epoch 32/125
8500/8500 [==============================] - 1s 79us/step - loss: 0.0032 - accuracy: 0.0000e+00
Epoch 33/125
8500/8500 [==============================] - 1s 78us/step - loss: 0.0033 - accuracy: 0.0000e+00
Epoch 34/125
8500/8500 [==============================] - 1s 79us/step - loss: 0.0038 - accuracy: 0.0000e+00
Epoch 35/125
8500/8500 [==============================] - 1s 78us/step - loss: 0.0035 - accuracy: 0.0000e+00
Epoch 36/125
8500/8500 [==============================] - 1s 78us/step - loss: 0.0032 - accuracy: 0.0000e+00
Epoch 37/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0032 - accuracy: 0.0000e+00
Epoch 38/125
8500/8500 [==============================] - 1s 78us/step - loss: 0.0032 - accuracy: 0.0000e+00
Epoch 39/125
8500/8500 [==============================] - 1s 79us/step - loss: 0.0032 - accuracy: 0.0000e+00
Epoch 40/125
8500/8500 [==============================] - 1s 81us/step - loss: 0.0028 - accuracy: 0.0000e+00
Epoch 41/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0032 - accuracy: 0.0000e+00
Epoch 42/125
8500/8500 [==============================] - 1s 77us/step - loss: 0.0029 - accuracy: 0.0000e+00
Epoch 43/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0029 - accuracy: 0.0000e+00
Epoch 44/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0029 - accuracy: 0.0000e+00
Epoch 45/125
8500/8500 [==============================] - 1s 79us/step - loss: 0.0028 - accuracy: 0.0000e+00
Epoch 46/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0031 - accuracy: 0.0000e+00
Epoch 47/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0025 - accuracy: 0.0000e+00
Epoch 48/125
8500/8500 [==============================] - 1s 79us/step - loss: 0.0022 - accuracy: 0.0000e+00
Epoch 49/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0027 - accuracy: 0.0000e+00
Epoch 50/125
8500/8500 [==============================] - 1s 79us/step - loss: 0.0028 - accuracy: 0.0000e+00
Epoch 51/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0024 - accuracy: 0.0000e+00
Epoch 52/125
8500/8500 [==============================] - 1s 78us/step - loss: 0.0024 - accuracy: 0.0000e+00
Epoch 53/125
8500/8500 [==============================] - 1s 79us/step - loss: 0.0023 - accuracy: 0.0000e+00
Epoch 54/125
8500/8500 [==============================] - 1s 78us/step - loss: 0.0026 - accuracy: 0.0000e+00
Epoch 55/125
8500/8500 [==============================] - 1s 81us/step - loss: 0.0023 - accuracy: 0.0000e+00
Epoch 56/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0020 - accuracy: 0.0000e+00
Epoch 57/125
8500/8500 [==============================] - 1s 78us/step - loss: 0.0024 - accuracy: 0.0000e+00
Epoch 58/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0022 - accuracy: 0.0000e+00
Epoch 59/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0021 - accuracy: 0.0000e+00
Epoch 60/125
8500/8500 [==============================] - 1s 78us/step - loss: 0.0022 - accuracy: 0.0000e+00
Epoch 61/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0020 - accuracy: 0.0000e+00
Epoch 62/125
8500/8500 [==============================] - 1s 81us/step - loss: 0.0022 - accuracy: 0.0000e+00
Epoch 63/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0022 - accuracy: 0.0000e+00
Epoch 64/125
8500/8500 [==============================] - 1s 82us/step - loss: 0.0023 - accuracy: 0.0000e+00
Epoch 65/125
8500/8500 [==============================] - 1s 81us/step - loss: 0.0023 - accuracy: 0.0000e+00
Epoch 66/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0018 - accuracy: 0.0000e+00
Epoch 67/125
8500/8500 [==============================] - 1s 81us/step - loss: 0.0021 - accuracy: 0.0000e+00
Epoch 68/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0020 - accuracy: 0.0000e+00
Epoch 69/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0020 - accuracy: 0.0000e+00
Epoch 70/125
8500/8500 [==============================] - 1s 81us/step - loss: 0.0018 - accuracy: 0.0000e+00
Epoch 71/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0019 - accuracy: 0.0000e+00
Epoch 72/125
8500/8500 [==============================] - 1s 79us/step - loss: 0.0018 - accuracy: 0.0000e+00
Epoch 73/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0018 - accuracy: 0.0000e+00
Epoch 74/125
8500/8500 [==============================] - 1s 81us/step - loss: 0.0018 - accuracy: 0.0000e+00
Epoch 75/125
8500/8500 [==============================] - 1s 81us/step - loss: 0.0019 - accuracy: 0.0000e+00
Epoch 76/125
8500/8500 [==============================] - 1s 81us/step - loss: 0.0018 - accuracy: 0.0000e+00
Epoch 77/125
8500/8500 [==============================] - 1s 83us/step - loss: 0.0016 - accuracy: 0.0000e+00
Epoch 78/125
8500/8500 [==============================] - 1s 79us/step - loss: 0.0019 - accuracy: 0.0000e+00
Epoch 79/125
8500/8500 [==============================] - 1s 79us/step - loss: 0.0019 - accuracy: 0.0000e+00
Epoch 80/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0016 - accuracy: 0.0000e+00
Epoch 81/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0018 - accuracy: 0.0000e+00
Epoch 82/125
8500/8500 [==============================] - 1s 81us/step - loss: 0.0017 - accuracy: 0.0000e+00
Epoch 83/125
8500/8500 [==============================] - 1s 81us/step - loss: 0.0017 - accuracy: 0.0000e+00
Epoch 84/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0016 - accuracy: 0.0000e+00
Epoch 85/125
8500/8500 [==============================] - 1s 82us/step - loss: 0.0017 - accuracy: 0.0000e+00
Epoch 86/125
8500/8500 [==============================] - 1s 81us/step - loss: 0.0017 - accuracy: 0.0000e+00
Epoch 87/125
8500/8500 [==============================] - 1s 83us/step - loss: 0.0017 - accuracy: 0.0000e+00
Epoch 88/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0016 - accuracy: 0.0000e+00
Epoch 89/125
8500/8500 [==============================] - 1s 82us/step - loss: 0.0016 - accuracy: 0.0000e+00
Epoch 90/125
8500/8500 [==============================] - 1s 81us/step - loss: 0.0018 - accuracy: 0.0000e+00
Epoch 91/125
8500/8500 [==============================] - 1s 81us/step - loss: 0.0015 - accuracy: 0.0000e+00
Epoch 92/125
8500/8500 [==============================] - 1s 82us/step - loss: 0.0014 - accuracy: 0.0000e+00
Epoch 93/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0016 - accuracy: 0.0000e+00
Epoch 94/125
8500/8500 [==============================] - 1s 81us/step - loss: 0.0016 - accuracy: 0.0000e+00
Epoch 95/125
8500/8500 [==============================] - 1s 83us/step - loss: 0.0014 - accuracy: 0.0000e+00
Epoch 96/125
8500/8500 [==============================] - 1s 81us/step - loss: 0.0014 - accuracy: 0.0000e+00
Epoch 97/125
8500/8500 [==============================] - 1s 81us/step - loss: 0.0016 - accuracy: 0.0000e+00
Epoch 98/125
8500/8500 [==============================] - 1s 81us/step - loss: 0.0015 - accuracy: 0.0000e+00
Epoch 99/125
8500/8500 [==============================] - 1s 81us/step - loss: 0.0014 - accuracy: 0.0000e+00
Epoch 100/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0015 - accuracy: 0.0000e+00
Epoch 101/125
8500/8500 [==============================] - 1s 81us/step - loss: 0.0014 - accuracy: 0.0000e+00
Epoch 102/125
8500/8500 [==============================] - 1s 82us/step - loss: 0.0015 - accuracy: 0.0000e+00
Epoch 103/125
8500/8500 [==============================] - 1s 81us/step - loss: 0.0013 - accuracy: 0.0000e+00
Epoch 104/125
8500/8500 [==============================] - 1s 81us/step - loss: 0.0014 - accuracy: 0.0000e+00
Epoch 105/125
8500/8500 [==============================] - 1s 81us/step - loss: 0.0013 - accuracy: 0.0000e+00
Epoch 106/125
8500/8500 [==============================] - 1s 81us/step - loss: 0.0012 - accuracy: 0.0000e+00
Epoch 107/125
8500/8500 [==============================] - 1s 82us/step - loss: 0.0014 - accuracy: 0.0000e+00
Epoch 108/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0012 - accuracy: 0.0000e+00
Epoch 109/125
8500/8500 [==============================] - 1s 81us/step - loss: 0.0013 - accuracy: 0.0000e+00
Epoch 110/125
8500/8500 [==============================] - 1s 81us/step - loss: 0.0012 - accuracy: 0.0000e+00
Epoch 111/125
8500/8500 [==============================] - 1s 81us/step - loss: 0.0012 - accuracy: 0.0000e+00
Epoch 112/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0011 - accuracy: 0.0000e+00
Epoch 113/125
8500/8500 [==============================] - 1s 81us/step - loss: 0.0014 - accuracy: 0.0000e+00
Epoch 114/125
8500/8500 [==============================] - 1s 81us/step - loss: 0.0011 - accuracy: 0.0000e+00
Epoch 115/125
8500/8500 [==============================] - 1s 79us/step - loss: 0.0012 - accuracy: 0.0000e+00
Epoch 116/125
8500/8500 [==============================] - 1s 82us/step - loss: 0.0013 - accuracy: 0.0000e+00
Epoch 117/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0013 - accuracy: 0.0000e+00
Epoch 118/125
8500/8500 [==============================] - 1s 82us/step - loss: 0.0011 - accuracy: 0.0000e+00
Epoch 119/125
8500/8500 [==============================] - 1s 79us/step - loss: 0.0012 - accuracy: 0.0000e+00
Epoch 120/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0012 - accuracy: 0.0000e+00
Epoch 121/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0011 - accuracy: 0.0000e+00
Epoch 122/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0011 - accuracy: 0.0000e+00
Epoch 123/125
8500/8500 [==============================] - 1s 82us/step - loss: 0.0012 - accuracy: 0.0000e+00
Epoch 124/125
8500/8500 [==============================] - 1s 81us/step - loss: 0.0011 - accuracy: 0.0000e+00
Epoch 125/125
8500/8500 [==============================] - 1s 80us/step - loss: 0.0018 - accuracy: 0.0000e+00
array([[ 0.6434634 , -0.09752402,  0.8342059 ,  1.6331654 ,  0.82901144,
        -0.00917255]], dtype=float32)

Hope this answers your question. Happy Learning.


来源: stackexchange

问:
Vuejs : Open a collapse menu when a particular tab is active and close it when it is not active
I have two methods forceOpenSettings() and forceCloseSettings(). I need these for opening and closing of a collapsable section. the methods are working fine as I tested it separately. But I need to do this based on a condition, I have b-tab with 4 tabs. Out of which when i click on a tab the collpase should open, and whenever the tab becomes inactive , the collapse must close

```<code><b-tabs content-class="mt-3">
  <b-tab title="First" active><p>I'm the first tab</p></b-tab>
  <b-tab title="Second"><p>I'm the second tab</p></b-tab>
</b-tabs>
</code>```

The same thing I'am achieving in a b-collapse using @show and @hide and it working fine,

```<code><b-collapse role="tabpanel" @show="forceOpenSettings" @hide="forceCloseSettings">......</b-collapse>
</code>```

答:
You don't need multiple functions to do this.

You can have one function that removes the active attribute from all the tabs and then just makes the one you clicked on active. Just give all the  components a class of tab and then you can use this one function for all the tabs that has a class of tab. Then you can run the method with the @click="doTabs()" directive.

I've updated the answer to apply to a Vue instance.

Run the snippet to see it in action.

new Vue({
  el: '#app',
  methods: {
    doTabs() {
      const tabs = document.querySelectorAll('.tab')
      tabs.forEach(i => i.removeAttribute('active'))
      event.currentTarget.setAttribute('active', true)
    }
  }
})```
<pre class="snippet-code-css lang-css prettyprint-override"><code>.tab {padding: 10px; border: 1px solid #ccc; cursor: pointer; display: flex; display: block}
[active] {background-color: #eee}
.content {padding-left: 20px; font-size: 12px; visibility: hidden; opacity: 0; transition: all 0.2s ease; margin-top: -40px}
[active] .content {visibility: visible; opacity: 1;margin-top: 0}</code>```

I'm the first tab

Here is all the
accordion content

I'm the second tab

Here is all the
accordion content

```

ContentLicense: CC BY-SA 4.0

Body:
I have two methods forceOpenSettings() and forceCloseSettings(). I need these for opening and closing of a collapsable section. the methods are working fine as I tested it separately. But I need to do this based on a condition, I have b-tab with 4 tabs. Out of which when i click on a tab the collpase should open, and whenever the tab becomes inactive , the collapse must close

I'm the first tab

I'm the second tab

The same thing I'am achieving in a b-collapse using @show and @hide and it working fine,

......

Body:
You don't need multiple functions to do this.

You can have one function that removes the active attribute from all the tabs and then just makes the one you clicked on active. Just give all the <b-tab> components a class of tab and then you can use this one function for all the tabs that has a class of tab. Then you can run the method with the @click="doTabs()" directive.

I've updated the answer to apply to a Vue instance.

Run the snippet to see it in action.

new Vue({
  el: '#app',
  methods: {
    doTabs() {
      const tabs = document.querySelectorAll('.tab')
      tabs.forEach(i => i.removeAttribute('active'))
      event.currentTarget.setAttribute('active', true)
    }
  }
})

.tab {padding: 10px; border: 1px solid #ccc; cursor: pointer; display: flex; display: block}
[active] {background-color: #eee}
.content {padding-left: 20px; font-size: 12px; visibility: hidden; opacity: 0; transition: all 0.2s ease; margin-top: -40px}
[active] .content {visibility: visible; opacity: 1;margin-top: 0}

<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
  <div title="First" class="tab" @click="doTabs()" active>
    <p>I'm the first tab</p>
    <div class="content">
      <p>Here is all the<br>accordion content</p>
    </div>
  </div>
  <div title="Second" class="tab" @click="doTabs()">
    <p>I'm the second tab</p>
    <div class="content">
      <p>Here is all the<br>accordion content</p>
    </div>
  </div>
</div>


问:
Is there a way to "install" nuget package like the way Visual Studio does, but on a deployment server
Background:

I am reasonably new to packaging and publishing nuget. Long story short, I have a C# project (Let's call it MYAPI project) which depends on a bunch of other nuget packages. Some consumers of MYAPI, expect to reference it as a nuget package and deal with their products' deployment on their own, while some other consumers expect MYAPI dlls to be installed in specific folders from where they will pick it up at runtime.

So I have packaged MYAPI as a nuget and published it onto an internal nuget server.

Issue:

How do I install my nuget package onto the servers in a way that it will have all the required dependencies. I want it to look like how the bin\debug folder looks like i.e. based on the target framework, copy the relevant files from all the dependency nuget packages including the main nuget package (MYAPI in this case)

I know I can achieve this by packaging MYAPI as a zip file or an msi in addition to the nuget package. But I don't want multiple types of packages for MYAPI, and would prefer to stick to just nuget package. I also understand I can reference all the dependency in my <files> section of nuspec, but I think it is a poor man's way of doing it.

Is there a way to do it just like Visual Studio does it i.e. download main nuget package and all its dependencies, extract them and then copy the relevant (framework version based) files from all the extracted nuget packages into the bin\debug folder. If that is not available out of the box, can someone point me to the "intelligence" VS uses to copy the files into bin\debug folder, so i can replicate it in an install script.

EDIT:

This is a regular .NET Framework project, and I am talking of installing on say a production server where development tools like MSBuild, VS won't be available. I can still have the nuget.exe command as it is a single executable.

答:
Is there a way to “install” nuget package like the way Visual Studio
  does, but on a deployment server

I think you have some misunderstanding about this issue and I am afraid what you want can not be implemented by nuget.

Actually, it is MSBuild job to copy related nuget package's content into bin\Debug.

In fact, MSBuild(MSBuild.exe) is an executable with a vs development environment.

Nuget is just responsible for downloading the package to your local and then associating it with your project. The actual content copy operation is purely a job of MSBuild.

In VS IDE, MSBuild is responsible for this operation. When you click build (actually it calls MSBuild.exe), the dependency DLLs of nuget package will be copied to your output folder.

To prove it, you can create a new empty project and then install this nuget package, then check whether the files are under bin\Debug. After that, please execute Build to check whether the files exists.

Solution

Since VS2017, MSBuild can be installed separately without VS IDE.

You can install Build Tool for Visual Studio 2019.

Under All Downloads--> Tools for Visual Studio 2019--> Build Tool for Visual Studio 2019

Since it can be installed separately from VS and is lightweight, many developers now use this to build projects on production servers.

When you use nuget.exe install such nuget package in your project,then use Build tool to execute such command msbuild xxx\xxx\xxx.csproj -t:build to build project. After that, you will see them in bin\Debug folder.

Update 1

Actually, nuget does the job which decides which corresponding dependencies to copy. But nuget passes these info into MSBuild. Nuget just determines the corresponding information which is like making a plan ,the specific action is performed by MSBuild, including reference, restore, copy, and so on. So you should run MSBuild to get what you want so far.

In addition, if you still get what you want and skip MSBuild to get the file directly, you could suggest a feature to the Team.(click Suggest a Feature).


问:
How to translate float3 to SIMD3<Float> (Xcode 11 Swift 5 giving depreciation warning with float3 and float4)
I am trying to get my code to be warning free. As I've just updated my Xcode and am know getting warning signs. I also have my attempted at fixing this below as well.

This is the code that is giving me the warnings:

Code:

```<code>extension float4x4 {
var translation: float3 {
    return float3(columns.3.x, columns.3.y, columns.3.z)
}

init(translation vector: float3) {
    self.init(float4(1, 0, 0, 0),
              float4(0, 1, 0, 0),
              float4(0, 0, 1, 0),
              float4(vector.x, vector.y, vector.z, 1))
 }
}

extension float4 {
  var xyz: float3 {
    return float3(x, y, z)
}
</code>```

This is my attempted to translate this below:

Code:

```<code>extension SIMD4 {
var translation: SIMD3<Float> {
    return SIMD3(columns.3.x, columns.3.y, columns.3.z)
}

  init(translation vector: SIMD3<Float>) {
    self.init(SIMD4<Float>(1, 0, 0, 0),
              SIMD4<Float>(0, 1, 0, 0),
              SIMD4<Float>(0, 0, 1, 0),
              SIMD4(vector.x, vector.y, vector.z))
  }
}

  extension SIMD4 {
    var xyz: SIMD3<Float> {
      return SIMD3<Float>(x, y, z) as! SIMD3<Float>
    }
  }
</code>```

答:
Basically, I have tried just to replace:

```<code>float3
</code>```

with:

```<code>SIMD3<Float>
</code>```

And the warning has been disappeared.

Body:
I am trying to get my code to be warning free. As I've just updated my Xcode and am know getting warning signs. I also have my attempted at fixing this below as well.

This is the code that is giving me the warnings:

Code:

extension float4x4 {
var translation: float3 {
    return float3(columns.3.x, columns.3.y, columns.3.z)
}

init(translation vector: float3) {
    self.init(float4(1, 0, 0, 0),
              float4(0, 1, 0, 0),
              float4(0, 0, 1, 0),
              float4(vector.x, vector.y, vector.z, 1))
 }
}

extension float4 {
  var xyz: float3 {
    return float3(x, y, z)
}

This is my attempted to translate this below:

Code:

extension SIMD4 {
var translation: SIMD3<Float> {
    return SIMD3(columns.3.x, columns.3.y, columns.3.z)
}

  init(translation vector: SIMD3<Float>) {
    self.init(SIMD4<Float>(1, 0, 0, 0),
              SIMD4<Float>(0, 1, 0, 0),
              SIMD4<Float>(0, 0, 1, 0),
              SIMD4(vector.x, vector.y, vector.z))
  }
}

  extension SIMD4 {
    var xyz: SIMD3<Float> {
      return SIMD3<Float>(x, y, z) as! SIMD3<Float>
    }
  }

Body:
Basically, I have tried just to replace:

float3

with:

SIMD3<Float>

And the warning has been disappeared.


问:
How to create sh script which will run SQL file on CentOS without sqlplus lib
I'd need to create a sh script, which will connect to Oracle DB and then execute a SQL file.
The problem is that sqlplus is not installed on that Cent-OS machine and most probably it won't be installed either.
Is there a way how to do this?</p>

答:
If some java version is installed on the server, you can create a simple class that will connect to oracle DB via JDBC, load the sql script and execute it.

Create and compile java class

Upload class file, sql script + oracle_driver (jar file) (https://www.oracle.com/database/technologies/jdbcdriver-ucp-downloads.html)

Execute the java program


问:
PHP braces { } replace <?php ?>?
I've seen in someones source code they load template.tpl and inside is ...value="{$phcode}"...
does {$phcode} replace <?php $phcode ?>

I don't find any reference in php manual.

答:
A .tpl file isn't a PHP file and isn't parsed by the PHP engine. I'd guess you're looking at a Smarty template.

For the record, <?php $phcode ?> does nothing. You are probably thinking of either <?php echo $phcode ?> or <?= $phcode ?>, either of which is pretty close to exactly what Smarty does with that piece of code, yes.

ContentLicense: CC BY-SA 3.0

Title: PHP braces { } replace <?php ?>?


问:
Edge Detection using PyOpenCL
I was having an issue while writing a python script to detect the edge using PyOpenCl. I am new to OpenCL and while trying I encountered a problem which after many tweaks, I am unable to solve. below is the python code:

edge.py:

import numpy as np
import pyopencl as cl
from PIL import Image
from time import time

def getKernel(krnl):
    kernel = open(krnl).read()
    return kernel

def findedges(p,d,image):

    data = np.asarray(image).astype(np.uint8)

    platform = cl.get_platforms()[p]
    device = platform.get_devices()[d]
    cntx = cl.Context([device])
    queue = cl.CommandQueue(cntx)

    mf = cl.mem_flags
    im = cl.Buffer(cntx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=data)
    out = cl.Buffer(cntx,mf.WRITE_ONLY,data.nbytes)

    prgm = cl.Program(cntx,getKernel('edge.c')%(data.shape[1],data.shape[0])).build()

    prgm.detectedge(queue,data.shape,None,im,out)

    result = np.empty_like(data)

    cl.enqueue_copy(queue,result,out)
    result = result.astype(np.uint8)
    print(result)

    img = Image.fromarray(result)
    #img.show()
    img.save('coinsedge.png')

if __name__ == '__main__':

    image = Image.open('coins.png')
    #(1,0) is my platform 1, device 0 = "AMD gpu"
    #(0,0) for intel processor
    findedges(1,0,image)

```

<p>and my kernel file : edge.c</p>

<pre class="lang-c prettyprint-override"><code>
__kernel void detectedge(__global int *im,__global int *out){
      int j = get_global_id(1);
      int i = get_global_id(0);
      int width = %d;
      int rown = %d;
      int value;

              value = -im[(i)*width + j] -  0* im[(i)*width + j+1] + im[(i)*width + j+2]
                      -2*im[(i+1)*width + j] +  0*im[(i+1)*width + j+1] + 2*im[(i+1)*width + j+2]
                      -im[(i+2)*width + j] -  0*im[(i+2)*width + j+1] + im[(i+2)*width + j+2];

              value = (value < 0   ? 0   : value);
              value = (value > 255 ? 255 : value);
              out[i*width + j] = value;

  }

</code>```

Now there are no run-time warnings/errors but the output is what I was not expecting. Here is the input and its output:
This is my input image:

And this is my output:

答:
I think the issue is with the size of the input and output buffers you are passing to the kernel. The image is one uint8 per pixel and you sized your buffer according to data.nbytes. The kernel is reading and writing 4 byte pixels.

I only had to change this line and it works:

```<code>data = np.asarray(image).astype(np.int32)
</code>```

Title: Edge Detection using PyOpenCL

Body:
I was having an issue while writing a python script to detect the edge using PyOpenCl. I am new to OpenCL and while trying I encountered a problem which after many tweaks, I am unable to solve. below is the python code:

edge.py:

import numpy as np
import pyopencl as cl
from PIL import Image
from time import time

def getKernel(krnl):
    kernel = open(krnl).read()
    return kernel

def findedges(p,d,image):

    data = np.asarray(image).astype(np.uint8)

    platform = cl.get_platforms()[p]
    device = platform.get_devices()[d]
    cntx = cl.Context([device])
    queue = cl.CommandQueue(cntx)

    mf = cl.mem_flags
    im = cl.Buffer(cntx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=data)
    out = cl.Buffer(cntx,mf.WRITE_ONLY,data.nbytes)

    prgm = cl.Program(cntx,getKernel('edge.c')%(data.shape[1],data.shape[0])).build()

    prgm.detectedge(queue,data.shape,None,im,out)

    result = np.empty_like(data)

    cl.enqueue_copy(queue,result,out)
    result = result.astype(np.uint8)
    print(result)

    img = Image.fromarray(result)
    #img.show()
    img.save('coinsedge.png')

if __name__ == '__main__':

    image = Image.open('coins.png')
    #(1,0) is my platform 1, device 0 = "AMD gpu"
    #(0,0) for intel processor
    findedges(1,0,image)

and my kernel file : edge.c

__kernel void detectedge(__global int *im,__global int *out){
      int j = get_global_id(1);
      int i = get_global_id(0);
      int width = %d;
      int rown = %d;
      int value;

              value = -im[(i)*width + j] -  0* im[(i)*width + j+1] + im[(i)*width + j+2]
                      -2*im[(i+1)*width + j] +  0*im[(i+1)*width + j+1] + 2*im[(i+1)*width + j+2]
                      -im[(i+2)*width + j] -  0*im[(i+2)*width + j+1] + im[(i+2)*width + j+2];

              value = (value < 0   ? 0   : value);
              value = (value > 255 ? 255 : value);
              out[i*width + j] = value;

  }

Now there are no run-time warnings/errors but the output is what I was not expecting. Here is the input and its output:
This is my input image:

And this is my output:

Body:
I think the issue is with the size of the input and output buffers you are passing to the kernel. The image is one uint8 per pixel and you sized your buffer according to data.nbytes. The kernel is reading and writing 4 byte pixels.

I only had to change this line and it works:

data = np.asarray(image).astype(np.int32)


问:
npm error ELIFECYCLE on ctrl+c
I've started a new socket.io project with heroku. The server runs fine locally on windows. I start it with npm start but when I shut it down with ctrl + c I get this error in the console:

```<code>npm ERR! Windows_NT 6.3.9600
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\
node_modules\\npm\\bin\\npm-cli.js" "start"
npm ERR! node v6.11.4
npm ERR! npm  v3.10.10
npm ERR! code ELIFECYCLE
npm ERR! test1@1.0.0 start: `node index.js`
npm ERR! Exit status 3221225786
npm ERR!
npm ERR! Failed at the test1@1.0.0 start script 'node index.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the test1 package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node index.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs test1
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls test1
npm ERR! There is likely additional logging output above.
</code>```

I have searched for a solution but the very little I have been able to find has given no solution. I've tried updating npm and node, running npm install again, clearing the npm cache and probably some other actions I can't recall.

Here is my index.js

```<code>const express = require('express');
const socketIO = require('socket.io');
const path = require('path');

const PORT = process.env.PORT || 3000;

const server = express()
  .use(express.static(__dirname + '/client'))
  .listen(PORT, () => console.log(`Listening on ${ PORT }`));

const io = socketIO(server);

const pg = require('pg');
var connectionString = "postgres://jdirjtnfueksiw:823e80fbae9599f0d6797f82342d83bccf1caea764b8a1659356f3ee89r69f94@ec1-78-222-138-451.compute-1.amazonaws.com:5432/jf84jd75jgu26d5?ssl=true";

pg.connect(connectionString, function(err, client, done) {
    if (err) {
        throw err;
    }
    else {
        console.log('Database connection test successful');
    }
});

io.on('connection', function (socket) {
        socket.emit('connected');

        console.log('New connection from ' + socket.request.connection.remoteAddress);

        socket.on('disconnect', function () {
            console.log('Player left');
        });
    });
</code>```

my package.json

```<code>{
  "name": "test1",
  "version": "1.0.0",
  "engines": {
    "node": "6.11.4"
  },
  "main": "index.js",
  "scripts": {
    "start": "node index.js"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "pg": "6.x",
    "express": "4.13.4",
    "socket.io": "1.4.6"
  },
  "devDependencies": {},
  "description": ""
}
</code>```

Thank you for any help.

答:
In the index.js can you try putting the following code:

```<code>process.on('SIGINT', () => {
    process.exit();
});
</code>```

I think the issue is that Ctrl+C kills the application but there is still some process running in the background. This will ensure that it is terminated.

Hope this helps!

Title: npm error ELIFECYCLE on ctrl+c

Body:
I've started a new socket.io project with heroku. The server runs fine locally on windows. I start it with npm start but when I shut it down with ctrl + c I get this error in the console:

npm ERR! Windows_NT 6.3.9600
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\
node_modules\\npm\\bin\\npm-cli.js" "start"
npm ERR! node v6.11.4
npm ERR! npm  v3.10.10
npm ERR! code ELIFECYCLE
npm ERR! test1@1.0.0 start: `node index.js`
npm ERR! Exit status 3221225786
npm ERR!
npm ERR! Failed at the test1@1.0.0 start script 'node index.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the test1 package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node index.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs test1
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls test1
npm ERR! There is likely additional logging output above.

I have searched for a solution but the very little I have been able to find has given no solution. I've tried updating npm and node, running npm install again, clearing the npm cache and probably some other actions I can't recall.

Here is my index.js

const express = require('express');
const socketIO = require('socket.io');
const path = require('path');

const PORT = process.env.PORT || 3000;

const server = express()
  .use(express.static(__dirname + '/client'))
  .listen(PORT, () => console.log(`Listening on ${ PORT }`));

const io = socketIO(server);

const pg = require('pg');
var connectionString = "postgres://jdirjtnfueksiw:823e80fbae9599f0d6797f82342d83bccf1caea764b8a1659356f3ee89r69f94@ec1-78-222-138-451.compute-1.amazonaws.com:5432/jf84jd75jgu26d5?ssl=true";

pg.connect(connectionString, function(err, client, done) {
    if (err) {
        throw err;
    }
    else {
        console.log('Database connection test successful');
    }
});

io.on('connection', function (socket) {
        socket.emit('connected');

        console.log('New connection from ' + socket.request.connection.remoteAddress);

        socket.on('disconnect', function () {
            console.log('Player left');
        });
    });

my package.json

{
  "name": "test1",
  "version": "1.0.0",
  "engines": {
    "node": "6.11.4"
  },
  "main": "index.js",
  "scripts": {
    "start": "node index.js"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "pg": "6.x",
    "express": "4.13.4",
    "socket.io": "1.4.6"
  },
  "devDependencies": {},
  "description": ""
}

Thank you for any help.

Body:
In the index.js can you try putting the following code:

process.on('SIGINT', () => {
    process.exit();
});

I think the issue is that Ctrl+C kills the application but there is still some process running in the background. This will ensure that it is terminated.

Hope this helps!


问:
E/AndroidRuntime: FATAL EXCEPTION: main crash when app start
```<code>D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.dslr.camera.pixol, PID: 8021
    java.lang.RuntimeException: Unable to get provider com.google.android.gms.ads.MobileAdsInitProvider: java.lang.IllegalStateException:
</code>```

```<code>******************************************************************************
* The Google Mobile Ads SDK was initialized incorrectly. AdMob publishers    *
* should follow the instructions here:                                       *
* https://googlemobileadssdk.page.link/admob-android-update-manifest         *
* to add a valid App ID inside the AndroidManifest.                          *
* Google Ad Manager publishers should follow instructions here:              *
* https://googlemobileadssdk.page.link/ad-manager-android-update-manifest.   *
******************************************************************************

    at android.app.ActivityThread.installProvider(ActivityThread.java:6988)
    at android.app.ActivityThread.installContentProviders(ActivityThread.java:6528)
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6445)
    at android.app.ActivityThread.access$1300(ActivityThread.java:219)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1859)
    at android.os.Handler.dispatchMessage(Handler.java:107)
    at android.os.Looper.loop(Looper.java:214)
    at android.app.ActivityThread.main(ActivityThread.java:7356)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
 Caused by: java.lang.IllegalStateException:

******************************************************************************
* The Google Mobile Ads SDK was initialized incorrectly. AdMob publishers    *
* should follow the instructions here:                                       *
* https://googlemobileadssdk.page.link/admob-android-update-manifest         *
* to add a valid App ID inside the AndroidManifest.                          *
* Google Ad Manager publishers should follow instructions here:              *
* https://googlemobileadssdk.page.link/ad-manager-android-update-manifest.   *
******************************************************************************

    at com.google.android.gms.internal.ads.zzxw.attachInfo(com.google.android.gms:play-services-ads-lite@@18.3.0:27)
    at com.google.android.gms.ads.MobileAdsInitProvider.attachInfo(com.google.android.gms:play-services-ads-lite@@18.3.0:3)
    at android.app.ActivityThread.installProvider(ActivityThread.java:6983)
        ... 10 more
</code>```

I/Process: Sending signal. PID: 8021 SIG: 9
Process 8021 terminated.

```<code>compileSdkVersion 29
flavorDimensions "default"
buildToolsVersion "29.0.2"
defaultConfig {
    minSdkVersion 21
    targetSdkVersion 29
    multiDexEnabled true
</code>```

i can't understand where is the problem, compile is ok and when i try to run the app i get crash and app exit. what i can do, please help me
Thanks

答:
you need to initialize the Admob in your application level or in your activity so you need to add this line after  onCreate.

```<code>String AdmobID ="ca-app-pub-3940256099942544~3347511713";
MobileAds.initialize(this, AdmobID);
</code>```

and don't forget to replace the AdmobId with yours.

Body:
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.dslr.camera.pixol, PID: 8021
    java.lang.RuntimeException: Unable to get provider com.google.android.gms.ads.MobileAdsInitProvider: java.lang.IllegalStateException:

******************************************************************************
* The Google Mobile Ads SDK was initialized incorrectly. AdMob publishers    *
* should follow the instructions here:                                       *
* https://googlemobileadssdk.page.link/admob-android-update-manifest         *
* to add a valid App ID inside the AndroidManifest.                          *
* Google Ad Manager publishers should follow instructions here:              *
* https://googlemobileadssdk.page.link/ad-manager-android-update-manifest.   *
******************************************************************************

    at android.app.ActivityThread.installProvider(ActivityThread.java:6988)
    at android.app.ActivityThread.installContentProviders(ActivityThread.java:6528)
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6445)
    at android.app.ActivityThread.access$1300(ActivityThread.java:219)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1859)
    at android.os.Handler.dispatchMessage(Handler.java:107)
    at android.os.Looper.loop(Looper.java:214)
    at android.app.ActivityThread.main(ActivityThread.java:7356)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
 Caused by: java.lang.IllegalStateException:

******************************************************************************
* The Google Mobile Ads SDK was initialized incorrectly. AdMob publishers    *
* should follow the instructions here:                                       *
* https://googlemobileadssdk.page.link/admob-android-update-manifest         *
* to add a valid App ID inside the AndroidManifest.                          *
* Google Ad Manager publishers should follow instructions here:              *
* https://googlemobileadssdk.page.link/ad-manager-android-update-manifest.   *
******************************************************************************

    at com.google.android.gms.internal.ads.zzxw.attachInfo(com.google.android.gms:play-services-ads-lite@@18.3.0:27)
    at com.google.android.gms.ads.MobileAdsInitProvider.attachInfo(com.google.android.gms:play-services-ads-lite@@18.3.0:3)
    at android.app.ActivityThread.installProvider(ActivityThread.java:6983)
        ... 10 more

I/Process: Sending signal. PID: 8021 SIG: 9
Process 8021 terminated.

compileSdkVersion 29
flavorDimensions "default"
buildToolsVersion "29.0.2"
defaultConfig {
    minSdkVersion 21
    targetSdkVersion 29
    multiDexEnabled true

i can't understand where is the problem, compile is ok and when i try to run the app i get crash and app exit. what i can do, please help me
Thanks

Body:
you need to initialize the Admob in your application level or in your activity so you need to add this line after  onCreate.

String AdmobID ="ca-app-pub-3940256099942544~3347511713";
MobileAds.initialize(this, AdmobID);

and don't forget to replace the AdmobId with yours.


问:
The amount of Xcode tasks increase after every build
Since I'm using Xcode 10.0, the amount of tasks which Xcode is building increases every time when I build the project. To reset the amount of tasks I have to clear the project. Can anyone else retrace this issue? The main problem is, that the build time increases with the amount of tasks.

EDIT

Same behavior in Xcode Version 10.1 (10B61)

答: Rishi Indolia's answer in conjunction with disabling the automatic reloading of views in the storyboard is what did it for me.


问:
Select all values from last date that is shared between rows grouped by a value
I have a Postgresql table with a list of values for countries over time, and their continents. Values can be NULL. I’d like to get the sum for each continent over time, up to the latest date each continent has data for.

This is my table (view on DB Fiddle):

```<code>| continent | country | date       | value | id  |
| --------- | ------- | ---------- | ----- | --- |
| Europe    | Germany | 2020-05-25 | 10    | 1   |
| Europe    | Germany | 2020-05-26 | 11    | 2   |
| Europe    | Germany | 2020-05-27 | 12    | 3   |
| Europe    | Germany | 2020-05-28 | 13    | 4   |
| Europe    | Italy   | 2020-05-25 | 20    | 5   |
| Europe    | Italy   | 2020-05-26 | 21    | 6   |
| Europe    | Italy   | 2020-05-27 | 22    | 7   |
| Europe    | Italy   | 2020-05-28 | 23    | 8   |
| Europe    | France  | 2020-05-25 | 30    | 9   |
| Europe    | France  | 2020-05-26 | 31    | 10  |
| Europe    | France  | 2020-05-27 | 32    | 11  |
| Europe    | France  | 2020-05-28 | NULL  | 12  |
| Africa    | Congo   | 2020-05-25 | 40    | 13  |
| Africa    | Congo   | 2020-05-26 | 41    | 14  |
| Africa    | Congo   | 2020-05-27 | NULL  | 15  |
</code>```

And this is what I’d like to get back. Note that the Europe includes data up to the 27th, because France has no data for the 28th, and Africa up to the 26th, because that’s the last date its countries have data for.

```<code>| continent | date       | value |
| --------- | ---------- | ----- |
| Europe    | 2020-05-27 | 66    |
| Africa    | 2020-05-26 | 41    |
| Europe    | 2020-05-26 | 63    |
| Africa    | 2020-05-25 | 40    |
| Europe    | 2020-05-25 | 60    |
</code>```

I managed to almost get there by including the number of countries per continent that have data on each date.

SELECT
    countries.continent,
    countries.date,
    SUM(countries.value) AS value,
    COUNT(countries.country) AS countries_count
FROM
    countries
WHERE
    countries.value IS NOT NULL
GROUP BY
    countries.continent,
    countries.date
ORDER BY
    countries.date DESC,
    countries.continent;
```

```| continent | date       | value | countries_count |
| --------- | ---------- | ----- | --------------- |
| Europe    | 2020-05-28 | 36    | 2               |
| Europe    | 2020-05-27 | 66    | 3               |
| Africa    | 2020-05-26 | 41    | 1               |
| Europe    | 2020-05-26 | 63    | 3               |
| Africa    | 2020-05-25 | 40    | 1               |
| Europe    | 2020-05-25 | 60    | 3               |
```

<p>I also managed to get the number of countries per continent.</p>

<pre class="lang-sql prettyprint-override"><code>SELECT
    countries.continent,
    COUNT(DISTINCT countries.country) as number_of_countries
FROM
    countries
GROUP BY
    countries.continent;
</code>```

```<code>| continent | number_of_countries |
| --------- | ------------------- |
| Africa    | 1                   |
| Europe    | 3                   |
</code>```

I’m stuck on how to combine the two queries to filter out rows that haven’t got the full number of countries for the continent (e. g. select rows where countries_count is 3 for Europe and 1 for Africa.

This is the end result I’d like to get back:

```<code>| continent | date       | value |
| --------- | ---------- | ----- |
| Europe    | 2020-05-27 | 66    |
| Africa    | 2020-05-26 | 41    |
| Europe    | 2020-05-26 | 63    |
| Africa    | 2020-05-25 | 40    |
| Europe    | 2020-05-25 | 60    |
</code>```

Or maybe there’s a completely different way to go about this?

View on DB Fiddle

答:
You can use NOT IN within your WHERE Clause :

```<code>SELECT
    c.continent,
    c.date,
    SUM(c.value) AS value,
    COUNT(DISTINCT c.country) AS countries_count
FROM countries c
WHERE date NOT IN
    ( SELECT date
        FROM countries
       WHERE value IS NULL )
GROUP BY c.continent, c.date
ORDER BY c.date DESC, c.continent;
</code>```

Body:
I have a Postgresql table with a list of values for countries over time, and their continents. Values can be NULL. I’d like to get the sum for each continent over time, up to the latest date each continent has data for.

This is my table (view on DB Fiddle):

| continent | country | date       | value | id  |
| --------- | ------- | ---------- | ----- | --- |
| Europe    | Germany | 2020-05-25 | 10    | 1   |
| Europe    | Germany | 2020-05-26 | 11    | 2   |
| Europe    | Germany | 2020-05-27 | 12    | 3   |
| Europe    | Germany | 2020-05-28 | 13    | 4   |
| Europe    | Italy   | 2020-05-25 | 20    | 5   |
| Europe    | Italy   | 2020-05-26 | 21    | 6   |
| Europe    | Italy   | 2020-05-27 | 22    | 7   |
| Europe    | Italy   | 2020-05-28 | 23    | 8   |
| Europe    | France  | 2020-05-25 | 30    | 9   |
| Europe    | France  | 2020-05-26 | 31    | 10  |
| Europe    | France  | 2020-05-27 | 32    | 11  |
| Europe    | France  | 2020-05-28 | NULL  | 12  |
| Africa    | Congo   | 2020-05-25 | 40    | 13  |
| Africa    | Congo   | 2020-05-26 | 41    | 14  |
| Africa    | Congo   | 2020-05-27 | NULL  | 15  |

And this is what I’d like to get back. Note that the Europe includes data up to the 27th, because France has no data for the 28th, and Africa up to the 26th, because that’s the last date its countries have data for.

| continent | date       | value |
| --------- | ---------- | ----- |
| Europe    | 2020-05-27 | 66    |
| Africa    | 2020-05-26 | 41    |
| Europe    | 2020-05-26 | 63    |
| Africa    | 2020-05-25 | 40    |
| Europe    | 2020-05-25 | 60    |

I managed to almost get there by including the number of countries per continent that have data on each date.

SELECT
    countries.continent,
    countries.date,
    SUM(countries.value) AS value,
    COUNT(countries.country) AS countries_count
FROM
    countries
WHERE
    countries.value IS NOT NULL
GROUP BY
    countries.continent,
    countries.date
ORDER BY
    countries.date DESC,
    countries.continent;

| continent | date       | value | countries_count |
| --------- | ---------- | ----- | --------------- |
| Europe    | 2020-05-28 | 36    | 2               |
| Europe    | 2020-05-27 | 66    | 3               |
| Africa    | 2020-05-26 | 41    | 1               |
| Europe    | 2020-05-26 | 63    | 3               |
| Africa    | 2020-05-25 | 40    | 1               |
| Europe    | 2020-05-25 | 60    | 3               |

I also managed to get the number of countries per continent.

SELECT
    countries.continent,
    COUNT(DISTINCT countries.country) as number_of_countries
FROM
    countries
GROUP BY
    countries.continent;

| continent | number_of_countries |
| --------- | ------------------- |
| Africa    | 1                   |
| Europe    | 3                   |

I’m stuck on how to combine the two queries to filter out rows that haven’t got the full number of countries for the continent (e. g. select rows where countries_count is 3 for Europe and 1 for Africa.

This is the end result I’d like to get back:

| continent | date       | value |
| --------- | ---------- | ----- |
| Europe    | 2020-05-27 | 66    |
| Africa    | 2020-05-26 | 41    |
| Europe    | 2020-05-26 | 63    |
| Africa    | 2020-05-25 | 40    |
| Europe    | 2020-05-25 | 60    |

Or maybe there’s a completely different way to go about this?

View on DB Fiddle

Body:
You can use NOT IN within your WHERE Clause :

SELECT
    c.continent,
    c.date,
    SUM(c.value) AS value,
    COUNT(DISTINCT c.country) AS countries_count
FROM countries c
WHERE date NOT IN
    ( SELECT date
        FROM countries
       WHERE value IS NULL )
GROUP BY c.continent, c.date
ORDER BY c.date DESC, c.continent;


问:
Using Relative Paths with Matlab Coder
I am trying to generate C code for a Matlab function. It uses mongoose web server for communication. If I place the .h/.c files in the same folder as the .m file I can compile everything fine using:

```<code>coder.cinclude('mongoose.h');
coder.updateBuildInfo('addSourceFiles','mongoose.c');
coder.cinclude('rest.h');
coder.updateBuildInfo('addSourceFiles','rest.c');
</code>```

I would like to keep my .c files and .m files separate, so moving C files to a folder named native/ causes compilation to fail as expected. Thus, I tell Matlab where to find them using:

```<code>customDir = '/full/path/to/native';
coder.updateBuildInfo('addIncludePaths', customDir);
coder.updateBuildInfo('addSourcePaths', customDir);
</code>```

Which works. However it works only with absolute paths and not with relative paths. This is a problem since each contributor to this projects keeps the source folder in a different location. What is the proper way to tell Matlab native file locations using relative paths to Matlab working directory?

答:
You can also use the $(START_DIR) marcro which gives you the path to the working folder of your project.

Just just neet to specify where your source files are relative to this path then

Title: Using Relative Paths with Matlab Coder

Body:
I am trying to generate C code for a Matlab function. It uses mongoose web server for communication. If I place the .h/.c files in the same folder as the .m file I can compile everything fine using:

coder.cinclude('mongoose.h');
coder.updateBuildInfo('addSourceFiles','mongoose.c');
coder.cinclude('rest.h');
coder.updateBuildInfo('addSourceFiles','rest.c');

I would like to keep my .c files and .m files separate, so moving C files to a folder named native/ causes compilation to fail as expected. Thus, I tell Matlab where to find them using:

customDir = '/full/path/to/native';
coder.updateBuildInfo('addIncludePaths', customDir);
coder.updateBuildInfo('addSourcePaths', customDir);

Which works. However it works only with absolute paths and not with relative paths. This is a problem since each contributor to this projects keeps the source folder in a different location. What is the proper way to tell Matlab native file locations using relative paths to Matlab working directory?


问:
impossible to html parsing facebook public profile with php
i grabbed an html from this url : http://facebook.com/zuck
there is no problem to echo it to the client browser but i found it impossible to parse it with php.

i am trying to parse the text inside div tags for example :

```<code>preg_match_all("/<div class=\"mediaPageName\">(.*)<\/div>/",$html,$matches);
print_r($matches);
</code>```

returns empty array
i also tried with DOMDocument and with PHP Simple HTML DOM Parser both of them return empty elements and can't grab the text of the html.

how is it even possible?
there is a solution to that?

答: You're probably going to be much better off in the long run if you just use the Graph API. The profile picture and some basic account information is public and requires no authentication or authorization. Just issue a request for http://graph.facebook.com/zuck/picture for example.

Body:
i grabbed an html from this url : http://facebook.com/zuck
there is no problem to echo it to the client browser but i found it impossible to parse it with php.

i am trying to parse the text inside div tags for example :

preg_match_all("/
(.*)<\/div>/",$html,$matches);
print_r($matches);

returns empty array
i also tried with DOMDocument and with PHP Simple HTML DOM Parser both of them return empty elements and can't grab the text of the html.

how is it even possible?
there is a solution to that?


问:
Add see more option to the server data in angular 8
I am facing an issue with my project.

I want to add see more option to a paragraph and that paragraph's data is coming from a server.

I know how to add see more option to HTML paragraph, but I don't know how to add see more option to the data that is coming from the server.

```<code><p>Jayesh Vyas Jayesh Vyas Jayesh Vyas Jayesh Vyas Jayesh Vyas
Jayesh Vyas Jayesh Vyas Jayesh Vyas Jayesh Vyas Jayesh Vyas
Jayesh Vyas Jayesh Vyas <span id="dots">...</span>
<span id="more">Jayesh Vyas Jayesh Vyas Jayesh Vyas Jayesh Vyas
Jayesh Vyas Jayesh Vyas Jayesh Vyas Jayesh Vyas Jayesh Vyas
Jayesh Vyas Jayesh Vyas Jayesh Vyas Jayesh Vyas Jayesh Vyas
Jayesh Vyas Jayesh Vyas Jayesh Vyas Jayesh Vyas Jayesh Vyas
Jayesh Vyas Jayesh Vyas Jayesh Vyas .</span></p>
<button onclick="myFunction()" id="myBtn">Read more</button>
</code>```

JavaScript code

```<code><script>
function myFunction() {
  var dots = document.getElementById("dots");
  var moreText = document.getElementById("more");
  var btnText = document.getElementById("myBtn");

  if (dots.style.display === "none") {
    dots.style.display = "inline";
    btnText.innerHTML = "Read more";
    moreText.style.display = "none";
  } else {
    dots.style.display = "none";
    btnText.innerHTML = "Read less";
    moreText.style.display = "inline";
  }
}
</script>
</code>```

So you can see above I tried above code for a paragraph and it is working fine for me.

but in my project, the HTML component is as below.

```<code><div  class="col-12 col-lg-12" *ngFor="let post of rec?.attributes?.Postings | filter : searchText | filter:filterText; let i=index">
<div class="col-12 noRightPadding" style="overflow-wrap: break-word;white-space: pre-line;word-break:break-all;
">{{post?.attributes?.Message}} </div>
</div>
</code>```

you can see the paragraph is coming as post.attributes.Message and I don't have an idea how to add see more option for this if it exceeds more than two lines.

can anyone help me with this?

答:
I strongly recommand you to use word-wrap and text-overflow CSS properties.

Example: https://codepen.io/doliG/pen/oNjrVBK

With angular, the toggle function can simply change a boolean value

class MyComponent {
  showFullText = false;

  toggle() {
    this.showFullText = !this.showFullText;
  }
}
```

<p>And then in template, something like</p>

<pre class="lang-html prettyprint-override"><code><p [class.something]="showFullText">{{ veryLongText }}</p>
</code>```

Good luck.

Body:
I am facing an issue with my project.

I want to add see more option to a paragraph and that paragraph's data is coming from a server.

I know how to add see more option to HTML paragraph, but I don't know how to add see more option to the data that is coming from the server.

Jayesh Vyas Jayesh Vyas Jayesh Vyas Jayesh Vyas Jayesh Vyas
Jayesh Vyas Jayesh Vyas Jayesh Vyas Jayesh Vyas Jayesh Vyas
Jayesh Vyas Jayesh Vyas ...
Jayesh Vyas Jayesh Vyas Jayesh Vyas Jayesh Vyas
Jayesh Vyas Jayesh Vyas Jayesh Vyas Jayesh Vyas Jayesh Vyas
Jayesh Vyas Jayesh Vyas Jayesh Vyas Jayesh Vyas Jayesh Vyas
Jayesh Vyas Jayesh Vyas Jayesh Vyas Jayesh Vyas Jayesh Vyas
Jayesh Vyas Jayesh Vyas Jayesh Vyas .

<button onclick="myFunction()" id="myBtn">Read more</button>

JavaScript code

So you can see above I tried above code for a paragraph and it is working fine for me.

but in my project, the HTML component is as below.

{{post?.attributes?.Message}}

you can see the paragraph is coming as post.attributes.Message and I don't have an idea how to add see more option for this if it exceeds more than two lines.

can anyone help me with this?

Body:
I strongly recommand you to use word-wrap and text-overflow CSS properties.

Example: https://codepen.io/doliG/pen/oNjrVBK

With angular, the toggle function can simply change a boolean value

class MyComponent {
  showFullText = false;

  toggle() {
    this.showFullText = !this.showFullText;
  }
}

And then in template, something like

<p [class.something]="showFullText">{{ veryLongText }}</p>

Good luck.


问:
Location for session files in Apache/PHP
What is the default location of session files on an installation of Apache/PHP on Ubuntu 10.10?</p>

答:
Non of the above worked for me using the IUS repo for CentOS 7 with PHP 7.2:

```<code>php -v
> PHP 7.2.30 (cli) (built: Apr 19 2020 00:32:29) ( NTS )

php -r 'echo session_save_path(), "\n";
>

php -r 'echo sys_get_temp_dir(), "\n";'
> /tmp
</code>```

However, sessions weren't saved in the /tmp folder, but in the /var/lib/php/mod_php/session/ folder:

```<code>ls /var/lib/php/mod_php/session/
> sess_3cebqoq314pcnc2jgqiu840h0k  sess_ck5dtaerol28fpctj6nutbn6fn  sess_i24lgt2v2l58op5kfmj1k6qb3h  sess_nek5q1alop8fkt84gliie91703
> sess_9ff74f4q5ihccnv6com2a8409t  sess_dvrt9fmfuolr8bqt9efdpcbj0d  sess_igdaksn26hm1s5nfvtjfb53pl7  sess_tgf5b7gkgno8kuvl966l9ce7nn
</code>```

ContentLicense: CC BY-SA 2.5

Body:
Non of the above worked for me using the IUS repo for CentOS 7 with PHP 7.2:

php -v
> PHP 7.2.30 (cli) (built: Apr 19 2020 00:32:29) ( NTS )

php -r 'echo session_save_path(), "\n";
>

php -r 'echo sys_get_temp_dir(), "\n";'
> /tmp

However, sessions weren't saved in the /tmp folder, but in the /var/lib/php/mod_php/session/ folder:

ls /var/lib/php/mod_php/session/
> sess_3cebqoq314pcnc2jgqiu840h0k  sess_ck5dtaerol28fpctj6nutbn6fn  sess_i24lgt2v2l58op5kfmj1k6qb3h  sess_nek5q1alop8fkt84gliie91703
> sess_9ff74f4q5ihccnv6com2a8409t  sess_dvrt9fmfuolr8bqt9efdpcbj0d  sess_igdaksn26hm1s5nfvtjfb53pl7  sess_tgf5b7gkgno8kuvl966l9ce7nn


问:
`Vector.erase()` does not work for vector of classes
I've made a class of gym pass that has expiration date (int expiration), price for the pass (float price) and name of its' holder (string data). It also has services (char services), where 0 is basic, 1 is with free showers and 2 is VIP room.

Here's the definition of class:

    class GymPass
    {
        int expiration; //the amount of days
        char services; //0 - basic, 1 - shower, 2 - VIP room
        float price = ((int)services - 47) * expiration;
        string data; //client's identifiable data
    public:

        GymPass()
        {
            cout << "this: " << this;
            expiration = 0;
            services = '0';
            price = 0;
            data = "Lorem ipsum";
        }
        Pass(int expiration, char services, string data)
        {
            this->expiration = expiration;
            this->services = services;
            this->data = data;
        }

        void Print()
        {
            cout << "Gym Pass: ";
            switch (services)
            {
            case '0':
            {
                cout << "Basic gym access, ";
            }
            case '1':
            {
                cout << "gym + shower room, ";
            }
            case '2':
            {
                cout << "Luxurious gym pass with VIP room, ";
            }
            default:
            {
                cout << "Error."; //this should never happen
            }
            }
            cout << "valid for: " << expiration << " days, price: " << price << " zl." << endl;
        }
        void NewPass()
        {
            cout << "Choose service type: \n0 - basic\n1 - showers included\n2 - vip room included";
            {
                char temp{};
                do
                {
                    cin >> temp;
                    if (!((int)temp > 47 & (int)temp < 51)) cout << endl << "Incorrect service type.";
                } while (!((int)temp > 47 & (int)temp < 51));
                this->services = temp;
            }
            cout << endl << "Input the expiration date of the Pass:";
            cin >> this->expiration;
            cout << endl << "Input your name: ";
            cin >> this->data;
        }
        friend bool operator==(const GymPass& lhs, const GymPass& rhs)
        {
            if (lhs.price != rhs.price) return false;
            if (!(lhs.data._Equal(rhs.data))) return false;
            if (lhs.services != rhs.services) return false;
            if (lhs.expiration != rhs.expiration) return false;
            return true;
        }
    };
```
<p>I also made a class that's basically a vector of my <code>GymPass</code> classes. I'm trying to make a void function to delete one gym pass, but the erase throws error:</p>
<p><code>no instance of overloaded function "std::vector<_Ty, _Alloc>::erase [with _Ty=GymPass, _Alloc=std::allocator<GymPass>]" matches the argument list</code></p>
<p>Like a good programmer, I've done hours of googling, but to no luck. Here's definition of gym class</p>
<pre class="lang-cpp prettyprint-override"><code>     class Gym
    {
        vector <GymPass> Clients;
    public:
        void add(GymPass pass)
        {
            Clients.push_back(pass);
        }
        void remove(GymPass pass)
        {
            for (int i = 0; i < Clients.size(); i++)
            {
                if (Clients[i] == pass) Clients.erase(i);
            }
        }
    };
</code>```

void remove is the delete function, where I get the error. How do I fix the error?

答:
std::vector::erase takes an iterator not an index as the argument.

```<code>Stali_Klienci.erase(Stali_Klienci.begin() + i);
</code>```

is a reasonable hack. Stali_Klienci.begin() is the iterator to the first element, the + i increments the iterator to the ith element.

If you want to remove every element from a std::vector then clear does that in one call.

Body:
I've made a class of gym pass that has expiration date (int expiration), price for the pass (float price) and name of its' holder (string data). It also has services (char services), where 0 is basic, 1 is with free showers and 2 is VIP room.

Here's the definition of class:

    class GymPass
    {
        int expiration; //the amount of days
        char services; //0 - basic, 1 - shower, 2 - VIP room
        float price = ((int)services - 47) * expiration;
        string data; //client's identifiable data
    public:

        GymPass()
        {
            cout << "this: " << this;
            expiration = 0;
            services = '0';
            price = 0;
            data = "Lorem ipsum";
        }
        Pass(int expiration, char services, string data)
        {
            this->expiration = expiration;
            this->services = services;
            this->data = data;
        }

        void Print()
        {
            cout << "Gym Pass: ";
            switch (services)
            {
            case '0':
            {
                cout << "Basic gym access, ";
            }
            case '1':
            {
                cout << "gym + shower room, ";
            }
            case '2':
            {
                cout << "Luxurious gym pass with VIP room, ";
            }
            default:
            {
                cout << "Error."; //this should never happen
            }
            }
            cout << "valid for: " << expiration << " days, price: " << price << " zl." << endl;
        }
        void NewPass()
        {
            cout << "Choose service type: \n0 - basic\n1 - showers included\n2 - vip room included";
            {
                char temp{};
                do
                {
                    cin >> temp;
                    if (!((int)temp > 47 & (int)temp < 51)) cout << endl << "Incorrect service type.";
                } while (!((int)temp > 47 & (int)temp < 51));
                this->services = temp;
            }
            cout << endl << "Input the expiration date of the Pass:";
            cin >> this->expiration;
            cout << endl << "Input your name: ";
            cin >> this->data;
        }
        friend bool operator==(const GymPass& lhs, const GymPass& rhs)
        {
            if (lhs.price != rhs.price) return false;
            if (!(lhs.data._Equal(rhs.data))) return false;
            if (lhs.services != rhs.services) return false;
            if (lhs.expiration != rhs.expiration) return false;
            return true;
        }
    };

I also made a class that's basically a vector of my GymPass classes. I'm trying to make a void function to delete one gym pass, but the erase throws error:

no instance of overloaded function "std::vector<_Ty, _Alloc>::erase [with _Ty=GymPass, _Alloc=std::allocator<GymPass>]" matches the argument list

Like a good programmer, I've done hours of googling, but to no luck. Here's definition of gym class

     class Gym
    {
        vector <GymPass> Clients;
    public:
        void add(GymPass pass)
        {
            Clients.push_back(pass);
        }
        void remove(GymPass pass)
        {
            for (int i = 0; i < Clients.size(); i++)
            {
                if (Clients[i] == pass) Clients.erase(i);
            }
        }
    };

void remove is the delete function, where I get the error. How do I fix the error?

Body:
std::vector::erase takes an iterator not an index as the argument.

Stali_Klienci.erase(Stali_Klienci.begin() + i);

is a reasonable hack. Stali_Klienci.begin() is the iterator to the first element, the + i increments the iterator to the ith element.

If you want to remove every element from a std::vector then clear does that in one call.