<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Nonlinear Fit - How to check for success? in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Nonlinear-Fit-How-to-check-for-success/m-p/600846#M80420</link>
    <description>&lt;P&gt;That'll do it.&amp;nbsp; Thanks Jed!&lt;/P&gt;</description>
    <pubDate>Tue, 14 Feb 2023 12:25:10 GMT</pubDate>
    <dc:creator>AApperson</dc:creator>
    <dc:date>2023-02-14T12:25:10Z</dc:date>
    <item>
      <title>Nonlinear Fit - How to check for success?</title>
      <link>https://community.jmp.com/t5/Discussions/Nonlinear-Fit-How-to-check-for-success/m-p/600498#M80395</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Overview:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;How can I check to see a Nonlinear fit succeeded?&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;(Real-data doesn't always converge and may need manual review for automation/test/product issues.)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Detail:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;I would like to script a response after a nonlinear fit fails to converge.&amp;nbsp; If the fit fails, I need to process another way, and/or eventually label for manual review. (I'm sampling a population, then for each part, doing a non-linear fit.&amp;nbsp; Generally if I fail convergence, there was a test issue somewhere; I don't actually want to loosen the convergence criteria.)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;('Failed' message: "Failed: Cannot Decrease Objective Function")&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Nonlinear Fail Screenshot.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/50091i16B5465CA55A7137/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Nonlinear Fail Screenshot.png" alt="Nonlinear Fail Screenshot.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Modified script from Numeric Derivatives Only (Help &amp;gt; Scripting Index &amp;gt; "&amp;lt;&amp;lt;Nonlinear")&lt;/P&gt;&lt;P&gt;(Currently running JMP 15.2.1)&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
dt = Open(
	"$SAMPLE_DATA/Nonlinear Examples/US Population.jmp"
);

// Random, intentionally divergent, formula on this dataset
dt &amp;lt;&amp;lt; New Column( "Random", Numeric, Formula( Random LogLogistic(5) ) );

dt &amp;lt;&amp;lt; New Column( "FancyPredictionFormula",
	Numeric,
	Continuous,
	Formula(
		Parameter(
			{Rth0 = 735, n = 0.5},
			(:year / :pop) * ((1 - ((n - 1) * :pop * Rth0) / (:year
			 * (300 / :year) ^ n)) ^ (-1 / (n - 1)) - 1)
		)
	)
);

nonlinear = dt &amp;lt;&amp;lt; Nonlinear(
	Y(  :Name( "Random" ) ),
	X( :Name("FancyPredictionFormula") ),
	Expand Intermediate Formulas( 1 ),
	Numeric Derivatives Only( 1 ),
	QuasiNewton SR1,
	Interation Limit(50),
	Finish,
	Plot( 0 ),
	Confidence Limits,
	Save Estimates
);

// How to check if nonlinear fit succeeded?&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;Ideal.&lt;/U&gt;&lt;/P&gt;&lt;P&gt;If there is a bool status variable returned by the Nonlinear fit platform somewhere indicating success or failure, that would be the ideal method to verify success, I think.&lt;/P&gt;&lt;P&gt;&lt;U&gt;Alternative 1.&lt;/U&gt;&lt;/P&gt;&lt;P&gt;I can also tabulate or take a summary of the data to see if all the&amp;nbsp;&lt;FONT face="verdana,geneva"&gt;:&lt;FONT color="#0000FF"&gt;Name&lt;/FONT&gt;(&lt;FONT color="#993366"&gt;"FancyPredictionFormula"&lt;/FONT&gt;)&lt;/FONT&gt; values are zero.&amp;nbsp; (Values seem to be 0 if the fit fails).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;Alternative 2. &lt;/U&gt;&lt;/P&gt;&lt;P&gt;There's probably a way to check the XML and read the 'failed' message.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your time and consideration.&lt;/P&gt;&lt;P&gt;-Aubrey&lt;/P&gt;</description>
      <pubDate>Thu, 08 Jun 2023 16:36:20 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Nonlinear-Fit-How-to-check-for-success/m-p/600498#M80395</guid>
      <dc:creator>AApperson</dc:creator>
      <dc:date>2023-06-08T16:36:20Z</dc:date>
    </item>
    <item>
      <title>Re: Nonlinear Fit - How to check for success?</title>
      <link>https://community.jmp.com/t5/Discussions/Nonlinear-Fit-How-to-check-for-success/m-p/600622#M80404</link>
      <description>&lt;P&gt;Here's an approach using Alternative 2a (scraping the words from the report). The first 2 lines do the actual work, and the third line is just a simple example of what to do with the information; you likely have something else in mind for this part.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;// How to check if nonlinear fit succeeded?
r = nonlinear &amp;lt;&amp;lt; report;
alltext = r[Outline Box("Control Panel")] &amp;lt;&amp;lt; get text;
if (contains(alltext, "Cannot Decrease"), caption ("Failed: Cannot Decrease ..."));&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 13 Feb 2023 21:28:25 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Nonlinear-Fit-How-to-check-for-success/m-p/600622#M80404</guid>
      <dc:creator>Jed_Campbell</dc:creator>
      <dc:date>2023-02-13T21:28:25Z</dc:date>
    </item>
    <item>
      <title>Re: Nonlinear Fit - How to check for success?</title>
      <link>https://community.jmp.com/t5/Discussions/Nonlinear-Fit-How-to-check-for-success/m-p/600846#M80420</link>
      <description>&lt;P&gt;That'll do it.&amp;nbsp; Thanks Jed!&lt;/P&gt;</description>
      <pubDate>Tue, 14 Feb 2023 12:25:10 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Nonlinear-Fit-How-to-check-for-success/m-p/600846#M80420</guid>
      <dc:creator>AApperson</dc:creator>
      <dc:date>2023-02-14T12:25:10Z</dc:date>
    </item>
    <item>
      <title>Re: Nonlinear Fit - How to check for success?</title>
      <link>https://community.jmp.com/t5/Discussions/Nonlinear-Fit-How-to-check-for-success/m-p/601016#M80443</link>
      <description>&lt;P&gt;I wonder if a better check is if the text is anything other than success:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;If( Not( Contains( alltext, "Converged" ) ),
	// trap failure
	,
	// proceed after success
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 14 Feb 2023 19:27:20 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Nonlinear-Fit-How-to-check-for-success/m-p/601016#M80443</guid>
      <dc:creator>Mark_Bailey</dc:creator>
      <dc:date>2023-02-14T19:27:20Z</dc:date>
    </item>
    <item>
      <title>Re: Nonlinear Fit - How to check for success?</title>
      <link>https://community.jmp.com/t5/Discussions/Nonlinear-Fit-How-to-check-for-success/m-p/601121#M80448</link>
      <description>&lt;P&gt;You are closer to where I am heading with it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've been working with:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;if (contains(alltext, "Failed"), caption ("Failed: Do additional action now ..."));&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;As a catch all, but I'm considering adding more of a case statement (or I guess multiple 'ifs'), to specifically handle the fail reason.&lt;CODE class=" language-jsl"&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-jsl"&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;e.g. I can run again with a higher iteration count if I catch this fail-reason:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;contains(alltext, "Maximum Iteration Exceeded");&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The real motivation is, 'most' parts will converge with a numerical approach, but some seem to require analytical.&amp;nbsp; I'm not sure what's happening to cause this.&amp;nbsp; Convergence criteria?&amp;nbsp; But the 'fix' is to run again without numerical derivatives, something like:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;nonlinear = dt &amp;lt;&amp;lt; Nonlinear(
	Y(  :Name( "Random" ) ),
	X( :Name("FancyPredictionFormula") ),
	Expand Intermediate Formulas( 1 ),
	Newton,
	Finish,
	Plot( 0 ),
	Confidence Limits,
	Save Estimates
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;After catching with:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;contains(alltext, "Cannot Decrease Objective Function");&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 14 Feb 2023 21:53:21 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Nonlinear-Fit-How-to-check-for-success/m-p/601121#M80448</guid>
      <dc:creator>AApperson</dc:creator>
      <dc:date>2023-02-14T21:53:21Z</dc:date>
    </item>
    <item>
      <title>Re: Nonlinear Fit - How to check for success?</title>
      <link>https://community.jmp.com/t5/Discussions/Nonlinear-Fit-How-to-check-for-success/m-p/601522#M80489</link>
      <description>&lt;P&gt;The usual culprit behind failing to converge is the starting parameter values. It is often sufficient to use domain-specific heuristics to initialize them when available.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Feb 2023 16:58:52 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Nonlinear-Fit-How-to-check-for-success/m-p/601522#M80489</guid>
      <dc:creator>Mark_Bailey</dc:creator>
      <dc:date>2023-02-15T16:58:52Z</dc:date>
    </item>
  </channel>
</rss>

