How to count points under the curve?Picking points in a plane under a curve given by a listHow to select points from a table that are within some regionSelecting points on either side of a curveApproximating an ornamental curveCount the number of regions made by Lissajous curvePlotting the image of a curve under a flowReducing the number of plotmarkers in listlineplotHow to calculate the control points of a Bézier curve?Plotting the sum of two points on an elliptic curveRegion bounded by the curveRandom points around the given curveFinding Area Under a Curveshowing the grid points on the curve
How can God warn people of the upcoming rapture without disrupting society?
Are employers legally allowed to pay employees in goods and services equal to or greater than the minimum wage?
(A room / an office) where an artist works
Installing Windows to flash BIOS, then reinstalling Ubuntu
How far did Gandalf and the Balrog drop from the bridge in Moria?
Why aren’t there water shutoff valves for each room?
Help, I cannot decide when to start the story
Why aren't rockets built with truss structures inside their fuel & oxidizer tanks to increase structural strength?
If "more guns less crime", how do gun advocates explain that the EU has less crime than the US?
Will using a resistor in series with a LED to control its voltage increase the total energy expenditure?
Tempoverlustspiel
If you know the location of an invisible creature, can you attack it?
PhD advisor lost funding, need advice
How do some PhD students get 10+ papers? Is that what I need for landing good faculty position?
Why is the Lucas test not recommended to differentiate higher alcohols?
Boss asked a co-worker to assault me
Word for an event that will likely never happen again
Can lodestones be used to magnetize crude iron weapons?
Can the IPA represent all languages' tones?
How do you deal with the emotions of not being the one to find the cause of a bug?
The cat ate your input again!
Corroded Metal vs Magical Armor, should it melt it?
In which case does the Security misconfiguration vulnerability apply to?
Why aren't rainbows blurred-out into nothing after they are produced?
How to count points under the curve?
Picking points in a plane under a curve given by a listHow to select points from a table that are within some regionSelecting points on either side of a curveApproximating an ornamental curveCount the number of regions made by Lissajous curvePlotting the image of a curve under a flowReducing the number of plotmarkers in listlineplotHow to calculate the control points of a Bézier curve?Plotting the sum of two points on an elliptic curveRegion bounded by the curveRandom points around the given curveFinding Area Under a Curveshowing the grid points on the curve
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
$begingroup$
I need a formula to calculate how many points are there under the curve $y=x$.
plotting graphics
$endgroup$
add a comment |
$begingroup$
I need a formula to calculate how many points are there under the curve $y=x$.
plotting graphics
$endgroup$
$begingroup$
Some related: (97299), (157149), (181620)...I think there's more, but couldn't find the right search terms.
$endgroup$
– Michael E2
Aug 1 at 20:46
add a comment |
$begingroup$
I need a formula to calculate how many points are there under the curve $y=x$.
plotting graphics
$endgroup$
I need a formula to calculate how many points are there under the curve $y=x$.
plotting graphics
plotting graphics
edited Aug 2 at 7:43
J. M. is away♦
100k10 gold badges316 silver badges473 bronze badges
100k10 gold badges316 silver badges473 bronze badges
asked Aug 1 at 13:02
MathMath
313 bronze badges
313 bronze badges
$begingroup$
Some related: (97299), (157149), (181620)...I think there's more, but couldn't find the right search terms.
$endgroup$
– Michael E2
Aug 1 at 20:46
add a comment |
$begingroup$
Some related: (97299), (157149), (181620)...I think there's more, but couldn't find the right search terms.
$endgroup$
– Michael E2
Aug 1 at 20:46
$begingroup$
Some related: (97299), (157149), (181620)...I think there's more, but couldn't find the right search terms.
$endgroup$
– Michael E2
Aug 1 at 20:46
$begingroup$
Some related: (97299), (157149), (181620)...I think there's more, but couldn't find the right search terms.
$endgroup$
– Michael E2
Aug 1 at 20:46
add a comment |
3 Answers
3
active
oldest
votes
$begingroup$
Try
p = RandomReal[0, 1, 50, 2]
pu=Select[p, #[[2]] < #[[1]] &]
Length[pu] (* number of points yi<xi*)
Show[Plot[x, x, 0, 1], ListPlot[p],ListPlot[pu, PlotStyle -> Red]]
$endgroup$
2
$begingroup$
One could also usepu = Select[p, Apply[Greater]]
in this case. A slower, but generalizable approach would bermf = RegionMember[ImplicitRegion[y <= x, x, y]]; pu = Select[p, rmf]
$endgroup$
– J. M. is away♦
Aug 1 at 13:33
$begingroup$
How about if i want to do that in sine curve?
$endgroup$
– Math
Aug 2 at 13:07
$begingroup$
@Math Something likeSelect[p, #[[2]] <Sin[ #[[1]] ] &]
$endgroup$
– Ulrich Neumann
Aug 2 at 13:13
add a comment |
$begingroup$
p = RandomReal[0, 1, 50, 2]
Count[p, x_, y_ /; y < x]
This is many times more efficient for long lists:
Total[UnitStep[Subtract @@ Transpose[p]]]
Edit:
A few timings under version 12.0 on macos:
p = RandomReal[0, 1, 1000000, 2];
Length[Select[p, #[[2]] < #[[1]] &]] // RepeatedTiming
Count[p, x_, y_ /; y < x] // RepeatedTiming
Total[UnitStep[Subtract @@ Transpose[p]]] // RepeatedTiming
1.31, 499894
0.757, 499894
0.0089, 499894
$endgroup$
$begingroup$
Very interesting alternatives. By the way the last one is the slowest (MMA v.11.0.1)
$endgroup$
– Ulrich Neumann
Aug 1 at 14:19
$begingroup$
@UlrichNeumann Really? That is indeed surprising... Unfornately, I cannot test it under v. 11.0.1; I have removed it recently.
$endgroup$
– Henrik Schumacher
Aug 1 at 16:26
$begingroup$
Similar timings under v10.4 and 11.3.
$endgroup$
– corey979
Aug 1 at 16:33
2
$begingroup$
@UlrichNeumann That is surprising. What if you try the compiled versionCompile[p,_Real,2,Total[UnitStep[p.1,-1]]]
?
$endgroup$
– Silvia
Aug 2 at 3:20
$begingroup$
@Silvia Great idea to useDot
! And I am also surprised thatCompile
makes a difference here.
$endgroup$
– Henrik Schumacher
Aug 2 at 3:21
|
show 1 more comment
$begingroup$
You can use RegionMember
for this:
reg = RegionMember[ImplicitRegion[y<x, x,y]];
Tally @ reg[p]
False, 23, True, 27
This will not be as fast as Henrik's answer.
$endgroup$
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "387"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f203097%2fhow-to-count-points-under-the-curve%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
Try
p = RandomReal[0, 1, 50, 2]
pu=Select[p, #[[2]] < #[[1]] &]
Length[pu] (* number of points yi<xi*)
Show[Plot[x, x, 0, 1], ListPlot[p],ListPlot[pu, PlotStyle -> Red]]
$endgroup$
2
$begingroup$
One could also usepu = Select[p, Apply[Greater]]
in this case. A slower, but generalizable approach would bermf = RegionMember[ImplicitRegion[y <= x, x, y]]; pu = Select[p, rmf]
$endgroup$
– J. M. is away♦
Aug 1 at 13:33
$begingroup$
How about if i want to do that in sine curve?
$endgroup$
– Math
Aug 2 at 13:07
$begingroup$
@Math Something likeSelect[p, #[[2]] <Sin[ #[[1]] ] &]
$endgroup$
– Ulrich Neumann
Aug 2 at 13:13
add a comment |
$begingroup$
Try
p = RandomReal[0, 1, 50, 2]
pu=Select[p, #[[2]] < #[[1]] &]
Length[pu] (* number of points yi<xi*)
Show[Plot[x, x, 0, 1], ListPlot[p],ListPlot[pu, PlotStyle -> Red]]
$endgroup$
2
$begingroup$
One could also usepu = Select[p, Apply[Greater]]
in this case. A slower, but generalizable approach would bermf = RegionMember[ImplicitRegion[y <= x, x, y]]; pu = Select[p, rmf]
$endgroup$
– J. M. is away♦
Aug 1 at 13:33
$begingroup$
How about if i want to do that in sine curve?
$endgroup$
– Math
Aug 2 at 13:07
$begingroup$
@Math Something likeSelect[p, #[[2]] <Sin[ #[[1]] ] &]
$endgroup$
– Ulrich Neumann
Aug 2 at 13:13
add a comment |
$begingroup$
Try
p = RandomReal[0, 1, 50, 2]
pu=Select[p, #[[2]] < #[[1]] &]
Length[pu] (* number of points yi<xi*)
Show[Plot[x, x, 0, 1], ListPlot[p],ListPlot[pu, PlotStyle -> Red]]
$endgroup$
Try
p = RandomReal[0, 1, 50, 2]
pu=Select[p, #[[2]] < #[[1]] &]
Length[pu] (* number of points yi<xi*)
Show[Plot[x, x, 0, 1], ListPlot[p],ListPlot[pu, PlotStyle -> Red]]
answered Aug 1 at 13:17
Ulrich NeumannUlrich Neumann
13.5k7 silver badges22 bronze badges
13.5k7 silver badges22 bronze badges
2
$begingroup$
One could also usepu = Select[p, Apply[Greater]]
in this case. A slower, but generalizable approach would bermf = RegionMember[ImplicitRegion[y <= x, x, y]]; pu = Select[p, rmf]
$endgroup$
– J. M. is away♦
Aug 1 at 13:33
$begingroup$
How about if i want to do that in sine curve?
$endgroup$
– Math
Aug 2 at 13:07
$begingroup$
@Math Something likeSelect[p, #[[2]] <Sin[ #[[1]] ] &]
$endgroup$
– Ulrich Neumann
Aug 2 at 13:13
add a comment |
2
$begingroup$
One could also usepu = Select[p, Apply[Greater]]
in this case. A slower, but generalizable approach would bermf = RegionMember[ImplicitRegion[y <= x, x, y]]; pu = Select[p, rmf]
$endgroup$
– J. M. is away♦
Aug 1 at 13:33
$begingroup$
How about if i want to do that in sine curve?
$endgroup$
– Math
Aug 2 at 13:07
$begingroup$
@Math Something likeSelect[p, #[[2]] <Sin[ #[[1]] ] &]
$endgroup$
– Ulrich Neumann
Aug 2 at 13:13
2
2
$begingroup$
One could also use
pu = Select[p, Apply[Greater]]
in this case. A slower, but generalizable approach would be rmf = RegionMember[ImplicitRegion[y <= x, x, y]]; pu = Select[p, rmf]
$endgroup$
– J. M. is away♦
Aug 1 at 13:33
$begingroup$
One could also use
pu = Select[p, Apply[Greater]]
in this case. A slower, but generalizable approach would be rmf = RegionMember[ImplicitRegion[y <= x, x, y]]; pu = Select[p, rmf]
$endgroup$
– J. M. is away♦
Aug 1 at 13:33
$begingroup$
How about if i want to do that in sine curve?
$endgroup$
– Math
Aug 2 at 13:07
$begingroup$
How about if i want to do that in sine curve?
$endgroup$
– Math
Aug 2 at 13:07
$begingroup$
@Math Something like
Select[p, #[[2]] <Sin[ #[[1]] ] &]
$endgroup$
– Ulrich Neumann
Aug 2 at 13:13
$begingroup$
@Math Something like
Select[p, #[[2]] <Sin[ #[[1]] ] &]
$endgroup$
– Ulrich Neumann
Aug 2 at 13:13
add a comment |
$begingroup$
p = RandomReal[0, 1, 50, 2]
Count[p, x_, y_ /; y < x]
This is many times more efficient for long lists:
Total[UnitStep[Subtract @@ Transpose[p]]]
Edit:
A few timings under version 12.0 on macos:
p = RandomReal[0, 1, 1000000, 2];
Length[Select[p, #[[2]] < #[[1]] &]] // RepeatedTiming
Count[p, x_, y_ /; y < x] // RepeatedTiming
Total[UnitStep[Subtract @@ Transpose[p]]] // RepeatedTiming
1.31, 499894
0.757, 499894
0.0089, 499894
$endgroup$
$begingroup$
Very interesting alternatives. By the way the last one is the slowest (MMA v.11.0.1)
$endgroup$
– Ulrich Neumann
Aug 1 at 14:19
$begingroup$
@UlrichNeumann Really? That is indeed surprising... Unfornately, I cannot test it under v. 11.0.1; I have removed it recently.
$endgroup$
– Henrik Schumacher
Aug 1 at 16:26
$begingroup$
Similar timings under v10.4 and 11.3.
$endgroup$
– corey979
Aug 1 at 16:33
2
$begingroup$
@UlrichNeumann That is surprising. What if you try the compiled versionCompile[p,_Real,2,Total[UnitStep[p.1,-1]]]
?
$endgroup$
– Silvia
Aug 2 at 3:20
$begingroup$
@Silvia Great idea to useDot
! And I am also surprised thatCompile
makes a difference here.
$endgroup$
– Henrik Schumacher
Aug 2 at 3:21
|
show 1 more comment
$begingroup$
p = RandomReal[0, 1, 50, 2]
Count[p, x_, y_ /; y < x]
This is many times more efficient for long lists:
Total[UnitStep[Subtract @@ Transpose[p]]]
Edit:
A few timings under version 12.0 on macos:
p = RandomReal[0, 1, 1000000, 2];
Length[Select[p, #[[2]] < #[[1]] &]] // RepeatedTiming
Count[p, x_, y_ /; y < x] // RepeatedTiming
Total[UnitStep[Subtract @@ Transpose[p]]] // RepeatedTiming
1.31, 499894
0.757, 499894
0.0089, 499894
$endgroup$
$begingroup$
Very interesting alternatives. By the way the last one is the slowest (MMA v.11.0.1)
$endgroup$
– Ulrich Neumann
Aug 1 at 14:19
$begingroup$
@UlrichNeumann Really? That is indeed surprising... Unfornately, I cannot test it under v. 11.0.1; I have removed it recently.
$endgroup$
– Henrik Schumacher
Aug 1 at 16:26
$begingroup$
Similar timings under v10.4 and 11.3.
$endgroup$
– corey979
Aug 1 at 16:33
2
$begingroup$
@UlrichNeumann That is surprising. What if you try the compiled versionCompile[p,_Real,2,Total[UnitStep[p.1,-1]]]
?
$endgroup$
– Silvia
Aug 2 at 3:20
$begingroup$
@Silvia Great idea to useDot
! And I am also surprised thatCompile
makes a difference here.
$endgroup$
– Henrik Schumacher
Aug 2 at 3:21
|
show 1 more comment
$begingroup$
p = RandomReal[0, 1, 50, 2]
Count[p, x_, y_ /; y < x]
This is many times more efficient for long lists:
Total[UnitStep[Subtract @@ Transpose[p]]]
Edit:
A few timings under version 12.0 on macos:
p = RandomReal[0, 1, 1000000, 2];
Length[Select[p, #[[2]] < #[[1]] &]] // RepeatedTiming
Count[p, x_, y_ /; y < x] // RepeatedTiming
Total[UnitStep[Subtract @@ Transpose[p]]] // RepeatedTiming
1.31, 499894
0.757, 499894
0.0089, 499894
$endgroup$
p = RandomReal[0, 1, 50, 2]
Count[p, x_, y_ /; y < x]
This is many times more efficient for long lists:
Total[UnitStep[Subtract @@ Transpose[p]]]
Edit:
A few timings under version 12.0 on macos:
p = RandomReal[0, 1, 1000000, 2];
Length[Select[p, #[[2]] < #[[1]] &]] // RepeatedTiming
Count[p, x_, y_ /; y < x] // RepeatedTiming
Total[UnitStep[Subtract @@ Transpose[p]]] // RepeatedTiming
1.31, 499894
0.757, 499894
0.0089, 499894
edited Aug 1 at 16:24
answered Aug 1 at 14:07
Henrik SchumacherHenrik Schumacher
67.1k5 gold badges96 silver badges185 bronze badges
67.1k5 gold badges96 silver badges185 bronze badges
$begingroup$
Very interesting alternatives. By the way the last one is the slowest (MMA v.11.0.1)
$endgroup$
– Ulrich Neumann
Aug 1 at 14:19
$begingroup$
@UlrichNeumann Really? That is indeed surprising... Unfornately, I cannot test it under v. 11.0.1; I have removed it recently.
$endgroup$
– Henrik Schumacher
Aug 1 at 16:26
$begingroup$
Similar timings under v10.4 and 11.3.
$endgroup$
– corey979
Aug 1 at 16:33
2
$begingroup$
@UlrichNeumann That is surprising. What if you try the compiled versionCompile[p,_Real,2,Total[UnitStep[p.1,-1]]]
?
$endgroup$
– Silvia
Aug 2 at 3:20
$begingroup$
@Silvia Great idea to useDot
! And I am also surprised thatCompile
makes a difference here.
$endgroup$
– Henrik Schumacher
Aug 2 at 3:21
|
show 1 more comment
$begingroup$
Very interesting alternatives. By the way the last one is the slowest (MMA v.11.0.1)
$endgroup$
– Ulrich Neumann
Aug 1 at 14:19
$begingroup$
@UlrichNeumann Really? That is indeed surprising... Unfornately, I cannot test it under v. 11.0.1; I have removed it recently.
$endgroup$
– Henrik Schumacher
Aug 1 at 16:26
$begingroup$
Similar timings under v10.4 and 11.3.
$endgroup$
– corey979
Aug 1 at 16:33
2
$begingroup$
@UlrichNeumann That is surprising. What if you try the compiled versionCompile[p,_Real,2,Total[UnitStep[p.1,-1]]]
?
$endgroup$
– Silvia
Aug 2 at 3:20
$begingroup$
@Silvia Great idea to useDot
! And I am also surprised thatCompile
makes a difference here.
$endgroup$
– Henrik Schumacher
Aug 2 at 3:21
$begingroup$
Very interesting alternatives. By the way the last one is the slowest (MMA v.11.0.1)
$endgroup$
– Ulrich Neumann
Aug 1 at 14:19
$begingroup$
Very interesting alternatives. By the way the last one is the slowest (MMA v.11.0.1)
$endgroup$
– Ulrich Neumann
Aug 1 at 14:19
$begingroup$
@UlrichNeumann Really? That is indeed surprising... Unfornately, I cannot test it under v. 11.0.1; I have removed it recently.
$endgroup$
– Henrik Schumacher
Aug 1 at 16:26
$begingroup$
@UlrichNeumann Really? That is indeed surprising... Unfornately, I cannot test it under v. 11.0.1; I have removed it recently.
$endgroup$
– Henrik Schumacher
Aug 1 at 16:26
$begingroup$
Similar timings under v10.4 and 11.3.
$endgroup$
– corey979
Aug 1 at 16:33
$begingroup$
Similar timings under v10.4 and 11.3.
$endgroup$
– corey979
Aug 1 at 16:33
2
2
$begingroup$
@UlrichNeumann That is surprising. What if you try the compiled version
Compile[p,_Real,2,Total[UnitStep[p.1,-1]]]
?$endgroup$
– Silvia
Aug 2 at 3:20
$begingroup$
@UlrichNeumann That is surprising. What if you try the compiled version
Compile[p,_Real,2,Total[UnitStep[p.1,-1]]]
?$endgroup$
– Silvia
Aug 2 at 3:20
$begingroup$
@Silvia Great idea to use
Dot
! And I am also surprised that Compile
makes a difference here.$endgroup$
– Henrik Schumacher
Aug 2 at 3:21
$begingroup$
@Silvia Great idea to use
Dot
! And I am also surprised that Compile
makes a difference here.$endgroup$
– Henrik Schumacher
Aug 2 at 3:21
|
show 1 more comment
$begingroup$
You can use RegionMember
for this:
reg = RegionMember[ImplicitRegion[y<x, x,y]];
Tally @ reg[p]
False, 23, True, 27
This will not be as fast as Henrik's answer.
$endgroup$
add a comment |
$begingroup$
You can use RegionMember
for this:
reg = RegionMember[ImplicitRegion[y<x, x,y]];
Tally @ reg[p]
False, 23, True, 27
This will not be as fast as Henrik's answer.
$endgroup$
add a comment |
$begingroup$
You can use RegionMember
for this:
reg = RegionMember[ImplicitRegion[y<x, x,y]];
Tally @ reg[p]
False, 23, True, 27
This will not be as fast as Henrik's answer.
$endgroup$
You can use RegionMember
for this:
reg = RegionMember[ImplicitRegion[y<x, x,y]];
Tally @ reg[p]
False, 23, True, 27
This will not be as fast as Henrik's answer.
answered Aug 1 at 15:51
Carl WollCarl Woll
89k3 gold badges117 silver badges228 bronze badges
89k3 gold badges117 silver badges228 bronze badges
add a comment |
add a comment |
Thanks for contributing an answer to Mathematica Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f203097%2fhow-to-count-points-under-the-curve%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
$begingroup$
Some related: (97299), (157149), (181620)...I think there's more, but couldn't find the right search terms.
$endgroup$
– Michael E2
Aug 1 at 20:46