Data transformation from int into series - python

I created a loop to simulate the training for neural network and I find it odd that the weights that was first assigned as an Int turned into a Series
Sample Data (Note: created multiple samples of the same rows to make it up to 100 observations):
# x1 x2 y
data = [ [3.5, 1.5, 1],
[2.0, 1.0, 0],
[4.0, 1.5, 1],
[3.0, 1.0, 0],
[3.5, 0.5, 1],
[2.0, 0.5, 0],
[5.5, 1.0, 1],
[1.0, 1.0, 0] ]
#[4.5, 1.0, 1]
data = pd.DataFrame(data, columns = ["Length", "Width", "Class"])
data
Assigning Variables:
w1 = np.random.randn()
w2 = np.random.randn()
b = np.random.randn()
print(w1)
print(w2)
print(b)
Training Loop:
learning_rate = 0.2
#costs = []
for x in range(50000):
z = train_data["Length"] * w1 + train_data["Width"] + b
preds = sigmoid(z)
target = train_data["Class"]
cost = np.square(preds - target)
derivcost_pred = 2 * (preds - target)
derivpred_sigp = sigmoid_p(z)
dcost_dz = derivcost_pred * derivpred_sigp
dz_dw1 = train_data["Length"]
dz_dw2 = train_data["Width"]
dz_db = 1
dcost_dw1 = dcost_dz * dz_dw1
dcost_dw2 = dcost_dz * dz_dw2
dcost_db = dcost_dz * dz_db
w1 = w1 - learning_rate * dcost_dw1
w2 = w2 - learning_rate * dcost_dw2
b = b - learning_rate * dcost_db
My question here is how to get the last w1, w2, b value that was trained?
Also, if I'll use the series, how can I access the last value instead?
Lastly, let me know If did something wrong with the loop

For your first question, since you want the last w1, w2, b value that was trained, I will assume that this corresponds to x=50000-1. If this is correct, just add one line to the end of the loop
for x in range(50000):
.
.
.
if x==50000-1: costs.append([w1, w2, b])
# Print results
w1_trained, w2_trained, b_trained = costs[0][0], costs[0][1], costs[0][2]
print(w1_trained, w2_trained, b_trained)

Related

Can I turn this for loop into recursion or dynamic programming?

I am trying to make the code that I have into either recursion or dynamic programming.
import numpy as np
index_list = [1, 2, 0]
weights = [0.3, 0.8]
A_matrix = np.asarray([[0, 1, 2], [0, 1, 2], [0, 1, 2]])
initial_best_vector = A_matrix[:, 1]
# set best_vector_combinations to initial_best_vector
best_vector_combinations = initial_best_vector
for index, _ in enumerate(index_list[1:]):
best_vector_combinations = (
1 - weights[index]
) * best_vector_combinations + (
weights[index] * A_matrix[:, index_list[index + 1]]
)
Is it possible to do so? What I am doing is a nested linear combination of vectors, with the initial base being the initial_best_vector, which corresponds to the index_list.
In other words, let c_i be the columns of the matrix A, I want:
((1-0.3) * c_1 + 0.3 * c_2) * (1-0.8) + 0.8 * c_0
I hope to make this case more general to hold for any length of numbers.
Edit:
The code:
def calculate(vectors, weights):
if not (vectors or weights):
return 0
if not weights:
return vectors[0]
return vectors[0]*(1-weights[0]) + weights[0] * (calculate(vectors[1:], weights[1:]))
vectors = [1,2,3]
weights = [0.2, 0.3]
calculate(vectors, weights) = 1.26
but expected answer is 1.74 where i would expect first case to be 0.8 * 1 + 0.2 * 2 = 1.2, then second to be 1.2 * 0.7 + 3 * 0.3 = 1.74. Note I replaced your typo result to calculate but still unable to recover 1.74.
If you want a recursive implementation, if would be helpful to start with a simpler example and figure out the recurrence relation.
Let vectors = [8,5,2,1] (1D array for simplicity) and let weights = [0.5, 0.8, 0.1, 0.2].
First step of computation: (8 * 0.5) + (1-0.5)*(result of second step).
Second step: 5 * 0.8 + (1-0.8)*(result of third step).
You can work this out further, but the basic relation is
result(vectors, weights) =
(
vectors[0]*weights[0]) +
(1-weights[0]) * (result(vectors[1:], weights[1:]))
) if (vectors and weights) else 0
Implementation:
def calculate(vectors, weights):
if not (vectors or weights):
return 0
if not weights:
return vectors[0]
return vectors[0]*weights[0] + (1-weights[0]) * (calculate(vectors[1:], weights[1:]))
print(calculate([1,2,3], [0.2,0.3])) #left to right processing, 1.26
print(calculate([1,2,3][::-1], [0.2,0.3][::-1])) #right to left processing, 1.74

How to restrict the contour plot only to 3sigma variation for a 2Dimensional gaussian?

I was a bit curious on plotting the contour plots for a 2 dimensional gaussian distribution. In my case, for a given set of 2D points, I cluster them into different grid cells and compute the covariance matrix for every cell and plot the gaussian distribution for each and every cell. When I plot I do not want the entire contour for the cell but the distribution restricted within 3 sigma of the data points. Is there anyway it could be done ?
My code is as follows:
import numpy as np
import matplotlib.pyplot as plt
def createCells():
partition = 4
coords = [np.linspace(-1.0 , 1.0, num = partition + 1) for i in range(2)]
x, y = np.meshgrid(*coords)
return x, y
def probab(mean, covMat, lPoints):
lPoints = lPoints[..., np.newaxis] if lPoints.ndim == 2 else lPoints ## Create vectorized values for the x, y
if np.linalg.det(covMat) > 0:
factor1 = (2*np.pi)*(np.linalg.det(covMat)**(-1/2))
factor2 = np.exp((-1/2)*np.einsum('ijk,jl,ilk->ik', lPoints - mean, np.linalg.inv(covMat), lPoints - mean))
return factor1*factor2
if __name__ == '__main__':
points = np.array([[-0.35, -0.15], [0.1, 0.1], [-0.1, 0.1], [0.05, 0.05],[0.25, 0.05], [0.1, 0.15], [0.1, 0.2], [-0.2, -0.2], [-0.25, 0.25], [0.45, 0.45], [0.75, 0.75], [0.6, 0.6], [0.55, 0.55], [0.7, 0.7], [0.68, 0.73]])
x1, y1 = createCells()
x = x1[0]
y = y1[:,0]
lP = np.array([])
numberOftimes = 0
for i in range(len(x) - 1):
for j in range(len(y) - 1):
count = 0
meanX = 0.0
meanY = 0.0
localPoints = []
covMat1 = np.array([])
covMat2 = np.array([])
for point in points:
inbetween_x = x[i] <= point[0] <= x[i + 1]
inbetween_y = y[j] <= point[1] <= y[j + 1]
if inbetween_x and inbetween_y:
count += 1
meanX += point[0]
meanY += point[1]
localPoints.append([point[0], point[1]])
if count >= 2:
numberOftimes += 1
#print(f"The local points are {localPoints}")
localPoints = np.array(localPoints)
meanX /= count
meanY /= count
meanXY = np.array([meanX, meanY])
#print(meanXY.shape)
#print(localPoints.shape)
lP = localPoints - meanXY
for k in range(count):
lPtranspose = (np.array([lP[k]])).T
lPCurrent = (np.array([lP[k]]))
if len(covMat1) > 0:
covMat1 += lPtranspose.dot(lPCurrent)
else:
covMat1 = lPtranspose*lP[k]
covMat1 /= count
lPoints = localPoints[..., np.newaxis] if lP.ndim == 2 else lP ## Create vectorized values for the x, y
meanXY1 = localPoints.mean(0)
meanXY2 = lPoints.mean(0)
covMat3 = np.einsum('ijk, ikj->jk', lPoints - meanXY2, lPoints - meanXY2) / lPoints[0] - 1
#yamlStatus = self.savingYaml(i, j, meanXY, covMat3) ## To store the cell parameters in a yaml file (for now its just out of scope for the question)
if np.linalg.det(covMat3) > 0: #compute the probability only if the det is not 0
Xx = np.linspace(x[i], x[i + 1], 1000)
Yy = np.linspace(y[i], y[i + 1], 1000)
Xx,Yy = np.meshgrid(Xx, Yy)
lPoints = np.vstack((Xx.flatten(), Yy.flatten())).T
pos = np.empty(Xx.shape + (2,))
pos[:, :, 0] = Xx
pos[:, :, 1] = Yy
z2 = probab(meanXY2, covMat3, lPoints)
summed = np.sum(z2)
z2 = z2.reshape(1000, 1000)
cs = plt.contourf(Xx, Yy, z2)#, cmap=cm.viridis)
plt.clabel(cs)
localPoints = []
#print(f"The number of times count is greater than 1 is {numberOftimes}")
plt.plot(x1, y1, marker='.', linestyle='none', markersize=20)
plt.plot(points[:,0 ], points[:, 1], marker='.', linestyle='none', markersize=10)
plt.grid(linewidth=0.5)#abs(x1[0][0]-y1[0][0]))
plt.show()

pytorch (numpy) calculation about the closest pixels to points

I am trying to solve a complicated problem.
For example, I have a batch of 2D predicted images (softmax output, value between 0 and 1) with size: Batch x H x W and ground truth Batch x H x W
The light gray color pixels are the background with value 0, and the dark gray color pixels are the foreground with value 1. I try to compute the mass center coordinates using scipy.ndimage.center_of_mass on each ground truth image. Then I get the center location point C (red color) for each ground truth. The C points set is Batch x 1.
Now, for each pixel A (yellow color) in the predicted images, I want to get three pixels B1, B2, B3 (blue color) which are the closest to A on the line AC (here C is corresponding location of mass center in ground truth).
I used following code to get the three closest points B1, B2, B3.
def connect(ends, m=3):
d0, d1 = np.abs(np.diff(ends, axis=0))[0]
if d0 > d1:
return np.c_[np.linspace(ends[0, 0], ends[1, 0], m + 1, dtype=np.int32),
np.round(np.linspace(ends[0, 1], ends[1, 1], m + 1))
.astype(np.int32)]
else:
return np.c_[np.round(np.linspace(ends[0, 0], ends[1, 0], m + 1))
.astype(np.int32),
np.linspace(ends[0, 1], ends[1, 1], m + 1, dtype=np.int32)]
So the B points set is Batch x 3 x H x W.
Then, I want to compute like this: |Value(A)-Value(B1)|+|Value(A)-Value(B2)|+|Value(A)-Value(B3)|. The size of the result should be Batch x H x W.
Is there any numpy vectorization tricks that can be used to update the value of each pixel in predicted images? Or can this be solved using pytorch functions? I need to find a method to update the whole image. The predicted image is the softmax output. I cannot use for loop to compute each single value since it will become non-differentiable. Thanks a lot.
As suggested by #Matin, you could consider Bresenham's algorithm to get your points on the AC line.
A simplistic PyTorch implementation could be as follows (directly adapted from the pseudo-code here ; could be optimized):
import torch
def get_points_from_low(x0, y0, x1, y1, num_points=3):
dx = x1 - x0
dy = y1 - y0
xi = torch.sign(dx)
yi = torch.sign(dy)
dy = dy * yi
D = 2 * dy - dx
y = y0
x = x0
points = []
for n in range(num_points):
x = x + xi
is_D_gt_0 = (D > 0).long()
y = y + is_D_gt_0 * yi
D = D + 2 * dy - is_D_gt_0 * 2 * dx
points.append(torch.stack((x, y), dim=-1))
return torch.stack(points, dim=len(x0.shape))
def get_points_from_high(x0, y0, x1, y1, num_points=3):
dx = x1 - x0
dy = y1 - y0
xi = torch.sign(dx)
yi = torch.sign(dy)
dx = dx * xi
D = 2 * dx - dy
y = y0
x = x0
points = []
for n in range(num_points):
y = y + yi
is_D_gt_0 = (D > 0).long()
x = x + is_D_gt_0 * xi
D = D + 2 * dx - is_D_gt_0 * 2 * dy
points.append(torch.stack((x, y), dim=-1))
return torch.stack(points, dim=len(x0.shape))
def get_points_from(x0, y0, x1, y1, num_points=3):
is_dy_lt_dx = (torch.abs(y1 - y0) < torch.abs(x1 - x0)).long()
is_x0_gt_x1 = (x0 > x1).long()
is_y0_gt_y1 = (y0 > y1).long()
sign = 1 - 2 * is_x0_gt_x1
x0_comp, x1_comp, y0_comp, y1_comp = x0 * sign, x1 * sign, y0 * sign, y1 * sign
points_low = get_points_from_low(x0_comp, y0_comp, x1_comp, y1_comp, num_points=num_points)
points_low *= sign.view(-1, 1, 1).expand_as(points_low)
sign = 1 - 2 * is_y0_gt_y1
x0_comp, x1_comp, y0_comp, y1_comp = x0 * sign, x1 * sign, y0 * sign, y1 * sign
points_high = get_points_from_high(x0_comp, y0_comp, x1_comp, y1_comp, num_points=num_points) * sign
points_high *= sign.view(-1, 1, 1).expand_as(points_high)
is_dy_lt_dx = is_dy_lt_dx.view(-1, 1, 1).expand(-1, num_points, 2)
points = points_low * is_dy_lt_dx + points_high * (1 - is_dy_lt_dx)
return points
# Inputs:
# (#todo: extend A to cover all points in maps):
A = torch.LongTensor([[0, 1], [8, 6]])
C = torch.LongTensor([[6, 4], [2, 3]])
num_points = 3
# Getting points between A and C:
# (#todo: what if there's less than `num_points` between A-C?)
Bs = get_points_from(A[:, 0], A[:, 1], C[:, 0], C[:, 1], num_points=num_points)
print(Bs)
# tensor([[[1, 1],
# [2, 2],
# [3, 2]],
# [[7, 6],
# [6, 5],
# [5, 5]]])
Once you have your points, you could retrieve their "values" (Value(A), Value(B1), etc.) using torch.index_select() (note that as of now, this method only accept 1D indices, so you need to unravel your data). All things put together, this would look like something such as the following (extending A from shape (Batch, 2) to (Batch, H, W, 2) is left for exercise...)
# Inputs:
# (#todo: extend A to cover all points in maps):
A = torch.LongTensor([[0, 1], [8, 6]])
C = torch.LongTensor([[6, 4], [2, 3]])
batch_size = A.shape[0]
num_points = 3
map_size = (9, 9)
map_num_elements = map_size[0] * map_size[1]
map_values = torch.stack((torch.arange(0, map_num_elements).view(*map_size),
torch.arange(0, -map_num_elements, -1).view(*map_size)))
# Getting points between A and C:
# (#todo: what if there's less than `num_points` between A-C?)
Bs = get_points_from(A[:, 0], A[:, 1], C[:, 0], C[:, 1], num_points=num_points)
# Get map values in positions A:
A_unravel = torch.arange(0, batch_size) * map_num_elements
A_unravel = A_unravel + A[:, 0] * map_size[1] + A[:, 1]
values_A = torch.index_select(map_values.view(-1), dim=0, index=A_unravel)
print(values_A)
# tensor([ 1, -4])
# Get map values in positions A:
A_unravel = torch.arange(0, batch_size) * map_num_elements
A_unravel = A_unravel + A[:, 0] * map_size[1] + A[:, 1]
values_A = torch.index_select(map_values.view(-1), dim=0, index=A_unravel)
print(values_A)
# tensor([ 1, -78])
# Get map values in positions B:
Bs_flatten = Bs.view(-1, 2)
Bs_unravel = (torch.arange(0, batch_size)
.unsqueeze(1)
.repeat(1, num_points)
.view(num_points * batch_size) * map_num_elements)
Bs_unravel = Bs_unravel + Bs_flatten[:, 0] * map_size[1] + Bs_flatten[:, 1]
values_B = torch.index_select(map_values.view(-1), dim=0, index=Bs_unravel)
values_B = values_B.view(batch_size, num_points)
print(values_B)
# tensor([[ 10, 20, 29],
# [-69, -59, -50]])
# Compute result:
res = torch.abs(values_A.unsqueeze(-1).expand_as(values_B) - values_B)
print(res)
# tensor([[ 9, 19, 28],
# [ 9, 19, 28]])
res = torch.sum(res, dim=1)
print(res)
# tensor([56, 56])

How to calculate weight to minimize variance?

given several vectors:
x1 = [3 4 6]
x2 = [2 8 1]
x3 = [5 5 4]
x4 = [6 2 1]
I wanna find weight w1, w2, w3 to each item, and get the weighted sum of each vector: yi = w1*i1 + w2*i2 + w3*i3. for example, y1 = 3*w1 + 4*w2 + 6*w3
to make the variance of these values(y1, y2, y3, y4) to be minimized.
notice: w1, w2, w3 should > 0, and w1 + w2 + w3 = 1
I don't know what kind of problems it should be... and how to solve it in python or matlab?
You can start with building a loss function stating the variance and the constraints on w's. The mean is m = (1/4)*(y1 + y2 + y3 + y4). The variance is then (1/4)*((y1-m)^2 + (y2-m)^2 + (y3-m)^2 + (y4-m)^2) and the constraint is a*(w1+w2+w3 - 1) where a is the Lagrange multiplier. The problem looks like to me a convex optimisation with convex constraints since the loss function is quadratic with respect to target variables (w1,w2,w3) and the constraints are linear. You can look for projected gradient descent algorithms which respect to the constraints provided. Take a look to here http://www.ifp.illinois.edu/~angelia/L5_exist_optimality.pdf There are no straightforward analytic solutions to such kind of problems in general.
w = [5, 6, 7]
x1 = [3, 4, 6]
x2 = [2, 8, 1]
x3 = [5, 5, 4]
y1, y2, y3 = 0, 0, 0
for index, i in enumerate(w):
y1 = y1 + i * x1[index]
y2 = y2 + i * x2[index]
y3 = y3 + i * x3[index]
print(min(y1, y2, y3))
I think I maybe get the purpose of your problem.But if you want to find the smallest value, I hope this can help you.
I just make the values fixed, you can make it to be the def when you see this is one way to solve your question.
I don't know much about optimization problem, but I get the idea of gradient descent so I tried to reduce the weight between the max score and min score, my script is below:
# coding: utf-8
import numpy as np
#7.72
#7.6
#8.26
def get_max(alist):
max_score = max(alist)
idx = alist.index(max_score)
return max_score, idx
def get_min(alist):
max_score = min(alist)
idx = alist.index(max_score)
return max_score, idx
def get_weighted(alist,aweight):
res = []
for i in range(0, len(alist)):
res.append(alist[i]*aweight[i])
return res
def get_sub(list1, list2):
res = []
for i in range(0, len(list1)):
res.append(list1[i] - list2[i])
return res
def grad_dec(w,dist, st = 0.001):
max_item, max_item_idx = get_max(dist)
min_item, min_item_idx = get_min(dist)
w[max_item_idx] = w[max_item_idx] - st
w[min_item_idx] = w[min_item_idx] + st
def cal_score(w, x):
score = []
print 'weight', w ,x
for i in range(0, len(x)):
score_i = 0
for j in range(0,5):
score_i = w[j]*x[i][j] + score_i
score.append(score_i)
# check variance is small enough
print 'score', score
return score
# cal_score(w,x)
if __name__ == "__main__":
init_w = [0.2, 0.2, 0.2, 0.2, 0.2, 0.2]
x = [[7.3, 10, 8.3, 8.8, 4.2], [6.8, 8.9, 8.4, 9.7, 4.2], [6.9, 9.9, 9.7, 8.1, 6.7]]
score = cal_score(init_w,x)
variance = np.var(score)
round = 0
for round in range(0, 100):
if variance < 0.012:
print 'ok'
break
max_score, idx = get_max(score)
min_score, idx2 = get_min(score)
weighted_1 = get_weighted(x[idx], init_w)
weighted_2 = get_weighted(x[idx2], init_w)
dist = get_sub(weighted_1, weighted_2)
# print max_score, idx, min_score, idx2, dist
grad_dec(init_w, dist)
score = cal_score(init_w, x)
variance = np.var(score)
print 'variance', variance
print score
In my practice it really can reduce the variance. I am very glad but I don't know whether my solution is solid in math.
My full solution can be viewed in PDF.
The trick is to put the vectors x_i as columns of a matrix X.
Then writing the problem becomes a Convex Problem with constrain of the solution to be on the Unit Simplex.
I solved it using Projected Sub Gradient Method.
I calculated the Gradient of the objective function and created a projection to the Unit Simplex.
Now all needed is to iterate them.
I validated my solution using CVX.
% StackOverflow 44984132
% How to calculate weight to minimize variance?
% Remarks:
% 1. sa
% TODO:
% 1. ds
% Release Notes
% - 1.0.000 08/07/2017
% * First release.
%% General Parameters
run('InitScript.m');
figureIdx = 0; %<! Continue from Question 1
figureCounterSpec = '%04d';
generateFigures = OFF;
%% Simulation Parameters
dimOrder = 3;
numSamples = 4;
mX = randi([1, 10], [dimOrder, numSamples]);
vE = ones([dimOrder, 1]);
%% Solve Using CVX
cvx_begin('quiet')
cvx_precision('best');
variable vW(numSamples)
minimize( (0.5 * sum_square_abs( mX * vW - (1 / numSamples) * (vE.' * mX * vW) * vE )) )
subject to
sum(vW) == 1;
vW >= 0;
cvx_end
disp([' ']);
disp(['CVX Solution - [ ', num2str(vW.'), ' ]']);
%% Solve Using Projected Sub Gradient
numIterations = 20000;
stepSize = 0.001;
simplexRadius = 1; %<! Unit Simplex Radius
stopThr = 1e-6;
hKernelFun = #(vW) ((mX * vW) - ((1 / numSamples) * ((vE.' * mX * vW) * vE)));
hObjFun = #(vW) 0.5 * sum(hKernelFun(vW) .^ 2);
hGradFun = #(vW) (mX.' * hKernelFun(vW)) - ((1 / numSamples) * vE.' * (hKernelFun(vW)) * mX.' * vE);
vW = rand([numSamples, 1]);
vW = vW(:) / sum(vW);
for ii = 1:numIterations
vGradW = hGradFun(vW);
vW = vW - (stepSize * vGradW);
% Projecting onto the Unit Simplex
% sum(vW) == 1, vW >= 0.
vW = ProjectSimplex(vW, simplexRadius, stopThr);
end
disp([' ']);
disp(['Projected Sub Gradient Solution - [ ', num2str(vW.'), ' ]']);
%% Restore Defaults
% set(0, 'DefaultFigureWindowStyle', 'normal');
% set(0, 'DefaultAxesLooseInset', defaultLoosInset);
You can see the full code in StackOverflow Q44984132 (PDF is available as well).

scipy.optimize.minimize convergence issues

I have a function that I wish to optimize, but that is returning nans.
Here is the function (fnRestrictParams is a helper function):
def fnRestrictParams(vParams):
vRestrictedParams = vParams
vRestrictedParams[1] = exp(vParams[1])
vRestrictedParams[2] = exp(vParams[2]) / (1 + exp(vParams[2]))
return(vRestrictedParams)
def fnGASGaussianCopulaLikelihood(vParams, iT, mData):
dLL = 0 # initialize the likelihood at zero
vRestrictedParams = fnRestrictParams(vParams)
dOmega = vRestrictedParams[0]
dA = vRestrictedParams[1]
dB = vRestrictedParams[2]
dFactor = dOmega
dOmega = dOmega*(1 - dB)
vFactor = np.zeros(iT)
for t in range(iT):
# compute the copula parameters based on the factors
rho = (1 - exp(-dFactor))/(1 + exp(-dFactor))
rho2 = rho * rho
vFactor[t] = rho
# quantile functions
qu = sps.norm.ppf(mData[t, :])
x = qu[0] ** 2 + qu[1] ** 2
y = qu[0] * qu[1]
# get the log pdf of the copula, and its gradient with respect to the copula parameters
dLL += -0.5 * np.log(1 - rho2) - 0.5 * (rho2 * x - 2 * rho * y) / (1 - rho2)
# scaled score function
dSt = (2 / (1 - rho2)) * (y - rho - rho * (x - 2) / (1 + rho2))
# GAS recursion
dFactor = dOmega + dA * dSt + dB * dFactor
dLL = dLL/iT
return(-dLL)
The data to test this function is here.
I know that this function works correctly, because I have compared the output to an implementation available from the original authors (in another programming language).
# load the data
mData = np.loadtxt("./Data/Patton4filtered.csv",
skiprows=1, usecols = tuple(range(1, 4)), delimiter = ",")
# test the likelihood function
for x in np.arange(3.1, 4, .1):
print(fnGASGaussianCopulaLikelihood([x, -5, 5.0], mData.shape[0], mData[:, [0, 1]]))
However, when I try to optimize this function using scipy.optimize.minimize:
# optimize the function without the gradient
spoGC = spo.minimize(fnGASGaussianCopulaLikelihood, np.array([0.005,-5,5.0]),
args = (int(mData.shape[0]), mData[:, [0, 1]]),
method = 'BFGS', options = {'disp': True, 'gtol': 1e-10, 'eps': 1e-10})
I get:
Optimization terminated successfully.
Current function value: nan
Iterations: 0
Function evaluations: 5
Gradient evaluations: 1
Out[34]:
(array([ 0.005 , 1.0067607 , 0.72974065]),
nan,
array([ nan, nan, nan]),
array([[1, 0, 0],
[0, 1, 0],
[0, 0, 1]]),
5,
1,
0)
which is clearly no good. I am unable to figure out what is causing this issue. Any help would be appreciated.

Categories

Resources