resampling to avoid limit - nchoosek

조회 수: 3 (최근 30일)
Joel Schelander
Joel Schelander 2021년 4월 14일
댓글: Steven Lord 2021년 4월 15일
I am investigating the combination of vehicles and houses.
My equation for this is:
i=nchoosek(1:numel(VID1),size(Hcombos,2));
Where VID1 is a cell containing all the possible combinations of vechicles for one house and size(Hcombos2,2) is the number of households.
My problem is that I have 429 vehicles and 36 households. I need to limit the number of combinations I generate: when I combine 429 vehicles with 36 houses, I should get out 1000 (arbitrary) of those combinations. .
  댓글 수: 1
Adam Danz
Adam Danz 2021년 4월 14일
편집: Adam Danz 2021년 4월 14일
Sounds like you need to use randperm.
To choose 1000 unique random samples from values 1:429,
randperm(429, 1000)

댓글을 달려면 로그인하십시오.

채택된 답변

Steven Lord
Steven Lord 2021년 4월 14일
Assuming VID1 has 429 elements and Hcombos has 36 rows, that means you're trying to generate one of this many combinations:
N = nchoosek(429, 36)
Warning: Result may not be exact. Coefficient is greater than 9.007199e+15 and is only accurate to 15 digits
N = 3.4817e+52
If you were planning to operate on each combination in turn, how fast can you perform those operations? Let's assume you could process a million combinations a second. How long would it take?
years(seconds(N/1e6))
ans = 1.1033e+39
To think about that period of time you need to look at the timeline of the far future.
Let's talk about the bigger picture for a second. What exactly do these combinations represent? Do you just want a logical matrix of size [numel(VID1),size(Hcombos,2)] with restrictions on how many true values can be in each row and/or each column, to map households and vehicles? Do you want random permutation matrices?
  댓글 수: 2
Joel Schelander
Joel Schelander 2021년 4월 14일
I have 36 houses and 429 electric vehicles. So what the combinations do is:
What happens to the total power demand of house 1, 2 and 3 if they each have a vehicle?
nchoosek(429,3).
And study from 1 House to 36 Houses combined.
nchoosek(429,1)..nchoosek(429,2)... and so on.
Random permutation matrices is more what im looking for yes.
Steven Lord
Steven Lord 2021년 4월 15일
Okay, so what you're looking for is a matrix of size [numberOfHouses numberOfVehicles] where each row has exactly one value equal to 1 and the rest are 0 and where each column has either no value equal to 1 or exactly one value equal to 1?
If you want the transpose of that matrix instead with the limitations on rows and columns swapped accordingly that's fine, I mainly just want to make sure I understand the problem.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

제품


릴리스

R2017b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by