/// <summary> /// Initializes weights of all spatial synapses in a Kohonen connector. /// </summary> /// <param name="connector"> /// The Kohonen connector to initialize. /// </param> /// <exception cref="ArgumentNullException"> /// If <c>connector</c> is <c>null</c> /// </exception> public void Initialize(KohonenConnectorND connector) { Helper.ValidateNotNull(connector, "connector"); foreach (KohonenSynapseND synapse in connector.Synapses) { synapse.Weight = constant; } }
/// <summary> /// Initializes weights of all spatial synapses in a Kohonen connector 3D. /// </summary> /// <param name="connector"> /// The Kohonen connector to initialize. /// </param> /// <exception cref="ArgumentNullException"> /// If <c>connector</c> is <c>null</c> /// </exception> public void Initialize(KohonenConnectorND connector) { Helper.ValidateNotNull(connector, "connector"); foreach (KohonenSynapseND synapse in connector.Synapses) { synapse.Weight = Helper.GetRandom(minLimit, maxLimit); } }
/// <summary> /// Initializes weights of all spatial synapses in a Kohonen connector 3D. /// </summary> /// <param name="connector"> /// The Kohonen connector to initialize. /// </param> /// <exception cref="ArgumentNullException"> /// If <c>connector</c> is <c>null</c> /// </exception> public void Initialize(KohonenConnectorND connector) { Helper.ValidateNotNull(connector, "connector"); int i = 0; foreach (KohonenSynapseND synapse in connector.Synapses) { synapse.Weight = Inputs[i]; i++; } }
/// <summary> /// Initializes weights of all spatial synapses in a Kohonen connector 3D. /// </summary> /// <param name="connector"> /// The Kohonen connector to initialize. /// </param> /// <exception cref="ArgumentNullException"> /// If <c>connector</c> is <c>null</c> /// </exception> public void Initialize(KohonenConnectorND connector) { Helper.ValidateNotNull(connector, "connector"); int i = 0; double[] normalized = Helper.GetRandomVector(connector.SynapseCount, 1d); foreach (KohonenSynapseND synapse in connector.Synapses) { synapse.Weight = normalized[i++]; } }
/// <summary> /// Creates a new Kohonen Synapse connecting the given neurons /// </summary> /// <param name="sourceNeuron"> /// The source neuron /// </param> /// <param name="targetNeuron"> /// The target neuron /// </param> /// <param name="parent"> /// Parent connector containing this synapse /// </param> /// <exception cref="System.ArgumentNullException"> /// If any of the arguments is <c>null</c> /// </exception> public KohonenSynapseND(INeuron sourceNeuron, PositionNeuron targetNeuron, KohonenConnectorND parent) { Helper.ValidateNotNull(sourceNeuron, "sourceNeuron"); Helper.ValidateNotNull(targetNeuron, "targetNeuron"); Helper.ValidateNotNull(parent, "parent"); this.weight = 1d; sourceNeuron.TargetSynapses.Add(this); targetNeuron.SourceSynapses.Add(this); this.sourceNeuron = sourceNeuron; this.targetNeuron = targetNeuron; this.parent = parent; }
/// <summary> /// Initializes weights of all spatial synapses in a Kohonen connector. /// </summary> /// <param name="connector"> /// The Kohonen connector to initialize. /// </param> /// <exception cref="ArgumentNullException"> /// If <c>connector</c> is <c>null</c> /// </exception> public void Initialize(KohonenConnectorND connector) { Helper.ValidateNotNull(connector, "connector"); double nGuyenWidrowFactor = NGuyenWidrowFactor( connector.SourceLayer.NeuronCount, connector.TargetLayer.NeuronCount); int synapsesPerNeuron = connector.SynapseCount / connector.TargetLayer.NeuronCount; foreach (INeuron neuron in connector.TargetLayer.Neurons) { int i = 0; double[] normalizedVector = Helper.GetRandomVector(synapsesPerNeuron, nGuyenWidrowFactor); foreach (KohonenSynapseND synapse in connector.GetSourceSynapses(neuron)) { synapse.Weight = normalizedVector[i++]; } } }
void Solve() { #region prepare and assign trainingSet.Clear(); for (int i = 0; i < trainVectorCount; i++) { List <double> dl = new List <double>(); for (int j = 0; j < trainVectorDimension; j++) { dl.Add(trainVectors[i][j]); } trainingSet.Add(new TrainingSample(dl.ToArray())); } /// process /// start learning /// get learning radius for neighborhood function int learningRadius = 0; for (int i = 0; i < dimension; i++) { if (size[i] > learningRadius) { learningRadius = size[i]; } } learningRadius /= 2; INeighborhoodFunction neighborhoodFunction = new GaussianFunction(learningRadius, netUP.neighborDistance) as INeighborhoodFunction; if (neighborhood) { neighborhoodFunction = new MexicanHatFunction(learningRadius) as INeighborhoodFunction; } LatticeTopology topology = LatticeTopology.Rectangular; if (latticeTopology) { topology = LatticeTopology.Hexagonal; } /// instantiate relevant network layers KohonenLayer inputLayer = new KohonenLayer(trainVectorDimension); KohonenLayerND outputLayer = new KohonenLayerND(size, neighborhoodFunction, topology); KohonenConnectorND connector = new KohonenConnectorND(inputLayer, outputLayer, netUP.initialNodes); if (netUP.initialNodes.Length != 0) { connector.Initializer = new GivenInput(netUP.initialNodes); } else { connector.Initializer = new RandomFunction(0.0, 1.0); } outputLayer.SetLearningRate(learningRate, 0.05d); outputLayer.IsDimensionCircular = isDimensionCircular; network = new KohonenNetworkND(inputLayer, outputLayer); network.useRandomTrainingOrder = randomTrainingOrder; inputLayer.ParallelComputation = false; outputLayer.ParallelComputation = parallelComputing; #endregion #region delegates network.BeginEpochEvent += new TrainingEpochEventHandler( delegate(object senderNetwork, TrainingEpochEventArgs args) { #region trainingCylce if (network == null || !GO) { return; } trainedVectors = new double[outputLayer.neuronCount, trainVectorDimension]; for (int i = 0; i < outputLayer.neuronCount; i++) { IList <ISynapse> synapses = (network.OutputLayer as KohonenLayerND)[outputLayer.adressBook[i]].SourceSynapses; for (int j = 0; j < trainVectorDimension; j++) { trainedVectors[i, j] = synapses[j].Weight; } } //make new net here netP = new CrowNetSOMNDP(size, isDimensionCircular, latticeTopology, neighborhood, trainedVectors, outputLayer.adressBook); counter++; #endregion }); network.EndSampleEvent += new TrainingSampleEventHandler( delegate(object senderNetwork, TrainingSampleEventArgs args) { netP.winner = outputLayer.WinnerND.CoordinateND; }); #endregion network.Learn(trainingSet, cycles); }