head	1.5;
access;
symbols;
locks; strict;
comment	@ * @;


1.5
date	94.08.29.04.20.22;	author rjj;	state Exp;
branches;
next	1.4;

1.4
date	94.07.21.03.43.27;	author rjj;	state Exp;
branches;
next	1.3;

1.3
date	94.07.21.02.31.53;	author rjj;	state Exp;
branches;
next	1.2;

1.2
date	94.07.07.04.25.39;	author rjj;	state Exp;
branches;
next	1.1;

1.1
date	94.07.01.01.18.05;	author rjj;	state Exp;
branches;
next	;


desc
@Initial implementation for the Hopfield Neural Network algorithm.  Buggy!
@


1.5
log
@Modified include stmts to be iac++ 2.0 compliant.
Added exit() to main() for pickey systems.
@
text
@// test-hopfield.c      Section: 13.2
//      Copyright 1994, Center for Computer Vision and Visualization,
//      University of Florida.  All rights reserved.
// This test program uses a set of fixed examplar images.
// Its purpose is not to provide a general shell for building and
//      testing the Hopfield algoritm, but rather to illustrate
//      the algorithm is a reasonable way.
//

#include "DDTempl.h"
#include "IntConv.h"
#include "make-examplars.h"
#include "convert-hopfield-images.h"
#include "hopfield.h"
#include "scale-to-uchar.h"

#include "PSIter.h"


////////////////////////////////////////////////////////////////////////
// Utility code supporting testing of the Hopfield algorithm
////////////////////////////////////////////////////////////////////////

// Corrupt a {0,1} valued image
IA_Image<IA_Point<int>,int>
corrupt( const IA_Image<IA_Point<int>,int> & image ) {

    IA_Image<IA_Point<int>,int>  corrupted_image(image.domain(),0);

    unsigned short seed[3];
    long seconds;

    seconds = time((long *) 0);
    memcpy(seed, &seconds, sizeof(seconds));

    seed48(seed);

    IA_PSIter<IA_Point<int> >
	psi(image.domain());
    IA_Point<int> ip;

    while(psi(ip)) {
	if( lrand48() % 10000 < 1000)	    {
	    corrupted_image[ip] = (image(ip) + 1) % 2;
	} else	{
	    corrupted_image[ip] = image(ip);
	}
    }
    return corrupted_image;
}  /* end corrupt */


// Another approach would be to define this as an IA_Closure<IP,int>
//    that would behave much as an iterator.  However, this works.
int random_select( const IA_Set<IA_Point<int> > &rps,
		   IA_Point<int> & rpt)
{
    int n,pick;
    n = rps.card();

    if(n == 0) {
	return 0;
    } else {
	pick = int (lrand48() % n);
	rpt = rps.index(pick);
	return 1;
    }
}


////////////////////////////////////////////////////////////////////////
// Driver code for testing the Hopfield algorithm
////////////////////////////////////////////////////////////////////////

// The Asynchronous version of the Hopfield algorithm.
// This verison is guaranteed to converge, but may be somewhat
//    slower than the synchronous version.
// However, since we perform the liner_product() on a restricted
//    poinset of one point, this version is not much slower
//    than the synchronous version.
//
IA_Image<IA_Point<int>,int>
a_crank( const IA_Image<IA_Point<int>,int> & a_in,  // 1D image
	 const IA_DDTemplate<IA_Image<IA_Point<int>,int> > & t ) {

    IA_Image<IA_Point<int>,int>
	aa( a_in ), b( a_in.domain(), 0 ), c( a_in.domain(), 0 );

    IA_Point<int> pt;

    int outer_count = 0;
    while( aa != b ) {
	cout << "a_crank.outer_count: " << ++outer_count << endl;
	IA_Set<IA_Point<int> > yps( aa.domain() );

	b = aa;
	while( random_select( yps, pt ) ) {
	    IA_Set<IA_Point<int> > ips( pt );
	    IA_Image<IA_Point<int>,int>
		alpt = linear_product( aa, t, ips ),
		a_for_limit = aa.restrict( ips );

	    c = Hopfield_hard_limiter( alpt, a_for_limit );

	    aa[ pt ] = c( pt );  // Update one point at a time
	    yps /= ips;          // Forget this point
	}
    }
    return aa;
}


// Synchronous verison of the Hopfield algorithm.
IA_Image<IA_Point<int>,int>
p_crank( const IA_Image<IA_Point<int>,int> & a_in,
	 const IA_DDTemplate<IA_Image<IA_Point<int>,int> > & t ) {

    IA_Image<IA_Point<int>,int>
	a_out( a_in ),
	b( a_in.domain(), 0 );

    int count = 0;
    while( a_out != b ) {
	cerr << "p_crank.count = " << ++count << endl;

	b = a_out;
	a_out = Hopfield_hard_limiter( linear_product( a_out, t ), a_out );
    }
    return a_out;
}


// This driver allows the choice of either corrupting the examplar
//    or not, before trying to match it.  It also supports choosing
//    either the Asynchronous or Synchronous Hopfield algorithm.

void
drive( const IA_Image<IA_Point<int>,int> & examplar,  // {0,1} valued image
       const IA_DDTemplate<IA_Image<IA_Point<int>,int> > & t,
       int which_crank,
       int corrupt_the_image ) {

    IA_Image<IA_Point<int>,int>  c;
    if ( corrupt_the_image ) {
	c = corrupt( examplar ); // {0,1} valued image
    } else {
	c = examplar;
    }
    // The input to try to match, but still {0,1} valued
    display( scale_to_uchar( convert_to_2D( c, 10 ) ) );

    IA_Image<IA_Point<int>,u_char>	udi;

    c = 2*c - 1;       // Convert c to range {-1,+1}

    if (which_crank == 0) {
	udi = scale_to_uchar( convert_to_2D( a_crank( c, t ), 10 ) );
    } else {
	udi = scale_to_uchar( convert_to_2D( p_crank( c, t ), 10 ) );
    }
    display( udi );
}



// Present the menu of choices to the user.
int main() {

    int sync_routine = 0;       // Asynchronous
    int corrupt_the_image = 1;  // Yes, corrupt it.

    cerr << "Hopfield Neural Net Simulation" << endl;

    cerr << "initializing examplars ....";
    IA_Image<IA_Point<int>,int>  e[ 6 ];


    // A trick to turn binary {0,1} valued images
    //    into {-1,1} valued images
    e[0] = 2*examplar_1() - 1;
    e[1] = 2*examplar_2() - 1;
    e[2] = 2*examplar_3() - 1;
    e[3] = 2*examplar_4() - 1;
    e[4] = 2*examplar_9() - 1;
    e[5] = 2*examplar_X() - 1;

    cerr << "done." << endl;

    cerr << "Initializing Hopfield template ...";
    int N( e[0].domain().sup()( 0 ) + 1 );
    HopfieldTemplate
	HopT( e, 6 );  // weights.pgm


    IA_DDTemplate<IA_Image<IA_Point<int>,int> >  ht( HopT );

    cerr << "done." << endl;

    cerr << "Writing out HopfieldTemplate weight image ...";
    IA_Image<IA_Point<int>,u_char>
	weights( scale_to_uchar( HopT.weight_image() ) );
    weights.write_PGM( "weights.pgm" );
    cerr << "wrote file: weights.pgm.  Done." << endl;


    char choice;
    for(;;)  {
	cerr << "Toggles: "
	     << "S(" << sync_routine << ") (0=>async,1=>sync), "
	     << "C(" << corrupt_the_image << ") (1=>corrupt)\n"
	     << "Select examplar pattern from 1 2 3 4 9 X.  Q to exit."
	     << " ?" << endl;

	if ( (choice = getchar()) == 'q')  break;
	getchar();  // clear the new line

	switch(choice) 	{
	case '1':
	    drive( examplar_1(), ht, sync_routine, corrupt_the_image );
	    break;
	case '2':
	    drive( examplar_2(), ht, sync_routine, corrupt_the_image );
	    break;
        case '3':
	    drive( examplar_3(), ht, sync_routine, corrupt_the_image );
	    break;
	case '4':
	    drive( examplar_4(), ht, sync_routine, corrupt_the_image );
	    break;
	case '9':
	    drive( examplar_9(), ht, sync_routine, corrupt_the_image );
	    break;
	case 'x':
	case 'X':
	    drive( examplar_X(), ht, sync_routine, corrupt_the_image );
	    break;

	case 's':
	case 'S':
	    sync_routine = sync_routine ? 0 : 1;
	    break;
	case 'c':
	case 'C':
	    corrupt_the_image = corrupt_the_image ? 0 : 1;
	    break;
	default:
	    cerr << "Can't deal with character <" << choice
		 << ">\n" << endl;
	    break;
	}
    }

    exit( 0 );
}
@


1.4
log
@Cleaned up version of the Hopfield code.
@
text
@d11 1
a11 1
#include "IntConvolutions.h"
d167 1
a167 1
void main() {
d252 2
@


1.3
log
@This version works, but still needs to be cleaned up.
  I'm checking it in while I know it works.
@
text
@d1 7
a7 1
// test-hopfield.c
d21 1
a21 1
// dsp\'s code
a23 73
#include "ClosureI.h"
// dsp\'s f() function
IA_Image<IA_Point<int>,int>
dsp_f( const IA_Image<IA_Point<int>,int> & image1,
       const IA_Image<IA_Point<int>,int> & image2 ) {

    IA_Image<IA_Point<int>,int> image3( image1.domain(), 0 );

    IA_PSIter<IA_Point<int> > iter(image1.domain());

    IA_Point<int> iterp;

    while( iter(iterp) ) {
	if(image1(iterp) == 0) 	 {
	    image3[iterp] = image2(iterp);
	} else if(image1(iterp) > 0) {
	    image3[iterp] = 1;
	} else {
	    image3[iterp] = -1;
	}
    }
    return image3;
}


class hop_temp_image: public IA_ClosureI<IA_Point<int>,int>  {
private:
    IA_Point<int> h_i;
    IA_Image<IA_Point<int>,int> h_e;

public:
    hop_temp_image(IA_Set<IA_Point<int> > ps,
		   IA_Image<IA_Point<int>,int> e,
		   const IA_Point<int>& i):
    IA_ClosureI<IA_Point<int>,int>(ps) {
	h_e = e;
	h_i = i;
    }

    int operator() (const IA_Point<int>& j) const  {
	return h_e(IA_Point<int>(h_i[0],j[0]));
    }   

    IA_ClosureI<IA_Point<int>,int> *clone_self() const {
	return new hop_temp_image(*this);
    }
};

  
class hop_temp: public IA_ClosureDT<IA_Image<IA_Point<int>,int> >  {
private:
    IA_Set<IA_Point<int> > ps;
    IA_Image<IA_Point<int>,int> e;

public:
    hop_temp(const IA_Set<IA_Point<int> >& _ps, IA_Image<IA_Point<int>,int> _e)
    :IA_ClosureDT<IA_Image<IA_Point<int>,int> >(_ps),e(_e),ps(_ps){}

    IA_Image<IA_Point<int>,int> operator() (const IA_Point<int>& i) const {
	return IA_Image<IA_Point<int>,int>(hop_temp_image(ps,e,i));
    }
        
    IA_ClosureDT<IA_Image<IA_Point<int>,int> > *clone_self() const {
	return new hop_temp(*this);
    }

    IA_Image<IA_Point<int>,int> weight_image() const {
	return e;
    }
};



d28 1
a28 2
    IA_Image<IA_Point<int>,int>
	corrupted_image(image.domain(),0);
d53 2
d61 1
a61 1
    if(n == 0)     {
d63 1
a63 1
    }   else     {
a69 180
IA_Image<IA_Point<int>,int>
crank(IA_Image<IA_Point<int>,int> a,IA_Image<IA_Point<int>,int> ee)
{
    IA_Set<IA_Point<int> > inps(IA_Point<int>(0),IA_Point<int>(119));
    IA_Image<IA_Point<int>,int> aa(inps,0),cc(inps,0);

    int u,v;

    for(u=0;u<12;u++)       {
	for(v=0;v<10;v++)	  {
	    aa[IA_Point<int>(10*u+v)] = a[IA_Point<int>(u,v)];
	}
    }

    if (min( aa ) == 0) {
	cerr << "min(aa) == 0, adjusting to be {-1, +1}" << endl;
	cerr << "max(aa) == " << max(aa) << endl;
	aa = 2*aa - 1;
	cerr << "aa adjusted: min= " << min(aa)
	     << ", max= " << max(aa) << endl;
    }

    IA_Image<IA_Point<int>,int> b(aa.domain(),0);
    hop_temp t(aa.domain(),ee);

    IA_Point<int> pt;
    IA_Set<IA_Point<int> > yps;

    int count = 0;
    while(aa != b)      {
	cout << "crank0\n"; cout.flush();
	yps = aa.domain();

	b = aa;
	while(random_select(yps,pt))	  {
	    if(count % 120 == 0)	      {
		cout << "crank\n"; cout.flush();
	    }
	    count++;
#if 0
	    cc = dsp_f(linear_product(aa,t),aa);
#else
	    IA_Set<IA_Point<int> > ips( pt );
	    cc = dsp_f( linear_product(aa,t, ips),
		    aa.restrict( ips ) );
#endif
	    aa[pt] = cc[pt];
	    yps /= IA_Set<IA_Point<int> >(pt);
	}
    }


    IA_Set<IA_Point<int> > outps(IA_Point<int>(0,0),IA_Point<int>(11,9));

    IA_Image<IA_Point<int>,int> out(outps,0);

    for(u=0;u<12;u++)      {
	for(v=0;v<10;v++)	  {
	    out[IA_Point<int>(u,v)] = aa[IA_Point<int>(10*u+v)];
	}
    }
    return out;
}


void
dsp_main() {
    IA_Set<IA_Point<int> >
	eps(IA_Point<int>(0,0),IA_Point<int>(11,9)),
	eps1(IA_Point<int>(0),IA_Point<int>(119));

    IA_Image<IA_Point<int>,int>
	e0(eps,examplar_1().value_array().data_start(),120),
	e1(eps,examplar_2().value_array().data_start(),120),
	e2(eps,examplar_3().value_array().data_start(),120),
	e3(eps,examplar_4().value_array().data_start(),120),
	e4(eps,examplar_9().value_array().data_start(),120),
	e5(eps,examplar_X().value_array().data_start(),120);


    IA_Image<IA_Point<int>,int>
	e0f( examplar_1() ), e1f( examplar_1() ), e2f( examplar_1() ), 
	e3f( examplar_1() ), e4f( examplar_1() ), e5f( examplar_1() );
/*	e0f(eps1,one,120),
	e1f(eps1,two,120),
	e2f(eps1,three,120),
	e3f(eps1,four,120),
	e4f(eps1,nine,120),
	e5f(eps1,X,120);
	*/
    e0f = 2*e0f - 1;
    e1f = 2*e1f - 1;
    e2f = 2*e2f - 1;
    e3f = 2*e3f - 1;
    e4f = 2*e4f - 1;
    e5f = 2*e5f - 1;

    IA_Set<IA_Point<int> > eps2(IA_Point<int>(0,0),IA_Point<int>(119,119));

    IA_Image<IA_Point<int>,int> e(eps2,0);  // The weight image

    int i,j;
    for(i=0;i<120;i++) {
	for(j=0;j<120;j++) {
	    if(i != j) {
		e[IA_Point<int>(i,j)] =
		    e0f(IA_Point<int>(i))*e0f(IA_Point<int>(j))
		    + e1f(IA_Point<int>(i))*e1f(IA_Point<int>(j))
		    +e2f(IA_Point<int>(i))*e2f(IA_Point<int>(j))
		    +e3f(IA_Point<int>(i))*e3f(IA_Point<int>(j))
		    +e4f(IA_Point<int>(i))*e4f(IA_Point<int>(j))
		    +e5f(IA_Point<int>(i))*e5f(IA_Point<int>(j));
	    }
	}
    }

    scale_to_uchar( e ).write_PGM( "dsp_weights.pgm" );

    char choice;
    choice = ' ';

    IA_Image<IA_Point<int>,int> a;


    printf("Hopfield Neural Net Simulation\n");
    printf("Select an input pattern from 1, 2, 3, 4, 9, X.      q = Exit\n");

    while((choice = getchar()) != 'q')  {
	getchar();
	switch(choice) 	{
	case '1':
//	    display(IA_Image<IA_Point<int>,u_char>(chi_ge(e0,1)));
	    display( scale_to_uchar( e0 ) );
	    a = corrupt(e0);
//	    display(IA_Image<IA_Point<int>,u_char>(chi_ge(a,1)));
	    display( scale_to_uchar( a ) );
//	    display(IA_Image<IA_Point<int>,u_char>(chi_ge(crank(a,e),0)));
	    display( scale_to_uchar( crank(a,e) ) );
	    break;
	case '2':
	    display( scale_to_uchar( e1 ) );
	    a = corrupt(e1);
	    display( scale_to_uchar( a ) );
	    display( scale_to_uchar( crank(a,e) ) );
	    break;
        case '3':
	    display( scale_to_uchar( e2 ) );
	    a = corrupt(e2);
	    display( scale_to_uchar( a ) );
	    display( scale_to_uchar( crank(a,e) ) );
	    break;
	case '4':
	    display( scale_to_uchar( e3 ) );
	    a = corrupt(e3);
	    display( scale_to_uchar( a ) );
	    display( scale_to_uchar( crank(a,e) ) );
	    break;
	case '9':
	    display( scale_to_uchar( e4 ) );
	    a = corrupt(e4);
	    display( scale_to_uchar( a ) );
	    display( scale_to_uchar( crank(a,e) ) );
	    break;
	case 'x':
	case 'X':
	    display( scale_to_uchar( e5 ) );
	    a = corrupt(e5);
	    display( scale_to_uchar( a ) );
	    display( scale_to_uchar( crank(a,e) ) );
	    break;
	case 'q': printf("Bye\n");
	    break;
	default:
	    printf("Can't deal with that character.\n\n");
	    break;
	}
	cerr << "min(a) = " << min(a) << ", max(a) = " << max(a) << endl;
	printf("Another ?      Choices: 1, 2, 3, 4, 9, X        q = Exit\n");
    }
}
d72 1
a72 1
// rjj\'s code start\'s here
d75 7
a81 2

int g_fast = 1;
a85 2
    IA_Set<IA_Point<int> >
	inps( a_in.domain() );
d87 1
a87 1
	aa( a_in ), b( inps, 0 ), c( inps, 0 );
d92 2
a93 2
    while(aa != b)      {
	cout << "a_crank.outer_count: " << outer_count++ << endl;
d100 3
a102 21
		alpt,  R_alpt,             // linear_product(aa,t)
		a_for_limit, R_a_for_limit;
	    
	    alpt = linear_product( aa, t, ips );
	    a_for_limit = aa.restrict( ips );
	    if ( g_fast == 0) {

		R_alpt = alpt;  // The restricted versions
		R_a_for_limit = a_for_limit;

		alpt = linear_product( aa, t );  // The non-resticted vers
		a_for_limit = aa;

		if ( ( alpt(pt) != R_alpt(pt) ) ||
		     ( a_for_limit(pt) != R_a_for_limit(pt) ) ) {
		    cerr << "\n at: " << pt
			 << alpt(pt) << " != " << R_alpt(pt) << " or "
			 << a_for_limit(pt) << " != " << R_a_for_limit(pt)
			 << endl;
		}
	    }
d105 2
a106 10
#if 1
            IA_Image<IA_Point<int>,int>  C;
	    C = dsp_f( alpt, a_for_limit );
	    if ( c != C ) {
		cerr << "c(" << pt << ") = " << c( pt ) << endl;
		cerr << "C(" << pt << ") = " << C( pt ) << endl;
	    }
#endif
	    aa[ pt ] = c( pt );
	    yps /= ips;
d113 1
a113 1

d124 2
a125 3
	if ( count % 10 == 0 ) {
	    cerr << __FILE__ << "::p_crank.count = " << count << endl;
	}
a127 1
	count++;
d133 4
d149 2
d152 3
a154 6
    IA_Image<IA_Point<int>,u_char>
	udi;
#if 0
    udi =  scale_to_uchar( convert_to_2D( c, 10 ) );
    display( udi );
#endif
a155 2
    // Convert c to range {-1,+1}
    c = 2*c - 1;
d166 1
a166 38
void
run_tests( IA_Image<IA_Point<int>,int>  *examplar_images ) {

    IA_Set<IA_Point<int> >
	oneDps( examplar_images[0].domain() ),
	twoDps( convert_to_2D( examplar_images[0], 10 ).domain() );

    HopfieldTemplate     hop_rjj( examplar_images, 6 );
    IA_DDTemplate<IA_Image<IA_Point<int>,int> >
	ht_rjj( hop_rjj );

    hop_temp             hop_dsp( oneDps, hop_rjj.weight_image() );
    IA_DDTemplate<IA_Image<IA_Point<int>,int> >
	ht_dsp( hop_dsp );

    IA_Point<int> p;
    IA_PSIter<IA_Point<int> > psIter( oneDps );
    while( psIter( p ) ) {

	IA_Image<IA_Point<int>,int>
	    i_rjj( ht_rjj( p ) ),
	    i_dsp( ht_dsp( p ).restrict( oneDps ) );

	if ( i_rjj.domain() != oneDps ) {
	    cerr << "i_rjj.domain() = ";
	    i_rjj.domain().output( cerr );
	}

	if (i_rjj != i_dsp) {
	    cerr << "i_rjj != j_dsp, p = " << p << endl;
	    display( scale_to_uchar( convert_to_2D( i_rjj, 10 ) ) );
	    display( scale_to_uchar( convert_to_2D( i_dsp, 10 ) ) );
	}
    }
}



a170 1
    ::g_fast = 1;               // Argh, a global !  Use fast limiter call.
a192 1
//	HopT( e, 1 );  // weights-1examplar.pgm
d210 1
a210 2
	     << "C(" << corrupt_the_image << ") (1=>corrupt), "
	     << "F(" << g_fast << ") (1=>fast).\n"
a241 4
	case 't':
	case 'T':
	    run_tests( e );
	    break;
a244 8
	    break;
	case 'd':
	case 'D':
	    dsp_main();
	    break;
	case 'f':
	case 'F':
	    g_fast = ::g_fast ? 0 : 1;
@


1.2
log
@Bug fixes.
@
text
@d13 79
d136 184
d321 2
d324 1
a324 1
a_crank( const IA_Image<IA_Point<int>,int> & a_in,
a332 1
    IA_Set<IA_Point<int> > yps;
d337 1
a337 1
	yps = aa.domain();
a339 1
	int inner_count = 0;
d341 31
a371 3
	    if(inner_count % 119 == 0) {
		cout << "a_crank.inner_count: "
		     << inner_count << "\t" << pt << endl;
d373 1
a373 5
	    inner_count++;
	    IA_Set<IA_Point<int> > ips( pt );
//	    b = aa;
	    c = Hopfield_hard_limiter( linear_product( aa, t, ips ),
				       aa.restrict( ips ) );
d375 1
a375 1
	    yps /= IA_Set<IA_Point<int> >( pt );
d405 1
a405 1
drive( const IA_Image<IA_Point<int>,int> & examplar,
d407 2
a408 1
       int which_crank ) {
d410 6
a415 2
    IA_Image<IA_Point<int>,int>
	c = corrupt( examplar );
d418 3
a420 1
	udi(  scale_to_uchar( convert_to_2D( c, 10 ) ) );
d422 1
d424 2
a434 1
void main(int argc, char *argv[]) {
d436 36
a471 3
    // if a value was passed on the command line, use that
    // to select the convergence routine used.
    int sync_routine( argc > 1 ? atoi(argv[1]) : 0);
d474 1
a474 3
    cerr << "Hopfield Neural Net Simulation using "
	 << (sync_routine == 0 ? "asynchronous" : "synchronous" )
	 << " convergence routine." << endl;
d476 6
a484 9
    // Legacy code support
    IA_Image<IA_Point<int>,int>
	e0( examplar_1() ),
	e1( examplar_2() ),
	e2( examplar_3() ),
	e3( examplar_4() ),
	e4( examplar_9() ),
	e5( examplar_X() );

d486 1
a486 1
    // A slick trick to turn binary {0,1} valued images
a496 9
#if 0
    cerr << "Initalizing weight image ...";
    IA_Image<IA_Point<int>,int>
	w( hopfield_weight_image( e, 6 ) );

    scale_to_uchar( w ).write_PGM( "weight.pgm" );
    cerr << "done (wrote file: weight.pgm)." << endl;
#endif

d500 4
a503 5
#if 1
	HopT( e, 6 );
#else
        HopT( w );
#endif
d514 1
d516 7
a522 4
    choice = ' ';

    IA_Image<IA_Point<int>,int> a;

d524 2
a525 1
    printf("Select an input pattern from 1, 2, 3, 4, 9, X.      q = Exit\n");
a526 2
    while((choice = getchar()) != 'q')  {
	getchar();
d529 1
a529 1
	    drive( examplar_1(), ht, sync_routine );
d532 1
a532 1
	    drive( examplar_2(), ht, sync_routine );
d535 1
a535 1
	    drive( examplar_3(), ht, sync_routine );
d538 1
a538 1
	    drive( examplar_4(), ht, sync_routine );
d541 1
a541 1
	    drive( examplar_9(), ht, sync_routine );
d545 22
a566 1
	    drive( examplar_X(), ht, sync_routine );
a572 2
	cerr << "Another ?      Choices: 1, 2, 3, 4, 9, X        q = Exit\n"
	     << endl;
@


1.1
log
@Initial revision
@
text
@a7 1
#include "hopfield-weights.h"
d57 1
a57 1
/*
d59 2
a60 4
crank(IA_Image<IA_Point<int>,int> a,IA_Image<IA_Point<int>,int> ee)
{
    IA_Set<IA_Point<int> > inps(IA_Point<int>(0),IA_Point<int>(119));
    IA_Image<IA_Point<int>,int> aa(inps,0),cc(inps,0);
d62 4
a65 10
    int u,v;

    for(u=0;u<12;u++)       {
	for(v=0;v<10;v++)	  {
	    aa[IA_Point<int>(10*u+v)] = a[IA_Point<int>(u,v)];
	}
    }

    IA_Image<IA_Point<int>,int> b(aa.domain(),0);
    hop_temp t(aa.domain(),ee);
d70 1
a70 1
    int count = 0;
d72 1
a72 1
	cout << "crank0\n"; cout.flush();
d75 6
a80 3
	while(random_select(yps,pt))	  {
	    if(count % 120 == 0)	      {
		cout << "crank\n"; cout.flush();
d82 7
a88 5
	    count++;
	    b = aa;
	    cc = f(linear_product(aa,t),aa);
	    aa[pt] = cc[pt];
	    yps /= IA_Set<IA_Point<int> >(pt);
d91 2
a92 3


    IA_Set<IA_Point<int> > outps(IA_Point<int>(0,0),IA_Point<int>(11,9));
a93 1
    IA_Image<IA_Point<int>,int> out(outps,0);
a94 8
    for(u=0;u<12;u++)      {
	for(v=0;v<10;v++)	  {
	    out[IA_Point<int>(u,v)] = aa[IA_Point<int>(10*u+v)];
	}
    }
    return out;
}
*/
d106 3
a108 1
	cerr << __FILE__ << "::p_crank.count = " << count << endl;
d111 1
d119 2
a120 1
	 const IA_DDTemplate<IA_Image<IA_Point<int>,int> > & t ) {
d129 5
a133 1
    udi = scale_to_uchar( convert_to_2D( p_crank( c, t ), 10 ) );
d138 1
a138 1
main() {
d140 9
a148 1
    cerr << "Hopfield Neural Net Simulation\n" << endl;
d173 1
d180 1
d183 9
a191 6
    int N( 120 );
    IA_DDTemplate<IA_Image<IA_Point<int>,int> >
//	ht( Hopfield_template( e, 6 ) );
	ht( Hopfield_template( IA_boxy_pset( IA_Point<int>(   0 ),
					     IA_Point<int>( N-1 ) ),
			       w ) );
d194 5
d212 1
a212 1
	    drive( examplar_1(), ht );
d215 1
a215 1
	    drive( examplar_2(), ht );
d218 1
a218 1
	    drive( examplar_3(), ht );
d221 1
a221 1
	    drive( examplar_4(), ht );
d224 1
a224 1
	    drive( examplar_9(), ht );
d228 1
a228 1
	    drive( examplar_X(), ht );
@
