diff options
author | Erich Eckner <git@eckner.net> | 2018-12-13 11:34:48 +0100 |
---|---|---|
committer | Erich Eckner <git@eckner.net> | 2018-12-13 11:34:48 +0100 |
commit | a88a9cd73027bde05d3ec30649e8be44a7080e97 (patch) | |
tree | bc1a56a56a05269683ecb23620f406cb2e4c92ed | |
parent | 5244c3ae3901ce120eaeb58b07c335c3868b19f8 (diff) | |
download | epost-a88a9cd73027bde05d3ec30649e8be44a7080e97.tar.xz |
"fitte 2d-Gauße an ..." neu
-rw-r--r-- | epost.lpr | 11 | ||||
-rw-r--r-- | epost.lps | 197 | ||||
-rw-r--r-- | epostunit.pas | 111 | ||||
-rw-r--r-- | gausz2d.nb | 441 | ||||
-rw-r--r-- | gauszFit.inc | 51 | ||||
-rw-r--r-- | typenunit.pas | 5 | ||||
-rw-r--r-- | werteunit.pas | 224 |
7 files changed, 936 insertions, 104 deletions
@@ -361,6 +361,17 @@ begin aufraeumen; halt(1); end; + if istDasBefehl('fitte 2d-Gauße an',s,bekannteBefehle,true) then begin + i:=findeWerte(s,nil,@wertes,@konturen,false); + if i<0 then begin + aufraeumen; + halt(1); + end; + if wertes[i].fitte2dGausze(syntaxTest,inf) then + continue; + aufraeumen; + halt(1); + end; if istDasBefehl('Zeitfrequenzanalyse',s,bekannteBefehle,true) then begin j:=findeWerte(erstesArgument(s),nil,@wertes,@konturen,false); if j<0 then begin @@ -3,12 +3,11 @@ <ProjectSession> <Version Value="10"/> <BuildModes Active="Default"/> - <Units Count="25"> + <Units Count="26"> <Unit0> <Filename Value="epost.lpr"/> <IsPartOfProject Value="True"/> - <TopLine Value="565"/> - <CursorPos Y="583"/> + <CursorPos X="54" Y="13"/> <UsageCount Value="202"/> <Loaded Value="True"/> </Unit0> @@ -23,143 +22,134 @@ <Filename Value="epostunit.pas"/> <IsPartOfProject Value="True"/> <EditorIndex Value="1"/> - <TopLine Value="2025"/> - <CursorPos X="78" Y="1953"/> + <TopLine Value="6927"/> + <CursorPos X="25" Y="6956"/> <UsageCount Value="201"/> <Loaded Value="True"/> </Unit2> <Unit3> <Filename Value="werteunit.pas"/> <IsPartOfProject Value="True"/> - <EditorIndex Value="9"/> - <TopLine Value="1249"/> - <CursorPos X="53" Y="1281"/> + <EditorIndex Value="2"/> + <TopLine Value="961"/> + <CursorPos X="18" Y="977"/> <UsageCount Value="200"/> <Loaded Value="True"/> </Unit3> <Unit4> <Filename Value="typenunit.pas"/> <IsPartOfProject Value="True"/> - <IsVisibleTab Value="True"/> - <EditorIndex Value="12"/> - <TopLine Value="998"/> - <CursorPos X="25" Y="1011"/> + <EditorIndex Value="4"/> + <TopLine Value="3"/> + <CursorPos X="3" Y="21"/> <UsageCount Value="200"/> <Loaded Value="True"/> </Unit4> <Unit5> <Filename Value="../units/fftunit.pas"/> <IsPartOfProject Value="True"/> - <EditorIndex Value="3"/> + <EditorIndex Value="-1"/> <TopLine Value="13"/> <CursorPos X="100" Y="13"/> <UsageCount Value="201"/> - <Loaded Value="True"/> </Unit5> <Unit6> <Filename Value="../units/fftunit.inc"/> <IsPartOfProject Value="True"/> - <EditorIndex Value="4"/> + <EditorIndex Value="-1"/> <TopLine Value="152"/> <CursorPos Y="179"/> <UsageCount Value="202"/> - <Loaded Value="True"/> </Unit6> <Unit7> <Filename Value="gauszFit.inc"/> <IsPartOfProject Value="True"/> - <EditorIndex Value="11"/> - <CursorPos X="35" Y="10"/> + <IsVisibleTab Value="True"/> + <EditorIndex Value="3"/> <UsageCount Value="201"/> <Loaded Value="True"/> </Unit7> <Unit8> <Filename Value="werteunit.inc"/> <IsPartOfProject Value="True"/> - <EditorIndex Value="10"/> + <EditorIndex Value="-1"/> <TopLine Value="480"/> <CursorPos Y="515"/> - <UsageCount Value="196"/> - <Loaded Value="True"/> + <UsageCount Value="200"/> </Unit8> <Unit9> <Filename Value="fileunit.pas"/> <EditorIndex Value="-1"/> <CursorPos Y="204"/> - <UsageCount Value="196"/> + <UsageCount Value="194"/> </Unit9> <Unit10> <Filename Value="../units/mystringlistunit.pas"/> - <EditorIndex Value="8"/> - <TopLine Value="713"/> + <EditorIndex Value="-1"/> + <TopLine Value="712"/> <CursorPos X="22" Y="735"/> - <UsageCount Value="95"/> - <Loaded Value="True"/> + <UsageCount Value="94"/> </Unit10> <Unit11> <Filename Value="../units/lowlevelunit.pas"/> - <EditorIndex Value="7"/> - <TopLine Value="728"/> - <CursorPos X="22" Y="755"/> - <UsageCount Value="100"/> - <Loaded Value="True"/> + <EditorIndex Value="-1"/> + <TopLine Value="16"/> + <UsageCount Value="98"/> </Unit11> <Unit12> <Filename Value="../units/matheunit.pas"/> - <EditorIndex Value="5"/> + <EditorIndex Value="-1"/> <TopLine Value="1045"/> <CursorPos X="28" Y="1045"/> - <UsageCount Value="101"/> - <Loaded Value="True"/> + <UsageCount Value="99"/> </Unit12> <Unit13> <Filename Value="../units/systemunit.pas"/> - <EditorIndex Value="2"/> + <EditorIndex Value="-1"/> <TopLine Value="190"/> <CursorPos X="22" Y="195"/> - <UsageCount Value="100"/> - <Loaded Value="True"/> + <UsageCount Value="98"/> </Unit13> <Unit14> <Filename Value="/usr/lib/fpc/src/rtl/inc/objpash.inc"/> <EditorIndex Value="-1"/> <TopLine Value="176"/> <CursorPos X="23" Y="194"/> - <UsageCount Value="6"/> + <UsageCount Value="4"/> </Unit14> <Unit15> <Filename Value="/usr/lib/fpc/src/rtl/unix/bunxovlh.inc"/> <EditorIndex Value="-1"/> <TopLine Value="61"/> <CursorPos X="10" Y="99"/> - <UsageCount Value="1"/> + <UsageCount Value="9"/> </Unit15> <Unit16> <Filename Value="/usr/lib/fpc/src/rtl/unix/baseunix.pp"/> <UnitName Value="BaseUnix"/> <EditorIndex Value="-1"/> <TopLine Value="61"/> - <UsageCount Value="1"/> + <UsageCount Value="9"/> </Unit16> <Unit17> <Filename Value="/usr/lib/fpc/src/rtl/unix/bunxovl.inc"/> <EditorIndex Value="-1"/> <TopLine Value="414"/> <CursorPos X="20" Y="434"/> - <UsageCount Value="1"/> + <UsageCount Value="9"/> </Unit17> <Unit18> <Filename Value="/usr/lib/fpc/src/rtl/linux/bunxsysc.inc"/> <EditorIndex Value="-1"/> <TopLine Value="16"/> - <UsageCount Value="1"/> + <UsageCount Value="9"/> </Unit18> <Unit19> <Filename Value="/usr/lib/fpc/src/rtl/unix/bunxh.inc"/> <EditorIndex Value="-1"/> <TopLine Value="74"/> <CursorPos X="15" Y="102"/> - <UsageCount Value="1"/> + <UsageCount Value="9"/> </Unit19> <Unit20> <Filename Value="/usr/lib/fpc/src/packages/fcl-image/src/fpimage.pp"/> @@ -167,158 +157,157 @@ <EditorIndex Value="-1"/> <TopLine Value="10"/> <CursorPos X="3" Y="30"/> - <UsageCount Value="1"/> + <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="2"/> + <UsageCount Value="0"/> </Unit21> <Unit22> <Filename Value="GTIWebServerTestAggActionHandlerUnit.pas"/> <EditorIndex Value="-1"/> <TopLine Value="53"/> <CursorPos X="49" Y="82"/> - <UsageCount Value="2"/> + <UsageCount Value="0"/> </Unit22> <Unit23> <Filename Value="../units/protokollunit.pas"/> - <EditorIndex Value="6"/> - <TopLine Value="87"/> + <EditorIndex Value="-1"/> + <TopLine Value="18"/> <CursorPos X="3" Y="18"/> - <UsageCount Value="44"/> - <Loaded Value="True"/> + <UsageCount Value="43"/> </Unit23> <Unit24> <Filename Value="../fpGUI/src/corelib/render/software/agg_2D.pas"/> <EditorIndex Value="-1"/> <TopLine Value="2116"/> <CursorPos X="2" Y="2134"/> - <UsageCount Value="10"/> + <UsageCount Value="8"/> </Unit24> + <Unit25> + <Filename Value="../units/randomunit.pas"/> + <EditorIndex Value="-1"/> + <CursorPos X="19" Y="11"/> + <UsageCount Value="8"/> + </Unit25> </Units> - <JumpHistory Count="30" HistoryIndex="29"> + <JumpHistory Count="29" HistoryIndex="28"> <Position1> - <Filename Value="typenunit.pas"/> - <Caret Line="773" Column="72" TopLine="772"/> + <Filename Value="werteunit.pas"/> + <Caret Line="1753" Column="35" TopLine="1735"/> </Position1> <Position2> - <Filename Value="typenunit.pas"/> - <Caret Line="891" Column="33" TopLine="862"/> + <Filename Value="werteunit.pas"/> + <Caret Line="1709" Column="13" TopLine="1684"/> </Position2> <Position3> - <Filename Value="typenunit.pas"/> - <Caret Line="903" Column="33" TopLine="874"/> + <Filename Value="werteunit.pas"/> + <Caret Line="1706" Column="27" TopLine="1686"/> </Position3> <Position4> - <Filename Value="typenunit.pas"/> - <Caret Line="909" Column="46" TopLine="880"/> + <Filename Value="werteunit.pas"/> + <Caret Line="1707" Column="57" TopLine="1689"/> </Position4> <Position5> - <Filename Value="typenunit.pas"/> - <Caret Line="1047" Column="48" TopLine="1018"/> + <Filename Value="werteunit.pas"/> + <Caret Line="1680" Column="35" TopLine="1663"/> </Position5> <Position6> - <Filename Value="typenunit.pas"/> - <Caret Line="1048" Column="44" TopLine="1019"/> + <Filename Value="werteunit.pas"/> + <Caret Line="81" Column="77" TopLine="65"/> </Position6> <Position7> - <Filename Value="typenunit.pas"/> - <Caret Line="1049" Column="50" TopLine="1020"/> + <Filename Value="werteunit.pas"/> </Position7> <Position8> - <Filename Value="typenunit.pas"/> - <Caret Line="1050" Column="50" TopLine="1021"/> + <Filename Value="werteunit.pas"/> + <Caret Line="81" Column="77" TopLine="53"/> </Position8> <Position9> - <Filename Value="typenunit.pas"/> - <Caret Line="1051" Column="52" TopLine="1022"/> + <Filename Value="werteunit.pas"/> + <Caret Line="1623" Column="82" TopLine="1595"/> </Position9> <Position10> - <Filename Value="typenunit.pas"/> - <Caret Line="2282" Column="27" TopLine="2282"/> + <Filename Value="werteunit.pas"/> + <Caret Line="1633" Column="26" TopLine="1605"/> </Position10> <Position11> - <Filename Value="typenunit.pas"/> - <Caret Line="2729" Column="22" TopLine="2718"/> + <Filename Value="werteunit.pas"/> + <Caret Line="1634" Column="98" TopLine="1606"/> </Position11> <Position12> - <Filename Value="typenunit.pas"/> + <Filename Value="werteunit.pas"/> + <Caret Line="1678" Column="37" TopLine="1652"/> </Position12> <Position13> - <Filename Value="typenunit.pas"/> - <Caret Line="891" Column="33" TopLine="862"/> + <Filename Value="werteunit.pas"/> </Position13> <Position14> - <Filename Value="typenunit.pas"/> - <Caret Line="903" Column="33" TopLine="874"/> + <Filename Value="werteunit.pas"/> + <Caret Line="81" Column="77" TopLine="53"/> </Position14> <Position15> - <Filename Value="typenunit.pas"/> - <Caret Line="2281" Column="24" TopLine="2251"/> + <Filename Value="werteunit.pas"/> + <Caret Line="1623" Column="82" TopLine="1595"/> </Position15> <Position16> - <Filename Value="epostunit.pas"/> - <Caret Line="1157" Column="40" TopLine="1154"/> + <Filename Value="gauszFit.inc"/> + <Caret Line="18" Column="10"/> </Position16> <Position17> - <Filename Value="epostunit.pas"/> - <Caret Line="97" Column="43" TopLine="79"/> + <Filename Value="gauszFit.inc"/> + <Caret Line="17" Column="65"/> </Position17> <Position18> - <Filename Value="epostunit.pas"/> - <Caret Line="1157" Column="46" TopLine="1128"/> + <Filename Value="werteunit.pas"/> + <Caret Line="1687" Column="30" TopLine="1629"/> </Position18> <Position19> - <Filename Value="epostunit.pas"/> - <Caret Line="2447" Column="27" TopLine="2436"/> + <Filename Value="typenunit.pas"/> + <Caret Line="21" Column="3" TopLine="3"/> </Position19> <Position20> - <Filename Value="epostunit.pas"/> - <Caret Line="98" Column="43" TopLine="80"/> + <Filename Value="werteunit.pas"/> + <Caret Line="1842" Column="12" TopLine="1815"/> </Position20> <Position21> <Filename Value="epostunit.pas"/> - <Caret Line="1430" Column="46" TopLine="1785"/> + <Caret Line="3870" Column="44" TopLine="3870"/> </Position21> <Position22> <Filename Value="epostunit.pas"/> - <Caret Line="2454" Column="17" TopLine="2431"/> + <Caret Line="7930" Column="16" TopLine="7901"/> </Position22> <Position23> <Filename Value="epostunit.pas"/> - <Caret Line="2444" Column="49" TopLine="2427"/> + <Caret Line="2590" Column="40" TopLine="2573"/> </Position23> <Position24> <Filename Value="epostunit.pas"/> - <Caret Line="97" Column="43" TopLine="79"/> </Position24> <Position25> <Filename Value="epostunit.pas"/> - <Caret Line="1241" Column="18" TopLine="1222"/> + <Caret Line="2590" Column="40" TopLine="2562"/> </Position25> <Position26> <Filename Value="epostunit.pas"/> - <Caret Line="2431" TopLine="2417"/> + <Caret Line="2591" Column="35" TopLine="2563"/> </Position26> <Position27> <Filename Value="epostunit.pas"/> - <Caret Line="2456" TopLine="2436"/> + <Caret Line="2598" Column="55" TopLine="2570"/> </Position27> <Position28> <Filename Value="epostunit.pas"/> - <Caret Line="2455" Column="66" TopLine="2436"/> + <Caret Line="6954" Column="9" TopLine="6925"/> </Position28> <Position29> <Filename Value="epostunit.pas"/> - <Caret Line="2441" Column="89" TopLine="2421"/> + <Caret Line="6955" Column="31" TopLine="6926"/> </Position29> - <Position30> - <Filename Value="typenunit.pas"/> - <Caret Line="748" Column="127" TopLine="727"/> - </Position30> </JumpHistory> </ProjectSession> <Debugging> diff --git a/epostunit.pas b/epostunit.pas index ee920ec..91d8a55 100644 --- a/epostunit.pas +++ b/epostunit.pas @@ -165,6 +165,7 @@ type function fft(threads: longint; senkrecht,invers: boolean; const vor,nach: tFFTDatenordnung; fen: tFenster; hg: tExtendedArray; out pvFehler: extended; warn: tWarnStufe): boolean; overload; procedure initFuerGauszFit(sT: boolean; daten: tWerte; senkrecht: boolean; adLaenge: longint; adStart,adStop: extended); function fitteGausze(sT: boolean; f: tMyStringList; threads: longint): boolean; + function fitte2dGausze(sT: boolean; f: tMyStringList): boolean; function berechneZeitfrequenzanalyse(sT: boolean; f: tMyStringList; threads: longint; quelle: tWerte; warn: tWarnStufe): boolean; function berechneVerzerrung(sT: boolean; f: tMyStringList; threads: longint; quelle: tWerte; warn: tWarnStufe): boolean; function berechneLambdaZuOmegaVerzerrung(sT: boolean; f: tMyStringList; threads: longint; quelle: tWerte): boolean; @@ -3817,6 +3818,116 @@ begin result:=true; end; +function tWerte.fitte2dGausze(sT: boolean; f: tMyStringList): boolean; +var + bekannteBefehle: tMyStringList; + Zeit,offset,relVerb: extended; + anzahl,i: longint; + schritte,maximalSamples: int64; + s,datei: string; + pDatei: textFile; + parameter: tGausz2dParameterArray; + residuenBerechnen: boolean; +begin + result:=false; + if not sT then + gibAus('2d-Gauße fitten ...',3); + bekannteBefehle:=tMyStringList.create; + Zeit:=now; + anzahl:=1; + datei:=''; + relVerb:=0.001; + residuenBerechnen:=false; + maximalSamples:=256; + repeat + if not f.metaReadln(s,true) then begin + gibAus('Unerwartetes Dateiende!',3); + exit; + end; + bekannteBefehle.clear; + if istDasBefehl('Ende',s,bekannteBefehle,false) then break; + if istDasBefehl('Anzahl:',s,bekannteBefehle,true) then begin + anzahl:=round(exprToFloat(sT,s)); + continue; + end; + if istDasBefehl('maximale Sampleanzahl:',s,bekannteBefehle,true) then begin + maximalSamples:=round(sqrt(exprToFloat(sT,s))); + continue; + end; + if istDasBefehl('Residuen berechnen',s,bekannteBefehle,false) then begin + residuenBerechnen:=true; + continue; + end; + if istDasBefehl('Datei:',s,bekannteBefehle,true) then begin + if datei<>'' then begin + gibAus('Habe bereits eine Zieldatei beim Fitten eines 2d-Gaußes!',3); + bekannteBefehle.free; + exit; + end; + datei:=s; + continue; + end; + if istDasBefehl('relative Verbesserung:',s,bekannteBefehle,true) then begin + relVerb:=exprToFloat(sT,s); + continue; + end; + bekannteBefehle.sort; + gibAus('Verstehe Option '''+s+''' nicht beim Fitten eines 2d-Gaußes!'#10'Ich kenne:'#10+bekannteBefehle.text,3); + bekannteBefehle.free; + exit; + until false; + bekannteBefehle.free; + + if datei='' then begin + gibAus('Keine Datei zum 2dGauße-Fitten angegeben!',3); + exit; + end; + + if sT then begin + result:=true; + exit; + end; + + case genauigkeit of + gSingle: + schritte:=sWerte.gauszFit2d(anzahl,maximalSamples,relVerb,offset,parameter); + gDouble: + schritte:=dWerte.gauszFit2d(anzahl,maximalSamples,relVerb,offset,parameter); + gExtended: + schritte:=eWerte.gauszFit2d(anzahl,maximalSamples,relVerb,offset,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) + ); + closeFile(pDatei); + if residuenBerechnen then begin + gibAus('... Residuen berechnen ...',3); + case genauigkeit of + gSingle: + sWerte.gausz2dSubtrahieren(offset,parameter); + gDouble: + dWerte.gausz2dSubtrahieren(offset,parameter); + gExtended: + eWerte.gausz2dSubtrahieren(offset,parameter); + end{of case}; + end; + gibAus('... fertig '+timetostr(now-Zeit),3); + result:=true; +end; + function tWerte.berechneZeitfrequenzanalyse(sT: boolean; f: tMyStringList; threads: longint; quelle: tWerte; warn: tWarnStufe): boolean; var i,tMin,tMax,qlen: longint; diff --git a/gausz2d.nb b/gausz2d.nb new file mode 100644 index 0000000..90d3e5d --- /dev/null +++ b/gausz2d.nb @@ -0,0 +1,441 @@ +(* Content-type: application/vnd.wolfram.mathematica *) + +(*** Wolfram Notebook File ***) +(* http://www.wolfram.com/nb *) + +(* CreatedBy='Mathematica 8.0' *) + +(*CacheID: 234*) +(* Internal cache information: +NotebookFileLineBreakTest +NotebookFileLineBreakTest +NotebookDataPosition[ 157, 7] +NotebookDataLength[ 14942, 432] +NotebookOptionsPosition[ 14435, 410] +NotebookOutlinePosition[ 14773, 425] +CellTagsIndexPosition[ 14730, 422] +WindowFrame->Normal*) + +(* Beginning of Notebook Content *) +Notebook[{ + +Cell[CellGroupData[{ +Cell[BoxData[{ + RowBox[{ + RowBox[{ + RowBox[{"arg2d", "[", "r_", "]"}], ":=", + RowBox[{ + RowBox[{"-", + RowBox[{ + RowBox[{"(", + RowBox[{"xx", " ", + RowBox[{"r", "[", + RowBox[{"[", "1", "]"}], "]"}]}], ")"}], "^", "2"}]}], "-", + RowBox[{ + RowBox[{"(", + RowBox[{"yy", " ", + RowBox[{"r", "[", + RowBox[{"[", "2", "]"}], "]"}]}], ")"}], "^", "2"}]}]}], + ";"}], "\[IndentingNewLine]", + RowBox[{ + RowBox[{ + RowBox[{"g2d", "[", + RowBox[{"x_", ",", "y_"}], "]"}], ":=", + RowBox[{"Exp", "[", + RowBox[{"e", "+", + RowBox[{"arg2d", "[", + RowBox[{ + RowBox[{"RotationMatrix", "[", "\[Alpha]", "]"}], ".", + RowBox[{"{", + RowBox[{"x", ",", "y"}], "}"}]}], "]"}]}], "]"}]}], + ";"}], "\[IndentingNewLine]", + RowBox[{ + RowBox[{"Print", "[", + RowBox[{"\"\<arg = \>\"", ",", + RowBox[{"Collect", "[", + RowBox[{ + RowBox[{"FullSimplify", "[", + RowBox[{ + RowBox[{"Log", "@", + RowBox[{"g2d", "[", + RowBox[{"x", ",", "y"}], "]"}]}], ",", + RowBox[{"{", + RowBox[{ + RowBox[{"x", ">", "0"}], ",", + RowBox[{"y", ">", "0"}], ",", + RowBox[{"\[Alpha]", ">", "0"}], ",", + RowBox[{"e", ">", "0"}], ",", + RowBox[{"xx", ">", "0"}], ",", + RowBox[{"yy", ">", "0"}]}], "}"}]}], "]"}], ",", + RowBox[{"{", + RowBox[{"x", ",", "y"}], "}"}]}], "]"}]}], "]"}], + ";"}], "\[IndentingNewLine]", + RowBox[{ + RowBox[{"grad", "=", + RowBox[{"Map", "[", + RowBox[{ + RowBox[{ + RowBox[{"D", "[", + RowBox[{ + RowBox[{ + RowBox[{"(", + RowBox[{"vEx", "-", "of", "-", + RowBox[{"g2d", "[", + RowBox[{ + RowBox[{"x", "-", "x0"}], ",", + RowBox[{"y", "-", "y0"}]}], "]"}]}], ")"}], "^", "2"}], ",", + "#"}], "]"}], "&"}], ",", + RowBox[{"{", + RowBox[{"of", ",", "e", ",", "xx", ",", "yy", ",", "x0", ",", "y0"}], + "}"}]}], "]"}]}], ";"}], "\[IndentingNewLine]", + RowBox[{ + RowBox[{"grad", "=", + RowBox[{"grad", "/.", + RowBox[{"{", + RowBox[{ + RowBox[{"g2d", "[", + RowBox[{ + RowBox[{"x", "-", "x0"}], ",", + RowBox[{"y", "-", "y0"}]}], "]"}], "\[Rule]", "vFit"}], "}"}]}]}], + ";"}], "\[IndentingNewLine]", + RowBox[{ + RowBox[{"grad", "=", + RowBox[{ + RowBox[{"grad", "/", + RowBox[{"(", + RowBox[{"vEx", "-", "vFit", "-", "of"}], ")"}]}], "/", + RowBox[{"-", "2"}]}]}], ";"}], "\[IndentingNewLine]", + RowBox[{ + RowBox[{"Print", "[", + RowBox[{"\"\<d/dof = \>\"", ",", + RowBox[{"First", "@", "grad"}]}], "]"}], ";"}], "\[IndentingNewLine]", + RowBox[{ + RowBox[{"grad", "=", + RowBox[{ + RowBox[{"Rest", "@", "grad"}], "/", "vFit"}]}], + ";"}], "\[IndentingNewLine]", + RowBox[{ + RowBox[{"Print", "[", + RowBox[{"MatrixForm", "[", + RowBox[{"grad", "[", + RowBox[{"[", + RowBox[{"1", ";;", "3"}], "]"}], "]"}], "]"}], "]"}], + ";"}], "\[IndentingNewLine]", + RowBox[{ + RowBox[{"grad", "=", + RowBox[{"Rest", "@", + RowBox[{"Rest", "@", + RowBox[{"Rest", "@", "grad"}]}]}]}], ";"}], "\[IndentingNewLine]", + RowBox[{ + RowBox[{"grad", "=", + RowBox[{"FullSimplify", "@", "grad"}]}], ";"}], "\[IndentingNewLine]", + RowBox[{ + RowBox[{"grad", "=", + RowBox[{"grad", "/.", + RowBox[{"{", "\[IndentingNewLine]", + RowBox[{ + RowBox[{ + RowBox[{ + RowBox[{ + RowBox[{"xx", "^", "2"}], + RowBox[{ + RowBox[{"Cos", "[", "\[Alpha]", "]"}], "^", "2"}]}], "+", + RowBox[{ + RowBox[{"yy", "^", "2"}], + RowBox[{ + RowBox[{"Sin", "[", "\[Alpha]", "]"}], "^", "2"}]}]}], "\[Rule]", + RowBox[{"-", "xxs"}]}], ",", "\[IndentingNewLine]", + RowBox[{ + RowBox[{ + RowBox[{"yy", "^", "2"}], + RowBox[{ + RowBox[{"Cos", "[", "\[Alpha]", "]"}], "^", "2"}]}], "\[Rule]", + RowBox[{ + RowBox[{"-", "yys"}], "-", + RowBox[{ + RowBox[{"xx", "^", "2"}], + RowBox[{ + RowBox[{"Sin", "[", "\[Alpha]", "]"}], "^", "2"}]}]}]}]}], + "\[IndentingNewLine]", "}"}]}]}], ";"}], "\[IndentingNewLine]", + RowBox[{ + RowBox[{"grad", "=", + RowBox[{"FullSimplify", "@", "grad"}]}], ";"}], "\[IndentingNewLine]", + RowBox[{ + RowBox[{"grad", "=", + RowBox[{"grad", "/.", + RowBox[{"{", + RowBox[{ + RowBox[{"Sin", "[", + RowBox[{"2", "\[Alpha]"}], "]"}], "\[Rule]", + RowBox[{"xys", "/", + RowBox[{"(", + RowBox[{ + RowBox[{"xx", "^", "2"}], "-", + RowBox[{"yy", "^", "2"}]}], ")"}]}]}], "}"}]}]}], + ";"}], "\[IndentingNewLine]", + RowBox[{ + RowBox[{"grad", "=", + RowBox[{"FullSimplify", "@", "grad"}]}], ";"}], "\[IndentingNewLine]", + RowBox[{"MatrixForm", "@", + RowBox[{"Collect", "[", + RowBox[{"grad", ",", + RowBox[{"{", + RowBox[{"xxs", ",", "yys", ",", "xys"}], "}"}]}], + "]"}]}], "\[IndentingNewLine]", + RowBox[{"Map", "[", + RowBox[{ + RowBox[{ + RowBox[{"D", "[", + RowBox[{ + RowBox[{ + RowBox[{"(", + RowBox[{"v", "-", "v1", "-", "v2", "-", "v3"}], ")"}], "^", "2"}], + ",", "#"}], "]"}], "&"}], ",", + RowBox[{"{", + RowBox[{"v1", ",", "v2", ",", "v3"}], "}"}]}], "]"}]}], "Input", + CellChangeTimes->{{3.753609000042264*^9, 3.753609109599412*^9}, { + 3.753609166430565*^9, 3.753609210683228*^9}, {3.753610502865098*^9, + 3.753610547389407*^9}, {3.753610685030005*^9, 3.753610724175441*^9}, { + 3.753613975995905*^9, 3.753614047305752*^9}, {3.753614109773117*^9, + 3.7536141836411963`*^9}, {3.753614275749501*^9, 3.753614348955834*^9}, { + 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}}], + +Cell[CellGroupData[{ + +Cell[BoxData[ + InterpretationBox[ + RowBox[{"\<\"arg = \"\>", "\[InvisibleSpace]", + RowBox[{"e", "+", + RowBox[{"x", " ", "y", " ", + RowBox[{"(", + RowBox[{ + RowBox[{"2", " ", + SuperscriptBox["xx", "2"], " ", + RowBox[{"Cos", "[", "\[Alpha]", "]"}], " ", + RowBox[{"Sin", "[", "\[Alpha]", "]"}]}], "-", + RowBox[{"2", " ", + SuperscriptBox["yy", "2"], " ", + RowBox[{"Cos", "[", "\[Alpha]", "]"}], " ", + RowBox[{"Sin", "[", "\[Alpha]", "]"}]}]}], ")"}]}], "+", + RowBox[{ + SuperscriptBox["y", "2"], " ", + RowBox[{"(", + RowBox[{ + RowBox[{ + RowBox[{"-", + SuperscriptBox["yy", "2"]}], " ", + SuperscriptBox[ + RowBox[{"Cos", "[", "\[Alpha]", "]"}], "2"]}], "-", + RowBox[{ + SuperscriptBox["xx", "2"], " ", + SuperscriptBox[ + RowBox[{"Sin", "[", "\[Alpha]", "]"}], "2"]}]}], ")"}]}], "+", + RowBox[{ + SuperscriptBox["x", "2"], " ", + RowBox[{"(", + RowBox[{ + RowBox[{ + RowBox[{"-", + SuperscriptBox["xx", "2"]}], " ", + SuperscriptBox[ + RowBox[{"Cos", "[", "\[Alpha]", "]"}], "2"]}], "-", + RowBox[{ + SuperscriptBox["yy", "2"], " ", + SuperscriptBox[ + RowBox[{"Sin", "[", "\[Alpha]", "]"}], "2"]}]}], ")"}]}]}]}], + SequenceForm[ + "arg = ", $CellContext`e + $CellContext`x $CellContext`y ( + 2 $CellContext`xx^2 Cos[$CellContext`\[Alpha]] + Sin[$CellContext`\[Alpha]] - 2 $CellContext`yy^2 + Cos[$CellContext`\[Alpha]] + Sin[$CellContext`\[Alpha]]) + $CellContext`y^2 (-$CellContext`yy^2 + Cos[$CellContext`\[Alpha]]^2 - $CellContext`xx^2 + Sin[$CellContext`\[Alpha]]^2) + $CellContext`x^2 (-$CellContext`xx^2 + Cos[$CellContext`\[Alpha]]^2 - $CellContext`yy^2 + Sin[$CellContext`\[Alpha]]^2)], + Editable->False]], "Print", + CellChangeTimes->{{3.75361429503148*^9, 3.753614318831056*^9}, + 3.753614349506106*^9, {3.7536146194785757`*^9, 3.7536146510571117`*^9}, { + 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}}], + +Cell[BoxData[ + InterpretationBox[ + RowBox[{"\<\"d/dof = \"\>", "\[InvisibleSpace]", "1"}], + SequenceForm["d/dof = ", 1], + Editable->False]], "Print", + CellChangeTimes->{{3.75361429503148*^9, 3.753614318831056*^9}, + 3.753614349506106*^9, {3.7536146194785757`*^9, 3.7536146510571117`*^9}, { + 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}}], + +Cell[BoxData[ + TagBox[ + RowBox[{"(", "\[NoBreak]", + TagBox[GridBox[{ + {"1"}, + { + RowBox[{ + RowBox[{"-", "2"}], " ", "xx", " ", + SuperscriptBox[ + RowBox[{"(", + RowBox[{ + RowBox[{ + RowBox[{"(", + RowBox[{"x", "-", "x0"}], ")"}], " ", + RowBox[{"Cos", "[", "\[Alpha]", "]"}]}], "-", + RowBox[{ + RowBox[{"(", + RowBox[{"y", "-", "y0"}], ")"}], " ", + RowBox[{"Sin", "[", "\[Alpha]", "]"}]}]}], ")"}], "2"]}]}, + { + RowBox[{ + RowBox[{"-", "2"}], " ", "yy", " ", + SuperscriptBox[ + RowBox[{"(", + RowBox[{ + RowBox[{ + RowBox[{"(", + RowBox[{"y", "-", "y0"}], ")"}], " ", + RowBox[{"Cos", "[", "\[Alpha]", "]"}]}], "+", + RowBox[{ + RowBox[{"(", + RowBox[{"x", "-", "x0"}], ")"}], " ", + RowBox[{"Sin", "[", "\[Alpha]", "]"}]}]}], ")"}], "2"]}]} + }, + GridBoxAlignment->{ + "Columns" -> {{Center}}, "ColumnsIndexed" -> {}, "Rows" -> {{Baseline}}, + "RowsIndexed" -> {}}, + GridBoxSpacings->{"Columns" -> { + Offset[0.27999999999999997`], { + Offset[0.5599999999999999]}, + Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> { + Offset[0.2], { + Offset[0.4]}, + Offset[0.2]}, "RowsIndexed" -> {}}], + Column], "\[NoBreak]", ")"}], + Function[BoxForm`e$, + MatrixForm[BoxForm`e$]]]], "Print", + CellChangeTimes->{{3.75361429503148*^9, 3.753614318831056*^9}, + 3.753614349506106*^9, {3.7536146194785757`*^9, 3.7536146510571117`*^9}, { + 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}}] +}, Open ]], + +Cell[BoxData[ + TagBox[ + RowBox[{"(", "\[NoBreak]", + TagBox[GridBox[{ + { + RowBox[{ + RowBox[{ + RowBox[{"(", + RowBox[{ + RowBox[{ + RowBox[{"-", "2"}], " ", "x"}], "+", + RowBox[{"2", " ", "x0"}]}], ")"}], " ", "xxs"}], "+", + RowBox[{"xys", " ", + RowBox[{"(", + RowBox[{ + RowBox[{"-", "y"}], "+", "y0"}], ")"}]}]}]}, + { + RowBox[{ + RowBox[{ + RowBox[{"(", + RowBox[{ + RowBox[{"-", "x"}], "+", "x0"}], ")"}], " ", "xys"}], "+", + RowBox[{"2", " ", + RowBox[{"(", + RowBox[{ + RowBox[{"-", "y"}], "+", "y0"}], ")"}], " ", "yys"}]}]} + }, + GridBoxAlignment->{ + "Columns" -> {{Center}}, "ColumnsIndexed" -> {}, "Rows" -> {{Baseline}}, + "RowsIndexed" -> {}}, + GridBoxSpacings->{"Columns" -> { + Offset[0.27999999999999997`], { + Offset[0.5599999999999999]}, + Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> { + Offset[0.2], { + Offset[0.4]}, + Offset[0.2]}, "RowsIndexed" -> {}}], + Column], "\[NoBreak]", ")"}], + Function[BoxForm`e$, + MatrixForm[BoxForm`e$]]]], "Output", + CellChangeTimes->{{3.7536107127691*^9, 3.753610724693427*^9}, + 3.753613979180334*^9, {3.753614013881706*^9, 3.753614047823874*^9}, { + 3.7536141246760674`*^9, 3.753614142523868*^9}, 3.753614184108453*^9, { + 3.7536142950445347`*^9, 3.7536143188455753`*^9}, 3.7536143495149937`*^9, { + 3.7536146194771233`*^9, 3.753614651052931*^9}, {3.753614692259658*^9, + 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}}], + +Cell[BoxData[ + RowBox[{"{", + RowBox[{ + RowBox[{ + RowBox[{"-", "2"}], " ", + RowBox[{"(", + RowBox[{"v", "-", "v1", "-", "v2", "-", "v3"}], ")"}]}], ",", + RowBox[{ + RowBox[{"-", "2"}], " ", + RowBox[{"(", + RowBox[{"v", "-", "v1", "-", "v2", "-", "v3"}], ")"}]}], ",", + RowBox[{ + RowBox[{"-", "2"}], " ", + RowBox[{"(", + RowBox[{"v", "-", "v1", "-", "v2", "-", "v3"}], ")"}]}]}], + "}"}]], "Output", + CellChangeTimes->{{3.7536107127691*^9, 3.753610724693427*^9}, + 3.753613979180334*^9, {3.753614013881706*^9, 3.753614047823874*^9}, { + 3.7536141246760674`*^9, 3.753614142523868*^9}, 3.753614184108453*^9, { + 3.7536142950445347`*^9, 3.7536143188455753`*^9}, 3.7536143495149937`*^9, { + 3.7536146194771233`*^9, 3.753614651052931*^9}, {3.753614692259658*^9, + 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}}] +}, Open ]] +}, +WindowSize->{1231, 899}, +WindowMargins->{{149, Automatic}, {Automatic, 29}}, +FrontEndVersion->"8.0 for Linux x86 (64-bit) (November 7, 2010)", +StyleDefinitions->"Default.nb" +] +(* End of Notebook Content *) + +(* Internal cache information *) +(*CellTagsOutline +CellTagsIndex->{} +*) +(*CellTagsIndex +CellTagsIndex->{} +*) +(*NotebookFileOutline +Notebook[{ +Cell[CellGroupData[{ +Cell[579, 22, 5986, 181, 392, "Input"], +Cell[CellGroupData[{ +Cell[6590, 207, 2313, 57, 26, "Print"], +Cell[8906, 266, 576, 10, 23, "Print"], +Cell[9485, 278, 1962, 52, 56, "Print"] +}, Open ]], +Cell[11462, 333, 1876, 48, 55, "Output"], +Cell[13341, 383, 1078, 24, 30, "Output"] +}, Open ]] +} +] +*) + +(* End of internal cache information *) diff --git a/gauszFit.inc b/gauszFit.inc index 61be566..006ab36 100644 --- a/gauszFit.inc +++ b/gauszFit.inc @@ -15,3 +15,54 @@ 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/typenunit.pas b/typenunit.pas index 14660d4..bc5843d 100644 --- a/typenunit.pas +++ b/typenunit.pas @@ -14,6 +14,11 @@ const speicherHappen = 32768; // Anzahl an mit einem Mal zu reservierender Array type tExtraInfos = class; + tGausz2dParameter = record + xx,yy,x0,y0,a,e: extended; + // exp ( -(xx^2 * cos(a)^2 + yy^2 * sin(a)^2) * (X-x0)^2 - (yy^2 * cos(a)^2 + xx^2 * sin(a)^2) * (Y-y0)^2 + 2(xx^2 - yy^2) * cos(a)sin(a) * (X-x0) * (Y-y0) + e) + end; + tGausz2dParameterArray = array of tGausz2dParameter; tKomplexMachModus = (kmmReNull,kmmImNull,kmmPhZuf); tLowLevelHintergrundAbzugsArt = (haaKeine,haaRandDurchschnitt,haaRandMinimum,haaRandPerzentil,haaMinimum,haaVertikaleMittel,haaVertikaleMedianMittel); tHintergrundAbzugsArt = record diff --git a/werteunit.pas b/werteunit.pas index 07a33cb..05b5925 100644 --- a/werteunit.pas +++ b/werteunit.pas @@ -78,6 +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 ermittleRandDurchschnitt: extended; function ermittleRandMinimum: extended; function ermittleRandPerzentil(p: extended): extended; @@ -1618,6 +1620,228 @@ begin end; end; +function tLLWerte.gauszFit2d(anzahl,maximalSamples: longint; relativeVerbesserung: extended; out offset: extended; out parameter: tGausz2dParameterArray): 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; +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 + 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); + 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) + ); + 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); + 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); + 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); + 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); + 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; + 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; + 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); +var + x,y,i: 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; + 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] + - 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) + ); + end; + setLength(xxs,0); + setLength(yys,0); + setLength(xys,0); +end; + function tLLWerte.ermittleRandDurchschnitt: extended; var i: int64; |