diff options
author | Erich Eckner <git@eckner.net> | 2018-12-17 14:03:00 +0100 |
---|---|---|
committer | Erich Eckner <git@eckner.net> | 2018-12-17 14:03:00 +0100 |
commit | 64a36696d14c11b5cb28d811bb5b13613e4604ec (patch) | |
tree | 44e43cdc355bb32eee4fc5861ba67fd00d5579f4 | |
parent | a88a9cd73027bde05d3ec30649e8be44a7080e97 (diff) | |
download | epost-64a36696d14c11b5cb28d811bb5b13613e4604ec.tar.xz |
externes optimierung.pas verwenden um 2dGausze zu fitten
-rw-r--r-- | epost.lpi | 10 | ||||
-rw-r--r-- | epost.lps | 256 | ||||
-rw-r--r-- | epostunit.pas | 39 | ||||
-rw-r--r-- | gausz2d.nb | 375 | ||||
-rw-r--r-- | gauszFit.inc | 51 | ||||
-rw-r--r-- | werteunit.pas | 282 |
6 files changed, 608 insertions, 405 deletions
@@ -36,7 +36,7 @@ <PackageName Value="LazUtils"/> </Item1> </RequiredPackages> - <Units Count="9"> + <Units Count="11"> <Unit0> <Filename Value="epost.lpr"/> <IsPartOfProject Value="True"/> @@ -73,6 +73,14 @@ <Filename Value="werteunit.inc"/> <IsPartOfProject Value="True"/> </Unit8> + <Unit9> + <Filename Value="../units/optimierung.pas"/> + <IsPartOfProject Value="True"/> + </Unit9> + <Unit10> + <Filename Value="../units/optimierung.inc"/> + <IsPartOfProject Value="True"/> + </Unit10> </Units> </ProjectOptions> <CompilerOptions> @@ -3,11 +3,12 @@ <ProjectSession> <Version Value="10"/> <BuildModes Active="Default"/> - <Units Count="26"> + <Units Count="27"> <Unit0> <Filename Value="epost.lpr"/> <IsPartOfProject Value="True"/> - <CursorPos X="54" Y="13"/> + <TopLine Value="176"/> + <CursorPos X="31" Y="194"/> <UsageCount Value="202"/> <Loaded Value="True"/> </Unit0> @@ -22,8 +23,8 @@ <Filename Value="epostunit.pas"/> <IsPartOfProject Value="True"/> <EditorIndex Value="1"/> - <TopLine Value="6927"/> - <CursorPos X="25" Y="6956"/> + <TopLine Value="3890"/> + <CursorPos X="15" Y="3893"/> <UsageCount Value="201"/> <Loaded Value="True"/> </Unit2> @@ -31,17 +32,17 @@ <Filename Value="werteunit.pas"/> <IsPartOfProject Value="True"/> <EditorIndex Value="2"/> - <TopLine Value="961"/> - <CursorPos X="18" Y="977"/> + <TopLine Value="1716"/> + <CursorPos X="25" Y="1736"/> <UsageCount Value="200"/> <Loaded Value="True"/> </Unit3> <Unit4> <Filename Value="typenunit.pas"/> <IsPartOfProject Value="True"/> - <EditorIndex Value="4"/> - <TopLine Value="3"/> - <CursorPos X="3" Y="21"/> + <EditorIndex Value="6"/> + <TopLine Value="4"/> + <CursorPos Y="20"/> <UsageCount Value="200"/> <Loaded Value="True"/> </Unit4> @@ -64,8 +65,8 @@ <Unit7> <Filename Value="gauszFit.inc"/> <IsPartOfProject Value="True"/> - <IsVisibleTab Value="True"/> - <EditorIndex Value="3"/> + <EditorIndex Value="5"/> + <CursorPos X="9" Y="17"/> <UsageCount Value="201"/> <Loaded Value="True"/> </Unit7> @@ -78,236 +79,249 @@ <UsageCount Value="200"/> </Unit8> <Unit9> + <Filename Value="../units/optimierung.pas"/> + <IsPartOfProject Value="True"/> + <IsVisibleTab Value="True"/> + <EditorIndex Value="3"/> + <UsageCount Value="28"/> + <Loaded Value="True"/> + </Unit9> + <Unit10> <Filename Value="fileunit.pas"/> <EditorIndex Value="-1"/> <CursorPos Y="204"/> - <UsageCount Value="194"/> - </Unit9> - <Unit10> + <UsageCount Value="193"/> + </Unit10> + <Unit11> <Filename Value="../units/mystringlistunit.pas"/> <EditorIndex Value="-1"/> <TopLine Value="712"/> <CursorPos X="22" Y="735"/> - <UsageCount Value="94"/> - </Unit10> - <Unit11> + <UsageCount Value="93"/> + </Unit11> + <Unit12> <Filename Value="../units/lowlevelunit.pas"/> <EditorIndex Value="-1"/> <TopLine Value="16"/> - <UsageCount Value="98"/> - </Unit11> - <Unit12> + <UsageCount Value="97"/> + </Unit12> + <Unit13> <Filename Value="../units/matheunit.pas"/> <EditorIndex Value="-1"/> <TopLine Value="1045"/> <CursorPos X="28" Y="1045"/> - <UsageCount Value="99"/> - </Unit12> - <Unit13> + <UsageCount Value="98"/> + </Unit13> + <Unit14> <Filename Value="../units/systemunit.pas"/> <EditorIndex Value="-1"/> <TopLine Value="190"/> <CursorPos X="22" Y="195"/> - <UsageCount Value="98"/> - </Unit13> - <Unit14> + <UsageCount Value="97"/> + </Unit14> + <Unit15> <Filename Value="/usr/lib/fpc/src/rtl/inc/objpash.inc"/> <EditorIndex Value="-1"/> <TopLine Value="176"/> <CursorPos X="23" Y="194"/> - <UsageCount Value="4"/> - </Unit14> - <Unit15> + <UsageCount Value="3"/> + </Unit15> + <Unit16> <Filename Value="/usr/lib/fpc/src/rtl/unix/bunxovlh.inc"/> <EditorIndex Value="-1"/> <TopLine Value="61"/> <CursorPos X="10" Y="99"/> - <UsageCount Value="9"/> - </Unit15> - <Unit16> + <UsageCount Value="8"/> + </Unit16> + <Unit17> <Filename Value="/usr/lib/fpc/src/rtl/unix/baseunix.pp"/> <UnitName Value="BaseUnix"/> <EditorIndex Value="-1"/> <TopLine Value="61"/> - <UsageCount Value="9"/> - </Unit16> - <Unit17> + <UsageCount Value="8"/> + </Unit17> + <Unit18> <Filename Value="/usr/lib/fpc/src/rtl/unix/bunxovl.inc"/> <EditorIndex Value="-1"/> <TopLine Value="414"/> <CursorPos X="20" Y="434"/> - <UsageCount Value="9"/> - </Unit17> - <Unit18> + <UsageCount Value="8"/> + </Unit18> + <Unit19> <Filename Value="/usr/lib/fpc/src/rtl/linux/bunxsysc.inc"/> <EditorIndex Value="-1"/> <TopLine Value="16"/> - <UsageCount Value="9"/> - </Unit18> - <Unit19> + <UsageCount Value="8"/> + </Unit19> + <Unit20> <Filename Value="/usr/lib/fpc/src/rtl/unix/bunxh.inc"/> <EditorIndex Value="-1"/> <TopLine Value="74"/> <CursorPos X="15" Y="102"/> - <UsageCount Value="9"/> - </Unit19> - <Unit20> + <UsageCount Value="8"/> + </Unit20> + <Unit21> <Filename Value="/usr/lib/fpc/src/packages/fcl-image/src/fpimage.pp"/> <UnitName Value="FPimage"/> <EditorIndex Value="-1"/> <TopLine Value="10"/> <CursorPos X="3" Y="30"/> - <UsageCount Value="9"/> - </Unit20> - <Unit21> - <Filename Value="/usr/lib/fpc/src/rtl/objpas/math.pp"/> - <EditorIndex Value="-1"/> - <TopLine Value="351"/> - <CursorPos X="10" Y="368"/> - <UsageCount Value="0"/> + <UsageCount Value="8"/> </Unit21> <Unit22> - <Filename Value="GTIWebServerTestAggActionHandlerUnit.pas"/> - <EditorIndex Value="-1"/> - <TopLine Value="53"/> - <CursorPos X="49" Y="82"/> - <UsageCount Value="0"/> - </Unit22> - <Unit23> <Filename Value="../units/protokollunit.pas"/> <EditorIndex Value="-1"/> <TopLine Value="18"/> <CursorPos X="3" Y="18"/> - <UsageCount Value="43"/> - </Unit23> - <Unit24> + <UsageCount Value="42"/> + </Unit22> + <Unit23> <Filename Value="../fpGUI/src/corelib/render/software/agg_2D.pas"/> <EditorIndex Value="-1"/> <TopLine Value="2116"/> <CursorPos X="2" Y="2134"/> - <UsageCount Value="8"/> - </Unit24> - <Unit25> + <UsageCount Value="7"/> + </Unit23> + <Unit24> <Filename Value="../units/randomunit.pas"/> <EditorIndex Value="-1"/> <CursorPos X="19" Y="11"/> - <UsageCount Value="8"/> + <UsageCount Value="7"/> + </Unit24> + <Unit25> + <Filename Value="epost.lpi"/> + <EditorIndex Value="-1"/> + <UsageCount Value="9"/> + <DefaultSyntaxHighlighter Value="XML"/> </Unit25> + <Unit26> + <Filename Value="../units/optimierung.inc"/> + <IsPartOfProject Value="True"/> + <EditorIndex Value="4"/> + <CursorPos X="3" Y="2"/> + <UsageCount Value="24"/> + <Loaded Value="True"/> + </Unit26> </Units> - <JumpHistory Count="29" HistoryIndex="28"> + <JumpHistory Count="30" HistoryIndex="29"> <Position1> - <Filename Value="werteunit.pas"/> - <Caret Line="1753" Column="35" TopLine="1735"/> + <Filename Value="../units/optimierung.pas"/> + <Caret Line="182" Column="32" TopLine="165"/> </Position1> <Position2> - <Filename Value="werteunit.pas"/> - <Caret Line="1709" Column="13" TopLine="1684"/> + <Filename Value="../units/optimierung.pas"/> + <Caret Line="188" Column="34" TopLine="171"/> </Position2> <Position3> - <Filename Value="werteunit.pas"/> - <Caret Line="1706" Column="27" TopLine="1686"/> + <Filename Value="../units/optimierung.pas"/> + <Caret Line="197" Column="34" TopLine="180"/> </Position3> <Position4> - <Filename Value="werteunit.pas"/> - <Caret Line="1707" Column="57" TopLine="1689"/> + <Filename Value="../units/optimierung.pas"/> + <Caret Line="207" Column="11" TopLine="190"/> </Position4> <Position5> <Filename Value="werteunit.pas"/> - <Caret Line="1680" Column="35" TopLine="1663"/> + <Caret Line="1664" TopLine="1651"/> </Position5> <Position6> - <Filename Value="werteunit.pas"/> - <Caret Line="81" Column="77" TopLine="65"/> + <Filename Value="../units/optimierung.pas"/> + <Caret Line="165" Column="29" TopLine="150"/> </Position6> <Position7> - <Filename Value="werteunit.pas"/> + <Filename Value="../units/optimierung.pas"/> + <Caret Line="207" Column="61" TopLine="189"/> </Position7> <Position8> - <Filename Value="werteunit.pas"/> - <Caret Line="81" Column="77" TopLine="53"/> + <Filename Value="../units/optimierung.pas"/> + <Caret Line="13" Column="70"/> </Position8> <Position9> - <Filename Value="werteunit.pas"/> - <Caret Line="1623" Column="82" TopLine="1595"/> + <Filename Value="../units/optimierung.pas"/> + <Caret Line="65" Column="70" TopLine="48"/> </Position9> <Position10> - <Filename Value="werteunit.pas"/> - <Caret Line="1633" Column="26" TopLine="1605"/> + <Filename Value="../units/optimierung.pas"/> + <Caret Line="165" Column="29" TopLine="152"/> </Position10> <Position11> - <Filename Value="werteunit.pas"/> - <Caret Line="1634" Column="98" TopLine="1606"/> + <Filename Value="../units/optimierung.pas"/> + <Caret Line="321" Column="14" TopLine="296"/> </Position11> <Position12> - <Filename Value="werteunit.pas"/> - <Caret Line="1678" Column="37" TopLine="1652"/> + <Filename Value="../units/optimierung.pas"/> + <Caret Line="379" Column="23" TopLine="351"/> </Position12> <Position13> - <Filename Value="werteunit.pas"/> + <Filename Value="../units/optimierung.pas"/> </Position13> <Position14> - <Filename Value="werteunit.pas"/> - <Caret Line="81" Column="77" TopLine="53"/> + <Filename Value="../units/optimierung.pas"/> + <Caret Line="52" Column="35" TopLine="23"/> </Position14> <Position15> - <Filename Value="werteunit.pas"/> - <Caret Line="1623" Column="82" TopLine="1595"/> + <Filename Value="../units/optimierung.pas"/> + <Caret Line="244" Column="39" TopLine="238"/> </Position15> <Position16> - <Filename Value="gauszFit.inc"/> - <Caret Line="18" Column="10"/> + <Filename Value="../units/optimierung.pas"/> + <Caret Line="248" Column="24" TopLine="238"/> </Position16> <Position17> - <Filename Value="gauszFit.inc"/> - <Caret Line="17" Column="65"/> + <Filename Value="../units/optimierung.pas"/> + <Caret Line="293" Column="12" TopLine="264"/> </Position17> <Position18> - <Filename Value="werteunit.pas"/> - <Caret Line="1687" Column="30" TopLine="1629"/> + <Filename Value="../units/optimierung.pas"/> + <Caret Line="310" Column="21" TopLine="281"/> </Position18> <Position19> - <Filename Value="typenunit.pas"/> - <Caret Line="21" Column="3" TopLine="3"/> + <Filename Value="../units/optimierung.pas"/> + <Caret Line="316" Column="25" TopLine="294"/> </Position19> <Position20> - <Filename Value="werteunit.pas"/> - <Caret Line="1842" Column="12" TopLine="1815"/> + <Filename Value="../units/optimierung.pas"/> + <Caret Line="49" Column="5" TopLine="31"/> </Position20> <Position21> - <Filename Value="epostunit.pas"/> - <Caret Line="3870" Column="44" TopLine="3870"/> + <Filename Value="../units/optimierung.pas"/> + <Caret Line="324" Column="13" TopLine="300"/> </Position21> <Position22> - <Filename Value="epostunit.pas"/> - <Caret Line="7930" Column="16" TopLine="7901"/> + <Filename Value="../units/optimierung.pas"/> + <Caret Line="382" Column="23" TopLine="354"/> </Position22> <Position23> - <Filename Value="epostunit.pas"/> - <Caret Line="2590" Column="40" TopLine="2573"/> + <Filename Value="../units/optimierung.pas"/> </Position23> <Position24> - <Filename Value="epostunit.pas"/> + <Filename Value="../units/optimierung.pas"/> + <Caret Line="52" Column="35" TopLine="23"/> </Position24> <Position25> - <Filename Value="epostunit.pas"/> - <Caret Line="2590" Column="40" TopLine="2562"/> + <Filename Value="../units/optimierung.pas"/> + <Caret Line="247" Column="38" TopLine="226"/> </Position25> <Position26> - <Filename Value="epostunit.pas"/> - <Caret Line="2591" Column="35" TopLine="2563"/> + <Filename Value="../units/optimierung.pas"/> + <Caret Line="224" Column="30" TopLine="369"/> </Position26> <Position27> - <Filename Value="epostunit.pas"/> - <Caret Line="2598" Column="55" TopLine="2570"/> + <Filename Value="../units/optimierung.pas"/> + <Caret Line="52" Column="15" TopLine="34"/> </Position27> <Position28> - <Filename Value="epostunit.pas"/> - <Caret Line="6954" Column="9" TopLine="6925"/> + <Filename Value="../units/optimierung.pas"/> + <Caret Line="247" Column="24" TopLine="228"/> </Position28> <Position29> - <Filename Value="epostunit.pas"/> - <Caret Line="6955" Column="31" TopLine="6926"/> + <Filename Value="../units/optimierung.pas"/> + <Caret Line="224" Column="9" TopLine="212"/> </Position29> + <Position30> + <Filename Value="../units/optimierung.pas"/> + <Caret Line="223" Column="30" TopLine="194"/> + </Position30> </JumpHistory> </ProjectSession> <Debugging> diff --git a/epostunit.pas b/epostunit.pas index 91d8a55..d75eba8 100644 --- a/epostunit.pas +++ b/epostunit.pas @@ -3821,12 +3821,12 @@ end; function tWerte.fitte2dGausze(sT: boolean; f: tMyStringList): boolean; var bekannteBefehle: tMyStringList; - Zeit,offset,relVerb: extended; - anzahl,i: longint; + Zeit,relVerb: extended; + anzahl,i,j: longint; schritte,maximalSamples: int64; s,datei: string; pDatei: textFile; - parameter: tGausz2dParameterArray; + parameter: tExtendedArray; residuenBerechnen: boolean; begin result:=false; @@ -3890,38 +3890,35 @@ begin case genauigkeit of gSingle: - schritte:=sWerte.gauszFit2d(anzahl,maximalSamples,relVerb,offset,parameter); + schritte:=sWerte.gauszFit2d(anzahl,maximalSamples,relVerb,parameter); gDouble: - schritte:=dWerte.gauszFit2d(anzahl,maximalSamples,relVerb,offset,parameter); + schritte:=dWerte.gauszFit2d(anzahl,maximalSamples,relVerb,parameter); gExtended: - schritte:=eWerte.gauszFit2d(anzahl,maximalSamples,relVerb,offset,parameter); + schritte:=eWerte.gauszFit2d(anzahl,maximalSamples,relVerb,parameter); end{of case}; gibAus('... das waren '+intToStr(schritte)+' Schritte, Parameter speichern ...',3); assignFile(pDatei,datei); rewrite(pDatei); - writeln(pDatei,myFloatToStr(offset)); - for i:=0 to length(parameter)-1 do - with parameter[i] do - writeln( - pDatei, - myFloatToStr(xx)+' '+ - myFloatToStr(yy)+' '+ - myFloatToStr(x0)+' '+ - myFloatToStr(y0)+' '+ - myFloatToStr(a)+' '+ - myFloatToStr(e) - ); + writeln(pDatei,myFloatToStr(parameter[0])); + for i:=0 to anzahl-1 do begin + for j:=0 to 5 do begin + if j>0 then + write(pDatei,' '); + write(pDatei,myFloatToStr(parameter[1+6*i+j])); + end; + writeln(pDatei); + end; closeFile(pDatei); if residuenBerechnen then begin gibAus('... Residuen berechnen ...',3); case genauigkeit of gSingle: - sWerte.gausz2dSubtrahieren(offset,parameter); + sWerte.gausz2dSubtrahieren(parameter); gDouble: - dWerte.gausz2dSubtrahieren(offset,parameter); + dWerte.gausz2dSubtrahieren(parameter); gExtended: - eWerte.gausz2dSubtrahieren(offset,parameter); + eWerte.gausz2dSubtrahieren(parameter); end{of case}; end; gibAus('... fertig '+timetostr(now-Zeit),3); @@ -10,10 +10,10 @@ NotebookFileLineBreakTest NotebookFileLineBreakTest NotebookDataPosition[ 157, 7] -NotebookDataLength[ 14942, 432] -NotebookOptionsPosition[ 14435, 410] -NotebookOutlinePosition[ 14773, 425] -CellTagsIndexPosition[ 14730, 422] +NotebookDataLength[ 27278, 762] +NotebookOptionsPosition[ 26135, 735] +NotebookOutlinePosition[ 26550, 751] +CellTagsIndexPosition[ 26507, 748] WindowFrame->Normal*) (* Beginning of Notebook Content *) @@ -22,6 +22,12 @@ Notebook[{ Cell[CellGroupData[{ Cell[BoxData[{ RowBox[{ + RowBox[{"Clear", "[", + RowBox[{"Evaluate", "[", + RowBox[{ + RowBox[{"Context", "[", "]"}], "<>", "\"\<*\>\""}], "]"}], "]"}], + ";"}], "\[IndentingNewLine]", + RowBox[{ RowBox[{ RowBox[{"arg2d", "[", "r_", "]"}], ":=", RowBox[{ @@ -86,8 +92,9 @@ Cell[BoxData[{ RowBox[{"y", "-", "y0"}]}], "]"}]}], ")"}], "^", "2"}], ",", "#"}], "]"}], "&"}], ",", RowBox[{"{", - RowBox[{"of", ",", "e", ",", "xx", ",", "yy", ",", "x0", ",", "y0"}], - "}"}]}], "]"}]}], ";"}], "\[IndentingNewLine]", + RowBox[{ + "of", ",", "e", ",", "xx", ",", "yy", ",", "x0", ",", "y0", ",", + "\[Alpha]"}], "}"}]}], "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"grad", "=", RowBox[{"grad", "/.", @@ -201,7 +208,10 @@ Cell[BoxData[{ 3.753614614991173*^9, 3.7536147276984167`*^9}, {3.753615313269506*^9, 3.753615326654551*^9}, {3.753615384419899*^9, 3.753615414088451*^9}, { 3.753615580614621*^9, 3.753615740712741*^9}, {3.7536157813953323`*^9, - 3.753615786308958*^9}, {3.7536158874108458`*^9, 3.7536160378832207`*^9}}], + 3.753615786308958*^9}, {3.7536158874108458`*^9, 3.7536160378832207`*^9}, { + 3.753675831337633*^9, 3.7536758318774357`*^9}, {3.753693682122699*^9, + 3.753693692881207*^9}}, + CellLabel->"In[18]:=",ExpressionUUID->"14171ecc-591a-4b96-af22-9f7860bde8cd"], Cell[CellGroupData[{ @@ -262,7 +272,11 @@ Cell[BoxData[ 3.753614692263749*^9, 3.753614728244631*^9}, 3.75361532702458*^9, { 3.753615392673814*^9, 3.753615414437355*^9}, 3.753615604136612*^9, { 3.753615728195951*^9, 3.7536157412988*^9}, 3.753615786835373*^9, - 3.75361588966605*^9, {3.753615931942144*^9, 3.75361603888466*^9}}], + 3.75361588966605*^9, {3.753615931942144*^9, 3.75361603888466*^9}, + 3.753675833094645*^9, 3.753693693517261*^9}, + CellLabel-> + "During evaluation of \ +In[18]:=",ExpressionUUID->"a0fcd95d-d8f4-4b41-af48-0f9b52476c1d"], Cell[BoxData[ InterpretationBox[ @@ -274,7 +288,11 @@ Cell[BoxData[ 3.753614692263749*^9, 3.753614728244631*^9}, 3.75361532702458*^9, { 3.753615392673814*^9, 3.753615414437355*^9}, 3.753615604136612*^9, { 3.753615728195951*^9, 3.7536157412988*^9}, 3.753615786835373*^9, - 3.75361588966605*^9, {3.753615931942144*^9, 3.75361603891079*^9}}], + 3.75361588966605*^9, {3.753615931942144*^9, 3.75361603888466*^9}, + 3.753675833094645*^9, 3.753693693520195*^9}, + CellLabel-> + "During evaluation of \ +In[18]:=",ExpressionUUID->"33c683e5-22cc-4c32-af0c-3f0c99474830"], Cell[BoxData[ TagBox[ @@ -328,7 +346,11 @@ Cell[BoxData[ 3.753614692263749*^9, 3.753614728244631*^9}, 3.75361532702458*^9, { 3.753615392673814*^9, 3.753615414437355*^9}, 3.753615604136612*^9, { 3.753615728195951*^9, 3.7536157412988*^9}, 3.753615786835373*^9, - 3.75361588966605*^9, {3.753615931942144*^9, 3.7536160389127817`*^9}}] + 3.75361588966605*^9, {3.753615931942144*^9, 3.75361603888466*^9}, + 3.753675833094645*^9, 3.7536936935228853`*^9}, + CellLabel-> + "During evaluation of \ +In[18]:=",ExpressionUUID->"afc8061c-203e-4634-8d5d-559be671b5eb"] }, Open ]], Cell[BoxData[ @@ -356,7 +378,34 @@ Cell[BoxData[ RowBox[{"2", " ", RowBox[{"(", RowBox[{ - RowBox[{"-", "y"}], "+", "y0"}], ")"}], " ", "yys"}]}]} + RowBox[{"-", "y"}], "+", "y0"}], ")"}], " ", "yys"}]}]}, + { + RowBox[{"2", " ", + RowBox[{"(", + RowBox[{"xx", "-", "yy"}], ")"}], " ", + RowBox[{"(", + RowBox[{"xx", "+", "yy"}], ")"}], " ", + RowBox[{"(", + RowBox[{ + RowBox[{ + RowBox[{"(", + RowBox[{"y", "-", "y0"}], ")"}], " ", + RowBox[{"Cos", "[", "\[Alpha]", "]"}]}], "+", + RowBox[{ + RowBox[{"(", + RowBox[{"x", "-", "x0"}], ")"}], " ", + RowBox[{"Sin", "[", "\[Alpha]", "]"}]}]}], ")"}], " ", + RowBox[{"(", + RowBox[{ + RowBox[{ + RowBox[{"(", + RowBox[{"x", "-", "x0"}], ")"}], " ", + RowBox[{"Cos", "[", "\[Alpha]", "]"}]}], "+", + RowBox[{ + RowBox[{"(", + RowBox[{ + RowBox[{"-", "y"}], "+", "y0"}], ")"}], " ", + RowBox[{"Sin", "[", "\[Alpha]", "]"}]}]}], ")"}]}]} }, GridBoxAlignment->{ "Columns" -> {{Center}}, "ColumnsIndexed" -> {}, "Rows" -> {{Baseline}}, @@ -379,7 +428,11 @@ Cell[BoxData[ 3.753614728264624*^9}, 3.753615327050393*^9, {3.753615392700618*^9, 3.7536154144500237`*^9}, 3.7536156041660557`*^9, {3.753615728219289*^9, 3.7536157416101847`*^9}, 3.753615787964911*^9, 3.753615889682477*^9, { - 3.7536159322147493`*^9, 3.7536160389144897`*^9}}], + 3.7536159322147493`*^9, 3.7536160389144897`*^9}, 3.7536758343040447`*^9, + 3.7536936935257397`*^9}, + CellLabel-> + "Out[34]//MatrixForm=",ExpressionUUID->"0d7de383-9a8d-4be7-b9bc-\ +bc103daa06be"], Cell[BoxData[ RowBox[{"{", @@ -405,12 +458,285 @@ Cell[BoxData[ 3.753614728264624*^9}, 3.753615327050393*^9, {3.753615392700618*^9, 3.7536154144500237`*^9}, 3.7536156041660557`*^9, {3.753615728219289*^9, 3.7536157416101847`*^9}, 3.753615787964911*^9, 3.753615889682477*^9, { - 3.7536159322147493`*^9, 3.7536160389162073`*^9}}] + 3.7536159322147493`*^9, 3.7536160389144897`*^9}, 3.7536758343040447`*^9, + 3.753693693528349*^9}, + CellLabel->"Out[35]=",ExpressionUUID->"6ecb8d93-2f3f-41ed-8550-c9e9ec844fcc"] +}, Open ]], + +Cell[CellGroupData[{ + +Cell[BoxData[{ + RowBox[{ + RowBox[{"Clear", "[", + RowBox[{"Evaluate", "[", + RowBox[{ + RowBox[{"Context", "[", "]"}], "<>", "\"\<*\>\""}], "]"}], "]"}], + ";"}], "\[IndentingNewLine]", + RowBox[{ + RowBox[{"n", "=", "2"}], ";"}], "\[IndentingNewLine]", + RowBox[{ + RowBox[{"parameter", "=", + RowBox[{"Join", "[", "\[IndentingNewLine]", + RowBox[{ + RowBox[{"{", "of", "}"}], ",", "\[IndentingNewLine]", + RowBox[{"Flatten", "@", + RowBox[{"Table", "[", "\[IndentingNewLine]", + RowBox[{ + RowBox[{"{", + RowBox[{ + RowBox[{"e", "[", "i", "]"}], ",", + RowBox[{"xx", "[", "i", "]"}], ",", + RowBox[{"yy", "[", "i", "]"}], ",", + RowBox[{"x0", "[", "i", "]"}], ",", + RowBox[{"y0", "[", "i", "]"}], ",", + RowBox[{"\[Alpha]", "[", "i", "]"}]}], "}"}], ",", + "\[IndentingNewLine]", + RowBox[{"{", + RowBox[{"i", ",", "1", ",", "n"}], "}"}]}], "\[IndentingNewLine]", + "]"}]}]}], "\[IndentingNewLine]", "]"}]}], + ";"}], "\[IndentingNewLine]", + RowBox[{ + RowBox[{ + RowBox[{"dxs", "[", "i_", "]"}], ":=", + RowBox[{"x", "-", + RowBox[{"x0", "[", "i", "]"}]}]}], ";"}], "\[IndentingNewLine]", + RowBox[{ + RowBox[{ + RowBox[{"dys", "[", "i_", "]"}], ":=", + RowBox[{"y", "-", + RowBox[{"y0", "[", "i", "]"}]}]}], ";"}], "\[IndentingNewLine]", + RowBox[{ + RowBox[{ + RowBox[{"xxs", "[", "i_", "]"}], ":=", + RowBox[{ + RowBox[{"-", + RowBox[{ + RowBox[{"(", + RowBox[{ + RowBox[{"xx", "[", "i", "]"}], + RowBox[{"Cos", "[", + RowBox[{"\[Alpha]", "[", "i", "]"}], "]"}]}], ")"}], "^", "2"}]}], + "-", + RowBox[{ + RowBox[{"(", + RowBox[{ + RowBox[{"yy", "[", "i", "]"}], + RowBox[{"Sin", "[", + RowBox[{"\[Alpha]", "[", "i", "]"}], "]"}]}], ")"}], "^", "2"}]}]}], + ";"}], "\[IndentingNewLine]", + RowBox[{ + RowBox[{ + RowBox[{"yys", "[", "i_", "]"}], ":=", + RowBox[{ + RowBox[{"-", + RowBox[{ + RowBox[{"(", + RowBox[{ + RowBox[{"yy", "[", "i", "]"}], + RowBox[{"Cos", "[", + RowBox[{"\[Alpha]", "[", "i", "]"}], "]"}]}], ")"}], "^", "2"}]}], + "-", + RowBox[{ + RowBox[{"(", + RowBox[{ + RowBox[{"xx", "[", "i", "]"}], + RowBox[{"Sin", "[", + RowBox[{"\[Alpha]", "[", "i", "]"}], "]"}]}], ")"}], "^", "2"}]}]}], + ";"}], "\[IndentingNewLine]", + RowBox[{ + RowBox[{ + RowBox[{"xys", "[", "i_", "]"}], ":=", + RowBox[{ + RowBox[{"(", + RowBox[{ + RowBox[{ + RowBox[{"xx", "[", "i", "]"}], "^", "2"}], "-", + RowBox[{ + RowBox[{"yy", "[", "i", "]"}], "^", "2"}]}], ")"}], "2", + RowBox[{"Cos", "[", + RowBox[{"\[Alpha]", "[", "i", "]"}], "]"}], + RowBox[{"Sin", "[", + RowBox[{"\[Alpha]", "[", "i", "]"}], "]"}]}]}], + ";"}], "\[IndentingNewLine]", + RowBox[{ + RowBox[{ + RowBox[{"gausz", "[", "i_", "]"}], ":=", + RowBox[{"Exp", "[", + RowBox[{ + RowBox[{"e", "[", "i", "]"}], "+", + RowBox[{ + RowBox[{"xxs", "[", "i", "]"}], + RowBox[{ + RowBox[{"dxs", "[", "i", "]"}], "^", "2"}]}], "+", + RowBox[{ + RowBox[{"yys", "[", "i", "]"}], + RowBox[{ + RowBox[{"dys", "[", "i", "]"}], "^", "2"}]}], "+", + RowBox[{ + RowBox[{"xys", "[", "i", "]"}], + RowBox[{"dxs", "[", "i", "]"}], + RowBox[{"dys", "[", "i", "]"}]}]}], "]"}]}], + ";"}], "\[IndentingNewLine]", + RowBox[{ + RowBox[{"tmp", "=", + RowBox[{"of", "-", "val", "+", + RowBox[{"Sum", "[", + RowBox[{ + RowBox[{"gausz", "[", "i", "]"}], ",", + RowBox[{"{", + RowBox[{"i", ",", "1", ",", "n"}], "}"}]}], "]"}]}]}], + ";"}], "\[IndentingNewLine]", + RowBox[{ + RowBox[{"abstand", "=", + RowBox[{"tmp", "^", "2"}]}], ";"}], "\[IndentingNewLine]", + RowBox[{ + RowBox[{"gradAnalytisch", "=", + RowBox[{ + RowBox[{"Map", "[", + RowBox[{ + RowBox[{ + RowBox[{"D", "[", + RowBox[{"abstand", ",", "#"}], "]"}], "&"}], ",", "parameter"}], + "]"}], "/", "2"}]}], ";"}], "\[IndentingNewLine]", + RowBox[{ + RowBox[{"gradNumerisch", "=", + RowBox[{"Join", "[", "\[IndentingNewLine]", + RowBox[{ + RowBox[{"{", "tmp", "}"}], ",", "\[IndentingNewLine]", + RowBox[{"Flatten", "@", + RowBox[{"Table", "[", "\[IndentingNewLine]", + RowBox[{ + RowBox[{"tmp", "*", + RowBox[{"gausz", "[", "i", "]"}], "*", + RowBox[{"{", "\[IndentingNewLine]", + RowBox[{"1", ",", "\[IndentingNewLine]", + RowBox[{ + RowBox[{"-", "2"}], + RowBox[{"xx", "[", "i", "]"}], + RowBox[{ + RowBox[{"(", + RowBox[{ + RowBox[{ + RowBox[{"dxs", "[", "i", "]"}], + RowBox[{"Cos", "[", + RowBox[{"\[Alpha]", "[", "i", "]"}], "]"}]}], "-", + RowBox[{ + RowBox[{"dys", "[", "i", "]"}], + RowBox[{"Sin", "[", + RowBox[{"\[Alpha]", "[", "i", "]"}], "]"}]}]}], ")"}], "^", + "2"}]}], ",", "\[IndentingNewLine]", + RowBox[{ + RowBox[{"-", "2"}], + RowBox[{"yy", "[", "i", "]"}], + RowBox[{ + RowBox[{"(", + RowBox[{ + RowBox[{ + RowBox[{"dys", "[", "i", "]"}], + RowBox[{"Cos", "[", + RowBox[{"\[Alpha]", "[", "i", "]"}], "]"}]}], "+", + RowBox[{ + RowBox[{"dxs", "[", "i", "]"}], + RowBox[{"Sin", "[", + RowBox[{"\[Alpha]", "[", "i", "]"}], "]"}]}]}], ")"}], "^", + "2"}]}], ",", "\[IndentingNewLine]", + RowBox[{ + RowBox[{ + RowBox[{"-", "2"}], + RowBox[{"dxs", "[", "i", "]"}], + RowBox[{"xxs", "[", "i", "]"}]}], "-", + RowBox[{ + RowBox[{"xys", "[", "i", "]"}], + RowBox[{"dys", "[", "i", "]"}]}]}], ",", "\[IndentingNewLine]", + RowBox[{ + RowBox[{ + RowBox[{"-", "2"}], + RowBox[{"dys", "[", "i", "]"}], + RowBox[{"yys", "[", "i", "]"}]}], "-", + RowBox[{ + RowBox[{"xys", "[", "i", "]"}], + RowBox[{"dxs", "[", "i", "]"}]}]}], ",", "\[IndentingNewLine]", + RowBox[{"2", + RowBox[{"(", + RowBox[{ + RowBox[{ + RowBox[{"xx", "[", "i", "]"}], "^", "2"}], "-", + RowBox[{ + RowBox[{"yy", "[", "i", "]"}], "^", "2"}]}], ")"}], + RowBox[{"(", + RowBox[{ + RowBox[{ + RowBox[{"dys", "[", "i", "]"}], + RowBox[{"Cos", "[", + RowBox[{"\[Alpha]", "[", "i", "]"}], "]"}]}], "+", + RowBox[{ + RowBox[{"dxs", "[", "i", "]"}], + RowBox[{"Sin", "[", + RowBox[{"\[Alpha]", "[", "i", "]"}], "]"}]}]}], ")"}], + RowBox[{"(", + RowBox[{ + RowBox[{ + RowBox[{"dxs", "[", "i", "]"}], + RowBox[{"Cos", "[", + RowBox[{"\[Alpha]", "[", "i", "]"}], "]"}]}], "-", + RowBox[{ + RowBox[{"dys", "[", "i", "]"}], + RowBox[{"Sin", "[", + RowBox[{"\[Alpha]", "[", "i", "]"}], "]"}]}]}], ")"}]}]}], + "\[IndentingNewLine]", "}"}]}], ",", "\[IndentingNewLine]", + RowBox[{"{", + RowBox[{"i", ",", "1", ",", "n"}], "}"}]}], "\[IndentingNewLine]", + "]"}]}]}], "\[IndentingNewLine]", "]"}]}], + ";"}], "\[IndentingNewLine]", + RowBox[{ + RowBox[{"Map", "[", + RowBox[{ + RowBox[{ + RowBox[{ + RowBox[{"#", "[", + RowBox[{"[", "1", "]"}], "]"}], "/", + RowBox[{"#", "[", + RowBox[{"[", "2", "]"}], "]"}]}], "&"}], ",", + RowBox[{"Transpose", "@", + RowBox[{"{", + RowBox[{"gradAnalytisch", ",", "gradNumerisch"}], "}"}]}]}], "]"}], "//", + "FullSimplify"}]}], "Input", + CellChangeTimes->CompressedData[" +1:eJxTTMoPSmViYGAQBWIQfU3TwHHW99eOs5arhINove2B0SB6ytq7vSCa4VrL +FBA97Uv6VBDtcHvWTBD90sJ0IYiWe/xnCVjce8kdEM2vrv4YRAdPXfIMRPve +/PwNRJ/8bPoHRK96d4NhNpAWmB7DBqLDrroKgmg3b3dhEL2Jz0cCRD/S2gam +XdesVATRIqzvwPQllyOqIFri9SpTED1N+I8diNZY+9AZRG9oeOAOop9ui/QE +0f7C6lEgelZZZDSI/uy5JxFEp52alw+iH/Q0V4PoXRzzmkF0fNDlThB9yLql +G8x/4DMBRDstTZ4Eotekv5sOog0aW9aA6CXdLgdB9L9nYodBNABjjsh3 + "], + CellLabel-> + "In[1111]:=",ExpressionUUID->"34a6f57a-8574-41c4-a939-95322a68b897"], + +Cell[BoxData[ + RowBox[{"{", + RowBox[{ + "1", ",", "1", ",", "1", ",", "1", ",", "1", ",", "1", ",", "1", ",", "1", + ",", "1", ",", "1", ",", "1", ",", "1", ",", "1"}], "}"}]], "Output", + CellChangeTimes->{{3.75369466155869*^9, 3.753694950324045*^9}, { + 3.753695003404076*^9, 3.75369502978017*^9}, 3.7536952083998823`*^9, { + 3.753695251583177*^9, 3.753695283663467*^9}, {3.753695382017359*^9, + 3.7536953868153563`*^9}, 3.7536954306696663`*^9, 3.753695503918879*^9, { + 3.753695537175337*^9, 3.753695582122876*^9}, {3.753695612293651*^9, + 3.753695631181015*^9}, 3.7536956623065987`*^9, {3.753695767340137*^9, + 3.753695775511874*^9}, {3.753695809155635*^9, 3.753695819281898*^9}, + 3.753695963777269*^9, {3.7536960258027277`*^9, 3.75369609424415*^9}, + 3.753696125358079*^9, {3.7536962224536953`*^9, 3.753696285505844*^9}, + 3.7536963488743362`*^9, 3.753696404011689*^9, {3.753696463438328*^9, + 3.7536965756628036`*^9}, 3.753696608022929*^9, 3.753696647705496*^9, + 3.7536967933270683`*^9}, + CellLabel-> + "Out[1124]=",ExpressionUUID->"f765aec1-d1fe-460a-a1ee-acfdd6d2dfd3"] }, Open ]] }, -WindowSize->{1231, 899}, -WindowMargins->{{149, Automatic}, {Automatic, 29}}, -FrontEndVersion->"8.0 for Linux x86 (64-bit) (November 7, 2010)", +WindowSize->{1920, 1032}, +WindowMargins->{{1920, Automatic}, {3, Automatic}}, +PrivateNotebookOptions->{"VersionedStylesheet"->{"Default.nb"[8.] -> False}}, +FrontEndVersion->"11.3 for Linux x86 (64-bit) (March 6, 2018)", StyleDefinitions->"Default.nb" ] (* End of Notebook Content *) @@ -425,17 +751,20 @@ CellTagsIndex->{} (*NotebookFileOutline Notebook[{ Cell[CellGroupData[{ -Cell[579, 22, 5986, 181, 392, "Input"], +Cell[579, 22, 6372, 191, 492, "Input",ExpressionUUID->"14171ecc-591a-4b96-af22-9f7860bde8cd"], Cell[CellGroupData[{ -Cell[6590, 207, 2313, 57, 26, "Print"], -Cell[8906, 266, 576, 10, 23, "Print"], -Cell[9485, 278, 1962, 52, 56, "Print"] +Cell[6976, 217, 2466, 61, 33, "Print",ExpressionUUID->"a0fcd95d-d8f4-4b41-af48-0f9b52476c1d"], +Cell[9445, 280, 729, 14, 25, "Print",ExpressionUUID->"33c683e5-22cc-4c32-af0c-3f0c99474830"], +Cell[10177, 296, 2114, 56, 65, "Print",ExpressionUUID->"afc8061c-203e-4634-8d5d-559be671b5eb"] +}, Open ]], +Cell[12306, 355, 2936, 79, 83, "Output",ExpressionUUID->"0d7de383-9a8d-4be7-b9bc-bc103daa06be"], +Cell[15245, 436, 1207, 26, 35, "Output",ExpressionUUID->"6ecb8d93-2f3f-41ed-8550-c9e9ec844fcc"] }, Open ]], -Cell[11462, 333, 1876, 48, 55, "Output"], -Cell[13341, 383, 1078, 24, 30, "Output"] +Cell[CellGroupData[{ +Cell[16489, 467, 8526, 245, 768, "Input",ExpressionUUID->"34a6f57a-8574-41c4-a939-95322a68b897"], +Cell[25018, 714, 1101, 18, 35, "Output",ExpressionUUID->"f765aec1-d1fe-460a-a1ee-acfdd6d2dfd3"] }, Open ]] } ] *) -(* End of internal cache information *) diff --git a/gauszFit.inc b/gauszFit.inc index 006ab36..61be566 100644 --- a/gauszFit.inc +++ b/gauszFit.inc @@ -15,54 +15,3 @@ for ii:=wiMin to wiMax do begin parameter[nParams,true,3]:=parameter[nParams,true,3] - t3; end; {$ENDIF} - -{$IFDEF gausz2dFitBerechneWerte} -dOffset:=0; -for i:=0 to iteration-1 do begin - with dParameter[i] do begin - e:=0; - xx:=0; - yy:=0; - x0:=0; - y0:=0; - a:=0; - end; - with parameter[i] do begin - cas[i]:=cos(a); - sas[i]:=sin(a); - xxs[i]:=-sqr(xx*cas[i])-sqr(yy*sas[i]); - yys[i]:=-sqr(yy*cas[i])-sqr(xx*sas[i]); - xys[i]:=(sqr(xx)-sqr(yy))*2*cas[i]*sas[i]; - writeln(i,': xxs = ',xxs[i],' yys = ',yys[i],' xys = ',xys[i]); - end; -end; -abstand:=0; -for x:=0 to sXSteps-1 do - for y:=0 to sTSiz-1 do begin - val:= samples[x + y*sXSteps]; - tmp:= offset - val; - for i:=0 to iteration-1 do begin - dxs[i]:= x - parameter[i].x0; - dys[i]:= y - parameter[i].y0; - tmp:= tmp + - exp( - parameter[i].e + - xxs[i] * sqr(dxs[i]) + - yys[i] * sqr(dys[i]) + - xys[i] * dxs[i] * dys[i] - ); - end; - dOffset:= dOffset - tmp; - abstand:= abstand + sqr(tmp); - tmp:= tmp * (tmp - offset + val); // * vFit - for i:=0 to iteration-1 do - with dParameter[i] do begin - e:= e + tmp; - xx:= xx - 2 * tmp * parameter[i].xx * sqr(dxs[i]*cas[i] - dys[i]*sas[i]); - yy:= yy - 2 * tmp * parameter[i].yy * sqr(dys[i]*cas[i] + dxs[i]*sas[i]); - x0:= x0 - tmp * (2 * dxs[i] * xxs[i] + xys[i] * dys[i]); - y0:= y0 - tmp * (2 * dys[i] * yys[i] + xys[i] * dxs[i]); - a:= a - tmp * 2 * (sqr(parameter[i].xx) - sqr(parameter[i].yy)) * (dys[i]*cas[i] + dxs[i]*sas[i]) * (dxs[i]*cas[i] - dys[i]*sas[i]); - end; - end; -{$ENDIF} diff --git a/werteunit.pas b/werteunit.pas index 05b5925..47fe87a 100644 --- a/werteunit.pas +++ b/werteunit.pas @@ -6,7 +6,7 @@ interface uses classes, sysutils, typenunit, math, process, lowlevelunit, matheunit, fftunit, - randomunit; + randomunit, optimierung; type // tLLWerte ******************************************************************** @@ -78,8 +78,8 @@ type procedure integriere(qu: pTLLWerteDouble; xMi,xMa,tMi,tMa,xOf,tOf: longint; richtung: tIntegrationsRichtung); overload; procedure integriere(qu: pTLLWerteExtended; xMi,xMa,tMi,tMa,xOf,tOf: longint; richtung: tIntegrationsRichtung); overload; procedure gauszFit(amplituden,breiten,positionen,ueberlappe,hintergruende: pTLLWerteExtended; von,bis: longint; senkrecht: boolean; fensterBreite,maxBreite,maxVerschiebung: extended; positionsMitten: tExtendedArray); - function gauszFit2d(anzahl,maximalSamples: longint; relativeVerbesserung: extended; out offset: extended; out parameter: tGausz2dParameterArray): int64; - procedure gausz2dSubtrahieren(offset: extended; parameter: tGausz2dParameterArray); + function gauszFit2d(anzahl,maximalSamples: longint; relativeVerbesserung: extended; out parameter: tExtendedArray): int64; + procedure gausz2dSubtrahieren(parameter: tExtendedArray); function ermittleRandDurchschnitt: extended; function ermittleRandMinimum: extended; function ermittleRandPerzentil(p: extended): extended; @@ -137,7 +137,8 @@ const implementation -uses systemunit; +uses + systemunit; // tLLWerte ******************************************************************** @@ -1620,221 +1621,126 @@ begin end; end; -function tLLWerte.gauszFit2d(anzahl,maximalSamples: longint; relativeVerbesserung: extended; out offset: extended; out parameter: tGausz2dParameterArray): int64; +function tLLWerte.gauszFit2d(anzahl,maximalSamples: longint; relativeVerbesserung: extended; out parameter: tExtendedArray): int64; var - i,x,y,sXSteps,sTSiz,iteration: int64; - abstand,altAbstand,dOffset, - schritt,gradLen,tmp,val: extended; - samples,cas,sas,xxs,yys,xys, - dxs,dys,samples2: tExtendedArray; - dParameter: tGausz2dParameterArray; - bitteNochMal: boolean; + i,zoom: int64; + parameterBuffer: tGausz2dFitParameterBuffer; + optimierer: tDownHillSimplexOptimierer; begin if relativeVerbesserung<=0 then fehler('die relative Verbesserung wird niemals besser als ' + floatToStr(relativeVerbesserung)); - relativeVerbesserung:=sqr(relativeVerbesserung); - - i:=1; - while (params.xSteps div i > maximalSamples) or - (params.tSiz div i > maximalSamples) or - (params.xSteps mod i > 0) or - (params.tSiz mod i > 0) do begin - inc(i); - if i>params.xSteps then + + zoom:=1; + while (params.xSteps div zoom > maximalSamples) or + (params.tSiz div zoom > maximalSamples) or + (params.xSteps mod zoom > 0) or + (params.tSiz mod zoom > 0) do begin + inc(zoom); + if zoom>params.xSteps then fehler('So ein Mist, '+intToStr(params.xSteps)+' und '+intToStr(params.tSiz)+' scheinen einen zu kleinen größten gemeinsame Teiler zu haben.'); end; - sXSteps:=params.xSteps div i; - sTSiz:=params.tSiz div i; - setLength(samples,sXSteps*sTSiz); - setLength(samples2,length(samples)); - for x:=0 to sXSteps-1 do - for y:=0 to sTSiz-1 do - samples[x+y*sXSteps]:=0; - for x:=0 to params.xSteps-1 do - for y:=0 to params.tSiz-1 do - samples[round(x/(params.xSteps-1)*(sXSteps-1)) + round(y/(params.tSiz-1)*(sTSiz-1))*sTSiz]:= - samples[round(x/(params.xSteps-1)*(sXSteps-1)) + round(y/(params.tSiz-1)*(sTSiz-1))*sTSiz] + - werte[x + y*params.xSteps]; - for x:=0 to sXSteps-1 do - for y:=0 to sTSiz-1 do - samples[x+y*sXSteps]:= - samples[x+y*sXSteps] / params.xSteps * sXSteps / params.tSiz * sTSiz; - - offset:=params.minW + 0.1 * random * (params.maxW - params.minW); - dOffset:=0; - setLength(parameter,anzahl); - setLength(dParameter,anzahl); - setLength(cas,anzahl); - setLength(sas,anzahl); - setLength(xxs,anzahl); - setLength(yys,anzahl); - setLength(xys,anzahl); - setLength(dxs,anzahl); - setLength(dys,anzahl); - iteration:=0; - result:=0; - schritt:=1; - abstand:=1e9*sXSteps*sTSiz; - gradLen:=0; - bitteNochMal:=false; - repeat - if (gradLen<relativeVerbesserung) and not bitteNochMal then begin - inc(iteration); - if iteration>anzahl then - break; - for i:=0 to iteration-2 do - with parameter[i] do begin - xxs[i]:=-sqr(xx*cos(a))-sqr(yy*sin(a)); - yys[i]:=-sqr(yy*cos(a))-sqr(xx*sin(a)); - xys[i]:=(sqr(xx)-sqr(yy))*2*cos(a)*sin(a); + parameterBuffer:=tGausz2dFitParameterBuffer.create(anzahl); + case sizeOf(wGen) of + sizeOf(single): + parameterBuffer.initSamples(tSingleArray(werte),params.xSteps,params.tSiz,zoom); + sizeOf(double): + parameterBuffer.initSamples(tDoubleArray(werte),params.xSteps,params.tSiz,zoom); + sizeOf(extended): + parameterBuffer.initSamples(tExtendedArray(werte),params.xSteps,params.tSiz,zoom); + end{of case}; + + parameterBuffer.initParamsSchaetzung; + parameterBuffer.initOffset(params.minW + 0.1 * random * (params.maxW - params.minW)); + + optimierer:=tDownHillSimplexOptimierer.create( + parameterBuffer, + parameterBuffer.geschaetzteFitParams, + parameterBuffer.geschaetzteDFitParams + ); + result:= + optimierer.optimiere( + relativeVerbesserung, + relativeVerbesserung, + -1 + ); + setLength(parameter,1+6*anzahl); + parameter[0]:=optimierer.parameter[0]; // offset + for i:=0 to anzahl-1 do begin + parameter[6*i+1]:=optimierer.parameter[6*i+1] / zoom; // xx + parameter[6*i+2]:=optimierer.parameter[6*i+2] / zoom; // yy + parameter[6*i+3]:=optimierer.parameter[6*i+3] * zoom; // x0 + parameter[6*i+4]:=optimierer.parameter[6*i+4] * zoom; // y0 + parameter[6*i+5]:=optimierer.parameter[6*i+5]; // a + parameter[6*i+6]:=optimierer.parameter[6*i+6]; // e + end; + parameterBuffer.free; + optimierer.free; + +(* with dParameter[i] do begin + if abs(schritte[frei]*e)>=1 then begin // e darf sich maximal um 1 verändern + schritte[frei]:=abs(1/e); + bitteNochMal:=true; end; - for y:=0 to sTSiz-1 do - for x:=0 to sXSteps-1 do begin - samples2[x+y*sXSteps]:=samples[x+y*sXSteps] - offset; - for i:=0 to iteration-2 do - samples2[x+y*sXSteps]:=samples2[x+y*sXSteps] - exp( - parameter[i].e + - xxs[i] * sqr(x - parameter[i].x0) + - yys[i] * sqr(y - parameter[i].y0) + - xys[i] * (x - parameter[i].x0) * (y - parameter[i].y0) - ); + if abs(schritte[frei]*x0*2)>=sXSteps then begin // x0 darf sich maximal um sXSteps/2 verändern + schritte[frei]:=abs(sXSteps/2/x0); + bitteNochMal:=true; end; - with parameter[iteration-1] do begin - e:=0; - xx:=(10 + 0.5 * random) / sXSteps; - yy:=(10 + 0.5 * random) / sTSiz; - x0:=0; - y0:=0; - a:=0.01 * random - 0.005; - tmp:=offset-1; - for y:=0 to sTSiz-1 do - for x:=0 to sXSteps-1 do - if samples2[x+y*sXSteps]>tmp then begin - tmp:= samples2[x+y*sXSteps]; - x0:=x; - y0:=y; - end; - if tmp>0 then - e:=ln(tmp) - else - e:=0; - x:=round(x0); - y:=round(y0); - for i:=1 to min(x,sXSteps-1-x) do - if samples2[x+i+y*sXSteps] + samples2[x-i+y*sXSteps] < 2 * exp(-1) * samples2[x+y*sXSteps] then begin - xx:=1/i; - break; - end; - for i:=1 to min(y,sTSiz-1-y) do - if samples2[x+(y+i)*sXSteps] + samples2[x+(y-i)*sXSteps] - 2 * offset < 2 * exp(-1) * samples2[x+y*sXSteps] then begin - yy:=1/i; - break; - end; - writeln('+['+intToStr(iteration-1)+']: e = ',e,' 1/xx = ',1/xx,' 1/yy = ',1/yy,' x0 = ',x0,' y0 = ',y0,' a = ',a); - end; - end; - bitteNochMal:=false; - inc(result); - altAbstand:=abstand; - {$DEFINE gausz2dFitBerechneWerte} - {$I gauszFit.inc} - {$UNDEF gausz2dFitBerechneWerte} - - if abstand > altAbstand then - schritt:=schritt/2 - else if abstand > 0.7*altAbstand then - schritt:=schritt*1.1; - - for i:=0 to iteration-1 do - with dParameter[i] do begin - if abs(schritt*e)>=1 then begin // e darf sich maximal um 1 verändern - schritt:=abs(1/e); + if abs(schritte[frei]*y0*2)>=sTSiz then begin // y0 darf sich maximal um sTSiz/2 verändern + schritte[frei]:=abs(sTSiz/2/y0); bitteNochMal:=true; end; - if abs(schritt*x0*2)>=sXSteps then begin // x0 darf sich maximal um sXSteps/2 verändern - schritt:=abs(sXSteps/2/x0); + if abs(schritte[frei]*a*20)>=pi then begin // a darf sich maximal um pi/20 verändern + schritte[frei]:=abs(pi/20/a); bitteNochMal:=true; end; - if abs(schritt*y0*2)>=sTSiz then begin // y0 darf sich maximal um sTSiz/2 verändern - schritt:=abs(sTSiz/2/y0); + if parameter[i].xx - 2 * xx * schritte[frei] < 0 then begin // xx darf sich höchstens halbieren +// schritt:=parameter[i].xx / 2 / xx; + xx := parameter[i].xx / 2 / schritte[frei]; bitteNochMal:=true; end; - if abs(schritt*a*2)>=pi then begin // a darf sich maximal um pi/2 verändern - schritt:=abs(pi/2/a); + if xx * schritt > parameter[i].xx then begin // xx darf sich höchstens verdoppeln + schritt:=parameter[i].xx / xx; bitteNochMal:=true; end; - if parameter[i].xx - 2 * xx * schritt < 0 then begin // xx darf sich höchstens halbieren - schritt:=parameter[i].xx / 2 / xx; + if parameter[i].yy - 2 * yy * schritte[frei] < 0 then begin // yy darf sich höchstens halbieren +// schritt:=parameter[i].yy / 2 / yy; + yy := parameter[i].yy / 2 / schritte[frei]; bitteNochMal:=true; end; - if parameter[i].yy - 2 * yy * schritt < 0 then begin // yy darf sich höchstens halbieren - schritt:=parameter[i].yy / 2 / yy; + if yy * schritt > parameter[i].yy then begin // yy darf sich höchstens verdoppeln + schritt:=parameter[i].yy / yy; bitteNochMal:=true; end; end; - - writeln(iteration,': ',abstand,' ',schritt); - - offset:=offset - dOffset * schritt; - gradLen:=sqr(dOffset * schritt); - for i:=0 to iteration-1 do - with parameter[i] do begin - writeln('d['+intToStr(i)+']: e = ',dParameter[i].e,' xx = ',dParameter[i].xx,' yy = ',dParameter[i].yy,' x0 = ',dParameter[i].x0,' y0 = ',dParameter[i].y0,' a = ',dParameter[i].a); - e:=e - dParameter[i].e * schritt; - gradLen:=gradLen + sqr(dParameter[i].e * schritt); - xx:=xx - dParameter[i].xx * schritt; - if xx<0 then - xx:=-xx; - gradLen:=gradLen + sqr(dParameter[i].xx * schritt); - yy:=yy - dParameter[i].yy * schritt; - if yy<0 then - yy:=-yy; - gradLen:=gradLen + sqr(dParameter[i].yy * schritt); - x0:=x0 - dParameter[i].x0 * schritt; - gradLen:=gradLen + sqr(dParameter[i].x0 * schritt); - y0:=y0 - dParameter[i].y0 * schritt; - gradLen:=gradLen + sqr(dParameter[i].y0 * schritt); - a:=(a - dParameter[i].a * schritt) / 2 / pi; - a:=(a - round(a)) * 2 * pi; - gradLen:=gradLen + sqr(dParameter[i].a * schritt); - end; - until false; - for i:=0 to length(parameter)-1 do - with parameter[i] do begin - xx:=xx * sXSteps / params.xSteps; - yy:=yy * sTSiz / params.tSiz; - x0:=x0 / sXSteps * params.xSteps; - y0:=y0 / sTSiz * params.tSiz; - end; - setLength(samples,0); +*) end; -procedure tLLWerte.gausz2dSubtrahieren(offset: extended; parameter: tGausz2dParameterArray); +procedure tLLWerte.gausz2dSubtrahieren(parameter: tExtendedArray); var - x,y,i: longint; - xxs,yys,xys: tExtendedArray; + x,y,i,anzahl: longint; + xxs,yys,xys: tExtendedArray; begin - setLength(xxs,length(parameter)); - setLength(yys,length(parameter)); - setLength(xys,length(parameter)); - for i:=0 to length(parameter)-1 do - with parameter[i] do begin - xxs[i]:=-sqr(xx*cos(a))-sqr(yy*sin(a)); - yys[i]:=-sqr(yy*cos(a))-sqr(xx*sin(a)); - xys[i]:=(sqr(xx)-sqr(yy))*2*cos(a)*sin(a); - end; + anzahl:=length(parameter) div 6; + setLength(xxs,anzahl); + setLength(yys,anzahl); + setLength(xys,anzahl); + for i:=0 to length(xxs)-1 do begin + xxs[i]:=-sqr(parameter[1+6*i]*cos(parameter[5+6*i]))-sqr(parameter[2+6*i]*sin(parameter[5+6*i])); + yys[i]:=-sqr(parameter[2+6*i]*cos(parameter[5+6*i]))-sqr(parameter[1+6*i]*sin(parameter[5+6*i])); + xys[i]:=(sqr(parameter[1+6*i])-sqr(parameter[2+6*i]))*2*cos(parameter[5+6*i])*sin(parameter[5+6*i]); + end; for y:=0 to params.tSiz-1 do for x:=0 to params.xSteps-1 do begin - werte[x+y*params.xSteps]:= werte[x+y*params.xSteps] - offset; - for i:=0 to length(parameter)-1 do + werte[x+y*params.xSteps]:= werte[x+y*params.xSteps] - parameter[0]; + for i:=0 to anzahl-1 do werte[x+y*params.xSteps]:= werte[x+y*params.xSteps] - exp( - parameter[i].e + - xxs[i] * sqr(x - parameter[i].x0) + - yys[i] * sqr(y - parameter[i].y0) + - xys[i] * (x - parameter[i].x0) * (y - parameter[i].y0) + parameter[6+6*i] + + xxs[i] * sqr(x - parameter[3+6*i]) + + yys[i] * sqr(y - parameter[4+6*i]) + + xys[i] * (x - parameter[3+6*i]) * (y - parameter[4+6*i]) ); end; setLength(xxs,0); |