matlab - calculation gives me NaN -


I am trying to implement multilateral logistics regression using the gradient lineage, but my cost job is NaN Does the value of the weight tell me what I am doing? Calculates the cost for the gradient lineage, assumes there is a% extra feature in inputX, continuous and weights a class X. Function [cost] = costFunctionMultiNominal (inputX, resultY, weight)% UNTITLED8 Features matrix [rows, columns] = size (inputX); NumOfClasses = Size (weight, 1); Yoga = 0; I = for 1: rows class level academic = 0; For Jammu = 1: numOfClasses if resultY (i) == j denominatorSum = 0; For L = 1: numOfClasses denominatorSum = Denominator + XP ((InputX (I, :) * Weight (L, :) ') - 4444); End ** Class Level End = Class Level End + Log (XP (IPX (I, :) * Weight (Jay, :) '- 4444) / DinominatorSam); ** End End End = Equation + Class Level Easy; Cost of the end = equation / (- lines); Weight update function is:

  function [weight] = getWeightsUsingGradientDescentMultiNominal (training X, resulting in, iterMax, alpha, weight 0,0, lambda) Weighted weight, weight 0 diagrams are random weight by% return shield dynasty. Detailed description here is found in rows = size (training 1X, 1); cols = size (trainingX, 2) +1; Weight = weight 0; NumOfClasses = Size (weight, 1); Adding one to the input data for constant rules = one (rows, 1); X = [A training X]; % Each column corresponds to one weight, weight is updated according to the column:% together with the CTS function together tempCost = 0; Display (costFunctionMultiNominal (x, resultY, watt)); Plot (1, costFunctionMultiNominal (x, resultY, watt), 'r'); Wait; For N = 1: iterMax% has to do this for all classes, for i = rows in weighths = 1: numOfClasses% first calculates sigma on rows for all x x = sum (1, cols); For I = 1: rows p = -1 * calculation of multiples noamal (x (i, :), weight, j); If the result (i) == jp = 1 + p; End equation = Equation + X (i, :) * p; End weight (j, :) = weight (j, :) - (alpha) * (closing / (- lines) + lambda * weight (jay, :)); End cost = costfunctionmulti nonimal (x, result, weight); Performance (cost); costDiff = tempCost - cost; If I ~ = 0 & amp; Amp; Stomach (costdiff) / cost & lt; = 0.0001 display ('breaking down due to cost!'); break; End tempCost = cost; Plot (i, cost, 'r'); End stop; Finally   

As far as I understand, Nayen is coming in a lot of exponential terms. I tried to reduce the number of losses (-4444), but there was no benefit.

If I try NaN and she tells me that this cost is closed on the line in the ceremony (bold in the above code):

  classLevelSummation = classLevelSummation + Log (XP (InputX (I, :) * Weight (J., '' - 4444) / Negotiator);   

classLevelSummation becomes NaN, even if I remove the large constant value -4444

in the log (XP (blah) / two) This is unnecessary for exponent and then log in, these two actions undo each other, and this The call may be more than the floating point range if you remember that is equal to log (a / b) log (a) - Log (B) Code>.

exp has a simple overflow probability that you do an inf instead of a nan, though. You should check the value of denominatorSum because it also comes from an exponential term.

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -