Created
April 12, 2014 15:02
-
-
Save orome/10540005 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PDetect[sensloc_, srcloc_] := Exp[-EuclideanDistance[sensloc, srcloc]]; | |
PDFSrcloc[srcloc_] := | |
1/(2 \[Pi]) | |
Exp[-(srcloc[[1]]^2 + srcloc[[2]]^2)/ | |
2](*PDF[BinormalDistribution[{1,1},0],srcloc]*); | |
PDFJointSrcSens[srcloc_, senslocs_, sensstates_] := | |
PDFSrcloc[srcloc]* | |
If[Length[sensstates] > 0, | |
Times @@ | |
MapThread[ | |
If[#1, PDetect[#2, srcloc], | |
1 - PDetect[#2, srcloc]] &, {sensstates, senslocs}], 1]; | |
PDFSensLocs[senslocs_, sensstates_] := | |
PDFSensLocs[senslocs, sensstates] = | |
If[Length[sensstates] > 0, | |
NIntegrate[ | |
PDFJointSrcSens[{x, y}, senslocs, sensstates], {x, -Infinity, | |
Infinity}, {y, -Infinity, Infinity}], 1]; | |
PDFSrcLocGivenSens[srcloc_, senslocs_, | |
sensstates_] := (PDFJointSrcSens[srcloc, senslocs, sensstates])/ | |
PDFSensLocs[senslocs, sensstates]; | |
lastP = {}; states = {}; | |
detected[p_, src_] := RandomReal[] <= PDetect[p, src]; | |
Manipulate[With[{q = locs[[1]], p = Drop[locs, 1]}, | |
If[Length[lastP] < Length[p], | |
states = Append[states, detected[p[[-1]], q]]]; | |
If[Length[lastP] > Length[p], | |
states = states[[Flatten[Position[lastP, #] & /@ p]]]]; | |
lastP = p; | |
Show[ | |
ContourPlot[ | |
PDFSrcLocGivenSens[{x, y}, p, states], {x, -2, 2}, {y, -2, 2}, | |
PlotRange -> Full, ColorFunction -> GrayLevel, | |
ColorFunctionScaling -> True, Contours -> 20], | |
If[showsignal, | |
DensityPlot[EuclideanDistance[{x, y}, q], {x, -2, 2}, {y, -2, 2}, | |
PlotRange -> Full], {}], | |
Graphics[{ | |
If[debug && Length[p] > 0, | |
Text[TableForm[MapThread[List, {p, states}]], {0, 0}]], | |
If[showpoint, {Red, Table[Circle[q, i/20], {i, 3}]}], | |
(*Blue,Point[#]&/@p*) | |
MapThread[{If[#1, Green, White], Point[#2]} &, {states, p}] | |
}, | |
PlotRange -> 2] | |
] | |
], | |
{{showpoint, True, "Show point"}, {True, False}}, | |
{{showsignal, False, "Show signal"}, {True, False}}, | |
{{debug, False, "Debug"}, {True, False}}, | |
Row[{ | |
Button["Clear", {locs = {locs[[1]]}}, ImageSize -> 100, | |
Alignment -> {Center, Baseline}], | |
Button["Recalc", | |
states = ( RandomReal[] <= PDetect[#, locs[[1]]]) & /@ | |
Drop[locs, 1], ImageSize -> 100, Alignment -> {Center, Baseline}] | |
}], | |
{{locs, {{1, 1}}}, Locator, Appearance -> None, | |
LocatorAutoCreate -> 1}] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment