6
$\begingroup$

Bug introduced in 10.2 and fixed in 10.3


In the documentation of FindFormula, the first application of it is to predict the population of Poland.

data = EntityValue[Entity["Country", "Poland"], 
EntityProperty["Country", 
"Population", {"Date" -> 
Interval[{DateObject[{1950}], DateObject[{2015}]}]}]]
fit = FindFormula[data, x]

However, when I tried to run the code, it did not work and gave the following error:

FindFormula::wrgfmt: Argument {{QuantityMagnitude[Sun 1 Jan 1950 00:00:00GMT+8.],2.4824*10^7},{QuantityMagnitude[Mon 1 Jan 1951 00:00:00GMT+8.],2.52623*10^7},<<47>>,{QuantityMagnitude[Fri 1 Jan 1999 00:00:00GMT+8.],3.8336*10^7},<<16>>} at position 1 does not have the right format. Data should be a numerical array of depth less or equal than 2. >>

It seems that QuantityMagnitude cannot deal with that DateObject, but AbsoluteTime will do the job. My idea to fix this is to change some Mathematica code in FindFormula. I tried Information[FindFormula], but it returned a lot of private packages, and I don't know how to track down then. Is there any workaround to get FindFormula to work with these population data?

$\endgroup$
  • $\begingroup$ Have you tried converting the dates into something like AbsoluteTime[] instead and fitting with that? $\endgroup$ – J. M. will be back soon Jul 27 '15 at 4:37
  • $\begingroup$ Yes, I noticed this too. The documentation says FindFormula is experimental. I guess that means "beta", and the docs are out of sync with the development. Many of the other FindFormula documentation examples don't give the same output that's shown in the documentation. $\endgroup$ – Szabolcs Jul 27 '15 at 7:20
  • $\begingroup$ You might try fit = FindFormula[data // Normal, x]. I can't test this, I don't have V10.2 $\endgroup$ – m_goldberg Jul 27 '15 at 7:22
  • 4
    $\begingroup$ @Szabolcs The differences when evaluating the examples are because FindFormula uses stochastic algorithms with randomized seeds. There is a "RandomSeed" option that should make the function give the same answers always, but it's currently not working properly. $\endgroup$ – Stefan R Jul 27 '15 at 18:35
  • 1
    $\begingroup$ As to the question posed: This is a bug in FindFormula in 10.2 which we are aware of. $\endgroup$ – Stefan R Jul 27 '15 at 18:40
4
$\begingroup$

With J. M.'s idea, there is a temporary workaround to convert population data to lists and make it work with FindFormula. Assume data has been set like in the question.

data2 = Transpose[{(AbsoluteTime /@ 
      List /@ Range[First@#[[1]], First@#[[2]], 
        First@#[[3]]]) &[#[[2]]], #[[1]]}] &[
Flatten[data[[2]][[1 ;; 2]], 1]];
FindFormula[data2, x]

piecewise function

For some unknown reasons, this result is not the same as that in the doc. And the plot in the doc will be modified to this

ListPlot[MapAt[QuantityMagnitude, #, 2] & /@ data2]

the plot

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.