comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Dimeo genetic algorithm
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: Dimeo genetic algorithm [message #59460] Tue, 25 March 2008 02:37
Rob.Dimeo is currently offline  Rob.Dimeo
Messages: 21
Registered: September 2007
Junior Member
On Mar 24, 9:15 pm, David Fanning <n...@dfanning.com> wrote:
> Dr. Dimeo!? Pretty lofty title for someone who only has
> two people using his programs. ;-)
>
> Cheers,
>
> David
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming:http://www.dfanning.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")

And here I thought you needed to ride one of those cool orange bikes
to command lofty titles. :-)
Re: Dimeo genetic algorithm [message #59462 is a reply to message #59460] Mon, 24 March 2008 19:15 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
josea.malpica@gmail.com writes:

> Thank you very much Dr. Dimeo for your quick response to my post.
> It was this type of code that I needed to try do something similar.
> It has been a great help.

Dr. Dimeo!? Pretty lofty title for someone who only has
two people using his programs. ;-)

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: Dimeo genetic algorithm [message #59463 is a reply to message #59462] Mon, 24 March 2008 18:38 Go to previous message
josea.malpica is currently offline  josea.malpica
Messages: 12
Registered: March 2008
Junior Member
Thank you very much Dr. Dimeo for your quick response to my post.
It was this type of code that I needed to try do something similar.
It has been a great help.

Jose A. Malpica
Re: Dimeo genetic algorithm [message #59465 is a reply to message #59463] Mon, 24 March 2008 16:49 Go to previous message
Rob.Dimeo is currently offline  Rob.Dimeo
Messages: 21
Registered: September 2007
Junior Member
On Mar 24, 1:55 pm, josea.malp...@gmail.com wrote:
> I am using the genetic algorithms code by R. Dimeo (www.ncnr.nist.gov/
> staff/dimeo/idl_programs.html)
> for the optimization of image classification. I have tried to pass
> data (image matrices) to the function to by optimaze (test_func_1)
> from the main program.

Wow...there's a second user of this implementation of the GA! Let's
see if I can help with this.

You *should* be passing these data in via the functargs keyword as you
suspected. The way you have the code written in your posting though
has you passing the pointers in as parameters. The code example below
illustrates how you can pass in one array into a simple minimization
problem in 1-d. Specifically a pointer to the array is passed into
the routine. Compile the code below and type test_ga_min_fun.
Admittedly the syntax is probably not obvious. Sorry for posting all
of this code....but I hope it helps.

Rob Dimeo

; *********************************** ;
pro test_ga_iterproc,func, $
p, $
iter, $
interrupt, $
functargs = functargs, $
oref = oga, $
_Extra = extra
compile_opt hidden,idl2
oga->get_property,ave_fitness = ave_fitness
x = 1+indgen(iter+1)
y = ave_fitness[0:iter]
tvlct,r,g,b,/get
rnew = reverse(r) & gnew = reverse(g) & bnew = reverse(b)
tvlct,rnew,gnew,bnew
wset,extra.winpix
plot,[x],[y],psym = -4,title = 'Function evaluation',xtitle =
'Generation', $
ytitle = '<F(p)>'
wset,extra.winvis
device,copy = [0,0,!d.x_size,!d.y_size,0,0,extra.winpix]
tvlct,r,g,b
end
; ******************************************* ;
function ga_f1,p,_EXTRA = extra
x = p[0]
; Extract the array from the pointer passed in as
; a keyword.
a = *extra.aptr
z = 3.*total(a)*(1.-x)^2
return,z
end
; ******************************************* ;
function my_obj_fun,z,_Extra = extra
return,(extra.iter+1.) * (max(z)-z)
end
; ******************************************* ;
pro test_ga_min_fun
; Uses the simple genetic algorithm to minimize a function
; of a single variable.

; Create an array that we'll pass into the function to be minimized.
; Specifically create a pointer.
a = findgen(5)
aptr = ptr_new(a)

prange = [-9.0,9.0]
ofun = 'my_obj_fun'
func = 'ga_f1'
quiet = 0B

if ~quiet then begin
xsize = 400 & ysize = 400
window,0,xsize = xsize,ysize = ysize
winvis = 0
window,/free,/pixmap,xsize = xsize,ysize = ysize
winpix = !d.window
iterargs = {winvis:winvis,winpix:winpix}
iterproc = 'test_ga_iterproc'
endif
ftol = 1.e-2
ft = {aptr:aptr} ; These are the arguments that will be passed into
the function
; we are minimizing.
p = rmd_ga( ftol, $
function_value = function_value, $
function_name = func, $
functargs = ft, $
prange = prange, $
ncalls = ncalls, $
quiet = quiet, $
objective_function = ofun, $
pcross = 0.95, $
gene_length = 25, $
pmutate = 0.01, $
stretch_factor = 1., $
itmax = 100, $
iterproc = iterproc, $
iterargs = iterargs, $
npop = 100)

if ~quiet then wdelete,winpix
this_format = '(f15.3)'
print,'Best parameters: '+strtrim(string(p[0],format = this_format),2)
print,'Function value: '+strtrim(string(function_value,format =
this_format),2)


ptr_free,aptr

end
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: how to add chinese font in the 'xyouts' procedure
Next Topic: Add bitmaps to 'widget_base'

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 18:44:38 PDT 2025

Total time taken to generate the page: 0.00476 seconds