/** * This will connect the specified unit to be an input to this unit. * @param i The unit. * @param n It's connection number for this connection. * @return True if the connection was made, false otherwise. */ protected boolean connectInput(NeuralConnection i, int n) { for (int noa = 0; noa < m_numInputs; noa++) { if (i == m_inputList[noa]) { return false; } } if (m_numInputs >= m_inputList.length) { //then allocate more space to it. allocateInputs(); } m_inputList[m_numInputs] = i; m_inputNums[m_numInputs] = n; m_numInputs++; return true; }
/** * This will connect the specified unit to be an output to this unit. * @param o The unit. * @param n It's connection number for this connection. * @return True if the connection was made, false otherwise. */ protected boolean connectOutput(NeuralConnection o, int n) { for (int noa = 0; noa < m_numOutputs; noa++) { if (o == m_outputList[noa]) { return false; } } if (m_numOutputs >= m_outputList.length) { //then allocate more space to it. allocateOutputs(); } m_outputList[m_numOutputs] = o; m_outputNums[m_numOutputs] = n; m_numOutputs++; return true; }
m_outputList[noa-1].changeInputNum(m_outputNums[noa-1], noa-1);
/** * This function will remove all the inputs to this unit. * In doing so it will also terminate the connections at the other end. */ public void removeAllInputs() { for (int noa = 0; noa < m_numInputs; noa++) { //this command will simply remove any connections this node has //with the other in 1 go, rather than seperately. m_inputList[noa].disconnectOutput(this, -1); } //now reset the inputs. m_inputList = new NeuralConnection[0]; setType(getType() & (~INPUT)); if (getNumOutputs() == 0) { setType(getType() & (~CONNECTED)); } m_inputNums = new int[0]; m_numInputs = 0; }
/** * This function will remove all outputs to this unit. * In doing so it will also terminate the connections at the other end. */ public void removeAllOutputs() { for (int noa = 0; noa < m_numOutputs; noa++) { //this command will simply remove any connections this node has //with the other in 1 go, rather than seperately. m_outputList[noa].disconnectInput(this, -1); } //now reset the inputs. m_outputList = new NeuralConnection[0]; m_outputNums = new int[0]; setType(getType() & (~OUTPUT)); if (getNumInputs() == 0) { setType(getType() & (~CONNECTED)); } m_numOutputs = 0; }
boolean stat1 = s.disconnectOutput(t, -1); boolean stat2 = t.disconnectInput(s, -1); if (stat1 && stat2) { if ((s.getType() & PURE_INPUT) == PURE_INPUT) { t.setType(t.getType() & (~INPUT)); else if ((t.getType() & (PURE_OUTPUT)) == PURE_OUTPUT) { s.setType(s.getType() & (~OUTPUT)); if (s.getNumInputs() == 0 && s.getNumOutputs() == 0) { s.setType(s.getType() & (~CONNECTED)); if (t.getNumInputs() == 0 && t.getNumOutputs() == 0) { t.setType(t.getType() & (~CONNECTED));
disconnect(s, t); if (s == t) { return false; if ((t.getType() & PURE_INPUT) == PURE_INPUT) { return false; //target is an input node. if ((s.getType() & PURE_OUTPUT) == PURE_OUTPUT) { return false; //source is an output node if ((s.getType() & PURE_INPUT) == PURE_INPUT && (t.getType() & PURE_OUTPUT) == PURE_OUTPUT) { return false; //there is no actual working node in use if ((t.getType() & PURE_OUTPUT) == PURE_OUTPUT && t.getNumInputs() > 0) { return false; //more than 1 node is trying to feed a particular output if ((t.getType() & PURE_OUTPUT) == PURE_OUTPUT && (s.getType() & OUTPUT) == OUTPUT) { return false; //an output node already feeding out a final answer if (!s.connectOutput(t, t.getNumInputs())) { return false; if (!t.connectInput(s, s.getNumOutputs() - 1)) { s.disconnectOutput(t, t.getNumInputs()); return false;
NeuralConnection.connect(m_selected.get(noa), v.get(nob)); NeuralConnection.disconnect(m_selected.get(noa), v.get(nob)); NeuralConnection.disconnect(v.get(nob), m_selected.get(noa)); v.get(noa).removeAllInputs(); v.get(noa).removeAllOutputs(); removeNode(v.get(noa));
NeuralConnection.connect(m_neuralNodes[noc], temp); for (int noa = 0; noa < m_numAttributes; noa++) { for (int nob = 0; nob < m_numClasses; nob++) { NeuralConnection.connect(m_inputs[noa], m_neuralNodes[nob]); for (int noa = 0; noa < m_numAttributes; noa++) { for (int nob = m_numClasses; nob < m_numClasses + val; nob++) { NeuralConnection.connect(m_inputs[noa], m_neuralNodes[nob]); NeuralConnection.connect(m_neuralNodes[noa], m_neuralNodes[nob]);
m_inputNums[noa-1] = m_inputNums[noa]; m_inputList[noa-1].changeOutputNum(m_inputNums[noa-1], noa-1);
/** * This will connect the specified unit to be an input to this unit. * @param i The unit. * @param n It's connection number for this connection. * @return True if the connection was made, false otherwise. */ protected boolean connectInput(NeuralConnection i, int n) { //the function that this overrides can do most of the work. if (!super.connectInput(i, n)) { return false; } //note that the weights are shifted 1 forward in the array so //it leaves the numinputs aligned on the space the weight needs to go. m_weights[m_numInputs] = m_random.nextDouble() * .1 - .05; m_changeInWeights[m_numInputs] = 0; return true; }
disconnect(s, t); if (s == t) { return false; if ((t.getType() & PURE_INPUT) == PURE_INPUT) { return false; //target is an input node. if ((s.getType() & PURE_OUTPUT) == PURE_OUTPUT) { return false; //source is an output node if ((s.getType() & PURE_INPUT) == PURE_INPUT && (t.getType() & PURE_OUTPUT) == PURE_OUTPUT) { return false; //there is no actual working node in use if ((t.getType() & PURE_OUTPUT) == PURE_OUTPUT && t.getNumInputs() > 0) { return false; //more than 1 node is trying to feed a particular output if ((t.getType() & PURE_OUTPUT) == PURE_OUTPUT && (s.getType() & OUTPUT) == OUTPUT) { return false; //an output node already feeding out a final answer if (!s.connectOutput(t, t.getNumInputs())) { return false; if (!t.connectInput(s, s.getNumOutputs() - 1)) { s.disconnectOutput(t, t.getNumInputs()); return false;
boolean stat1 = s.disconnectOutput(t, -1); boolean stat2 = t.disconnectInput(s, -1); if (stat1 && stat2) { if ((s.getType() & PURE_INPUT) == PURE_INPUT) { t.setType(t.getType() & (~INPUT)); else if ((t.getType() & (PURE_OUTPUT)) == PURE_OUTPUT) { s.setType(s.getType() & (~OUTPUT)); if (s.getNumInputs() == 0 && s.getNumOutputs() == 0) { s.setType(s.getType() & (~CONNECTED)); if (t.getNumInputs() == 0 && t.getNumOutputs() == 0) { t.setType(t.getType() & (~CONNECTED));
/** * This function will remove all the inputs to this unit. * In doing so it will also terminate the connections at the other end. */ public void removeAllInputs() { for (int noa = 0; noa < m_numInputs; noa++) { //this command will simply remove any connections this node has //with the other in 1 go, rather than seperately. m_inputList[noa].disconnectOutput(this, -1); } //now reset the inputs. m_inputList = new NeuralConnection[0]; setType(getType() & (~INPUT)); if (getNumOutputs() == 0) { setType(getType() & (~CONNECTED)); } m_inputNums = new int[0]; m_numInputs = 0; }
/** * This function will remove all outputs to this unit. * In doing so it will also terminate the connections at the other end. */ public void removeAllOutputs() { for (int noa = 0; noa < m_numOutputs; noa++) { //this command will simply remove any connections this node has //with the other in 1 go, rather than seperately. m_outputList[noa].disconnectInput(this, -1); } //now reset the inputs. m_outputList = new NeuralConnection[0]; m_outputNums = new int[0]; setType(getType() & (~OUTPUT)); if (getNumInputs() == 0) { setType(getType() & (~CONNECTED)); } m_numOutputs = 0; }
NeuralConnection.connect(m_selected.get(noa), v.get(nob)); NeuralConnection.disconnect(m_selected.get(noa), v.get(nob)); NeuralConnection.disconnect(v.get(nob), m_selected.get(noa)); v.get(noa).removeAllInputs(); v.get(noa).removeAllOutputs(); removeNode(v.get(noa));
NeuralConnection.connect(m_neuralNodes[noc], temp); for (int noa = 0; noa < m_numAttributes; noa++) { for (int nob = 0; nob < m_numClasses; nob++) { NeuralConnection.connect(m_inputs[noa], m_neuralNodes[nob]); for (int noa = 0; noa < m_numAttributes; noa++) { for (int nob = m_numClasses; nob < m_numClasses + val; nob++) { NeuralConnection.connect(m_inputs[noa], m_neuralNodes[nob]); NeuralConnection.connect(m_neuralNodes[noa], m_neuralNodes[nob]);
m_inputNums[noa-1] = m_inputNums[noa]; m_inputList[noa-1].changeOutputNum(m_inputNums[noa-1], noa-1);
/** * This will connect the specified unit to be an input to this unit. * @param i The unit. * @param n It's connection number for this connection. * @return True if the connection was made, false otherwise. */ protected boolean connectInput(NeuralConnection i, int n) { //the function that this overrides can do most of the work. if (!super.connectInput(i, n)) { return false; } //note that the weights are shifted 1 forward in the array so //it leaves the numinputs aligned on the space the weight needs to go. m_weights[m_numInputs] = m_random.nextDouble() * .1 - .05; m_changeInWeights[m_numInputs] = 0; return true; }
/** * This creates the required output units. */ private void setupOutputs() throws Exception { m_outputs = new NeuralEnd[m_numClasses]; for (int noa = 0; noa < m_numClasses; noa++) { if (m_numeric) { m_outputs[noa] = new NeuralEnd(m_instances.classAttribute().name()); } else { m_outputs[noa] = new NeuralEnd(m_instances.classAttribute().value(noa)); } m_outputs[noa].setX(.9); m_outputs[noa].setY((noa + 1.0) / (m_numClasses + 1)); m_outputs[noa].setLink(false, noa); NeuralNode temp = new NeuralNode(String.valueOf(m_nextId), m_random, m_sigmoidUnit); m_nextId++; temp.setX(.75); temp.setY((noa + 1.0) / (m_numClasses + 1)); addNode(temp); NeuralConnection.connect(temp, m_outputs[noa]); } }