Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^3: Average Price Algorithm

by GrandFather (Saint)
on Feb 01, 2009 at 01:21 UTC ( [id://740492]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Average Price Algorithm
in thread Average Price Algorithm

The test sample:

demoAllocation ( "Distribution: nasty", {a => 30, b => 30}, { '1.0' => 40, '2.0' => 10, '4.0' => 10, } );

Prints:

Distribution: nasty a: 17 @ $1.00 10 @ $2.00 3 @ $4.00 bucket avg: $1.63, deviation: $-0.033 b: 23 @ $1.00 7 @ $4.00 bucket avg: $1.70, deviation: $0.033

However inspection of the original data suggests that simply allocating half of each original parcel to the two groups gives a perfect result.


Perl's payment curve coincides with its learning curve.

Replies are listed 'Best First'.
Re^4: Average Price Algorithm
by ELISHEVA (Prior) on Feb 01, 2009 at 07:45 UTC
    Many thanks for the example!

    GrandFather, I'm wondering if you would share your thoughts on

    • why this particular example fails to find the optimal solution?
    • whether there is a solution that would consistently address the reason for failure?

    It strikes me that it has something to do with relative factorization. For example, had the example been scaled down by 10 so that the number of buckets was relatively prime vis a vis the number of items assigned to each value, then the strategy of minimizing net deviation would have succeeded in finding the optimal result. Conversely, had the code I posted taken relative factorization into account, it would have found the optimal solution.

    Are there other examples you can think of, for which taking into account relative factorization would not help?

    Best, beth

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://740492]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (4)
As of 2024-04-25 15:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found