# Tag Info

22

Here I will attempt to provide a basic implementation of the random forest algorithm for classification. This is by no means fast and doesn't scale very well but otherwise is a nice classifier. I recommend reading Breiman and Cutler's page for information about random forests. The following are some helper functions that allow us to compute entropy and ...

16

I think the simple answer is, there isn't one, but you could always just use UML itself, particularly for behavioral diagrams, even if the code isn't object oriented. You wouldn't use class or object diagrams, but there is nothing to stop you from using, say, a component diagram. You may find the tutorial and white paper on building large software systems ...

14

I first create the plot with GridLines -> Automatic: plot = Plot[-Sin[x], {x, -10, 0}, PlotRange -> {{-10, 1}, {-1.1, 1.1}}, ImageSize -> {500, 100}, Axes -> False, GridLines -> Automatic] Then I combine your graphics object with plot using Inset: Manipulate[ Graphics[{Circle[], PointSize[0.012], Point[{Cos[t], Sin[t]}], ...

13

In the scalar approximation, the obstacle could be modeled by an abrupt change in the wave speed $c$. This speed is unity in your original calculation, and I'm just going to insert its inverse square as a prefactor in front of the second time derivative. The spatial shape is defined as an elongated box using Boole: tsunamiEqn = u /. NDSolve[{(1/(1 - 0....

12

Disclaimer: This is not an implementation of the Random Forest Algorithm. Also, while I have on occasion used random florists, until today I had not heard of the Random Forest Algorithm. I poked around a bit on the Net and learned that these take subsamples of data, subsampling the variables as well, and form decision trees for the subsetted subsamples. ...

12

First let me observe that your coding style makes debugging difficult, I highly recommend breaking giant expressions into manageable pieces. Second, in the code below I have used a different definition for the segments. Your version: $y=(x-x_1)^{curvature}\frac{y_2-y_1}{x_2-x_1}+y_1$ does not give an amplitude of $y_2$ at $x=x_2$ if $curvature\neq1$. I ...

9

The answer to the more general question of how necessary "software architecturizationing" is in Mathematica is, in short: Not that necessary. The reason is basically 1) lists 2) dynamic typing and 3) lists + dynamic typing. For example, Mathematica doesn't need classes/OO because lists allow you to represent a huge swath of data structures. You would gain ...

9

As of version 10.0 there is a built in implementation of Random Forests which is accessible through the Classify function. trainingset = {1 -> "A", 2 -> "A", 3.5 -> "B", 4 -> "B"}; classifier = Classify[trainingset, Method->"RandomForest"];

9

Standard errors and confidence intervals from linear and nonlinear regressions are obtained from the covariance matrix. Details about the covariance matrix can be obtained here. Briefly, the square root of the diagonal elements of the covariance matrix gives us the standard errors: se = Sqrt[nlm["CovarianceMatrix"]] // Diagonal (* {1.10159, 0.600123} *) ...

8

I'm going to be bold and attempt to edit the Ross code so that it is (a) a little easier to understand and (b) takes the same form of argument as LinearModelFit and other Mathematica prediction creators. I've also added some annotations to the critical code. My variable names are now far longer than the Ross names but perhaps for informative. So far in my ...

8

The limitation you quote is not a general limitation of Modelica. It is possible to define a Modelica component that has a variable number of inputs/outputs. Typically the number of inputs/outputs is then given by a parameter to that component. For example, the following component has one input but 2 outputs, varied with the parameter nout: model SIMO "...

8

Since you don't sem to have any explicit forward-looking / rational expectations elements in your system (the equation for Pie depends only on lags), I don't know why you are expressing your time subscripts as $T+2$ rather than $t$, $t-1$, $t-2$. Your system is essentially linear, so I would suggest that you define your system as a vector state variable ...

8

You may use NMinimize[] on the results of ParametricNDSolve[] like this: g = 9.81; m = 10; rho = 1.225; Cd = 0.5; A = 0.1; rcd = rho Cd A; vMax = 40; EndTime[theta_] := (2 vMax Sin[theta])/g + 5; sol[Ux_, Uy_, Uz_] := Quiet@ParametricNDSolve[{ m z''[t] == -m g - Tanh[z'[t]] 1/2 rcd (z'[t] - Uz)^2, z[0] == 0, z'[0] == v Cos[theta], m x''...

7

I haven't thought about this for delay differential equations, but for initial value problems, you can just think of the perturbation as a new initial value problem, then the only issue is stitching together the interpolating functions with Witch. Since you mention predator-prey systems lets use logistic growth as the example: sol1 = First@With[{r = 0.5, k =...

7

Here's a "compositional" approach. If you take things piece-by-piece it is not too hard to build up more complicalated demonstrations. Animate[Module[ {spazzyP, scrollingPaper, scrollingSine, circle, pCoords, yCoords, yellowDot, blueLine, offset = 1, range = 2 Pi, padding = 1, fmin = Floor[min]}, pCoords = {min + offset - Cos[min + offset], Sin[...

7

Pure GammaDistribution does not seem at all like a good fit even visually. You need probably a MixtureDistribution. You could BTW skip NonlinearModelFit and start playing with FindDistributionParameters. But I think you are better of trying out latest WL function FindDistribution. In automated regime it finds almost what you need: dis = FindDistribution[...

7

Your code is rather long, so here is a simple example of how to implement a parameter that randomly changes every $\Delta t$. dt = 0.2; sol = NDSolve[{ x'[t] == mu[t] x[t] , x[0] == 1 , mu[0] == -1 , WhenEvent[Mod[t, dt] == 0., mu[t] -> RandomReal[{-1, 1}]] } , {x, mu} , {t, 0, 10} , DiscreteVariables -> {mu} ];...

6

I very much enjoy Dan's approach in part because it is so simple both in concept and implementation. I'm taking the liberty here of suggesting a few arguable improvements to his terrific code. For makeForest (a) the data is in the same format as is used in functions such as LinearModelFit (a simple array instead of a list of rules of features onto class); (b)...

6

Yes you can, for example: thrust[t_, t0_: 1000] := 34020.000 UnitStep[t0 - t] end = 10000 soln = Table[ NDSolve[{ x''[t] == -((G M x[t])/Norm[{x[t], y[t], z[t]}]^3), y''[t] == -((G M y[t])/Norm[{x[t], y[t], z[t]}]^3) + 0.25 thrust[t, t0]/m, z''[t] == -((G M z[t])/Norm[{x[t], y[t], z[t]}]^3) + 0.75 thrust[t, ...

5

You can check the book Bayesian Logical Data Analysis for the Physical Sciences there is also Mathematica notebooks for v7 and v8 under Other Files section.

5

Same kind of approach as @einbandi's here but without insetting and the grid: Manipulate[ plot = Plot[-Sin[x - t], {x, 0, 10}, PlotRange -> {{-10, 1}, {-1.1, 1.1}}, ImageSize -> {500, 100}, Axes -> False, PlotStyle -> Blue]; line = Graphics@Line[{{0, Sin[t]}, {Cos[t], Sin[t]}}]; circle = Graphics[{...

5

There is an alternative solution to implement AMD into Mathematica, by using the MinCut function from the GraphUtilities Package. This function is not just working on Graphs but is also usable for Matrices. The algorithm is reordering the Matrix into blocks and effectively reducing the off diagonal elements. It can be involved rather easily. If one starts ...

5

How about this: s = Import["screw.obj"]; b = Import["board.obj"]; scr = First[s]; brd = First[b]; screwList = Table[{Hue[(5 i + j)/25], Translate[scr, {2 i - 1, RandomReal[{-.5, 2}], 1 - 2 j}]}, {i, 5}, {j, 5}]; Graphics3D[Join[{Brown, brd}, screwList],Lighting->"Neutral"] I added the board to the same Graphics3D as the screws, ...

5

I mentioned in the comment above that there is a general belief that the R-squared value is not a suitable metric for nonlinear models but that leaves us with the question, what is NonlinearModelFit calculating? The font of all knowledge, Wikipedia, informs us that the definition of R squared is 1-ssres/sstot where ssres is the sum of squares of the ...

5

You can also use RegionPlot3D: RegionPlot3D[ reg = (2 x^3 + y^2 + z^2 - 1)^3 - (1/10) x^2 z^3 - y^2 z^3 <= 0 && x >= 0, {x, -2, 2}, {y, -2, 2}, {z, -2, 2}, Mesh -> None, Boxed -> False, Axes -> None, PlotPoints -> 40, PlotStyle -> Red, Background -> Black] Implicit regions could be refined but is not as pleasing "...

5

Finding parameter starting estimates is an important starting point. I post this for illustration. There are many ways to approximate. Manipulate[ Show[ListPlot[data], Plot[s Exp[- a t] Sin[ b t + c] + f, {t, 0, 1000}]], {a, 0, 0.1}, {b, 0.001, 0.01}, {c, 1, 10}, {s, 20, 50}, {f, 5, 50}] Now fit model: nlm = NonlinearModelFit[data, amp Exp[- ...

4

This answer shows how to create UML diagrams in Mathematica. It is related to programming in Mathematica using Object-Oriented Design Patterns as discussed in my answer to the question General strategies to write big code in Mathematica?. Package functions This command imports the package UMLDiagramGeneration.m : Import["https://raw.githubusercontent.com/...

4

Maybe this will help. It's a collection of macro growth theory solved in Mathematica

4

Now that Mathematica has added WhenEvent we have the super sweet solution that requires non of this ugly boiler plate. For the single perturbation case we have the following: Module[{r = 0.5, k = 10, x0 = 5, perturb, sol}, perturb = WhenEvent[Mod[t, 200], x[t] -> 1.1 x[t]]; sol = NDSolveValue[{{x'[t] == r x[t] (1.0 - x[t]/k), x[0] == x0}, perturb}, ...

4

A bit puzzling, but I think you have problems with the levels in ListLogPlot (where you added another set of values), and with the PlotStyle directives (where you added options to a Directive). I changed a few things quasi-randomly and got something which I think is closer to what you want. Manipulate[ SeedRandom[seed]; Column[{ test2[μ_, σ_, S_, P_] :=...

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