Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>Approach 1</strong></p> <p>If the assignment what products belong to the three price segments never changes, why don't you simply build 3 lists, one for the products in each price segment (assuming these sets are disjoint). Then you may pick from these lists randomly (<a href="http://en.wikipedia.org/wiki/Sampling_%28statistics%29#Replacement_of_selected_units" rel="nofollow">either with or without replacement</a> - as you like). The number of items for each class is given by the ratios.</p> <p><strong>Approach 2</strong></p> <p>If the product-price-segment assignment is intended to be pre-specified, e.g., by passing corresponding price values for each segment on function call, you may want to have the products sorted by price and use a binary search to select the <a href="http://en.wikipedia.org/wiki/K-nearest_neighbor_algorithm" rel="nofollow">m-nearest-neighbors</a> (for example). The parameter <code>m</code> could be specified according to the ratios. If you specify a maximum distance you may reject products that are outside the desired price range.</p> <p><strong>Approach 3</strong></p> <p>If the product-price-segment assignment needs to be determined autonomously, you could apply your <a href="http://en.wikipedia.org/wiki/Cluster_analysis" rel="nofollow">clustering</a> algorithm of choice, e.g., <a href="http://en.wikipedia.org/wiki/K-means" rel="nofollow">k-means</a>, to assign your products to, say, <code>k = 3</code> price segments. For the actual product selection you may proceed similarly as described above.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload