/** * Create a new synapse for this segment attached to the specified input source. * @param inputSource: the input source of the synapse to create. * @return the newly created synapse. */ Synapse* createSynapse(Segment* seg, Cell* inputSource, int initPerm) { /*if synapse array is full, need to increase capacity to add more*/ if(seg->numSynapses == seg->allocatedSynapses) { int newAllocation = seg->allocatedSynapses*2; seg->synapses = realloc(seg->synapses, newAllocation * sizeof(Synapse)); seg->allocatedSynapses = newAllocation; } initSynapse(&seg->synapses[seg->numSynapses], inputSource, initPerm); seg->numSynapses += 1; return &(seg->synapses[seg->numSynapses-1]); }
void Network::createMultiLayer(int M, int N, double weight, double parameter) { int nbNeurons = (M+N)*(M-N+1)/2; createNetwork(nbNeurons); // init neurons _neuronParameters.fill(parameter); // init synapses // for all layer for (int i=M,k=0; i>N; i--) { // select a neuron of this main layer for (int j=0; j<i; j++) { // add synapses from neurons of the main layer to all neurons of the sub-layer for (int l=0; l<i-1; l++) { initSynapse(k+j, k+i+l, weight); } } k += i; } // input neurons for (int i=0; i<M; i++) { addInput(i); } // output neurons for (int i=0; i<N; i++) { addOutput(nbNeurons - N + i); } }