Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

extnolfi.cc

Go to the documentation of this file.
00001 
00003 void NolfiNet::indexInputs () {
00004     for (int i=0; i<cells.size; i++)
00005         if (cells[i].mFinalType==CT_OUTPUT)
00006             cells[i].mFinalID = int (cells[i].mCoord.y+0.5);
00007 }
00008 
00009 void NolfiNet::indexHiddens (int hiddens) {
00010     // Index the hidden units according to their X-position. This is
00011     // one easy way to solve the problem
00012     int ind=0;
00013     for (int i=0; i<hiddens; i++) {
00014         // Find the unindexed hidden cell with the smallest X coordinate
00015         double minX = 666.0;
00016         int minNeuron = -1;
00017         
00018         for (int j=0; j<cells.size; j++)
00019             if (cells[j].mFinalType==CT_HIDDEN && cells[j].mCoord.x<=minX &&
00020                 cells[j].mFinalID==EMPTYID) {
00021                 minX = cells[j].mCoord.x;
00022                 minNeuron = j;
00023             }
00024         
00025         ASSERT (minNeuron!=-1);
00026         
00027         // Set the index of the smallest found unindexed cell
00028         cells[minNeuron].mFinalID = mInputs+ind;
00029         ind++;
00030     }
00031 }
00032 
00033 void NolfiNet::indexOutputs (int hiddens) {
00034     int totalUnits = mInputs+hiddens+mOutputs;
00035     for (int i=0; i<cells.size; i++)
00036         if (cells[i].mFinalType==CT_OUTPUT) {
00037             cells[i].mFinalID = mInputs+hiddens;//int ((mSize/mOutputs)/cells[i].mCoord.y);
00038             
00039             ASSERT (cells[i].mFinalID>=totalUnits-mOutputs);
00040             ASSERT (cells[i].mFinalID<totalUnits);
00041         }
00042 }
00043 
00044 void NolfiNet::removeDuplicates (int& rOutputs) {
00045     // Remove input and output cells with duplicate indices
00046     for (int i=0; i<cells.size; i++)
00047         for (int j=i+1; j<cells.size; j++)
00048             if (cells[i].mFinalID!=EMPTYID && cells[i].mFinalID == cells[j].mFinalID) {
00049                 cells[j].mFinalID = EMPTYID;
00050                 // We want to calculate the number of output units exactly
00051                 if (cells[i].mFinalType==CT_OUTPUT)
00052                     rOutputs--;
00053             }
00054 }
00055 
00056 int NolfiNet::connect (FreeNetwork& network) {
00057     int connections=0;
00058     for (int i=0; i<cells.size; i++) {
00059         // (sout << cells[i]).print("\n");
00060 
00061         // Only the cells that have been given a neuron index
00062         if (cells[i].mFinalID!=EMPTYID) {
00063             FreeNeuron& neuron = network[cells[i].mFinalID];
00064 
00065             // Set the neuron attributes
00066             neuron.setBias (cells[i].mBias);
00067             neuron.moveTo (cells[i].mCoord);
00068             
00069             // Generate the branch tip points
00070             PackArray<Coord2D> tips;
00071             cells[i].developAxon (tips, mSize);
00072                     
00073             // Now find other cells that lie near these points
00074             for (int j=0; j<cells.size; j++)
00075                 if (cells[j].mFinalID > cells[i].mFinalID && cells[j].mFinalType>CT_INPUT)
00076                     for (int k=0; k<tips.size; k++) {
00077                         double d = cells[j].mCoord.sqdist (tips[k]);
00078                         if (d < 25.0) {
00079                             // TRACE4 ("%d->%d: d(%d)=%f", i, j, k, d);
00080                             if (!neuron.connectedTo (cells[j].mFinalID)) {
00081                                 // Found a new target, add it to the network
00082                                 network.connect (cells[i].mFinalID, cells[j].mFinalID);
00083                                 connections++;
00084                                 break;  // Break from the k loop
00085                             }
00086                         }
00087                     }
00088 
00089             // Set the initial connection weights to the encoded weight
00090             for (int j=0; j<neuron.conns(); j++)
00091                 neuron[j].setWeight (cells[i].mWeight);
00092         }
00093     }
00094 
00095     return connections;
00096 }
00097 

Generated on Thu Feb 10 20:21:26 2005 for Annalee by doxygen1.2.18