I'm rewriting a function into a manipulatable graphic and while I'm happily surprised with how concise functional programming can be, I'm having trouble mapping the anonymous function Norm[#[[2]]-#[[1]]] &
on to the pairs of points represented below:
Generate the data
timeSeries =
Table[MapThread[List,{list,#}] &/@ NestList[
MapAt[RandomChoice[{
{#[[1]],#[[2]]+RandomVariate[NormalDistribution[0,sigma]]},
{#[[1]]+RandomVariate[NormalDistribution[0,sigma]],#[[2]]}
}] &,#,{#} &/@ RandomInteger[{1,Length@list},Ceiling[Length@list * (1-precision)]]] &,
list,20],{sigma,{5,10,15}}];
Output:
{Length@timeSeries,Length /@ timeSeries,Length /@ timeSeries[[1]], Length /@timeSeries[[1,1]],timeSeries[[1,1,1]]}
{3,{21,21,21},{30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30},{2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2},{{114686.,132379.},{114686.,132379.}}}
Norm[#[[2]]-#[[1]]] & /@ timeSeries[[1,9]]
{2.43774,0.,8.73786,0.,0.,0.,0.,0.,0.446609,3.23359,3.73703,0.,8.29204,5.33826,0.,0.,0.,6.65264,3.52166,3.80975,8.55396,1.92847,0.,0.,0.,0.,0.,0.,0.,0.}
I had assumed this was a relatively common type of preprocessing for data sets but couldn't find a solution online. I've tried several configurations of Map, MapThread
, etc. on different levelspec
but haven't stumbled upon a combination that works yet. Moving past trial-and-error does anyone have any suggestions for how to properly map the above stated function on to all the pairs of 2D points?
Update:
Added more info. list
is the initial list of 2D points.
list
? What isprecision
? Please provide full data expamples. Moreover, please provide minimal examples.Norm
does not appear in your input code fortimeSeries
, so why should we parse it? $\endgroup$Map[ Norm[#[[2]] - #[[1]]] &, timeSeries[[All, 9]], {2} ]
? $\endgroup$