diff options
author | Erich Eckner <git@eckner.net> | 2018-12-20 11:35:48 +0100 |
---|---|---|
committer | Erich Eckner <git@eckner.net> | 2018-12-20 11:35:48 +0100 |
commit | 9c1573fcacb80ec59e4dc16734b2d05259897354 (patch) | |
tree | d55f40120509b2cc9e424b3e5cde4d1a964b109e | |
parent | 8f2b777e353647c038f63a3d24835b8e502435b3 (diff) | |
download | epost-9c1573fcacb80ec59e4dc16734b2d05259897354.tar.xz |
epostunit.pas: faktorisieren neu
-rw-r--r-- | epost.lpr | 11 | ||||
-rw-r--r-- | epost.lps | 154 | ||||
-rw-r--r-- | epostunit.pas | 211 | ||||
-rw-r--r-- | werteunit.pas | 70 |
4 files changed, 368 insertions, 78 deletions
@@ -372,6 +372,17 @@ begin aufraeumen; halt(1); end; + if istDasBefehl('faktorisiere',s,bekannteBefehle,true) then begin + i:=findeWerte(s,nil,@wertes,@konturen,false); + if i<0 then begin + aufraeumen; + halt(1); + end; + if wertes[i].faktorisiere(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 @@ -7,8 +7,8 @@ <Unit0> <Filename Value="epost.lpr"/> <IsPartOfProject Value="True"/> - <TopLine Value="176"/> - <CursorPos X="31" Y="194"/> + <TopLine Value="351"/> + <CursorPos X="22" Y="381"/> <UsageCount Value="202"/> <Loaded Value="True"/> </Unit0> @@ -23,24 +23,25 @@ <Filename Value="epostunit.pas"/> <IsPartOfProject Value="True"/> <EditorIndex Value="1"/> - <TopLine Value="3856"/> - <CursorPos X="18" Y="3881"/> + <TopLine Value="4096"/> + <CursorPos X="27" Y="4124"/> <UsageCount Value="201"/> <Loaded Value="True"/> </Unit2> <Unit3> <Filename Value="werteunit.pas"/> <IsPartOfProject Value="True"/> - <EditorIndex Value="2"/> - <TopLine Value="1613"/> - <CursorPos Y="1630"/> + <IsVisibleTab Value="True"/> + <EditorIndex Value="3"/> + <TopLine Value="1487"/> + <CursorPos X="74" Y="1513"/> <UsageCount Value="200"/> <Loaded Value="True"/> </Unit3> <Unit4> <Filename Value="typenunit.pas"/> <IsPartOfProject Value="True"/> - <EditorIndex Value="6"/> + <EditorIndex Value="7"/> <TopLine Value="4"/> <CursorPos Y="20"/> <UsageCount Value="200"/> @@ -65,7 +66,7 @@ <Unit7> <Filename Value="gauszFit.inc"/> <IsPartOfProject Value="True"/> - <EditorIndex Value="5"/> + <EditorIndex Value="6"/> <CursorPos X="9" Y="17"/> <UsageCount Value="201"/> <Loaded Value="True"/> @@ -81,19 +82,18 @@ <Unit9> <Filename Value="../units/optimierung.pas"/> <IsPartOfProject Value="True"/> - <IsVisibleTab Value="True"/> - <EditorIndex Value="3"/> + <EditorIndex Value="4"/> <TopLine Value="86"/> <CursorPos X="26" Y="115"/> - <UsageCount Value="29"/> + <UsageCount Value="36"/> <Loaded Value="True"/> </Unit9> <Unit10> <Filename Value="../units/optimierung.inc"/> <IsPartOfProject Value="True"/> - <EditorIndex Value="4"/> + <EditorIndex Value="5"/> <CursorPos X="3" Y="2"/> - <UsageCount Value="25"/> + <UsageCount Value="32"/> <Loaded Value="True"/> </Unit10> <Unit11> @@ -112,15 +112,17 @@ <Unit13> <Filename Value="../units/lowlevelunit.pas"/> <EditorIndex Value="-1"/> - <TopLine Value="16"/> + <TopLine Value="19"/> + <CursorPos Y="50"/> <UsageCount Value="97"/> </Unit13> <Unit14> <Filename Value="../units/matheunit.pas"/> - <EditorIndex Value="-1"/> - <TopLine Value="1045"/> - <CursorPos X="28" Y="1045"/> - <UsageCount Value="98"/> + <EditorIndex Value="2"/> + <TopLine Value="1130"/> + <CursorPos X="60" Y="1147"/> + <UsageCount Value="99"/> + <Loaded Value="True"/> </Unit14> <Unit15> <Filename Value="../units/systemunit.pas"/> @@ -205,126 +207,122 @@ <DefaultSyntaxHighlighter Value="XML"/> </Unit26> </Units> - <JumpHistory Count="30" HistoryIndex="29"> + <JumpHistory Count="29" HistoryIndex="28"> <Position1> - <Filename Value="../units/optimierung.pas"/> - <Caret Line="38" Column="92" TopLine="20"/> + <Filename Value="werteunit.pas"/> </Position1> <Position2> - <Filename Value="../units/optimierung.pas"/> - <Caret Line="100" Column="112" TopLine="82"/> + <Filename Value="werteunit.pas"/> + <Caret Line="81" Column="115" TopLine="63"/> </Position2> <Position3> - <Filename Value="../units/optimierung.pas"/> + <Filename Value="werteunit.pas"/> + <Caret Line="1470" Column="120" TopLine="1454"/> </Position3> <Position4> - <Filename Value="../units/optimierung.pas"/> - <Caret Line="38" Column="121" TopLine="9"/> + <Filename Value="werteunit.pas"/> + <Caret Line="1475" Column="35" TopLine="1455"/> </Position4> <Position5> - <Filename Value="../units/optimierung.pas"/> - <Caret Line="100" Column="143" TopLine="82"/> + <Filename Value="werteunit.pas"/> + <Caret Line="1473" Column="16" TopLine="1456"/> </Position5> <Position6> - <Filename Value="../units/optimierung.pas"/> - <Caret Line="111" Column="58" TopLine="87"/> + <Filename Value="werteunit.pas"/> + <Caret Line="1472" Column="14" TopLine="1457"/> </Position6> <Position7> - <Filename Value="../units/optimierung.pas"/> - <Caret Line="112" Column="34" TopLine="94"/> + <Filename Value="werteunit.pas"/> + <Caret Line="1480" Column="31" TopLine="1463"/> </Position7> <Position8> - <Filename Value="../units/optimierung.pas"/> - <Caret Line="180" Column="59" TopLine="162"/> + <Filename Value="werteunit.pas"/> + <Caret Line="1483" Column="29" TopLine="1464"/> </Position8> <Position9> - <Filename Value="../units/optimierung.pas"/> - <Caret Line="189" TopLine="168"/> + <Filename Value="werteunit.pas"/> + <Caret Line="1470" Column="97" TopLine="1458"/> </Position9> <Position10> - <Filename Value="../units/optimierung.pas"/> - <Caret Line="196" Column="64" TopLine="179"/> + <Filename Value="epostunit.pas"/> + <Caret Line="4093" Column="82" TopLine="4067"/> </Position10> <Position11> - <Filename Value="../units/optimierung.pas"/> - <Caret Line="197" TopLine="180"/> + <Filename Value="epostunit.pas"/> + <Caret Line="4115" Column="82" TopLine="4083"/> </Position11> <Position12> - <Filename Value="../units/optimierung.pas"/> - <Caret Line="234" TopLine="202"/> + <Filename Value="werteunit.pas"/> + <Caret Line="1491" Column="33" TopLine="1466"/> </Position12> <Position13> - <Filename Value="../units/optimierung.pas"/> - <Caret Line="177" Column="12" TopLine="158"/> + <Filename Value="werteunit.pas"/> + <Caret Line="81" Column="16" TopLine="56"/> </Position13> <Position14> - <Filename Value="../units/optimierung.pas"/> - <Caret Line="178" Column="16" TopLine="160"/> + <Filename Value="werteunit.pas"/> + <Caret Line="1507" Column="69" TopLine="1476"/> </Position14> <Position15> - <Filename Value="../units/optimierung.pas"/> - <Caret Line="190" Column="34" TopLine="174"/> + <Filename Value="werteunit.pas"/> + <Caret Line="82" Column="86" TopLine="66"/> </Position15> <Position16> - <Filename Value="../units/optimierung.pas"/> - <Caret Line="18" Column="5"/> + <Filename Value="werteunit.pas"/> + <Caret Line="1513" Column="93" TopLine="1481"/> </Position16> <Position17> - <Filename Value="../units/optimierung.pas"/> - <Caret Line="69" TopLine="43"/> + <Filename Value="epostunit.pas"/> + <Caret Line="3947" Column="13" TopLine="3934"/> </Position17> <Position18> - <Filename Value="../units/optimierung.pas"/> - <Caret Line="421" Column="12" TopLine="388"/> + <Filename Value="epostunit.pas"/> + <Caret Line="3951" Column="17" TopLine="3924"/> </Position18> <Position19> - <Filename Value="../units/optimierung.pas"/> - <Caret Line="253" TopLine="225"/> + <Filename Value="epostunit.pas"/> + <Caret Line="4046" Column="10" TopLine="4024"/> </Position19> <Position20> - <Filename Value="../units/optimierung.pas"/> - <Caret Line="415" Column="58" TopLine="396"/> + <Filename Value="epostunit.pas"/> + <Caret Line="4049" Column="18" TopLine="4031"/> </Position20> <Position21> - <Filename Value="../units/optimierung.pas"/> - <Caret Line="14" Column="42"/> + <Filename Value="epostunit.pas"/> + <Caret Line="4082" Column="17" TopLine="4065"/> </Position21> <Position22> - <Filename Value="../units/optimierung.pas"/> - <Caret Line="192" Column="39" TopLine="175"/> + <Filename Value="werteunit.pas"/> + <Caret Line="1499" Column="96" TopLine="1482"/> </Position22> <Position23> - <Filename Value="../units/optimierung.pas"/> - <Caret Line="429" TopLine="397"/> + <Filename Value="werteunit.pas"/> + <Caret Line="82" Column="25" TopLine="65"/> </Position23> <Position24> <Filename Value="werteunit.pas"/> - <Caret Line="1624" Column="62" TopLine="1618"/> + <Caret Line="1513" Column="86" TopLine="1488"/> </Position24> <Position25> - <Filename Value="werteunit.pas"/> - <Caret Line="81" Column="116" TopLine="64"/> + <Filename Value="epostunit.pas"/> + <Caret Line="4065" Column="11" TopLine="4036"/> </Position25> <Position26> - <Filename Value="werteunit.pas"/> - <Caret Line="1630" TopLine="1613"/> + <Filename Value="epostunit.pas"/> + <Caret Line="4040" Column="11" TopLine="4038"/> </Position26> <Position27> - <Filename Value="epostunit.pas"/> - <Caret Line="3897" Column="95" TopLine="3875"/> + <Filename Value="../units/matheunit.pas"/> + <Caret Line="70" Column="11" TopLine="52"/> </Position27> <Position28> <Filename Value="epostunit.pas"/> - <Caret Line="3830" Column="40" TopLine="3806"/> + <Caret Line="4040" Column="11" TopLine="4038"/> </Position28> <Position29> <Filename Value="epostunit.pas"/> - <Caret Line="3884" Column="61" TopLine="3867"/> + <Caret Line="4102" Column="27" TopLine="4074"/> </Position29> - <Position30> - <Filename Value="../units/optimierung.pas"/> - <Caret Line="71" TopLine="55"/> - </Position30> </JumpHistory> </ProjectSession> <Debugging> diff --git a/epostunit.pas b/epostunit.pas index 0d7f829..7f190c8 100644 --- a/epostunit.pas +++ b/epostunit.pas @@ -166,6 +166,7 @@ type 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 faktorisiere(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; @@ -3940,6 +3941,216 @@ begin result:=true; end; +function tWerte.faktorisiere(sT: boolean; f: tMyStringList): boolean; +var + bekannteBefehle: tMyStringList; + Zeit,tmpE: extended; + anzahl,i,j: longint; + s,datei: string; + pDatei: textFile; + lineOut,tmpEA: tExtendedArray; + maxima,maxima2: tLongintArray; + toepfe: tIntPointArray; + formen: array of tExtendedArray; + residuenBerechnen,auszenHorizontal: boolean; +begin + result:=false; + if not sT then + gibAus('faktorisiere ...',3); + bekannteBefehle:=tMyStringList.create; + Zeit:=now; + anzahl:=1; + datei:=''; + residuenBerechnen:=false; + auszenHorizontal:=false; + 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('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('äußere Dimension:',s,bekannteBefehle,true) then begin + if s='horizontal' then + auszenHorizontal:=true + else if s='vertikal' then + auszenHorizontal:=false + else begin + gibAus(''''+s+''' ist keine gültige äußere Dimension beim Faktorisieren - ich kenne nur ''horizontal'' und ''vertikal''!',3); + bekannteBefehle.free; + exit + end; + continue; + end; + bekannteBefehle.sort; + gibAus('Verstehe Option '''+s+''' nicht beim Faktorisieren!'#10'Ich kenne:'#10+bekannteBefehle.text,3); + bekannteBefehle.free; + exit; + until false; + bekannteBefehle.free; + + if (datei='') and not residuenBerechnen then begin + gibAus('Keine Ausgaben beim Faktorisieren!',3); + exit; + end; + + if sT then begin + result:=true; + exit; + end; + + case genauigkeit of + gSingle: + lineOut:=sWerte.integriereZuLineOut(not auszenHorizontal); + gDouble: + lineOut:=dWerte.integriereZuLineOut(not auszenHorizontal); + gExtended: + lineOut:=eWerte.integriereZuLineOut(not auszenHorizontal); + end{of case}; + + setLength(maxima,0); + i:=0; + for j:=0 to length(lineOut)-1 do + if ((j=0) or (lineOut[j]>lineOut[j-1])) and + ((j=length(lineOut)-1) or (lineOut[j]>lineOut[j+1])) then begin + if length(maxima)<=i then + setLength(maxima,i+128); + maxima[i]:=j; + inc(i); + end; + setLength(maxima,i); + + sortiereNachDominanz(maxima,lineOut); + setLength(maxima,anzahl); + + setLength(maxima2,anzahl); + setLength(tmpEA,anzahl); + for i:=0 to length(tmpEA)-1 do begin + tmpEA[i]:=maxima[i]; + maxima2[i]:=maxima[i]; + maxima[i]:=i; + end; + sortiereNachWert(maxima,tmpEA,false); + setLength(tmpEA,0); + setLength(toepfe,anzahl); + for i:=0 to length(toepfe)-1 do begin + if i>0 then + toepfe[length(toepfe)-1-i]['y']:=(maxima2[maxima[i-1]]+maxima2[maxima[i]]) div 2 + else if auszenHorizontal then + toepfe[length(toepfe)-1-i]['y']:=_xSteps-1 + else + toepfe[length(toepfe)-1-i]['y']:=_tSiz-1; + if i<length(toepfe)-1 then + toepfe[length(toepfe)-1-i]['x']:=(maxima2[maxima[i]]+maxima2[maxima[i+1]]) div 2 + 1 + else + toepfe[length(toepfe)-1-i]['x']:=0; + end; + + case genauigkeit of + gSingle: + sWerte.integriereTopfweise(auszenHorizontal,toepfe,formen); + gDouble: + dWerte.integriereTopfweise(auszenHorizontal,toepfe,formen); + gExtended: + eWerte.integriereTopfweise(auszenHorizontal,toepfe,formen); + end{of case}; + + // normieren + for i:=0 to length(toepfe)-1 do begin + tmpE:=0; + for j:=toepfe[i]['x'] to toepfe[i]['y'] do + tmpE:=tmpE + lineOut[j]; + if tmpE = 0 then + continue; + tmpE:=1/tmpE; + for j:=0 to length(formen[i])-1 do + formen[i,j]:=formen[i,j] * tmpE; + end; + + if datei<>'' then begin + gibAus('... speichern ...',3); + assignFile(pDatei,datei); + rewrite(pDatei); + if auszenHorizontal then begin + writeln(pDatei,'Töpfe'); + for i:=0 to length(toepfe)-1 do + for j:=toepfe[i]['x'] to toepfe[i]['y'] do + writeln( + pDatei, + intToStr(i) + #9 + + myFloatToStr(transformationen.positionAufAchseZuWert(lOben,j/_xSteps)) + #9 + + myFloatToStr(lineOut[j]) + ); + writeln(pDatei); + for i:=0 to length(toepfe)-1 do begin + writeln(pDatei,'Topf '+intToStr(i)); + for j:=0 to length(formen[i])-1 do + writeln( + pDatei, + myFloatToStr(transformationen.positionAufAchseZuWert(lLinks,j/_tSiz)) + #9 + + myFloatToStr(formen[i][j]) + ); + writeln(pDatei); + end; + end + else begin + writeln(pDatei,'Töpfe'); + for i:=0 to length(toepfe)-1 do + for j:=toepfe[i]['x'] to toepfe[i]['y'] do + writeln( + pDatei, + intToStr(i) + #9 + + myFloatToStr(transformationen.positionAufAchseZuWert(lLinks,j/_tSiz)) + #9 + + myFloatToStr(lineOut[j]) + ); + writeln(pDatei); + for i:=0 to length(toepfe)-1 do begin + writeln(pDatei,'Topf '+intToStr(i)); + for j:=0 to length(formen[i])-1 do + writeln( + pDatei, + myFloatToStr(transformationen.positionAufAchseZuWert(lOben,j/_xSteps)) + #9 + + myFloatToStr(formen[i][j]) + ); + writeln(pDatei); + end; + end; + closeFile(pDatei); + end; + + if residuenBerechnen then begin + gibAus('... Residuen berechnen ...',3); + case genauigkeit of + gSingle: + sWerte.produktSubtrahieren(auszenHorizontal,toepfe,lineOut,formen); + gDouble: + dWerte.produktSubtrahieren(auszenHorizontal,toepfe,lineOut,formen); + gExtended: + eWerte.produktSubtrahieren(auszenHorizontal,toepfe,lineOut,formen); + 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/werteunit.pas b/werteunit.pas index f1cd5aa..08ae73e 100644 --- a/werteunit.pas +++ b/werteunit.pas @@ -77,6 +77,9 @@ type procedure integriere(qu: pTLLWerteSingle; xMi,xMa,tMi,tMa,xOf,tOf: longint; richtung: tIntegrationsRichtung); overload; 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; + function integriereZuLineOut(horizontal: boolean): tExtendedArray; + procedure integriereTopfweise(horizontal: boolean; toepfe: tIntPointArray; out formen: tExtendedArrayArray); + procedure produktSubtrahieren(auszenHorizontal: boolean; toepfe: tIntPointArray; lineOut: tExtendedArray; formen: tExtendedArrayArray); procedure gauszFit(amplituden,breiten,positionen,ueberlappe,hintergruende: pTLLWerteExtended; von,bis: longint; senkrecht: boolean; fensterBreite,maxBreite,maxVerschiebung: extended; positionsMitten: tExtendedArray); function gauszFit2d(anzahl,maximalSamples: longint; minVerbesserung, minSchritt: extended; maxSchritte: int64; out parameter: tExtendedArray): int64; procedure gausz2dSubtrahieren(parameter: tExtendedArray); @@ -1443,6 +1446,73 @@ procedure tLLWerte.integriere(qu: pTLLWerteExtended; xMi,xMa,tMi,tMa,xOf,tOf: lo {$INCLUDE werteunit.inc} {$UNDEF tLLWerte_integriere} +function tLLWerte.integriereZuLineOut(horizontal: boolean): tExtendedArray; +var + x,y: int64; +begin + if horizontal then begin + setLength(result,params.tSiz); + for y:=0 to length(result)-1 do begin + result[y]:=0; + for x:=0 to params.xSteps-1 do + result[y]:=result[y] + werte[x + y*params.xSteps]; + end; + end + else begin + setLength(result,params.xSteps); + for x:=0 to length(result)-1 do + result[x]:=0; + for y:=0 to params.tSiz-1 do + for x:=0 to length(result)-1 do + result[x]:=result[x] + werte[x + y*params.xSteps]; + end; +end; + +procedure tLLWerte.integriereTopfweise(horizontal: boolean; toepfe: tIntPointArray; out formen: tExtendedArrayArray); +var + i,j,k: int64; +begin + setLength(formen,length(toepfe)); + if horizontal then begin + for i:=0 to length(toepfe)-1 do + setLength(formen[i],params.tSiz); + end + else + for i:=0 to length(toepfe)-1 do + setLength(formen[i],params.xSteps); + for i:=0 to length(toepfe)-1 do + for j:=0 to length(formen[i])-1 do + formen[i,j]:=0; + if horizontal then begin + for i:=0 to params.tSiz-1 do + for j:=0 to length(toepfe)-1 do + for k:=toepfe[j]['x'] to toepfe[j]['y'] do + formen[j,i]:=formen[j,i] + werte[k+i*params.xSteps]; + end + else + for i:=0 to length(toepfe)-1 do + for j:=toepfe[i]['x'] to toepfe[i]['y'] do + for k:=0 to params.xSteps-1 do + formen[i,k]:=formen[i,k] + werte[k+j*params.xSteps]; +end; + +procedure tLLWerte.produktSubtrahieren(auszenHorizontal: boolean; toepfe: tIntPointArray; lineOut: tExtendedArray; formen: tExtendedArrayArray); +var + i,j,k: longint; +begin + if auszenHorizontal then begin + for i:=0 to params.tSiz-1 do + for j:=0 to length(toepfe)-1 do + for k:=toepfe[j]['x'] to toepfe[j]['y'] do + werte[k + i*params.xSteps]:= werte[k + i*params.xSteps] - lineOut[k] * formen[j][i]; + end + else + for i:=0 to length(toepfe)-1 do + for j:=toepfe[i]['x'] to toepfe[i]['y'] do + for k:=0 to params.xSteps-1 do + werte[k + j*params.xSteps]:= werte[k + j*params.xSteps] - lineOut[j] * formen[i][k]; +end; + procedure tLLWerte.gauszFit(amplituden,breiten,positionen,ueberlappe,hintergruende: pTLLWerteExtended; von,bis: longint; senkrecht: boolean; fensterBreite,maxBreite,maxVerschiebung: extended; positionsMitten: tExtendedArray); var i,j,ii,zaehl, // Zähler |