Tag Info

Hot answers tagged

26

Given that your data is on an integer grid, it may be sufficient to define a boundary point as one which does not have 4 neighbours (up, down, left, right) boundary = Complement[spiel, Intersection @@ Outer[Plus, {{0, 1}, {0, -1}, {1, 0}, {-1, 0}}, spiel, 1]]; ListPlot[boundary]


24

Some function definitions first. AkimaInterpolation[] stolen from here (Thanks JM, wherever you are!): AkimaInterpolation[data_] := Module[{dy}, dy = #2/#1 & @@@ Differences[data]; Interpolation[Transpose[{List /@ data[[All, 1]], data[[All, -1]], With[{wp = Abs[#4 - #3], wm = Abs[#2 - #1]}, If[wp + wm == 0, (#2 + #3)/2, (wp #2 + wm ...


23

It is possible to include the number of peaks (denoted $n$ below) in minimum searching. First we create some test data: peakfunc[A_, μ_, σ_, x_] = A^2 E^(-((x - μ)^2/(2 σ^2))); dataconfig = {{.7, -12, 1}, {2.2, 0, 5}, {1, 9, 2}, {1, 15, 2}}; datafunc = peakfunc[##, x] & @@@ dataconfig; data = Table[{x, Total[datafunc] + .1 RandomReal[{-1, 1}]}, {x, ...


22

test = {5, 6, 9, 3, 2, 6, 7, 8, 1, 1, 4, 7} MaxFilter[test, 1] (* {6, 9, 9, 9, 6, 7, 8, 8, 8, 4, 7, 7} *) You can also use Max /@ Transpose[{Rest[Append[#, 0]], #, Most[Prepend[#, 0]]}] &[yourList] which is competitive with the MM MaxFilter, but will allow you to change the 'slide' (e.g.pad with zeroes, or other arbitrary 'start').


20

You are looking for ideas, so I will venture a partial solution in the hope it might inspire something useful. The idea presented here is to exploit a statistical model of the heartbeat intervals as a way to test the goodness of any attempted clustering of the data. The approach is general, because it is based on maximum likelihood methods, but I will ...


18

One very simple basic approach is the following (I assume you already loaded the variable spiel) With[{m = Normal@SparseArray[spiel -> 1]}, boundary = Position[m - Erosion[m, 1, Padding -> 0], 1]; ListPlot[{Position[m, 1], boundary}, PlotStyle -> {Gray, Red}]]


17

Here are the two ways I have successfully used MongoDB with Mathematica. AFAIK much of this would also apply to similar DBs such as CouchDB. A. Easy way One working example used a third party Mongo supplier such as 28msec.io and use URLFetch e.g. With this supplier you can both read from and write to the database using HTTP GET and simple query strings. ...


15

myAtoms = {"H", "Li", "Na"}; defCols = myAtoms /. ColorData["Atoms", "ColorRules"]; newCols = {Pink, Yellow, LightBlue}; ColorData["Atoms", "Panel"] /. Thread[defCols -> newCols] Edit: Changing the font color isn't related to the ColorRules, but to the special formatting used by the Panel. So it's cumbersome, but you can see that Mma uses a similar ...


14

Seeing as how someone has been nice enough to write the C-code for you, you could just use that. Assuming you have a C compiler on your machine, here's how you use it within Mathematica. Note that code is defined below. (* Be sure to define code first! *) Needs["CCompilerDriver`"]; url = "http://www.stackexchange.com/"; checksum = CreateExecutable[code, ...


13

Here is a bit clumsy (had very little time) approach виа combination of new functionality Entity and regions. (* get the states *) divisions = EntityValue[Entity["AdministrativeDivision", {_, "UnitedStates"}], "Entities"]; (* get polygons of borders *) dat = EntityValue[ divisions, {"Population", "Polygon"}] /. {GeoPosition -> Identity, ...


12

NIntegrate has many advanced options that let you control which algorithms and strategies it will use. I'm quite sure that you can find a set of options that will make NIntegrate work well enough for the desired task, but of course these numerical algorithms will never be quite as fast and precise as an exact solution, which your sums and Integrates results ...


12

I am not sure what exactly that rank mean. But here's direct rough porting of code: ConvertStrToInt[url_String, init_, factor_] := Fold[FromDigits[IntegerDigits[#1*factor + #2, 16, 8], 16] &, init, ToCharacterCode[url]]; HashURL[url_String]:= Block[{c1, c2,t1, t2}, c1=ConvertStrToInt[url, 5381,33]; c2=ConvertStrToInt[url, 0,65599]; ...


12

This filters out your points by their EuclideanDistance. I think it makes a pretty good job preserving the curve's features with very few points: rx[n_] := Accumulate[Prepend[RandomVariate[ExponentialDistribution[1000], n], 0]] ry[n_] := Accumulate[Prepend[RandomVariate[NormalDistribution[0, .001], n], 0]] c = Transpose[{rx@#, ry@#}] &@100000; t = ...


12

To reduce the number of points, I'd use Interpolation: f = Interpolation[Transpose@{x,y}, InterpolationOrder->1]; Plot[f@x,{x,0,100}]


12

My interpretation of your question is that you want to fit a linear combination of peaked functions with non-negative coefficients. Beware: The minimum misfit solution with non-negative coefficients is a few isolated delta-functions. Therefore, allowing peaks widths is useless, whether for least square or least absolute error, because the minimum allowed ...


12

I know you said you didn't want to reinvent the wheel, but sometimes, it's fun to do so. The code below creates a palette with a Periodic Table and a few buttons to make useful tool tips. It shows how one might change the colors based on properties grabbed from ElementData. Note that this code was written for version 9, and if you wish to use it in ...


12

I ran into the same issue. Dataset and nested Associations have a structure ideally suited for JSON export, but the JSON exporter only supports lists of rules. Any other type of expression triggers the error you see. Export The workaround is to recursively convert all nested associations to lists of rules. normalAsc[expr_] := expr //. a_Association ...


12

Looking at your plotted data you can see about 40 cycles of the dominant frequency, this tells you that the peak will appear somewhere around the 40th element of the DFT. That's in the region where your plot of the DFT is clipped, so it's no wonder you can't see the peak. Looking at the relevant part of the DFT you can see the peak quite clearly: ...


12

Edit Applying @Kuba's y-rescaling trick works here as well, just pass the rescaling through the DistanceFunction option tour2 = FindShortestTour[data, DistanceFunction -> (EuclideanDistance[#1 {1, 30}, #2 {1, 30}] &)]; ListLinePlot[data[[tour2[[2]]]], Epilog -> {PointSize@0.01, Red, Point /@ data}] Here's as close as I can come with ...


11

You can read lines from an InputStream strm (opened with OpenRead) in batches: lines=ReadList[strm, "String", 4000] You can vary the chunk size based on your application, 4000 is a number I found to work well for reading web server logs with lines that aren't crazy-long. You can also reposition for random access on startup. Version 9 improves the use of ...


11

Here is a modified version of belisarius' answer I ended up using. Instead of using the euclidean distance to find out if two points are close to each other I set a fixed rectangle in an area and collapse it into a line. For instance, consider the same example. rx[n_] := Accumulate[Prepend[RandomVariate[ExponentialDistribution[1000], n], 0]] ry[n_] := ...


11

update Just to clean things up a bit, we can use the discussion here to make a couple functions that help extract the frequency data from this dataset. I define two functions findPeriod and reconstruct: Clear[findPeriod]; findPeriod[data_, threshold_] := Module[{fs, s1, s = {}, i, a0f, af, pf, pos, fr, frpos, fdata, fdatac, n, per}, n = ...


11

Using the fourth and fifth arguments of Partition gives you exactly what you want lis = {5, 6, 9, 3, 2, 6, 7, 8, 1, 1, 4, 7} Max @@@ Partition[lis, 3, 1, {2, 2}, {}] Gives: {6, 9, 9, 9, 6, 7, 8, 8, 8, 4, 7, 7} Update As Simon Wood suggested in the comment below (I also know this but on my system the difference isn't that much), Maping Max instead ...


11

Another option is Developer`PartitionMap. In RunnyKine's solution we first partition the list and sweep through it to add Max to every element. With Developer`PartitionMap we can do both at the same time, which is faster. Here's a table for reference. My first table was incorrect and I apologize for that, it was an honest mistake which I am not sure how it ...


11

I will take the data as a time history. First I assume that the x-values are equally spaced and work out the time increment and frequency increment and then plot the data. tinc = data[[2, 1]] - data[[1, 1]]; finc = 1/(tinc Length[data]); ListPlot[data] This looks like almost two cycles of a sine wave with a frequency of about 0.1 and an amplitude of 17. ...


11

There is no built in option, however for the US it's very easy because the coordinates of the state borderlines are all over the Internet. This led me to one such data set. I'll include how I cleaned it up, like this: data = Import["http://econym.org.uk/gmap/states.xml"]; name[{"name" -> n_, ___}] := n coordinates[XMLElement["point", {"lat" -> lat_, ...


11

data = Table[{i, i}, {i, 10}]; model = a + b x ^2; Unrestricted model: nlm = NonlinearModelFit[data, model, {a, b}, x] // Normal $ 0.0863422 x^2+2.17582 $ Model restricted to pass through {5,5}: nlmr = NonlinearModelFit[data, {model, (model /. x -> 5 ) == 5}, {a, b}, x] // Normal $ 0.0790502 x^2+3.02375 $ Picture: Show[Plot[{nlm, ...


10

A simple Mathematica-only solution is: CountLines[file_String /; FileExistsQ[file]] := Module[{counter = 0, str = OpenRead@file}, While[ Read[str, Record, NullRecords -> True] =!= EndOfFile, counter++ ]; Close[str]; counter]; which is quite slow of course, so 123 MB (1978142 ...


10

Lots of answers, but none of them leveraging this, so here is another. null[_String] := Null Length @ ReadList["data.txt", null @ String, NullRecords -> True] On my system this is more than three times as fast as Rolf Mertig's CountLines, and a lot more concise as well. If even one Null for every record is too much memory usage then read in blocks of ...


10

You want to remove high-frequency noise while retaining the low-frequency signal. This is a job for a bandpass filter. A simple one is the MovingAverage, which you can apply like so: xsi = Interpolation[MovingAverage[data, 20]] Plot[{Derivative[1][xsi][t], Cos[t]}, {t, 0, 6.25}, PlotRange -> {-1.1, 1.1}]



Only top voted, non community-wiki answers of a minimum length are eligible