Introduction
Introduction
Symbolic Regression is a methodology for functional identification, where an analytical expression is constructed such that it fits a given data set, typically obtained as a result of an experiment or an engineering test. Genetic Programming has been used in the past to discover empirical Physics Laws. Being in general NP-hard, Symbolic Regression may employ Dimensional Analysis in an attempt to improve its computational efficiency. This work explores the possibility of using Dimensional Analysis to facilitate the search for analytical functions that fit the mystery data. A brute force strategy is employed to pursue the discovery of potential candidates for the formula of the quantity of interest (QoI).
The Wolfram Language data set with the Laws of Physics and their physical quantities
The Wolfram Language data set with the Laws of Physics and their physical quantities
The Wolfram Language (WL) has an impressive repository of equations expressing known Laws of Physics. They can be accessed using the WL function FormulaData[ ]. For the purpose of the present study, the repository is used as a formula provider.
An array with the names of the laws in the repository is constructed as allTheLawsNames, together with an Association, allTheLaws, which links a given QoI to its analytical formula expressed using various physical quantities.
An array with the names of the laws in the repository is constructed as allTheLawsNames, together with an Association, allTheLaws, which links a given QoI to its analytical formula expressed using various physical quantities.
In[]:=
allTheLawsNames=Delete[FormulaData[],{{88},{107},{197},{242},{537},{538},{657},{658},{722},{723}}];(*thereareissueswiththedefinitionsofthephysicalquantitiesexcludedabove;bugreportedtoWolfram*)allTheLaws=FormulaData[#,"Association"]&/@allTheLawsNames;
A list is then created with all the equations of the known Laws of Physics, as well as a list holding all the functions which appear in those equations:
In[]:=
allTheLawsEqs=FormulaData[#]&/@allTheLawsNames;exprFunctions=Cases[allTheLawsEqs,(head_)[___]:>head,All];
Finally, a list of the groups of quantities intervening in each law is compiled:
In[]:=
allTheLawsTerms=FormulaData[#,"QuantityVariables"]&/@allTheLawsNames;
Selection of a Law of Physics for the study
Selection of a Law of Physics for the study
An arbitrary but significant law is sought,for instance the Newton’s Gravity Law. Because it is assumed that its formula label is not known a priori, a lookup will narrow the search:
In[]:=
FormulaLookup["Newton"]
Out[]=
{NewtonsLawOfCooling,NewtonsLawOfUniversalGravitation,NewtonsSecondLawConstantMass}
The precise WL name is then selected from the previous short list.
In[]:=
selectedLawName="NewtonsLawOfUniversalGravitation";
The LHS and the RHS terms of the formula for the selected law are extracted:
In[]:=
selectedLawEqLHS=Extract[Extract[#,{1}]&/@allTheLawsEqs[[Flatten@Position[allTheLawsNames,selectedLawName]]],{1}]selectedLawEqRHS=Extract[Extract[#,{2}]&/@allTheLawsEqs[[Flatten@Position[allTheLawsNames,selectedLawName]]],{1}]
Out[]=
F
Out[]=
m
1
m
2
2
r
The list of quantities for the selected law is:
In[]:=
selectedLawEqRHSTerms=Rest@Flatten@allTheLawsTerms[[Flatten@Position[allTheLawsNames,selectedLawName]]]
Out[]=
{,,}
r
m
1
m
2
The following is a helper function that assigns a given QuantityValue numerical values:
In[]:=
setQuantValue[quant_,vals_]:=quant->Quantity[vals,QuantityVariableCanonicalUnit[quant]];
Next, the data to be used for the Symbolic Regression process is compiled. For the selected Physics law - NewtonsLawOfUniversalGravitation - the data are three arrays corresponding to the dependent physical quantities, r, , and , respectively. Alternatively, in practice, these data may be read in from a plain text file.
m
1
m
2
In[]:=
dataSize=1000;quantData=RandomReal[{100.,},dataSize], RandomReal[{1000.,},dataSize], RandomReal[{10.,10000.},dataSize];
8
10.
20
10.
Using these data, the corresponding values of the QoI - F in this case - are calculated.
In[]:=
quantDataUnits=MapThread[setQuantValue[#1,#2]&,{selectedLawEqRHSTerms,quantData}];qoiDataUnits=FormulaData[selectedLawName,quantDataUnits];qoiDataUnits//Short
Out[]//Short=
F
For the purpose of the Symbolic Regression computations, the numerical data for the QoI are assigned to the vector
In[]:=
qoiData=QuantityMagnitude[qoiDataUnits[[2]]];
The distribution of the usage of the standard mathematical functions
The distribution of the usage of the standard mathematical functions
A list with all the standard mathematical functions is given by:
In[]:=
intrinsicMathFunctions=Symbol/@EntityValue[EntityClass["WolframLanguageSymbol","Attributes"->Entity["WolframLanguageSymbol","NumericFunction"]],"Name"];
Intersecting the list of terms with the list of standard mathematical functions, determine which of the latter are used in the Physics laws of the Wolfram Language repository:
In[]:=
commonFunctions=Intersection[exprFunctions,intrinsicMathFunctions]
Out[]=
{Abs,ArcCos,ArcCosh,ArcSec,ArcSin,ArcSinh,ArcTan,ArcTanh,BesselJ,BesselJZero,ChebyshevU,Cos,Cosh,Cot,Csc,EllipticE,EllipticK,Erfc,Factorial,Gamma,Haversine,InverseErf,Log,Max,Min,Plus,Power,Sin,Sinc,Sinh,Tan,Tanh,Times,ZernikeR,Zeta}
Next, it is determined the number of occurrences of each of the standard mathematical functions in the laws of Physics of the Wolfram Language repository, then generate a list that reflects these occurrences.
In[]:=
occMathFunction=Count[exprFunctions,#]&/@intrinsicMathFunctions;mathFunctionsWordCloudData=Flatten[MapThread[ConstantArray[#1,#2]&,{intrinsicMathFunctions,occMathFunction}]];
A word cloud visually reflects the distribution of the standard mathematical functions in the formulae of the Laws of Physics known to the Wolfram Language:
In[]:=
WordCloud[mathFunctionsWordCloudData]
Out[]=
An ordered list with the elements of the above word cloud is also created, with the most utilized functions first.
In[]:=
fPool=SortBy[MapThread[ConstantArray[#1,#2]&,{intrinsicMathFunctions,occMathFunction}],Length[#&]];mathFunctions=Map[First,Reverse[Take[fPool,-(Length[fPool]-Count[fPool,{}])]]]
Out[]=
{Power,Times,Plus,Sin,Log,Cos,Tan,ArcTan,Abs,Csc,ArcSinh,ArcSin,Cot,BesselJZero,Sinc,Min,Max,Gamma,Zeta,InverseErf,Haversine,EllipticK,ArcCosh,Sinh,Cosh,ChebyshevU,BesselJ,ArcSec,ZernikeR,Tanh,Factorial,Erfc,EllipticE,ArcTanh,ArcCos}
An evaluation of performing Symbolic Regression of Physics data with units
An evaluation of performing Symbolic Regression of Physics data with units
The next step is to employ the data in the arrays quantDataUnits (numeric values in quantData) and qoiDataUnits (numeric values in qoiData) in a Symbolic Regression analysis and attempt to recover the expression of the NewtonsLawOfUniversalGravitation.
An array of the topmost frequently used mathematical functions is built and assume they only take a minimal number of arguments.
In[]:=
nmbFunc=3;
In[]:=
funcs=MapThread[{#1,#2}&,{Take[mathFunctions,{1,nmbFunc}],MapThread[If[#1>0,2,1]&,{StringCount[ToString[Values[SyntaxInformation[#][[1]]]],"___"]&/@Take[mathFunctions,{1,nmbFunc}],ConstantArray[1,nmbFunc]}]}]
Out[]=
{{Power,2},{Times,2},{Plus,2}}
A random expression generator is used
In[]:=
ClearAll[RandomExpression,randomElement]randomElement[list_]:=list[[Random[Integer,{1,Length[list]}]]]RandomExpression[1,funcs_,terms_]:=randomElement[terms]RandomExpression[depth_?Positive,funcs_,terms_]:=Module[{f,n},{f,n}=randomElement[funcs];If[n>0,f@@Table[RandomExpression[depth-1,funcs,terms],{n}],f]]Attributes[RandomExpression]={HoldRest};
The random expression generator is called recursively in order to compose an attempt regression formula for the select QoI. The recursion depth is taken to be one unit higher than the number of physical quantities the QoI is considered to depend upon.
In[]:=
recursionDepth=First@Dimensions[selectedLawEqRHSTerms]+1;SRCandidateLaw=RandomExpression[recursionDepth,funcs,selectedLawEqRHSTerms];ExpandAll[SRCandidateLaw]
Out[]=
2++
r
m
1
m
2
()
r
m
1
r
m
2
A dimensional analysis of the terms of the resulting formula can be performed. For example, looking at the first term of the candidate formula,
At this point few things can be noticed:
◼
depending on the structure of the candidate formula, the WL function QuantityVariableCanonicalUnit[ ] may be only partially evaluated or even return some warning messages. In the former case, the exception may be intercepted using a construct like
This returns True if the candidate formula SRCandidateLaw terms have a well-determined dimensional form, and False otherwise. Obviously, a candidate formula whose terms all have well-determined dimensions is going to be pursued, a False would lead to a rejection.
◼
The expressions generated with the simple set of WL functions funcs, is not producing terms in which quantities are involved in divisions. This would require expanding the functional catalog func using rules:
Re-running the random expression generator,
and the dimensional analysis
Although now divisions do appear in expression of the candidate formula, the issues related to using the WL function QuantityVariableCanonicalUnit[ ] as a dimensional test may indicate a certain brittleness of the approach.
It is therefore clear that a more involved algorithm that adequately treats the exceptions raised by QuantityVariableCanonicalUnit[ ] needs to be developed.
It is therefore clear that a more involved algorithm that adequately treats the exceptions raised by QuantityVariableCanonicalUnit[ ] needs to be developed.
Conclusions and future work
Conclusions and future work
The development of a robust approach for Symbolic Regression based on the WL’s current Dimensional Analysis capabilities proved to be a rather difficult task which will require a sustained effort and more time (than the one for this Summer School). It is possible that the construction of the candidate formulae using the random expression generator may have to be done intrinsically consistent with the units system. That may constrain the expression generator to produce completely unviable formulae which have a low probability of having terms of consistent dimensions. It is therefore imperative to re-think the strategy for the random expression generator.
Alternatively, the approach which was studied earlier during this Summer School, constructed based on a design space contraction using Dimensional Analysis to find non-dimensional ratios, should be re-visited. Feeding non-dimensional terms into the random expression generator will ensure that it always operates with dimensionally consistent quantities. The need for constantly testing the terms of the resulting candidate formulae is therefore obviated. Moreover, that method turned out to lead directly to the desired QoI expression in many simple cases for Laws of Physics where the sought equation is dominated by multiplications of the physical quantities. Last but not least, the use of various Machine Learning methods should be seriously considered.
It is now time to return at the drawing board and build on top of the analytical foundation presented above.
Alternatively, the approach which was studied earlier during this Summer School, constructed based on a design space contraction using Dimensional Analysis to find non-dimensional ratios, should be re-visited. Feeding non-dimensional terms into the random expression generator will ensure that it always operates with dimensionally consistent quantities. The need for constantly testing the terms of the resulting candidate formulae is therefore obviated. Moreover, that method turned out to lead directly to the desired QoI expression in many simple cases for Laws of Physics where the sought equation is dominated by multiplications of the physical quantities. Last but not least, the use of various Machine Learning methods should be seriously considered.
It is now time to return at the drawing board and build on top of the analytical foundation presented above.