I meant to mention that I recognize there are optimizations that can be
made to the current approach.

For example, I can significantly reduce the iterations by filtering the
odometer to rows with columns of increasing order. Example: filter out 15
13 12 11 since I. expects it sorted and it would be the same result
(sorted) as 11 12 13 15. I may try that but was more interested in
completely different approaches
 On Apr 7, 2015 10:53 PM, "Joe Bogner" <[email protected]> wrote:

> I have an optimization problem that I figured I'd try solving with J
>
> I have a set of data with a target, multiplier, and weight. I'd like to
> calculate 4 multipliers that minimize the error from the current weighted
> value = ( target * multiplier * weight);
>
> In other words, I want to essentially fit 4 values to the existing
> population
>
> I can calculate 2 quickly and 3 takes about 3-4 minutes. I think 4 may
> take hours
>
> This is a brute force method, so I'm interested in alternatives... either
> in J or some other software. I'm not familiar enough with this class of
> problem to search for other solutions effectively
>
> Thank you for ideas
>
> odometer =: #: i.@(*/)
> NB. my range of values are constrained to 0 to 1 in hundredths
> nums=:(odometer 100 100 100)
> nums=:100%~nums
>
> NB. sample dataset has 10,000 rows to fit
> N=:10000
>
> NB. sample data has 4 populations, which have slightly different
> distributions
> gi=:(?.N#4)
> g=:'ABCD' {~ gi
>
> NB. maximum value
> l=:(?.N#100)
>
> NB. group a-d range of multipliers
> Ar=:(?.N#20)
> Br=:(?.N#50)
> Cr=:(?.N#70)
> Dr=:(?.N#90)
>
> NB. some weights
> w=:(?.N#10000)
>
> NB. select multiplier depending on A,B,C,D
> NB. there must be a better way to do this
> NB. ideally something like
> NB. (Ar,.Br,.Cr,.Dr,.gi) {~"1 gi
> lm =: 100 %~ ; ({~ 4&{"1) each <"1 (Ar,.Br,.Cr,.Dr,.gi)
>
> NB. weighted value
> p=: l*lm*w
> NB. total of all weighted values
> tp=: +/ p
>
>
> NB. cost function
> cost=: 3 : 0
> NB. find the odometer multiplier closest to the current
> flm=: lm ((],&0) {~ ([ I.~ ])) y
> ((tp-(+/ l*flm*w))^2),y
> )
> costs=. cost"1 nums
>
> NB. best 5
> best5=.(5 {. (/: (0{"1 costs))) { costs
>
> NB. re-run best
> cost 1}.  0{::best5
>
>
>
> The best two values are 0.26 and 0.51
> The best three values are 0.18 0.46 and 0.57
>
>
>
>
>
>
>
>
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to