Hi Henry,

Thanks for the tip. I looked into it and can see how its concepts overlap
my problem. I'm not sure how to generalize my problem into the simplex form
so that method can be used.

I found an example of using amoeba that made some sense to me:
https://www.astro.virginia.edu/class/oconnell/astr511/idl_5.1_html/idl6.htm
-- solving a simple x/y system of equations (like linear regression). I'm
also unable to figure out how to translate that problem to your amoeba
implementation

X=:(i.17)*5
Y =: 12.0, 24.3, 39.6, 51.0, 66.5, 78.4, 92.7, 107.8, 120.0, 135.5, 147.5,
161.0, 175.4, 187.4, 202.5, 215.4, 229.9

NB. linear regression is close to the referenced page output
NB. IDL prints:
NB. Intercept, Slope: 11.4100 2.72800
Y %. (X,.1)
2.72598 11.3667

Translating it to J
f=: 4 : '| (Y-(y+x*X))'

f amoeba 1e_12 (X,.Y)
|assertion failure
|   (1=-/$y)*.2=#$y


I'm stuck on the point that the shape of the y

Per amoeba.ijs:
NB. y is defined to be a simplex, that is, it is n+1 points in a
n-dimensional
NB. space.  So, the shape of y is (n+1),n.

1.) I'm not sure how I can convert the simple regression example to this
format. Can it be done?
2.) Can you provide some tips on how to restructure my problem for this? I
think my cost function may be OK as it seems conceptually similar to the
other amoeba example of minimizing the error

cost=: 3 : 0
NB. find the odometer multiplier closest to the current
flm=: lm ((],&0) {~ ([ I.~ ])) y
((tp-(+/ l*flm*w))^2),y
)



Thank you




On Wed, Apr 8, 2015 at 5:12 AM, Henry Rich <[email protected]> wrote:

> Look at amoeba.ijs in math/misc.
>
> Henry Rich
>
>
> On 4/7/2015 10:53 PM, Joe Bogner 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
>>
>>  ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to