示例#1
0
void SOMAW<TNeuron, TSOMParameters>::updateNeuron(TNeuron &neuron, MatVector<float> &data, float alpha, float phi) {


    for (uint i = 0; i < data.size(); i++) {
        //update neuron weights
        float distance = fabs(data[i] - neuron.weights[i]);
            neuron.avgDistance[i] = neuron.avgDistance[i] + this->parameters.k1 * ((neuron.dsWeights[i] * distance) - neuron.avgDistance[i]);
        }

    float average = neuron.avgDistance.sum() / neuron.avgDistance.size();

    //update neuron ds weights
    for (uint i = 0; i < data.size(); i++) {
        //update neuron weights
        float distance = fabs(data[i] - neuron.weights[i]);

            if (neuron.dsWeights[i] * distance > average)
                neuron.dsWeights[i] = this->parameters.k2 * neuron.dsWeights[i];
            else
                neuron.dsWeights[i] = this->parameters.k3 * neuron.dsWeights[i];
        }

    float sum  = neuron.dsWeights.sum();
    for (uint i = 0; i < data.size(); i++) {
            neuron.dsWeights[i] = neuron.dsWeights[i] / sum;
        }

    //update neuron weights
    for (uint i = 0; i < data.size(); i++) {
            neuron.weights[i] = neuron.weights[i] + phi * alpha * (data[i] - neuron.weights[i]);
        }
}
示例#2
0
float SOMAW<TNeuron, TSOMParameters>::presentPaternToNeuron(const MatVector<float> &data, TNeuron &neuron) {
    float distance = 0;

        for (uint i = 0; i < data.size(); i++) {
            distance += qrt(neuron.dsWeights[i]) * qrt(fabs(data[i] - neuron.weights[i]));
        }

    return (1 / (distance + 0.0000001));
}
double maxDistance(MatVector distancesTable, vector<locationNode> locationList) {
  double maxDist=0;
  int numNodes=distancesTable.size();
  for (int i=0; i<numNodes; i++) {
    for (int j=0; j<numNodes; j++) {
      if (distancesTable[i][j]>maxDist) maxDist=distancesTable[i][j];
    }
  }
  double maxArea=0;
  numNodes=locationList.size();
  for (int i=0; i<numNodes; i++) {
    if (locationList[i].area>maxArea) maxArea=locationList[i].area;
  }
  return maxDist+maxArea;
}